Skip to content

Commit

Permalink
Merge pull request #5 from yoomoney-tech/release/1.1.0
Browse files Browse the repository at this point in the history
Release/1.1.0
  • Loading branch information
Oscarworld authored Dec 11, 2020
2 parents 9cc3495 + f1cd6a3 commit 48fa0f7
Show file tree
Hide file tree
Showing 15 changed files with 172 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
### NEXT_VERSION_DESCRIPTION_BEGIN
### NEXT_VERSION_DESCRIPTION_END

## [1.1.0] (11-12-2020)

Added draw zero line.

## [1.0.0] (25-11-2020)

Move mobile analytics chart library to open-source
2 changes: 1 addition & 1 deletion MobileAnalyticsChartSwift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'MobileAnalyticsChartSwift'
s.version = '1.0.0'
s.version = '1.1.0'
s.homepage = 'https://github.com/yoomoney-tech/mobile-analytics-chart-swift/browse'
s.license = {
:type => "MIT",
Expand Down
10 changes: 10 additions & 0 deletions MobileAnalyticsChartSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
78201DA4250F9D6700408304 /* UIColor+Style.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78201D92250F9D6700408304 /* UIColor+Style.swift */; };
78201DA5250F9D6700408304 /* CGFloat+Space.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78201D93250F9D6700408304 /* CGFloat+Space.swift */; };
78201DA6250F9D6700408304 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78201D94250F9D6700408304 /* AppDelegate.swift */; };
783658F12582044000CBC150 /* ChartZeroLine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 783658F02582044000CBC150 /* ChartZeroLine.swift */; };
78E2D565250F9B7B0010639C /* MobileAnalyticsChartSwift.h in Headers */ = {isa = PBXBuildFile; fileRef = 78E2D563250F9B7B0010639C /* MobileAnalyticsChartSwift.h */; settings = {ATTRIBUTES = (Public, ); }; };
78E2D57E250F9BB40010639C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 78E2D57C250F9BB40010639C /* LaunchScreen.storyboard */; };
78E6E8422510F9820052E3D4 /* CustomChartViewIO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78E6E8412510F9820052E3D4 /* CustomChartViewIO.swift */; };
Expand Down Expand Up @@ -155,6 +156,7 @@
78201D92250F9D6700408304 /* UIColor+Style.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIColor+Style.swift"; sourceTree = "<group>"; };
78201D93250F9D6700408304 /* CGFloat+Space.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CGFloat+Space.swift"; sourceTree = "<group>"; };
78201D94250F9D6700408304 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
783658F02582044000CBC150 /* ChartZeroLine.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChartZeroLine.swift; sourceTree = "<group>"; };
78E2D560250F9B7B0010639C /* MobileAnalyticsChartSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MobileAnalyticsChartSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
78E2D563250F9B7B0010639C /* MobileAnalyticsChartSwift.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MobileAnalyticsChartSwift.h; sourceTree = "<group>"; };
78E2D564250F9B7B0010639C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -317,6 +319,7 @@
78201D1E250F9D3700408304 /* ChartRangeLabel.swift */,
78201D1C250F9D3700408304 /* ChartXAxis.swift */,
78201D19250F9D3700408304 /* ChartYAxis.swift */,
783658F02582044000CBC150 /* ChartZeroLine.swift */,
);
path = Configuration;
sourceTree = "<group>";
Expand Down Expand Up @@ -833,6 +836,7 @@
78201D43250F9D3700408304 /* AnalyticsDefinitionFactory.swift in Sources */,
78201D48250F9D3700408304 /* AnalyticsChartSpriteKitViewIO.swift in Sources */,
78201D44250F9D3700408304 /* AnalyticsYAxisLocalizationFactory.swift in Sources */,
783658F12582044000CBC150 /* ChartZeroLine.swift in Sources */,
78201D63250F9D3700408304 /* ColorTransition.swift in Sources */,
78201D65250F9D3700408304 /* Calculator.swift in Sources */,
78201D46250F9D3700408304 /* AnalyticsChartSpriteKitAssembly.swift in Sources */,
Expand Down Expand Up @@ -1008,6 +1012,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.1.0;
PRODUCT_BUNDLE_IDENTIFIER = ru.yoo.kassa.MobileAnalyticsChartSwift;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand All @@ -1032,6 +1037,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.1.0;
PRODUCT_BUNDLE_IDENTIFIER = ru.yoo.kassa.MobileAnalyticsChartSwiftExamplePods;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -1182,6 +1188,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.1.0;
PRODUCT_BUNDLE_IDENTIFIER = ru.yoo.kassa.MobileAnalyticsChartSwift;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand All @@ -1208,6 +1215,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.1.0;
PRODUCT_BUNDLE_IDENTIFIER = ru.yoo.kassa.MobileAnalyticsChartSwift;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand All @@ -1232,6 +1240,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.1.0;
PRODUCT_BUNDLE_IDENTIFIER = ru.yoo.kassa.MobileAnalyticsChartSwiftExamplePods;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "";
Expand All @@ -1256,6 +1265,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.1.0;
PRODUCT_BUNDLE_IDENTIFIER = ru.yoo.kassa.MobileAnalyticsChartSwiftExamplePods;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildSystemType</key>
<string>Original</string>
<key>PreviewsEnabled</key>
<false/>
</dict>
Expand Down
8 changes: 8 additions & 0 deletions MobileAnalyticsChartSwift/Calculator/Calculator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ public protocol Calculator {
linesCount: Int
) -> [(position: CGPoint, value: CGFloat)]

