Skip to content

Commit

Permalink
Animator non nil (#2981)
Browse files Browse the repository at this point in the history
* `Animator` is now non-optional in `Renderer` types

* Fixed merge with master
  • Loading branch information
jjatie authored and liuxuan30 committed Nov 24, 2017
1 parent bc40b16 commit 122013e
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 82 deletions.
11 changes: 4 additions & 7 deletions Source/Charts/Renderers/BarChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -228,7 +227,6 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer
if dataProvider.isDrawBarShadowEnabled
{
guard
let animator = animator,
let barData = dataProvider.barData
else { return }

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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.
Expand Down
9 changes: 3 additions & 6 deletions Source/Charts/Renderers/BubbleChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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()
Expand Down
13 changes: 4 additions & 9 deletions Source/Charts/Renderers/CandleStickChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions Source/Charts/Renderers/ChartDataRendererBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion Source/Charts/Renderers/CombinedChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ open class CombinedChartRenderer: DataRenderer

guard let
chart = chart,
let animator = animator,
let viewPortHandler = self.viewPortHandler
else { return }

Expand Down
13 changes: 4 additions & 9 deletions Source/Charts/Renderers/HorizontalBarChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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 }

Expand Down
20 changes: 5 additions & 15 deletions Source/Charts/Renderers/LineChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -294,7 +288,6 @@ open class LineChartRenderer: LineRadarRenderer
{
guard
let dataProvider = dataProvider,
let animator = animator,
let viewPortHandler = self.viewPortHandler
else { return }

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 }

Expand Down Expand Up @@ -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 }

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Source/Charts/Renderers/LineRadarRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
18 changes: 5 additions & 13 deletions Source/Charts/Renderers/PieChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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()
Expand Down
Loading

0 comments on commit 122013e

Please sign in to comment.