diff --git a/Charts.xcodeproj/project.pbxproj b/Charts.xcodeproj/project.pbxproj index 4ed4d10d2a..325b35e639 100644 --- a/Charts.xcodeproj/project.pbxproj +++ b/Charts.xcodeproj/project.pbxproj @@ -360,7 +360,9 @@ 098621EDFBF928494B94BEA1 /* Data */ = { isa = PBXGroup; children = ( - 3B9DD76FCE8D873300A822C7 /* Implementations */, + 22C014222006FFE800D5B025 /* ChartData */, + 3B9DD76FCE8D873300A822C7 /* ChartDataSet */, + 22C014232006FFFA00D5B025 /* ChartEntry */, DB2D9648877455028EBEAA8F /* DataSet Protocols */, ); name = Data; @@ -409,6 +411,37 @@ name = ChartRenderers; sourceTree = ""; }; + 22C014222006FFE800D5B025 /* ChartData */ = { + isa = PBXGroup; + children = ( + 0108D5925E21A47DA36A66AA /* BarChartData.swift */, + 559DB735FEA17AB90676D6CA /* BarLineScatterCandleBubbleChartData.swift */, + 7EDA3AD550AEFC93C8D15B9C /* BubbleChartData.swift */, + F4785FEACAE4367F36FB8868 /* CandleChartData.swift */, + E120E76C6F1B5877D56126DD /* ChartData.swift */, + 0DDE409E9ECF54D2C146A6F0 /* CombinedChartData.swift */, + 4C978F31F23C7D21197DC2A1 /* LineChartData.swift */, + 6E03A4987F72414A02A0631B /* PieChartData.swift */, + 4BBB57D6FA41029B08F26D7B /* RadarChartData.swift */, + E7AD2FC320A16CA1EE0A52F4 /* ScatterChartData.swift */, + ); + name = ChartData; + sourceTree = ""; + }; + 22C014232006FFFA00D5B025 /* ChartEntry */ = { + isa = PBXGroup; + children = ( + E3F8BFF1CBC58D5B9DBFFB9B /* BarChartDataEntry.swift */, + DD8ED233775EEC31243A6919 /* BubbleChartDataEntry.swift */, + D2E698FF540029B70AC97AD7 /* CandleChartDataEntry.swift */, + F22750328058DEC2F019646F /* ChartDataEntry.swift */, + 12409C3EA15787C11AF0D2BC /* ChartDataEntryBase.swift */, + BD02157CF8CEE1189BF681DA /* PieChartDataEntry.swift */, + 91EEEDE2AB8F2DA3AFCF0733 /* RadarChartDataEntry.swift */, + ); + name = ChartEntry; + sourceTree = ""; + }; 2647844720BC6574A544A337 /* Charts */ = { isa = PBXGroup; children = ( @@ -427,13 +460,23 @@ name = Charts; sourceTree = ""; }; - 3B9DD76FCE8D873300A822C7 /* Implementations */ = { + 3B9DD76FCE8D873300A822C7 /* ChartDataSet */ = { isa = PBXGroup; children = ( C9FE42E868A225C116537368 /* ChartBaseDataSet.swift */, - 740017197A160047EBB8A9A0 /* Standard */, + C31AA65EA27776F8C653C7E8 /* BarChartDataSet.swift */, + 6D717F0808DE7EC8A4AE9C2A /* BarLineScatterCandleBubbleChartDataSet.swift */, + B44829AF0ADA583F1F0279B7 /* BubbleChartDataSet.swift */, + 274116834B1B0345D622E027 /* CandleChartDataSet.swift */, + 6CEC0C69C89CE9B99F3B4409 /* ChartDataSet.swift */, + A5A75AA73C5AA381DA517959 /* LineChartDataSet.swift */, + 45E31A4356CC6F283C29954B /* LineRadarChartDataSet.swift */, + C58BD7B14BEA440783ED8D2B /* LineScatterCandleRadarChartDataSet.swift */, + A4FB5E3761EF8B4D1E1E1014 /* PieChartDataSet.swift */, + B1BA6B21CBDF77A15848994F /* RadarChartDataSet.swift */, + CB1DD1A0F64266A10EE94194 /* ScatterChartDataSet.swift */, ); - name = Implementations; + name = ChartDataSet; sourceTree = ""; }; 42824E1F334B0C484AF4C594 /* Highlight */ = { @@ -471,41 +514,6 @@ name = Components; sourceTree = ""; }; - 740017197A160047EBB8A9A0 /* Standard */ = { - isa = PBXGroup; - children = ( - 0108D5925E21A47DA36A66AA /* BarChartData.swift */, - E3F8BFF1CBC58D5B9DBFFB9B /* BarChartDataEntry.swift */, - C31AA65EA27776F8C653C7E8 /* BarChartDataSet.swift */, - 559DB735FEA17AB90676D6CA /* BarLineScatterCandleBubbleChartData.swift */, - 6D717F0808DE7EC8A4AE9C2A /* BarLineScatterCandleBubbleChartDataSet.swift */, - 7EDA3AD550AEFC93C8D15B9C /* BubbleChartData.swift */, - DD8ED233775EEC31243A6919 /* BubbleChartDataEntry.swift */, - B44829AF0ADA583F1F0279B7 /* BubbleChartDataSet.swift */, - F4785FEACAE4367F36FB8868 /* CandleChartData.swift */, - D2E698FF540029B70AC97AD7 /* CandleChartDataEntry.swift */, - 274116834B1B0345D622E027 /* CandleChartDataSet.swift */, - E120E76C6F1B5877D56126DD /* ChartData.swift */, - F22750328058DEC2F019646F /* ChartDataEntry.swift */, - 12409C3EA15787C11AF0D2BC /* ChartDataEntryBase.swift */, - 6CEC0C69C89CE9B99F3B4409 /* ChartDataSet.swift */, - 0DDE409E9ECF54D2C146A6F0 /* CombinedChartData.swift */, - 4C978F31F23C7D21197DC2A1 /* LineChartData.swift */, - A5A75AA73C5AA381DA517959 /* LineChartDataSet.swift */, - 45E31A4356CC6F283C29954B /* LineRadarChartDataSet.swift */, - C58BD7B14BEA440783ED8D2B /* LineScatterCandleRadarChartDataSet.swift */, - 6E03A4987F72414A02A0631B /* PieChartData.swift */, - BD02157CF8CEE1189BF681DA /* PieChartDataEntry.swift */, - A4FB5E3761EF8B4D1E1E1014 /* PieChartDataSet.swift */, - 4BBB57D6FA41029B08F26D7B /* RadarChartData.swift */, - 91EEEDE2AB8F2DA3AFCF0733 /* RadarChartDataEntry.swift */, - B1BA6B21CBDF77A15848994F /* RadarChartDataSet.swift */, - E7AD2FC320A16CA1EE0A52F4 /* ScatterChartData.swift */, - CB1DD1A0F64266A10EE94194 /* ScatterChartDataSet.swift */, - ); - name = Standard; - sourceTree = ""; - }; 74A391010038924F637D6752 /* Formatters */ = { isa = PBXGroup; children = ( diff --git a/ChartsDemo-iOS/Objective-C/DemoBaseViewController.m b/ChartsDemo-iOS/Objective-C/DemoBaseViewController.m index df5c159c63..a264f2a712 100644 --- a/ChartsDemo-iOS/Objective-C/DemoBaseViewController.m +++ b/ChartsDemo-iOS/Objective-C/DemoBaseViewController.m @@ -95,7 +95,7 @@ - (void)handleOption:(NSString *)key forChartView:(ChartViewBase *)chartView if ([key isEqualToString:@"toggleHighlight"]) { - chartView.data.highlightEnabled = !chartView.data.isHighlightEnabled; + chartView.data.isHighlightEnabled = !chartView.data.isHighlightEnabled; [chartView setNeedsDisplay]; } diff --git a/ChartsDemo-iOS/Objective-C/Demos/ColoredLineChartViewController.m b/ChartsDemo-iOS/Objective-C/Demos/ColoredLineChartViewController.m index a639f6911d..867b8627dc 100644 --- a/ChartsDemo-iOS/Objective-C/Demos/ColoredLineChartViewController.m +++ b/ChartsDemo-iOS/Objective-C/Demos/ColoredLineChartViewController.m @@ -44,7 +44,7 @@ - (void)viewDidLoad - (void)setupChart:(LineChartView *)chart data:(LineChartData *)data color:(UIColor *)color { - [(LineChartDataSet *)[data getDataSetByIndex:0] setCircleHoleColor:color]; + [(LineChartDataSet *)[data dataSetAtIndex:0] setCircleHoleColor:color]; chart.delegate = self; chart.backgroundColor = color; diff --git a/ChartsDemo-iOS/Objective-C/Demos/CombinedChartViewController.m b/ChartsDemo-iOS/Objective-C/Demos/CombinedChartViewController.m index a361e4c001..68b6abd969 100644 --- a/ChartsDemo-iOS/Objective-C/Demos/CombinedChartViewController.m +++ b/ChartsDemo-iOS/Objective-C/Demos/CombinedChartViewController.m @@ -151,7 +151,7 @@ - (void)optionTapped:(NSString *)key if ([key isEqualToString:@"removeDataSet"]) { int rnd = (int)arc4random_uniform((float)_chartView.data.dataSetCount); - [_chartView.data removeDataSet:[_chartView.data getDataSetByIndex:rnd]]; + [_chartView.data removeDataSet:[_chartView.data dataSetAtIndex:rnd]]; [_chartView.data notifyDataChanged]; [_chartView notifyDataSetChanged]; } diff --git a/ChartsDemo-iOS/Objective-C/Demos/LineChart2ViewController.m b/ChartsDemo-iOS/Objective-C/Demos/LineChart2ViewController.m index ccce0d614c..c192f4a9b3 100644 --- a/ChartsDemo-iOS/Objective-C/Demos/LineChart2ViewController.m +++ b/ChartsDemo-iOS/Objective-C/Demos/LineChart2ViewController.m @@ -282,7 +282,7 @@ - (void)chartValueSelected:(ChartViewBase * __nonnull)chartView entry:(ChartData { NSLog(@"chartValueSelected"); - [_chartView centerViewToAnimatedWithXValue:entry.x yValue:entry.y axis:[_chartView.data getDataSetByIndex:highlight.dataSetIndex].axisDependency duration:1.0]; + [_chartView centerViewToAnimatedWithXValue:entry.x yValue:entry.y axis:[_chartView.data dataSetAtIndex:highlight.dataSetIndex].axisDependency duration:1.0]; //[_chartView moveViewToAnimatedWithXValue:entry.x yValue:entry.y axis:[_chartView.data getDataSetByIndex:dataSetIndex].axisDependency duration:1.0]; //[_chartView zoomAndCenterViewAnimatedWithScaleX:1.8 scaleY:1.8 xValue:entry.x yValue:entry.y axis:[_chartView.data getDataSetByIndex:dataSetIndex].axisDependency duration:1.0]; diff --git a/ChartsDemo-iOS/Swift/DemoBaseViewController.swift b/ChartsDemo-iOS/Swift/DemoBaseViewController.swift index 82265eb594..b643420520 100644 --- a/ChartsDemo-iOS/Swift/DemoBaseViewController.swift +++ b/ChartsDemo-iOS/Swift/DemoBaseViewController.swift @@ -129,7 +129,7 @@ class DemoBaseViewController: UIViewController, ChartViewDelegate { chartView.setNeedsDisplay() case .toggleHighlight: - chartView.data!.highlightEnabled = !chartView.data!.isHighlightEnabled + chartView.data!.isHighlightEnabled = !chartView.data!.isHighlightEnabled chartView.setNeedsDisplay() case .animateX: diff --git a/ChartsDemo-iOS/Swift/Demos/ColoredLineChartViewController.swift b/ChartsDemo-iOS/Swift/Demos/ColoredLineChartViewController.swift index 7a8e443502..dfc3a2464c 100644 --- a/ChartsDemo-iOS/Swift/Demos/ColoredLineChartViewController.swift +++ b/ChartsDemo-iOS/Swift/Demos/ColoredLineChartViewController.swift @@ -31,7 +31,7 @@ class ColoredLineChartViewController: DemoBaseViewController { } func setupChart(_ chart: LineChartView, data: LineChartData, color: UIColor) { - (data.getDataSetByIndex(0) as! LineChartDataSet).circleHoleColor = color + (data[0] as! LineChartDataSet).circleHoleColor = color chart.delegate = self chart.backgroundColor = color diff --git a/ChartsDemo-iOS/Swift/Demos/CombinedChartViewController.swift b/ChartsDemo-iOS/Swift/Demos/CombinedChartViewController.swift index 82d26e6523..7e779f1a3f 100644 --- a/ChartsDemo-iOS/Swift/Demos/CombinedChartViewController.swift +++ b/ChartsDemo-iOS/Swift/Demos/CombinedChartViewController.swift @@ -112,7 +112,7 @@ class CombinedChartViewController: DemoBaseViewController { case .removeDataSet: let rnd = Int(arc4random_uniform(UInt32(chartView.data!.dataSetCount))) - chartView.data?.removeDataSet(chartView.data!.getDataSetByIndex(rnd)) + chartView.data?.removeDataSet(chartView.data![rnd]) chartView.data?.notifyDataChanged() chartView.notifyDataSetChanged() diff --git a/ChartsDemo-iOS/Swift/Demos/LineChart2ViewController.swift b/ChartsDemo-iOS/Swift/Demos/LineChart2ViewController.swift index 3132199f91..f7d8e5a1fb 100644 --- a/ChartsDemo-iOS/Swift/Demos/LineChart2ViewController.swift +++ b/ChartsDemo-iOS/Swift/Demos/LineChart2ViewController.swift @@ -194,7 +194,7 @@ class LineChart2ViewController: DemoBaseViewController { super.chartValueSelected(chartView, entry: entry, highlight: highlight) self.chartView.centerViewToAnimated(xValue: entry.x, yValue: entry.y, - axis: self.chartView.data!.getDataSetByIndex(highlight.dataSetIndex).axisDependency, + axis: self.chartView.data![highlight.dataSetIndex].axisDependency, duration: 1) //[_chartView moveViewToAnimatedWithXValue:entry.x yValue:entry.y axis:[_chartView.data getDataSetByIndex:dataSetIndex].axisDependency duration:1.0]; //[_chartView zoomAndCenterViewAnimatedWithScaleX:1.8 scaleY:1.8 xValue:entry.x yValue:entry.y axis:[_chartView.data getDataSetByIndex:dataSetIndex].axisDependency duration:1.0]; diff --git a/Source/Charts/Charts/BarLineChartViewBase.swift b/Source/Charts/Charts/BarLineChartViewBase.swift index 6b06ec6c5e..2bdce16c2f 100644 --- a/Source/Charts/Charts/BarLineChartViewBase.swift +++ b/Source/Charts/Charts/BarLineChartViewBase.swift @@ -1684,7 +1684,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD { if let h = getHighlightByTouchPoint(pt) { - return data!.entryForHighlight(h) + return data!.entry(for: h) } return nil } @@ -1695,7 +1695,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD let h = getHighlightByTouchPoint(pt) if let h = h { - return data?.getDataSetByIndex(h.dataSetIndex) as? BarLineScatterCandleBubbleChartDataSetProtocol + return data?[h.dataSetIndex] as? BarLineScatterCandleBubbleChartDataSetProtocol } return nil } diff --git a/Source/Charts/Charts/ChartViewBase.swift b/Source/Charts/Charts/ChartViewBase.swift index 8ddbb226ff..0f21234ad1 100644 --- a/Source/Charts/Charts/ChartViewBase.swift +++ b/Source/Charts/Charts/ChartViewBase.swift @@ -52,7 +52,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate guard let data = data else { return } // calculate how many digits are needed - setupDefaultFormatter(min: data.getYMin(), max: data.getYMax()) + setupDefaultFormatter(min: data.yMin, max: data.yMax) for set in data.dataSets { @@ -411,14 +411,14 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate Swift.print("Value not highlighted because data is nil") return } - - if dataSetIndex < 0 || dataSetIndex >= data.dataSetCount + + if data.indices.contains(dataSetIndex) { - highlightValue(nil, callDelegate: callDelegate) + highlightValue(Highlight(x: x, y: y, dataSetIndex: dataSetIndex, dataIndex: dataIndex), callDelegate: callDelegate) } else { - highlightValue(Highlight(x: x, y: y, dataSetIndex: dataSetIndex, dataIndex: dataIndex), callDelegate: callDelegate) + highlightValue(nil, callDelegate: callDelegate) } } @@ -436,7 +436,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate var high = highlight guard let h = high, - let entry = data?.entryForHighlight(h) + let entry = data?.entry(for: h) else { high = nil @@ -493,8 +493,8 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate for highlight in highlighted { guard - let set = data?.getDataSetByIndex(highlight.dataSetIndex), - let e = data?.entryForHighlight(highlight) + let set = data?[highlight.dataSetIndex], + let e = data?.entry(for: highlight) else { continue } let entryIndex = set.entryIndex(entry: e) diff --git a/Source/Charts/Charts/CombinedChartView.swift b/Source/Charts/Charts/CombinedChartView.swift index 8d13d2292a..dd548067ac 100644 --- a/Source/Charts/Charts/CombinedChartView.swift +++ b/Source/Charts/Charts/CombinedChartView.swift @@ -219,7 +219,7 @@ open class CombinedChartView: BarLineChartViewBase, CombinedChartDataProvider guard let set = combinedData?.getDataSetByHighlight(highlight), - let e = data?.entryForHighlight(highlight) + let e = data?.entry(for: highlight) else { continue } let entryIndex = set.entryIndex(entry: e) diff --git a/Source/Charts/Charts/PieChartView.swift b/Source/Charts/Charts/PieChartView.swift index b4bfbd6b7f..8ab6dd7b5b 100644 --- a/Source/Charts/Charts/PieChartView.swift +++ b/Source/Charts/Charts/PieChartView.swift @@ -194,14 +194,11 @@ open class PieChartView: PieRadarChartViewBase _absoluteAngles.reserveCapacity(entryCount) let yValueSum = (data as! PieChartData).yValueSum - - var dataSets = data.dataSets var cnt = 0 - for i in 0 ..< data.dataSetCount + for set in data { - let set = dataSets[i] let entryCount = set.entryCount for j in 0 ..< entryCount diff --git a/Source/Charts/Data/Implementations/Standard/BarChartData.swift b/Source/Charts/Data/Implementations/Standard/BarChartData.swift index 6516428275..04e1e6f8de 100644 --- a/Source/Charts/Data/Implementations/Standard/BarChartData.swift +++ b/Source/Charts/Data/Implementations/Standard/BarChartData.swift @@ -19,7 +19,7 @@ open class BarChartData: BarLineScatterCandleBubbleChartData super.init() } - public override init(dataSets: [ChartDataSetProtocol]?) + public override init(dataSets: [ChartDataSetProtocol]) { super.init(dataSets: dataSets) } diff --git a/Source/Charts/Data/Implementations/Standard/BarLineScatterCandleBubbleChartData.swift b/Source/Charts/Data/Implementations/Standard/BarLineScatterCandleBubbleChartData.swift index 715709708b..75eb8a278e 100644 --- a/Source/Charts/Data/Implementations/Standard/BarLineScatterCandleBubbleChartData.swift +++ b/Source/Charts/Data/Implementations/Standard/BarLineScatterCandleBubbleChartData.swift @@ -18,7 +18,7 @@ open class BarLineScatterCandleBubbleChartData: ChartData super.init() } - public override init(dataSets: [ChartDataSetProtocol]?) + public override init(dataSets: [ChartDataSetProtocol]) { super.init(dataSets: dataSets) } diff --git a/Source/Charts/Data/Implementations/Standard/BubbleChartData.swift b/Source/Charts/Data/Implementations/Standard/BubbleChartData.swift index 89fd484804..5a0a85563d 100644 --- a/Source/Charts/Data/Implementations/Standard/BubbleChartData.swift +++ b/Source/Charts/Data/Implementations/Standard/BubbleChartData.swift @@ -19,7 +19,7 @@ open class BubbleChartData: BarLineScatterCandleBubbleChartData super.init() } - public override init(dataSets: [ChartDataSetProtocol]?) + public override init(dataSets: [ChartDataSetProtocol]) { super.init(dataSets: dataSets) } diff --git a/Source/Charts/Data/Implementations/Standard/CandleChartData.swift b/Source/Charts/Data/Implementations/Standard/CandleChartData.swift index 2c0d3bd443..3cfe5bac35 100644 --- a/Source/Charts/Data/Implementations/Standard/CandleChartData.swift +++ b/Source/Charts/Data/Implementations/Standard/CandleChartData.swift @@ -18,7 +18,7 @@ open class CandleChartData: BarLineScatterCandleBubbleChartData super.init() } - public override init(dataSets: [ChartDataSetProtocol]?) + public override init(dataSets: [ChartDataSetProtocol]) { super.init(dataSets: dataSets) } diff --git a/Source/Charts/Data/Implementations/Standard/ChartData.swift b/Source/Charts/Data/Implementations/Standard/ChartData.swift index 16a4547699..ac9eb3aeda 100644 --- a/Source/Charts/Data/Implementations/Standard/ChartData.swift +++ b/Source/Charts/Data/Implementations/Standard/ChartData.swift @@ -13,50 +13,40 @@ import Foundation open class ChartData: NSObject, ExpressibleByArrayLiteral { - internal var _yMax: Double = -Double.greatestFiniteMagnitude - internal var _yMin: Double = Double.greatestFiniteMagnitude - internal var _xMax: Double = -Double.greatestFiniteMagnitude - internal var _xMin: Double = Double.greatestFiniteMagnitude - internal var _leftAxisMax: Double = -Double.greatestFiniteMagnitude - internal var _leftAxisMin: Double = Double.greatestFiniteMagnitude - internal var _rightAxisMax: Double = -Double.greatestFiniteMagnitude - internal var _rightAxisMin: Double = Double.greatestFiniteMagnitude + + @objc public internal(set) var xMax = -Double.greatestFiniteMagnitude + @objc public internal(set) var xMin = Double.greatestFiniteMagnitude + @objc public internal(set) var yMax = -Double.greatestFiniteMagnitude + @objc public internal(set) var yMin = Double.greatestFiniteMagnitude + var leftAxisMax = -Double.greatestFiniteMagnitude + var leftAxisMin = Double.greatestFiniteMagnitude + var rightAxisMax = -Double.greatestFiniteMagnitude + var rightAxisMin = Double.greatestFiniteMagnitude - internal var _dataSets = [ChartDataSetProtocol]() + var _dataSets = [Element]() public override required init() { super.init() } - public required init(arrayLiteral elements: ChartDataSetProtocol...) + public required init(arrayLiteral elements: Element...) { super.init() - - _dataSets = elements - - self.initialize(dataSets: _dataSets) + self.dataSets = elements } - @objc public init(dataSets: [ChartDataSetProtocol]?) + @objc public init(dataSets: [Element]) { super.init() - - _dataSets = dataSets ?? [ChartDataSetProtocol]() - - self.initialize(dataSets: _dataSets) + self.dataSets = dataSets } - @objc public convenience init(dataSet: ChartDataSetProtocol?) + @objc public convenience init(dataSet: Element) { - self.init(dataSets: dataSet === nil ? nil : [dataSet!]) - } - - internal func initialize(dataSets: [ChartDataSetProtocol]) - { - notifyDataChanged() + self.init(dataSets: [dataSet]) } - + /// Call this method to let the ChartData know that the underlying data has changed. /// Calling this performs all necessary recalculations needed when the contained data has changed. @objc open func notifyDataChanged() @@ -75,256 +65,120 @@ open class ChartData: NSObject, ExpressibleByArrayLiteral /// calc minimum and maximum y value over all datasets @objc open func calcMinMax() { - _yMax = -Double.greatestFiniteMagnitude - _yMin = Double.greatestFiniteMagnitude - _xMax = -Double.greatestFiniteMagnitude - _xMin = Double.greatestFiniteMagnitude - - forEach { calcMinMax(dataSet: $0) } - - _leftAxisMax = -Double.greatestFiniteMagnitude - _leftAxisMin = Double.greatestFiniteMagnitude - _rightAxisMax = -Double.greatestFiniteMagnitude - _rightAxisMin = Double.greatestFiniteMagnitude - - // left axis - let firstLeft = getFirstLeft(dataSets: dataSets) - - if firstLeft !== nil - { - _leftAxisMax = firstLeft!.yMax - _leftAxisMin = firstLeft!.yMin + leftAxisMax = -.greatestFiniteMagnitude + leftAxisMin = .greatestFiniteMagnitude + rightAxisMax = -.greatestFiniteMagnitude + rightAxisMin = .greatestFiniteMagnitude + yMax = -.greatestFiniteMagnitude + yMin = .greatestFiniteMagnitude + xMax = -.greatestFiniteMagnitude + xMin = .greatestFiniteMagnitude - for dataSet in _dataSets where dataSet.axisDependency == .left - { - if dataSet.yMin < _leftAxisMin - { - _leftAxisMin = dataSet.yMin - } - - if dataSet.yMax > _leftAxisMax - { - _leftAxisMax = dataSet.yMax - } - } - } - - // right axis - let firstRight = getFirstRight(dataSets: dataSets) - - if firstRight !== nil - { - _rightAxisMax = firstRight!.yMax - _rightAxisMin = firstRight!.yMin - - for dataSet in _dataSets where dataSet.axisDependency == .right - { - if dataSet.yMin < _rightAxisMin - { - _rightAxisMin = dataSet.yMin - } - - if dataSet.yMax > _rightAxisMax - { - _rightAxisMax = dataSet.yMax - } - } - } + forEach { calcMinMax(dataSet: $0) } } - + /// Adjusts the current minimum and maximum values based on the provided Entry object. @objc open func calcMinMax(entry e: ChartDataEntry, axis: YAxis.AxisDependency) { - if _yMax < e.y - { - _yMax = e.y - } - - if _yMin > e.y - { - _yMin = e.y - } - - if _xMax < e.x - { - _xMax = e.x - } - - if _xMin > e.x - { - _xMin = e.x - } - - if axis == .left - { - if _leftAxisMax < e.y - { - _leftAxisMax = e.y - } - - if _leftAxisMin > e.y - { - _leftAxisMin = e.y - } - } - else + xMax = Swift.max(xMax, e.x) + xMin = Swift.min(xMin, e.x) + yMax = Swift.max(yMax, e.y) + yMin = Swift.min(yMin, e.y) + + switch axis { - if _rightAxisMax < e.y - { - _rightAxisMax = e.y - } - - if _rightAxisMin > e.y - { - _rightAxisMin = e.y - } + case .left: + leftAxisMax = Swift.max(leftAxisMax, e.y) + leftAxisMin = Swift.min(leftAxisMin, e.y) + + case .right: + rightAxisMax = Swift.max(rightAxisMax, e.y) + rightAxisMin = Swift.min(rightAxisMin, e.y) } } /// Adjusts the minimum and maximum values based on the given DataSet. - @objc open func calcMinMax(dataSet d: ChartDataSetProtocol) + @objc open func calcMinMax(dataSet d: Element) { - if _yMax < d.yMax - { - _yMax = d.yMax - } - - if _yMin > d.yMin - { - _yMin = d.yMin - } - - if _xMax < d.xMax - { - _xMax = d.xMax - } - - if _xMin > d.xMin - { - _xMin = d.xMin - } - - if d.axisDependency == .left - { - if _leftAxisMax < d.yMax - { - _leftAxisMax = d.yMax - } - - if _leftAxisMin > d.yMin - { - _leftAxisMin = d.yMin - } - } - else + xMax = Swift.max(xMax, d.xMax) + xMin = Swift.min(xMin, d.xMin) + yMax = Swift.max(yMax, d.yMax) + yMin = Swift.min(yMin, d.yMin) + + switch d.axisDependency { - if _rightAxisMax < d.yMax - { - _rightAxisMax = d.yMax - } - - if _rightAxisMin > d.yMin - { - _rightAxisMin = d.yMin - } + case .left: + leftAxisMax = Swift.max(leftAxisMax, d.yMax) + leftAxisMin = Swift.min(leftAxisMin, d.yMin) + + case .right: + rightAxisMax = Swift.max(rightAxisMax, d.yMax) + rightAxisMin = Swift.min(rightAxisMin, d.yMin) } } /// - returns: The number of LineDataSets this object contains + // exists only for objc compatibility @objc open var dataSetCount: Int { - return _dataSets.count + return dataSets.count } - - /// - returns: The smallest y-value the data object contains. - @objc open var yMin: Double - { - return _yMin - } - - @nonobjc - open func getYMin() -> Double - { - return _yMin - } - + @objc open func getYMin(axis: YAxis.AxisDependency) -> Double { - if axis == .left + // TODO: Why does it make sense to return the other axisMin if there is none for the one requested? + switch axis { - if _leftAxisMin == Double.greatestFiniteMagnitude + case .left: + if leftAxisMin == .greatestFiniteMagnitude { - return _rightAxisMin + return rightAxisMin } else { - return _leftAxisMin + return leftAxisMin } - } - else - { - if _rightAxisMin == Double.greatestFiniteMagnitude + + case .right: + if rightAxisMin == .greatestFiniteMagnitude { - return _leftAxisMin + return leftAxisMin } else { - return _rightAxisMin + return rightAxisMin } } } - - /// - returns: The greatest y-value the data object contains. - @objc open var yMax: Double - { - return _yMax - } - - @nonobjc - open func getYMax() -> Double - { - return _yMax - } - + @objc open func getYMax(axis: YAxis.AxisDependency) -> Double { if axis == .left { - if _leftAxisMax == -Double.greatestFiniteMagnitude + if leftAxisMax == -.greatestFiniteMagnitude { - return _rightAxisMax + return rightAxisMax } else { - return _leftAxisMax + return leftAxisMax } } else { - if _rightAxisMax == -Double.greatestFiniteMagnitude + if rightAxisMax == -.greatestFiniteMagnitude { - return _leftAxisMax + return leftAxisMax } else { - return _rightAxisMax + return rightAxisMax } } } - - /// - returns: The minimum x-value the data object contains. - @objc open var xMin: Double - { - return _xMin - } - /// - returns: The maximum x-value the data object contains. - @objc open var xMax: Double - { - return _xMax - } - + /// - returns: All DataSet objects this ChartData object holds. - @objc open var dataSets: [ChartDataSetProtocol] + @objc open var dataSets: [Element] { get { @@ -336,33 +190,12 @@ open class ChartData: NSObject, ExpressibleByArrayLiteral notifyDataChanged() } } - - /// Retrieve the index of a ChartDataSet with a specific label from the ChartData. Search can be case sensitive or not. - /// - /// **IMPORTANT: This method does calculations at runtime, do not over-use in performance critical situations.** - /// - /// - parameter dataSets: the DataSet array to search - /// - parameter type: - /// - parameter ignorecase: if true, the search is not case-sensitive - /// - returns: The index of the DataSet Object with the given label. Sensitive or not. - internal func getDataSetIndexByLabel(_ label: String, ignorecase: Bool) -> Int - { - return ignorecase - ? index { $0.label?.caseInsensitiveCompare(label) == .orderedSame } ?? -1 - : index { $0.label == label } ?? -1 - } - - /// - returns: The labels of all DataSets as a string array. - internal func dataSetLabels() -> [String] - { - return compactMap { $0.label } - } - + /// Get the Entry for a corresponding highlight object /// /// - parameter highlight: /// - returns: The entry that is highlighted - @objc open func entryForHighlight(_ highlight: Highlight) -> ChartDataEntry? + @objc open func entry(for highlight: Highlight) -> ChartDataEntry? { guard indices.contains(highlight.dataSetIndex) else { return nil } return self[highlight.dataSetIndex].entryForXValue(highlight.x, closestToY: highlight.y) @@ -373,19 +206,16 @@ open class ChartData: NSObject, ExpressibleByArrayLiteral /// - parameter label: /// - parameter ignorecase: /// - returns: The DataSet Object with the given label. Sensitive or not. - @objc open func getDataSetByLabel(_ label: String, ignorecase: Bool) -> Element? + @objc open func dataSet(forLabel label: String, ignorecase: Bool) -> Element? { guard let index = index(forLabel: label, ignoreCase: ignorecase) else { return nil } return self[index] } - @objc open func getDataSetByIndex(_ index: Index) -> Element! + @objc(dataSetAtIndex:) + open func dataSet(at index: Index) -> Element? { - if index < 0 || index >= _dataSets.count - { - return nil - } - + guard dataSets.indices.contains(index) else { return nil } return self[index] } @@ -393,15 +223,10 @@ open class ChartData: NSObject, ExpressibleByArrayLiteral /// Also recalculates all minimum and maximum values. /// /// - returns: `true` if a DataSet was removed, `false` ifno DataSet could be removed. - @objc @discardableResult open func removeDataSet(_ dataSet: Element!) -> Bool + @objc @discardableResult open func removeDataSet(_ dataSet: Element) -> Element? { - guard - dataSet != nil, - let index = index(where: { $0 === dataSet }) - else { return false } - - _ = remove(at: index) - return true + guard let index = index(where: { $0 === dataSet }) else { return nil } + return remove(at: index) } /// Adds an Entry to the DataSet at the specified index. Entries are added to the end of the list. @@ -418,7 +243,7 @@ open class ChartData: NSObject, ExpressibleByArrayLiteral } /// Removes the given Entry object from the DataSet at the specified index. - @objc @discardableResult open func removeEntry(_ entry: ChartDataEntry, dataSetIndex: Int) -> Bool + @objc @discardableResult open func removeEntry(_ entry: ChartDataEntry, dataSetIndex: Index) -> Bool { guard indices.contains(dataSetIndex) else { return false } @@ -436,7 +261,7 @@ open class ChartData: NSObject, ExpressibleByArrayLiteral /// Removes the Entry object closest to the given xIndex from the ChartDataSet at the /// specified index. /// - returns: `true` if an entry was removed, `false` ifno Entry was found that meets the specified requirements. - @objc @discardableResult open func removeEntry(xValue: Double, dataSetIndex: Int) -> Bool + @objc @discardableResult open func removeEntry(xValue: Double, dataSetIndex: Index) -> Bool { guard indices.contains(dataSetIndex), @@ -447,57 +272,51 @@ open class ChartData: NSObject, ExpressibleByArrayLiteral } /// - returns: The DataSet that contains the provided Entry, or null, if no DataSet contains this entry. - @objc open func getDataSetForEntry(_ e: ChartDataEntry!) -> ChartDataSetProtocol? + @objc open func getDataSetForEntry(_ e: ChartDataEntry) -> Element? { - guard e != nil else { return nil } - return first { $0.entryForXValue(e.x, closestToY: e.y) === e } } /// - returns: The index of the provided DataSet in the DataSet array of this data object, or -1 if it does not exist. - @objc open func indexOfDataSet(_ dataSet: ChartDataSetProtocol) -> Int + @objc open func index(of dataSet: Element) -> Index { return index(where: { $0 === dataSet }) ?? -1 } /// - returns: The first DataSet from the datasets-array that has it's dependency on the left axis. Returns null if no DataSet with left dependency could be found. - @objc open func getFirstLeft(dataSets: [ChartDataSetProtocol]) -> ChartDataSetProtocol? + @objc open func getFirstLeft(dataSets: [Element]) -> Element? { return first { $0.axisDependency == .left } } /// - returns: The first DataSet from the datasets-array that has it's dependency on the right axis. Returns null if no DataSet with right dependency could be found. - @objc open func getFirstRight(dataSets: [ChartDataSetProtocol]) -> ChartDataSetProtocol? + @objc open func getFirstRight(dataSets: [Element]) -> Element? { return first { $0.axisDependency == .right } } /// - returns: All colors used across all DataSet objects this object represents. - // TODO: This should return a non-optional array - @objc open func getColors() -> [NSUIColor]? + @objc open func getColors() -> [NSUIColor] { - return flatMap { $0.colors.map { $0 } } + return reduce(into: []) { $0 += $1.colors } } /// Sets a custom ValueFormatter for all DataSets this data object contains. - @objc open func setValueFormatter(_ formatter: ValueFormatter?) + @objc open func setValueFormatter(_ formatter: ValueFormatter) { - guard let formatter = formatter - else { return } - forEach { $0.valueFormatter = formatter } } /// Sets the color of the value-text (color in which the value-labels are drawn) for all DataSets this data object contains. - @objc open func setValueTextColor(_ color: NSUIColor!) + @objc open func setValueTextColor(_ color: NSUIColor) { - forEach { $0.valueTextColor = color ?? $0.valueTextColor } + forEach { $0.valueTextColor = color } } /// Sets the font for all value-labels for all DataSets this data object contains. - @objc open func setValueFont(_ font: NSUIFont!) + @objc open func setValueFont(_ font: NSUIFont) { - forEach { $0.valueFont = font ?? $0.valueFont } + forEach { $0.valueFont = font } } /// Enables / disables drawing values (value-text) for all DataSets this data object contains. @@ -508,32 +327,22 @@ open class ChartData: NSObject, ExpressibleByArrayLiteral /// Enables / disables highlighting values for all DataSets this data object contains. /// If set to true, this means that values can be highlighted programmatically or by touch gesture. - @objc open var highlightEnabled: Bool + @objc open var isHighlightEnabled: Bool { - get - { - return first { $0.highlightEnabled == false } == nil - } - set - { - forEach { $0.highlightEnabled = newValue } - } + get { return first { $0.highlightEnabled == false } == nil } + set { forEach { $0.highlightEnabled = newValue } } } - - /// if true, value highlightning is enabled - @objc open var isHighlightEnabled: Bool { return highlightEnabled } - + /// Clears this data object from all DataSets and removes all Entries. /// Don't forget to invalidate the chart after this. @objc open func clearValues() { - dataSets.removeAll(keepingCapacity: false) - notifyDataChanged() + removeAll(keepingCapacity: false) } /// Checks if this data object contains the specified DataSet. /// - returns: `true` if so, `false` ifnot. - @objc open func contains(dataSet: ChartDataSetProtocol) -> Bool + @objc open func contains(dataSet: Element) -> Bool { return contains { $0 === dataSet } } @@ -545,7 +354,7 @@ open class ChartData: NSObject, ExpressibleByArrayLiteral } /// - returns: The DataSet object with the maximum number of entries or null if there are no DataSets. - @objc open var maxEntryCountSet: ChartDataSetProtocol? + @objc open var maxEntryCountSet: Element? { return self.max { $0.entryCount > $1.entryCount } } @@ -559,23 +368,23 @@ extension ChartData: MutableCollection public var startIndex: Index { - return _dataSets.startIndex + return dataSets.startIndex } public var endIndex: Index { - return _dataSets.endIndex + return dataSets.endIndex } public func index(after: Index) -> Index { - return _dataSets.index(after: after) + return dataSets.index(after: after) } public subscript(position: Index) -> Element { - get{ return _dataSets[position] } - set{ self._dataSets[position] = newValue } + get { return dataSets[position] } + set { self._dataSets[position] = newValue } } } @@ -584,7 +393,7 @@ extension ChartData: RandomAccessCollection { public func index(before: Index) -> Index { - return _dataSets.index(before: before) + return dataSets.index(before: before) } } @@ -704,14 +513,19 @@ extension ChartData : index { $0.label == label } } - public subscript(label: String, ignoreCase: Bool) -> Element? + public subscript(label label: String, ignoreCase ignoreCase: Bool) -> Element? { guard let index = index(forLabel: label, ignoreCase: ignoreCase) else { return nil } return self[index] } - public subscript(entry: ChartDataEntry) -> Element? + public subscript(entry entry: ChartDataEntry) -> Element? { + guard !(self is CombinedChartData) else + { + fatalError("subscript(entry:) not supported for CombinedData") + } + guard let index = index(where: { $0.entryForXValue(entry.x, closestToY: entry.y) === entry }) else { return nil } return self[index] } diff --git a/Source/Charts/Data/Implementations/Standard/CombinedChartData.swift b/Source/Charts/Data/Implementations/Standard/CombinedChartData.swift index 23e6992ebe..dbd4048b66 100644 --- a/Source/Charts/Data/Implementations/Standard/CombinedChartData.swift +++ b/Source/Charts/Data/Implementations/Standard/CombinedChartData.swift @@ -24,7 +24,7 @@ open class CombinedChartData: BarLineScatterCandleBubbleChartData super.init() } - public override init(dataSets: [ChartDataSetProtocol]?) + public override init(dataSets: [ChartDataSetProtocol]) { super.init(dataSets: dataSets) } @@ -103,15 +103,15 @@ open class CombinedChartData: BarLineScatterCandleBubbleChartData { _dataSets.removeAll() - _yMax = -Double.greatestFiniteMagnitude - _yMin = Double.greatestFiniteMagnitude - _xMax = -Double.greatestFiniteMagnitude - _xMin = Double.greatestFiniteMagnitude + yMax = -Double.greatestFiniteMagnitude + yMin = Double.greatestFiniteMagnitude + xMax = -Double.greatestFiniteMagnitude + xMin = Double.greatestFiniteMagnitude - _leftAxisMax = -Double.greatestFiniteMagnitude - _leftAxisMin = Double.greatestFiniteMagnitude - _rightAxisMax = -Double.greatestFiniteMagnitude - _rightAxisMin = Double.greatestFiniteMagnitude + leftAxisMax = -Double.greatestFiniteMagnitude + leftAxisMin = Double.greatestFiniteMagnitude + rightAxisMax = -Double.greatestFiniteMagnitude + rightAxisMin = Double.greatestFiniteMagnitude let allData = self.allData @@ -122,48 +122,48 @@ open class CombinedChartData: BarLineScatterCandleBubbleChartData let sets = data.dataSets _dataSets.append(contentsOf: sets) - if data.yMax > _yMax + if data.yMax > yMax { - _yMax = data.yMax + yMax = data.yMax } - if data.yMin < _yMin + if data.yMin < yMin { - _yMin = data.yMin + yMin = data.yMin } - if data.xMax > _xMax + if data.xMax > xMax { - _xMax = data.xMax + xMax = data.xMax } - if data.xMin < _xMin + if data.xMin < xMin { - _xMin = data.xMin + xMin = data.xMin } for dataset in sets { if dataset.axisDependency == .left { - if dataset.yMax > _leftAxisMax + if dataset.yMax > leftAxisMax { - _leftAxisMax = dataset.yMax + leftAxisMax = dataset.yMax } - if dataset.yMin < _leftAxisMin + if dataset.yMin < leftAxisMin { - _leftAxisMin = dataset.yMin + leftAxisMin = dataset.yMin } } else { - if dataset.yMax > _rightAxisMax + if dataset.yMax > rightAxisMax { - _rightAxisMax = dataset.yMax + rightAxisMax = dataset.yMax } - if dataset.yMin < _rightAxisMin + if dataset.yMin < rightAxisMin { - _rightAxisMin = dataset.yMin + rightAxisMin = dataset.yMin } } } @@ -209,23 +209,17 @@ open class CombinedChartData: BarLineScatterCandleBubbleChartData return allData.index(of: data) } - open override func removeDataSet(_ dataSet: ChartDataSetProtocol!) -> Bool + open override func removeDataSet(_ dataSet: ChartDataSetProtocol) -> Element? { - let datas = allData - - var success = false - - for data in datas + for data in allData { - success = data.removeDataSet(dataSet) - - if success + if let e = data.removeDataSet(dataSet) { - break + return e } } - return success + return nil } open override func removeEntry(_ entry: ChartDataEntry, dataSetIndex: Int) -> Bool @@ -255,7 +249,7 @@ open class CombinedChartData: BarLineScatterCandleBubbleChartData /// /// - parameter highlight: /// - returns: The entry that is highlighted - open override func entryForHighlight(_ highlight: Highlight) -> ChartDataEntry? + @objc override open func entry(for highlight: Highlight) -> ChartDataEntry? { if highlight.dataIndex >= allData.count { @@ -264,21 +258,15 @@ open class CombinedChartData: BarLineScatterCandleBubbleChartData let data = dataByIndex(highlight.dataIndex) - if highlight.dataSetIndex >= data.dataSetCount + if highlight.dataSetIndex >= data.endIndex { return nil } // The value of the highlighted entry could be NaN - if we are not interested in highlighting a specific value. - let entries = data.getDataSetByIndex(highlight.dataSetIndex).entriesForXValue(highlight.x) - for e in entries - { - if e.y == highlight.y || highlight.y.isNaN - { - return e - } - } - return nil + return data[highlight.dataSetIndex] + .entriesForXValue(highlight.x) + .first { $0.y == highlight.y || highlight.y.isNaN } } /// Get dataset for highlight @@ -294,7 +282,7 @@ open class CombinedChartData: BarLineScatterCandleBubbleChartData let data = dataByIndex(highlight.dataIndex) - if highlight.dataSetIndex >= data.dataSetCount + if highlight.dataSetIndex >= data.endIndex { return nil } diff --git a/Source/Charts/Data/Implementations/Standard/LineChartData.swift b/Source/Charts/Data/Implementations/Standard/LineChartData.swift index 468620ff49..fe3eb92862 100644 --- a/Source/Charts/Data/Implementations/Standard/LineChartData.swift +++ b/Source/Charts/Data/Implementations/Standard/LineChartData.swift @@ -19,7 +19,7 @@ open class LineChartData: ChartData super.init() } - public override init(dataSets: [ChartDataSetProtocol]?) + public override init(dataSets: [ChartDataSetProtocol]) { super.init(dataSets: dataSets) } diff --git a/Source/Charts/Data/Implementations/Standard/PieChartData.swift b/Source/Charts/Data/Implementations/Standard/PieChartData.swift index 775474327d..2c26535b8e 100644 --- a/Source/Charts/Data/Implementations/Standard/PieChartData.swift +++ b/Source/Charts/Data/Implementations/Standard/PieChartData.swift @@ -18,7 +18,7 @@ open class PieChartData: ChartData super.init() } - public override init(dataSets: [ChartDataSetProtocol]?) + public override init(dataSets: [ChartDataSetProtocol]) { super.init(dataSets: dataSets) } @@ -61,16 +61,13 @@ open class PieChartData: ChartData } } - open override func getDataSetByIndex(_ index: Int) -> ChartDataSetProtocol? + open override func dataSet(at index: ChartData.Index) -> ChartData.Element? { - if index != 0 - { - return nil - } - return super.getDataSetByIndex(index) + guard index == 0 else { return nil } + return self[index] } - open override func getDataSetByLabel(_ label: String, ignorecase: Bool) -> ChartDataSetProtocol? + open override func dataSet(forLabel label: String, ignorecase: Bool) -> ChartDataSetProtocol? { if dataSets.count == 0 || dataSets[0].label == nil { @@ -94,7 +91,7 @@ open class PieChartData: ChartData return nil } - open override func entryForHighlight(_ highlight: Highlight) -> ChartDataEntry? + @objc override open func entry(for highlight: Highlight) -> ChartDataEntry? { return dataSet?.entryForIndex(Int(highlight.x)) } diff --git a/Source/Charts/Data/Implementations/Standard/RadarChartData.swift b/Source/Charts/Data/Implementations/Standard/RadarChartData.swift index 313ca65147..2f8a2db7ae 100644 --- a/Source/Charts/Data/Implementations/Standard/RadarChartData.swift +++ b/Source/Charts/Data/Implementations/Standard/RadarChartData.swift @@ -34,7 +34,7 @@ open class RadarChartData: ChartData super.init() } - public override init(dataSets: [ChartDataSetProtocol]?) + public override init(dataSets: [ChartDataSetProtocol]) { super.init(dataSets: dataSets) } @@ -44,8 +44,8 @@ open class RadarChartData: ChartData super.init(dataSets: elements) } - open override func entryForHighlight(_ highlight: Highlight) -> ChartDataEntry? + @objc open override func entry(for highlight: Highlight) -> ChartDataEntry? { - return getDataSetByIndex(highlight.dataSetIndex)?.entryForIndex(Int(highlight.x)) + return self[highlight.dataSetIndex].entryForIndex(Int(highlight.x)) } } diff --git a/Source/Charts/Data/Implementations/Standard/ScatterChartData.swift b/Source/Charts/Data/Implementations/Standard/ScatterChartData.swift index b30304a1b2..6fbc7bbe3e 100644 --- a/Source/Charts/Data/Implementations/Standard/ScatterChartData.swift +++ b/Source/Charts/Data/Implementations/Standard/ScatterChartData.swift @@ -19,7 +19,7 @@ open class ScatterChartData: BarLineScatterCandleBubbleChartData super.init() } - public override init(dataSets: [ChartDataSetProtocol]?) + public override init(dataSets: [ChartDataSetProtocol]) { super.init(dataSets: dataSets) } diff --git a/Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift b/Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift index 8c6945f9ff..ee017d786a 100644 --- a/Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift +++ b/Source/Charts/Data/Interfaces/ChartDataSetProtocol.swift @@ -20,7 +20,7 @@ public protocol ChartDataSetProtocol /// Use this method to tell the data set that the underlying data has changed func notifyDataSetChanged() - /// Calculates the minimum and maximum x and y values (_xMin, _xMax, _yMin, _yMax). + /// Calculates the minimum and maximum x and y values (xMin, xMax, yMin, yMax). func calcMinMax() /// Calculates the min and max y-values from the Entry closest to the given fromX to the Entry closest to the given toX value. diff --git a/Source/Charts/Highlight/BarHighlighter.swift b/Source/Charts/Highlight/BarHighlighter.swift index 11ecfb631e..21e670d6c7 100644 --- a/Source/Charts/Highlight/BarHighlighter.swift +++ b/Source/Charts/Highlight/BarHighlighter.swift @@ -24,7 +24,7 @@ open class BarHighlighter: ChartHighlighter let pos = getValsForTouch(x: x, y: y) - if let set = barData.getDataSetByIndex(high.dataSetIndex) as? BarChartDataSetProtocol, + if let set = barData[high.dataSetIndex] as? BarChartDataSetProtocol, set.isStacked { return getStackedHighlight(high: high, diff --git a/Source/Charts/Highlight/CombinedHighlighter.swift b/Source/Charts/Highlight/CombinedHighlighter.swift index 7053df09d3..c292ec5515 100644 --- a/Source/Charts/Highlight/CombinedHighlighter.swift +++ b/Source/Charts/Highlight/CombinedHighlighter.swift @@ -48,13 +48,9 @@ open class CombinedHighlighter: ChartHighlighter } else { - for j in 0.. barData.dataSetCount + while _buffers.count > barData.count { _buffers.removeLast() } @@ -164,9 +164,9 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer let barData = dataProvider.barData else { return } - for i in 0 ..< barData.dataSetCount + for i in barData.indices { - guard let set = barData.getDataSetByIndex(i) as? BarChartDataSetProtocol else { + guard let set = barData[i] as? BarChartDataSetProtocol else { fatalError("Datasets for BarChartRenderer must conform to IBarChartDataset") } @@ -551,7 +551,7 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer for high in indices { guard - let set = barData.getDataSetByIndex(high.dataSetIndex) as? BarChartDataSetProtocol, + let set = barData[high.dataSetIndex] as? BarChartDataSetProtocol, set.isHighlightEnabled else { continue } diff --git a/Source/Charts/Renderers/BubbleChartRenderer.swift b/Source/Charts/Renderers/BubbleChartRenderer.swift index 8a70d37eab..e6c7131715 100644 --- a/Source/Charts/Renderers/BubbleChartRenderer.swift +++ b/Source/Charts/Renderers/BubbleChartRenderer.swift @@ -217,7 +217,7 @@ open class BubbleChartRenderer: BarLineScatterCandleBubbleRenderer for high in indices { guard - let dataSet = bubbleData.getDataSetByIndex(high.dataSetIndex) as? BubbleChartDataSetProtocol, + let dataSet = bubbleData[high.dataSetIndex] as? BubbleChartDataSetProtocol, dataSet.isHighlightEnabled, let entry = dataSet.entryForXValue(high.x, closestToY: high.y) as? BubbleChartDataEntry, isInBoundsX(entry: entry, dataSet: dataSet) diff --git a/Source/Charts/Renderers/CandleStickChartRenderer.swift b/Source/Charts/Renderers/CandleStickChartRenderer.swift index 53bd613708..0173e09af1 100644 --- a/Source/Charts/Renderers/CandleStickChartRenderer.swift +++ b/Source/Charts/Renderers/CandleStickChartRenderer.swift @@ -331,7 +331,7 @@ open class CandleStickChartRenderer: LineScatterCandleRadarRenderer for high in indices { guard - let set = candleData.getDataSetByIndex(high.dataSetIndex) as? CandleChartDataSetProtocol, + let set = candleData[high.dataSetIndex] as? CandleChartDataSetProtocol, set.isHighlightEnabled else { continue } diff --git a/Source/Charts/Renderers/HorizontalBarChartRenderer.swift b/Source/Charts/Renderers/HorizontalBarChartRenderer.swift index f95648206a..98df256f1a 100644 --- a/Source/Charts/Renderers/HorizontalBarChartRenderer.swift +++ b/Source/Charts/Renderers/HorizontalBarChartRenderer.swift @@ -37,19 +37,19 @@ open class HorizontalBarChartRenderer: BarChartRenderer if let barData = dataProvider?.barData { // Matche buffers count to dataset count - if _buffers.count != barData.dataSetCount + if _buffers.count != barData.count { - while _buffers.count < barData.dataSetCount + while _buffers.count < barData.count { _buffers.append(Buffer()) } - while _buffers.count > barData.dataSetCount + while _buffers.count > barData.count { _buffers.removeLast() } } - for i in stride(from: 0, to: barData.dataSetCount, by: 1) + for i in barData.indices { let set = barData.dataSets[i] as! BarChartDataSetProtocol let size = set.entryCount * (set.isStacked ? set.stackSize : 1) @@ -314,7 +314,7 @@ open class HorizontalBarChartRenderer: BarChartRenderer var negOffset: CGFloat let drawValueAboveBar = dataProvider.isDrawValueAboveBarEnabled - for dataSetIndex in 0 ..< barData.dataSetCount + for dataSetIndex in barData.indices { guard let dataSet = dataSets[dataSetIndex] as? BarChartDataSetProtocol else { continue } diff --git a/Source/Charts/Renderers/LegendRenderer.swift b/Source/Charts/Renderers/LegendRenderer.swift index e3b39aed3e..10ac1dff1a 100755 --- a/Source/Charts/Renderers/LegendRenderer.swift +++ b/Source/Charts/Renderers/LegendRenderer.swift @@ -42,10 +42,8 @@ open class LegendRenderer: NSObject, Renderer var entries: [LegendEntry] = [] // loop for building up the colors and labels used in the legend - for i in 0..