/// Make zero line coordinate for zero line.
func makeZeroLine(
frame: CGRect,
chartMargins: UIEdgeInsets,
minValue: CGFloat?,
maxValue: CGFloat?
) -> (start: CGPoint, end: CGPoint)?

/// Make dates for range diapasone.
func makeRangeDates() -> (start: Date, end: Date?)?

Expand Down
32 changes: 32 additions & 0 deletions MobileAnalyticsChartSwift/Calculator/CalculatorImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,38 @@ extension CalculatorImpl: Calculator {
}
}

public func makeZeroLine(
frame: CGRect,
chartMargins: UIEdgeInsets,
minValue: CGFloat?,
maxValue: CGFloat?
) -> (start: CGPoint, end: CGPoint)? {
guard valuesCount != 0,
let minValue = minValue ?? self.minValue,
let maxValue = maxValue ?? self.maxValue,
maxValue != minValue else {
return nil
}

let boundaryDiff = abs(maxValue - minValue)

guard boundaryDiff > 0 else {
return nil
}

let height = frame.height
- chartMargins.top
- chartMargins.bottom
let y = frame.minY
+ chartMargins.bottom
- minValue / boundaryDiff * height

return (
start: CGPoint(x: frame.minX, y: y),
end: CGPoint(x: frame.maxX, y: y)
)
}

