From 122013e01b700d1aa16a0669aa4500a099acb6e3 Mon Sep 17 00:00:00 2001 From: jjatie Date: Fri, 24 Nov 2017 01:22:02 -0500 Subject: [PATCH] Animator non nil (#2981) * `Animator` is now non-optional in `Renderer` types * Fixed merge with master --- .../Charts/Renderers/BarChartRenderer.swift | 11 ++++------ .../BarLineScatterCandleBubbleRenderer.swift | 4 ++-- .../Renderers/BubbleChartRenderer.swift | 9 +++------ .../Renderers/CandleStickChartRenderer.swift | 13 ++++-------- .../Renderers/ChartDataRendererBase.swift | 8 ++++---- .../Renderers/CombinedChartRenderer.swift | 1 - .../HorizontalBarChartRenderer.swift | 13 ++++-------- .../Charts/Renderers/LineChartRenderer.swift | 20 +++++-------------- .../Charts/Renderers/LineRadarRenderer.swift | 2 +- .../LineScatterCandleRadarRenderer.swift | 2 +- .../Charts/Renderers/PieChartRenderer.swift | 18 +++++------------ .../Charts/Renderers/RadarChartRenderer.swift | 13 ++++-------- .../Renderers/ScatterChartRenderer.swift | 7 ++----- 13 files changed, 39 insertions(+), 82 deletions(-) diff --git a/Source/Charts/Renderers/BarChartRenderer.swift b/Source/Charts/Renderers/BarChartRenderer.swift index 8aa3bc9b0a..40efff56da 100644 --- a/Source/Charts/Renderers/BarChartRenderer.swift +++ b/Source/Charts/Renderers/BarChartRenderer.swift @@ -25,7 +25,7 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer @objc open weak var dataProvider: BarChartDataProvider? - @objc public init(dataProvider: BarChartDataProvider?, animator: Animator?, viewPortHandler: ViewPortHandler?) + @objc public init(dataProvider: BarChartDataProvider?, animator: Animator, viewPortHandler: ViewPortHandler?) { super.init(animator: animator, viewPortHandler: viewPortHandler) @@ -72,8 +72,7 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer { guard let dataProvider = dataProvider, - let barData = dataProvider.barData, - let animator = animator + let barData = dataProvider.barData else { return } let barWidthHalf = barData.barWidth / 2.0 @@ -228,7 +227,6 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer if dataProvider.isDrawBarShadowEnabled { guard - let animator = animator, let barData = dataProvider.barData else { return } @@ -347,7 +345,7 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer rect.size.width = CGFloat(right - left) rect.size.height = CGFloat(bottom - top) - trans.rectValueToPixel(&rect, phaseY: animator?.phaseY ?? 1.0) + trans.rectValueToPixel(&rect, phaseY: animator.phaseY ) } open override func drawValues(context: CGContext) @@ -358,8 +356,7 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer guard let dataProvider = dataProvider, let viewPortHandler = self.viewPortHandler, - let barData = dataProvider.barData, - let animator = animator + let barData = dataProvider.barData else { return } var dataSets = barData.dataSets diff --git a/Source/Charts/Renderers/BarLineScatterCandleBubbleRenderer.swift b/Source/Charts/Renderers/BarLineScatterCandleBubbleRenderer.swift index 5ff9a87305..34fe15e34e 100644 --- a/Source/Charts/Renderers/BarLineScatterCandleBubbleRenderer.swift +++ b/Source/Charts/Renderers/BarLineScatterCandleBubbleRenderer.swift @@ -17,7 +17,7 @@ open class BarLineScatterCandleBubbleRenderer: DataRenderer { internal var _xBounds = XBounds() // Reusable XBounds object - public override init(animator: Animator?, viewPortHandler: ViewPortHandler?) + public override init(animator: Animator, viewPortHandler: ViewPortHandler?) { super.init(animator: animator, viewPortHandler: viewPortHandler) } @@ -26,7 +26,7 @@ open class BarLineScatterCandleBubbleRenderer: DataRenderer @objc internal func isInBoundsX(entry e: ChartDataEntry, dataSet: IBarLineScatterCandleBubbleChartDataSet) -> Bool { let entryIndex = dataSet.entryIndex(entry: e) - return Double(entryIndex) < Double(dataSet.entryCount) * (animator?.phaseX ?? 1.0) + return Double(entryIndex) < Double(dataSet.entryCount) * animator.phaseX } /// Calculates and returns the x-bounds for the given DataSet in terms of index in their values array. diff --git a/Source/Charts/Renderers/BubbleChartRenderer.swift b/Source/Charts/Renderers/BubbleChartRenderer.swift index d77311c459..00be34c54e 100644 --- a/Source/Charts/Renderers/BubbleChartRenderer.swift +++ b/Source/Charts/Renderers/BubbleChartRenderer.swift @@ -21,7 +21,7 @@ open class BubbleChartRenderer: BarLineScatterCandleBubbleRenderer { @objc open weak var dataProvider: BubbleChartDataProvider? - @objc public init(dataProvider: BubbleChartDataProvider?, animator: Animator?, viewPortHandler: ViewPortHandler?) + @objc public init(dataProvider: BubbleChartDataProvider?, animator: Animator, viewPortHandler: ViewPortHandler?) { super.init(animator: animator, viewPortHandler: viewPortHandler) @@ -61,8 +61,7 @@ open class BubbleChartRenderer: BarLineScatterCandleBubbleRenderer { guard let dataProvider = dataProvider, - let viewPortHandler = self.viewPortHandler, - let animator = animator + let viewPortHandler = self.viewPortHandler else { return } let trans = dataProvider.getTransformer(forAxis: dataSet.axisDependency) @@ -129,7 +128,6 @@ open class BubbleChartRenderer: BarLineScatterCandleBubbleRenderer let dataProvider = dataProvider, let viewPortHandler = self.viewPortHandler, let bubbleData = dataProvider.bubbleData, - let animator = animator, isDrawingValuesAllowed(dataProvider: dataProvider), let dataSets = bubbleData.dataSets as? [IBubbleChartDataSet] else { return } @@ -218,8 +216,7 @@ open class BubbleChartRenderer: BarLineScatterCandleBubbleRenderer guard let dataProvider = dataProvider, let viewPortHandler = self.viewPortHandler, - let bubbleData = dataProvider.bubbleData, - let animator = animator + let bubbleData = dataProvider.bubbleData else { return } context.saveGState() diff --git a/Source/Charts/Renderers/CandleStickChartRenderer.swift b/Source/Charts/Renderers/CandleStickChartRenderer.swift index 2b897aadf9..2b2e2a17e2 100644 --- a/Source/Charts/Renderers/CandleStickChartRenderer.swift +++ b/Source/Charts/Renderers/CandleStickChartRenderer.swift @@ -21,7 +21,7 @@ open class CandleStickChartRenderer: LineScatterCandleRadarRenderer { @objc open weak var dataProvider: CandleChartDataProvider? - @objc public init(dataProvider: CandleChartDataProvider?, animator: Animator?, viewPortHandler: ViewPortHandler?) + @objc public init(dataProvider: CandleChartDataProvider?, animator: Animator, viewPortHandler: ViewPortHandler?) { super.init(animator: animator, viewPortHandler: viewPortHandler) @@ -50,10 +50,7 @@ open class CandleStickChartRenderer: LineScatterCandleRadarRenderer @objc open func drawDataSet(context: CGContext, dataSet: ICandleChartDataSet) { - guard let - dataProvider = dataProvider, - let animator = animator - else { return } + guard let dataProvider = dataProvider else { return } let trans = dataProvider.getTransformer(forAxis: dataSet.axisDependency) @@ -240,8 +237,7 @@ open class CandleStickChartRenderer: LineScatterCandleRadarRenderer guard let dataProvider = dataProvider, let viewPortHandler = self.viewPortHandler, - let candleData = dataProvider.candleData, - let animator = animator + let candleData = dataProvider.candleData else { return } // if values are drawn @@ -332,8 +328,7 @@ open class CandleStickChartRenderer: LineScatterCandleRadarRenderer { guard let dataProvider = dataProvider, - let candleData = dataProvider.candleData, - let animator = animator + let candleData = dataProvider.candleData else { return } context.saveGState() diff --git a/Source/Charts/Renderers/ChartDataRendererBase.swift b/Source/Charts/Renderers/ChartDataRendererBase.swift index 8204de05b7..54cf64c273 100644 --- a/Source/Charts/Renderers/ChartDataRendererBase.swift +++ b/Source/Charts/Renderers/ChartDataRendererBase.swift @@ -15,13 +15,13 @@ import CoreGraphics @objc(ChartDataRendererBase) open class DataRenderer: Renderer { - @objc open var animator: Animator? + @objc open let animator: Animator - @objc public init(animator: Animator?, viewPortHandler: ViewPortHandler?) + @objc public init(animator: Animator, viewPortHandler: ViewPortHandler?) { - super.init(viewPortHandler: viewPortHandler) - self.animator = animator + + super.init(viewPortHandler: viewPortHandler) } @objc open func drawData(context: CGContext) diff --git a/Source/Charts/Renderers/CombinedChartRenderer.swift b/Source/Charts/Renderers/CombinedChartRenderer.swift index 72cb1f14d2..72d5ab85b3 100644 --- a/Source/Charts/Renderers/CombinedChartRenderer.swift +++ b/Source/Charts/Renderers/CombinedChartRenderer.swift @@ -42,7 +42,6 @@ open class CombinedChartRenderer: DataRenderer guard let chart = chart, - let animator = animator, let viewPortHandler = self.viewPortHandler else { return } diff --git a/Source/Charts/Renderers/HorizontalBarChartRenderer.swift b/Source/Charts/Renderers/HorizontalBarChartRenderer.swift index 2de854df43..2167d989bf 100644 --- a/Source/Charts/Renderers/HorizontalBarChartRenderer.swift +++ b/Source/Charts/Renderers/HorizontalBarChartRenderer.swift @@ -24,7 +24,7 @@ open class HorizontalBarChartRenderer: BarChartRenderer var rects = [CGRect]() } - public override init(dataProvider: BarChartDataProvider?, animator: Animator?, viewPortHandler: ViewPortHandler?) + public override init(dataProvider: BarChartDataProvider?, animator: Animator, viewPortHandler: ViewPortHandler?) { super.init(dataProvider: dataProvider, animator: animator, viewPortHandler: viewPortHandler) } @@ -69,8 +69,7 @@ open class HorizontalBarChartRenderer: BarChartRenderer { guard let dataProvider = dataProvider, - let barData = dataProvider.barData, - let animator = animator + let barData = dataProvider.barData else { return } let barWidthHalf = barData.barWidth / 2.0 @@ -201,10 +200,7 @@ open class HorizontalBarChartRenderer: BarChartRenderer // draw the bar shadow before the values if dataProvider.isDrawBarShadowEnabled { - guard - let animator = animator, - let barData = dataProvider.barData - else { return } + guard let barData = dataProvider.barData else { return } let barWidth = barData.barWidth let barWidthHalf = barWidth / 2.0 @@ -299,7 +295,7 @@ open class HorizontalBarChartRenderer: BarChartRenderer rect.size.width = CGFloat(right - left) rect.size.height = CGFloat(bottom - top) - trans.rectValueToPixelHorizontal(&rect, phaseY: animator?.phaseY ?? 1.0) + trans.rectValueToPixelHorizontal(&rect, phaseY: animator.phaseY) } open override func drawValues(context: CGContext) @@ -310,7 +306,6 @@ open class HorizontalBarChartRenderer: BarChartRenderer guard let dataProvider = dataProvider, let barData = dataProvider.barData, - let animator = animator, let viewPortHandler = self.viewPortHandler else { return } diff --git a/Source/Charts/Renderers/LineChartRenderer.swift b/Source/Charts/Renderers/LineChartRenderer.swift index fbb1f7be30..1f0b20c94b 100644 --- a/Source/Charts/Renderers/LineChartRenderer.swift +++ b/Source/Charts/Renderers/LineChartRenderer.swift @@ -21,7 +21,7 @@ open class LineChartRenderer: LineRadarRenderer { @objc open weak var dataProvider: LineChartDataProvider? - @objc public init(dataProvider: LineChartDataProvider?, animator: Animator?, viewPortHandler: ViewPortHandler?) + @objc public init(dataProvider: LineChartDataProvider?, animator: Animator, viewPortHandler: ViewPortHandler?) { super.init(animator: animator, viewPortHandler: viewPortHandler) @@ -86,10 +86,7 @@ open class LineChartRenderer: LineRadarRenderer @objc open func drawCubicBezier(context: CGContext, dataSet: ILineChartDataSet) { - guard - let dataProvider = dataProvider, - let animator = animator - else { return } + guard let dataProvider = dataProvider else { return } let trans = dataProvider.getTransformer(forAxis: dataSet.axisDependency) @@ -183,10 +180,7 @@ open class LineChartRenderer: LineRadarRenderer @objc open func drawHorizontalBezier(context: CGContext, dataSet: ILineChartDataSet) { - guard - let dataProvider = dataProvider, - let animator = animator - else { return } + guard let dataProvider = dataProvider else { return } let trans = dataProvider.getTransformer(forAxis: dataSet.axisDependency) @@ -294,7 +288,6 @@ open class LineChartRenderer: LineRadarRenderer { guard let dataProvider = dataProvider, - let animator = animator, let viewPortHandler = self.viewPortHandler else { return } @@ -465,7 +458,7 @@ open class LineChartRenderer: LineRadarRenderer /// Generates the path that is used for filled drawing. fileprivate func generateFilledPath(dataSet: ILineChartDataSet, fillMin: CGFloat, bounds: XBounds, matrix: CGAffineTransform) -> CGPath { - let phaseY = animator?.phaseY ?? 1.0 + let phaseY = animator.phaseY let isDrawSteppedEnabled = dataSet.mode == .stepped let matrix = matrix @@ -510,7 +503,6 @@ open class LineChartRenderer: LineRadarRenderer guard let dataProvider = dataProvider, let lineData = dataProvider.lineData, - let animator = animator, let viewPortHandler = self.viewPortHandler else { return } @@ -606,7 +598,6 @@ open class LineChartRenderer: LineRadarRenderer guard let dataProvider = dataProvider, let lineData = dataProvider.lineData, - let animator = animator, let viewPortHandler = self.viewPortHandler else { return } @@ -714,8 +705,7 @@ open class LineChartRenderer: LineRadarRenderer { guard let dataProvider = dataProvider, - let lineData = dataProvider.lineData, - let animator = animator + let lineData = dataProvider.lineData else { return } let chartXMax = dataProvider.chartXMax diff --git a/Source/Charts/Renderers/LineRadarRenderer.swift b/Source/Charts/Renderers/LineRadarRenderer.swift index 8616ec3a01..c25d4019ee 100644 --- a/Source/Charts/Renderers/LineRadarRenderer.swift +++ b/Source/Charts/Renderers/LineRadarRenderer.swift @@ -15,7 +15,7 @@ import CoreGraphics @objc(LineRadarChartRenderer) open class LineRadarRenderer: LineScatterCandleRadarRenderer { - public override init(animator: Animator?, viewPortHandler: ViewPortHandler?) + public override init(animator: Animator, viewPortHandler: ViewPortHandler?) { super.init(animator: animator, viewPortHandler: viewPortHandler) } diff --git a/Source/Charts/Renderers/LineScatterCandleRadarRenderer.swift b/Source/Charts/Renderers/LineScatterCandleRadarRenderer.swift index 2d3379960d..f74ff23d37 100644 --- a/Source/Charts/Renderers/LineScatterCandleRadarRenderer.swift +++ b/Source/Charts/Renderers/LineScatterCandleRadarRenderer.swift @@ -15,7 +15,7 @@ import CoreGraphics @objc(LineScatterCandleRadarChartRenderer) open class LineScatterCandleRadarRenderer: BarLineScatterCandleBubbleRenderer { - public override init(animator: Animator?, viewPortHandler: ViewPortHandler?) + public override init(animator: Animator, viewPortHandler: ViewPortHandler?) { super.init(animator: animator, viewPortHandler: viewPortHandler) } diff --git a/Source/Charts/Renderers/PieChartRenderer.swift b/Source/Charts/Renderers/PieChartRenderer.swift index 327cbc8503..92489b1245 100755 --- a/Source/Charts/Renderers/PieChartRenderer.swift +++ b/Source/Charts/Renderers/PieChartRenderer.swift @@ -21,7 +21,7 @@ open class PieChartRenderer: DataRenderer { @objc open weak var chart: PieChartView? - @objc public init(chart: PieChartView?, animator: Animator?, viewPortHandler: ViewPortHandler?) + @objc public init(chart: PieChartView?, animator: Animator, viewPortHandler: ViewPortHandler?) { super.init(animator: animator, viewPortHandler: viewPortHandler) @@ -108,10 +108,7 @@ open class PieChartRenderer: DataRenderer @objc open func drawDataSet(context: CGContext, dataSet: IPieChartDataSet) { - guard - let chart = chart, - let animator = animator - else {return } + guard let chart = chart else {return } var angle: CGFloat = 0.0 let rotationAngle = chart.rotationAngle @@ -262,8 +259,7 @@ open class PieChartRenderer: DataRenderer { guard let chart = chart, - let data = chart.data, - let animator = animator + let data = chart.data else { return } let center = chart.centerCircleBox @@ -559,10 +555,7 @@ open class PieChartRenderer: DataRenderer /// draws the hole in the center of the chart and the transparent circle / hole fileprivate func drawHole(context: CGContext) { - guard - let chart = chart, - let animator = animator - else { return } + guard let chart = chart else { return } if chart.drawHoleEnabled { @@ -668,8 +661,7 @@ open class PieChartRenderer: DataRenderer { guard let chart = chart, - let data = chart.data, - let animator = animator + let data = chart.data else { return } context.saveGState() diff --git a/Source/Charts/Renderers/RadarChartRenderer.swift b/Source/Charts/Renderers/RadarChartRenderer.swift index 57068555f7..d7b1c8b521 100644 --- a/Source/Charts/Renderers/RadarChartRenderer.swift +++ b/Source/Charts/Renderers/RadarChartRenderer.swift @@ -21,7 +21,7 @@ open class RadarChartRenderer: LineRadarRenderer { @objc open weak var chart: RadarChartView? - @objc public init(chart: RadarChartView?, animator: Animator?, viewPortHandler: ViewPortHandler?) + @objc public init(chart: RadarChartView?, animator: Animator, viewPortHandler: ViewPortHandler?) { super.init(animator: animator, viewPortHandler: viewPortHandler) @@ -55,10 +55,7 @@ open class RadarChartRenderer: LineRadarRenderer /// - parameter mostEntries: the entry count of the dataset with the most entries @objc internal func drawDataSet(context: CGContext, dataSet: IRadarChartDataSet, mostEntries: Int) { - guard let - chart = chart, - let animator = animator - else { return } + guard let chart = chart else { return } context.saveGState() @@ -141,8 +138,7 @@ open class RadarChartRenderer: LineRadarRenderer { guard let chart = chart, - let data = chart.data, - let animator = animator + let data = chart.data else { return } let phaseX = animator.phaseX @@ -299,8 +295,7 @@ open class RadarChartRenderer: LineRadarRenderer { guard let chart = chart, - let radarData = chart.data as? RadarChartData, - let animator = animator + let radarData = chart.data as? RadarChartData else { return } context.saveGState() diff --git a/Source/Charts/Renderers/ScatterChartRenderer.swift b/Source/Charts/Renderers/ScatterChartRenderer.swift index c9148caa7b..e8ce83cd24 100644 --- a/Source/Charts/Renderers/ScatterChartRenderer.swift +++ b/Source/Charts/Renderers/ScatterChartRenderer.swift @@ -21,7 +21,7 @@ open class ScatterChartRenderer: LineScatterCandleRadarRenderer { @objc open weak var dataProvider: ScatterChartDataProvider? - @objc public init(dataProvider: ScatterChartDataProvider?, animator: Animator?, viewPortHandler: ViewPortHandler?) + @objc public init(dataProvider: ScatterChartDataProvider?, animator: Animator, viewPortHandler: ViewPortHandler?) { super.init(animator: animator, viewPortHandler: viewPortHandler) @@ -54,7 +54,6 @@ open class ScatterChartRenderer: LineScatterCandleRadarRenderer { guard let dataProvider = dataProvider, - let animator = animator, let viewPortHandler = self.viewPortHandler else { return } @@ -107,7 +106,6 @@ open class ScatterChartRenderer: LineScatterCandleRadarRenderer guard let dataProvider = dataProvider, let scatterData = dataProvider.scatterData, - let animator = animator, let viewPortHandler = self.viewPortHandler else { return } @@ -204,8 +202,7 @@ open class ScatterChartRenderer: LineScatterCandleRadarRenderer { guard let dataProvider = dataProvider, - let scatterData = dataProvider.scatterData, - let animator = animator + let scatterData = dataProvider.scatterData else { return } context.saveGState()