diff --git a/Charts.xcodeproj/project.pbxproj b/Charts.xcodeproj/project.pbxproj index 1a61360a..f28679dd 100644 --- a/Charts.xcodeproj/project.pbxproj +++ b/Charts.xcodeproj/project.pbxproj @@ -108,6 +108,7 @@ B0D28C68BB9A958DC56EB214 /* DefaultValueFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 107D8F8163EE54D6D9E916B0 /* DefaultValueFormatter.swift */; }; B13C74B4FF705D7B595D01EF /* IAxisValueFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BD9DF16AF59680A3BB49452 /* IAxisValueFormatter.swift */; }; B539114951455C35BADAE3F3 /* PieChartDataSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = A4FB5E3761EF8B4D1E1E1014 /* PieChartDataSet.swift */; }; + B6BF9A561F91993A00E62A5D /* CombinedChartTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6BF9A551F91993A00E62A5D /* CombinedChartTests.swift */; }; B6C9F450D937B87224D29D5C /* IFillFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 818AC6B12505B7C0A53D62F9 /* IFillFormatter.swift */; }; B6DCC229615EFE706F64A37D /* LineScatterCandleRadarRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 923206233CA89FD03565FF87 /* LineScatterCandleRadarRenderer.swift */; }; B85DEB06B4C1AFFC8A0E3295 /* CircleShapeRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECE1B1623D3AF69CECAE8562 /* CircleShapeRenderer.swift */; }; @@ -266,6 +267,7 @@ B137428B41C143D5115726C4 /* Description.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = Description.swift; path = Source/Charts/Components/Description.swift; sourceTree = ""; }; B1BA6B21CBDF77A15848994F /* RadarChartDataSet.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = RadarChartDataSet.swift; path = Source/Charts/Data/Implementations/Standard/RadarChartDataSet.swift; sourceTree = ""; }; B44829AF0ADA583F1F0279B7 /* BubbleChartDataSet.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = BubbleChartDataSet.swift; path = Source/Charts/Data/Implementations/Standard/BubbleChartDataSet.swift; sourceTree = ""; }; + B6BF9A551F91993A00E62A5D /* CombinedChartTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CombinedChartTests.swift; path = Tests/Charts/CombinedChartTests.swift; sourceTree = ""; }; BA157EFF2F952192C11DF937 /* AnimatedMoveViewJob.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = AnimatedMoveViewJob.swift; path = Source/Charts/Jobs/AnimatedMoveViewJob.swift; sourceTree = ""; }; BA1A58428DC4780BAB4EAADC /* CandleStickChartView.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = CandleStickChartView.swift; path = Source/Charts/Charts/CandleStickChartView.swift; sourceTree = ""; }; BC19DC2434D65FFB446A61B7 /* XAxisRendererRadarChart.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = XAxisRendererRadarChart.swift; path = Source/Charts/Renderers/XAxisRendererRadarChart.swift; sourceTree = ""; }; @@ -514,6 +516,7 @@ 5C3F5E1A69EC06E86505F7B1 /* BarChartTests.swift */, 224EFF981FBAAC4700CF9B3B /* EquatableTests.swift */, 7AB9062A28AAB9469752A954 /* ChartUtilsTests.swift */, + B6BF9A551F91993A00E62A5D /* CombinedChartTests.swift */, D2E1819D72CD7B6C4A4E8048 /* LineChartTests.swift */, 064989451F5C99C7006E8BB3 /* Snapshot.swift */, ); @@ -946,6 +949,7 @@ files = ( 3B11556EB7DC034E2FC958E4 /* BarChartTests.swift in Sources */, 8E1192F7A7152E9DA92C56A9 /* ChartUtilsTests.swift in Sources */, + B6BF9A561F91993A00E62A5D /* CombinedChartTests.swift in Sources */, 2BF85BEA981B359A65E9BF67 /* LineChartTests.swift in Sources */, 064989461F5C99C7006E8BB3 /* Snapshot.swift in Sources */, 224EFF991FBAAC4700CF9B3B /* EquatableTests.swift in Sources */, diff --git a/ChartsDemo/Objective-C/Demos/CombinedChartViewController.m b/ChartsDemo/Objective-C/Demos/CombinedChartViewController.m index fa65aec9..c0eb2fa2 100644 --- a/ChartsDemo/Objective-C/Demos/CombinedChartViewController.m +++ b/ChartsDemo/Objective-C/Demos/CombinedChartViewController.m @@ -206,7 +206,7 @@ - (BarChartData *)generateBarData [set1 setColor:[UIColor colorWithRed:60/255.f green:220/255.f blue:78/255.f alpha:1.f]]; set1.valueTextColor = [UIColor colorWithRed:60/255.f green:220/255.f blue:78/255.f alpha:1.f]; set1.valueFont = [UIFont systemFontOfSize:10.f]; - set1.axisDependency = AxisDependencyLeft; + set1.axisDependency = AxisDependencyRight; BarChartDataSet *set2 = [[BarChartDataSet alloc] initWithValues:entries2 label:@""]; set2.stackLabels = @[@"Stack 1", @"Stack 2"]; @@ -216,7 +216,7 @@ - (BarChartData *)generateBarData ]; set2.valueTextColor = [UIColor colorWithRed:61/255.f green:165/255.f blue:255/255.f alpha:1.f]; set2.valueFont = [UIFont systemFontOfSize:10.f]; - set2.axisDependency = AxisDependencyLeft; + set2.axisDependency = AxisDependencyRight; float groupSpace = 0.06f; float barSpace = 0.02f; // x2 dataset diff --git a/Source/Charts/Data/Implementations/Standard/CombinedChartData.swift b/Source/Charts/Data/Implementations/Standard/CombinedChartData.swift index 9e2342a2..8d269edf 100644 --- a/Source/Charts/Data/Implementations/Standard/CombinedChartData.swift +++ b/Source/Charts/Data/Implementations/Standard/CombinedChartData.swift @@ -136,25 +136,31 @@ open class CombinedChartData: BarLineScatterCandleBubbleChartData { _xMin = data.xMin } - - if data.yMax > _leftAxisMax - { - _leftAxisMax = data.yMax - } - - if data.yMin < _leftAxisMin - { - _leftAxisMin = data.yMin - } - - if data.yMax > _rightAxisMax - { - _rightAxisMax = data.yMax - } - - if data.yMin < _rightAxisMin + + for dataset in sets { - _rightAxisMin = data.yMin + if dataset.axisDependency == .left + { + if dataset.yMax > _leftAxisMax + { + _leftAxisMax = dataset.yMax + } + if dataset.yMin < _leftAxisMin + { + _leftAxisMin = dataset.yMin + } + } + else + { + if dataset.yMax > _rightAxisMax + { + _rightAxisMax = dataset.yMax + } + if dataset.yMin < _rightAxisMin + { + _rightAxisMin = dataset.yMin + } + } } } } diff --git a/Tests/Charts/CombinedChartTests.swift b/Tests/Charts/CombinedChartTests.swift new file mode 100644 index 00000000..269ced68 --- /dev/null +++ b/Tests/Charts/CombinedChartTests.swift @@ -0,0 +1,104 @@ +// +// CombinedChartTests.swift +// ChartsTests +// +// Created by Xuan Liu on 14/10/2017. +// + +import XCTest +import FBSnapshotTestCase +@testable import Charts + +class CombinedChartTests: FBSnapshotTestCase +{ + var chart: CombinedChartView! + var lineDataSet: LineChartDataSet! + var barDataSet: BarChartDataSet! + + override func setUp() + { + super.setUp() + + // Set to `true` to re-capture all snapshots + self.recordMode = false + + // Sample data + let combinedData = CombinedChartData() + combinedData.barData = generateBarData() + combinedData.lineData = generateLineData() + chart = CombinedChartView(frame: CGRect(x: 0, y: 0, width: 480, height: 350)) + chart.backgroundColor = NSUIColor.clear + chart.leftAxis.axisMinimum = 0.0 + chart.rightAxis.axisMinimum = 0.0 + chart.data = combinedData + } + + func generateBarData() -> BarChartData + { + let values: [Double] = [8, 104, 81, 93, 52, 44, 97, 101, 75, 28, + 76, 25, 20, 13, 52, 44, 57, 23, 45, 91, + 99, 14, 84, 48, 40, 71, 106, 41, 45, 61] + + var entries: [ChartDataEntry] = Array() + + for (i, value) in values.enumerated() + { + entries.append(BarChartDataEntry(x: Double(i), y: value, icon: UIImage(named: "icon", in: Bundle(for: self.classForCoder), compatibleWith: nil))) + } + + barDataSet = BarChartDataSet(values: entries, label: "Bar chart unit test data") + barDataSet.drawIconsEnabled = false + + let data = BarChartData(dataSet: barDataSet) + data.barWidth = 0.85 + return data + } + + func generateLineData() -> LineChartData + { + let values: [Double] = [0, 254, 81, 93, 52, 44, 97, 101, 75, 28, + 76, 25, 20, 13, 52, 44, 57, 23, 45, 91, + 99, 14, 84, 48, 40, 71, 106, 41, 45, 61] + + var entries: [ChartDataEntry] = Array() + + for (i, value) in values.enumerated() + { + entries.append(ChartDataEntry(x: Double(i), y: value, icon: UIImage(named: "icon", in: Bundle(for: self.classForCoder), compatibleWith: nil))) + } + + lineDataSet = LineChartDataSet(values: entries, label: "Line chart unit test data") + lineDataSet.drawIconsEnabled = false + return LineChartData(dataSet: lineDataSet) + } + + override func tearDown() + { + // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + } + + func testDefaultAxisDependency() + { + FBSnapshotVerifyView(chart, identifier: Snapshot.identifier(UIScreen.main.bounds.size), tolerance: Snapshot.tolerance) + } + + func testLeftRightAxisDependency() + { + lineDataSet.axisDependency = .left + barDataSet.axisDependency = .right + chart.data?.notifyDataChanged() + chart.notifyDataSetChanged() + FBSnapshotVerifyView(chart, identifier: Snapshot.identifier(UIScreen.main.bounds.size), tolerance: Snapshot.tolerance) + } + + func testAllRightAxisDependency() + { + lineDataSet.axisDependency = .right + barDataSet.axisDependency = .right + chart.data?.notifyDataChanged() + chart.notifyDataSetChanged() + FBSnapshotVerifyView(chart, identifier: Snapshot.identifier(UIScreen.main.bounds.size), tolerance: Snapshot.tolerance) + } +} + diff --git a/Tests/ReferenceImages_64/ChartsTests.CombinedChartTests/testAllRightAxisDependency_iOS_375.0_667.0@2x.png b/Tests/ReferenceImages_64/ChartsTests.CombinedChartTests/testAllRightAxisDependency_iOS_375.0_667.0@2x.png new file mode 100644 index 00000000..c4dfe1df Binary files /dev/null and b/Tests/ReferenceImages_64/ChartsTests.CombinedChartTests/testAllRightAxisDependency_iOS_375.0_667.0@2x.png differ diff --git a/Tests/ReferenceImages_64/ChartsTests.CombinedChartTests/testAllRightAxisDependency_tvOS_1920.0_1080.0.png b/Tests/ReferenceImages_64/ChartsTests.CombinedChartTests/testAllRightAxisDependency_tvOS_1920.0_1080.0.png new file mode 100644 index 00000000..2e4743d9 Binary files /dev/null and b/Tests/ReferenceImages_64/ChartsTests.CombinedChartTests/testAllRightAxisDependency_tvOS_1920.0_1080.0.png differ diff --git a/Tests/ReferenceImages_64/ChartsTests.CombinedChartTests/testDefaultAxisDependency_iOS_375.0_667.0@2x.png b/Tests/ReferenceImages_64/ChartsTests.CombinedChartTests/testDefaultAxisDependency_iOS_375.0_667.0@2x.png new file mode 100644 index 00000000..c4dfe1df Binary files /dev/null and b/Tests/ReferenceImages_64/ChartsTests.CombinedChartTests/testDefaultAxisDependency_iOS_375.0_667.0@2x.png differ diff --git a/Tests/ReferenceImages_64/ChartsTests.CombinedChartTests/testDefaultAxisDependency_tvOS_1920.0_1080.0.png b/Tests/ReferenceImages_64/ChartsTests.CombinedChartTests/testDefaultAxisDependency_tvOS_1920.0_1080.0.png new file mode 100644 index 00000000..2e4743d9 Binary files /dev/null and b/Tests/ReferenceImages_64/ChartsTests.CombinedChartTests/testDefaultAxisDependency_tvOS_1920.0_1080.0.png differ diff --git a/Tests/ReferenceImages_64/ChartsTests.CombinedChartTests/testLeftRightAxisDependency_iOS_375.0_667.0@2x.png b/Tests/ReferenceImages_64/ChartsTests.CombinedChartTests/testLeftRightAxisDependency_iOS_375.0_667.0@2x.png new file mode 100644 index 00000000..2cd6c933 Binary files /dev/null and b/Tests/ReferenceImages_64/ChartsTests.CombinedChartTests/testLeftRightAxisDependency_iOS_375.0_667.0@2x.png differ diff --git a/Tests/ReferenceImages_64/ChartsTests.CombinedChartTests/testLeftRightAxisDependency_tvOS_1920.0_1080.0.png b/Tests/ReferenceImages_64/ChartsTests.CombinedChartTests/testLeftRightAxisDependency_tvOS_1920.0_1080.0.png new file mode 100644 index 00000000..bd033e47 Binary files /dev/null and b/Tests/ReferenceImages_64/ChartsTests.CombinedChartTests/testLeftRightAxisDependency_tvOS_1920.0_1080.0.png differ