public func makeRangeDates() -> (start: Date, end: Date?)? {
guard let start = data.first?.dates.first else {
return nil
Expand Down
2 changes: 1 addition & 1 deletion MobileAnalyticsChartSwift/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
</dict>
Expand Down
26 changes: 26 additions & 0 deletions MobileAnalyticsChartSwift/Render/Configuration/ChartZeroLine.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import UIKit

/// Type of chart zero line.
public struct ChartZeroLine {

/// Color of line.
public let color: UIColor

/// Width of line.
public let width: CGFloat

/// Creates instance of `ChartZeroLine`.
///
/// - Parameters:
/// - color: Color of line.
/// - width: Width of line.
///
/// - Returns: Instance of `ChartZeroLine`.
public init(
color: UIColor,
width: CGFloat
) {
self.color = color
self.width = width
}
}
6 changes: 6 additions & 0 deletions MobileAnalyticsChartSwift/Render/RenderConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public struct RenderConfiguration {
/// Entity of chart y axis.
public let yAxis: ChartYAxis?

/// Entity of chart zero line.
public let zeroLine: ChartZeroLine?

/// Entity of chart gesture state.
public let gestureState: ChartGestureState

Expand Down Expand Up @@ -42,6 +45,7 @@ public struct RenderConfiguration {
/// - rangeLabel: Entity of chart range label.
/// - xAxis: Entity of chart x axis.
/// - yAxis: Entity of chart y axis.
/// - zeroLine: Entity of chart zero line.
/// - gestureState: Entity of chart gesture state.
/// - animation: Entity of chart animation.
/// - definition: Entity of chart definition.
Expand All @@ -56,6 +60,7 @@ public struct RenderConfiguration {
rangeLabel: ChartRangeLabel?,
xAxis: ChartXAxis?,
yAxis: ChartYAxis?,
zeroLine: ChartZeroLine?,
gestureState: ChartGestureState,
animation: ChartAnimation,
definition: ChartDefinition?,
Expand All @@ -68,6 +73,7 @@ public struct RenderConfiguration {
self.rangeLabel = rangeLabel
self.xAxis = xAxis
self.yAxis = yAxis
self.zeroLine = zeroLine
self.gestureState = gestureState
self.animation = animation
self.definition = definition
Expand Down
2 changes: 2 additions & 0 deletions MobileAnalyticsChartSwift/Render/RenderDrawer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public protocol RenderDrawer: class {

func drawYAxisLabels()

func drawZeroLine()

func drawRangeLabel()

func drawDefinition()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public class RenderSpriteKitImpl: SKScene {

private var yAxisLabels = BasicNode()

private var zeroLine = SquareNode()

// MARK: - Addition

private var handlerActivated = false
Expand Down Expand Up @@ -159,6 +161,7 @@ extension RenderSpriteKitImpl {
rangeLabel,
yAxis,
yAxisLabels,
zeroLine,
xAxisLabels,
definitionNode,
definitionView,
Expand Down Expand Up @@ -239,6 +242,7 @@ extension RenderSpriteKitImpl {
}

yAxis.zPosition = 2
zeroLine.zPosition = 2

chartsNode.forEach {
$0.zPosition = 3
Expand Down Expand Up @@ -270,6 +274,7 @@ extension RenderSpriteKitImpl {
setupXAxisLabels()
setupYAxisLines()
setupYAxisLabels()
setupZeroLine()
}

private func setupChartNode() {
Expand Down Expand Up @@ -318,6 +323,10 @@ extension RenderSpriteKitImpl {
private func setupYAxisLabels() {
yAxisLabels.blendMode = .multiply
}

private func setupZeroLine() {
zeroLine.blendMode = .alpha
}
}

// MARK: - Configuration
Expand All @@ -335,6 +344,9 @@ extension RenderSpriteKitImpl {
if let configurationYAxis = configuration.yAxis {
configureYAxis(configurationYAxis)
}
if let configurationZeroLine = configuration.zeroLine {
configureZeroLine(configurationZeroLine)
}
if let configurationDefinition = configuration.definition {
configureDefinitionNode(configurationDefinition)
definitionsPoint.forEach {
Expand Down Expand Up @@ -433,6 +445,13 @@ extension RenderSpriteKitImpl {
yAxisLabelHeight = configuration.labelFont.lineHeight
}

private func configureZeroLine(
_ configuration: ChartZeroLine
) {
zeroLine.strokeColor = configuration.color
zeroLine.lineWidth = configuration.width
}

private func configureGesture(
view: SKView,
configuration: ChartGestureState
Expand Down Expand Up @@ -893,6 +912,7 @@ extension RenderSpriteKitImpl: RenderDrawer {
drawChart()
drawXAxis()
drawYAxisLabels()
drawZeroLine()
drawDefinition()
}

Expand Down Expand Up @@ -1019,6 +1039,25 @@ extension RenderSpriteKitImpl: RenderDrawer {
}
}

public func drawZeroLine() {
guard let configurationZeroLine = configuration.zeroLine else { return }

if let zeroLinePosition = calculator.makeZeroLine(
frame: chartFrame,
chartMargins: configuration.chartMargins,
minValue: currentMinValue,
maxValue: currentMaxValue
) {
let path = CGMutablePath()
path.move(to: zeroLinePosition.start)
path.addLine(to: zeroLinePosition.end)
path.closeSubpath()
zeroLine.path = path.copy(dashingWithPhase: 5, lengths: [10, 10])
} else {
zeroLine.path = nil
}
}

public func drawRangeLabel() {
guard let configurationRangeLabel = configuration.rangeLabel,
let dates = calculator.makeRangeDates() else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,27 @@ extension UIColor {
if #available(iOS 13, *) {
return UIColor { (UITraitCollection: UITraitCollection) -> UIColor in
if UITraitCollection.userInterfaceStyle == .dark {
return UIColor(white: 1, alpha: 0.12)
return UIColor(white: 1, alpha: 0.05)
} else {
return UIColor(white: 0, alpha: 0.12)
return UIColor(white: 0, alpha: 0.05)
}
}
} else {
return UIColor(white: 0, alpha: 0.12)
return UIColor(white: 0, alpha: 0.05)
}
}()

static var borderZeroLine: UIColor = {
if #available(iOS 13, *) {
return UIColor { (UITraitCollection: UITraitCollection) -> UIColor in
if UITraitCollection.userInterfaceStyle == .dark {
return UIColor(white: 1, alpha: 0.1)
} else {
return UIColor(white: 0, alpha: 0.1)
}
}
} else {
return UIColor(white: 0, alpha: 0.21)
}
}()

Expand Down
Loading

0 comments on commit 48fa0f7

Please sign in to comment.