Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed redundant ivars in BarLineChartViewBase #3043

Merged
merged 4 commits into from
Dec 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Source/Charts/Charts/BarChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ open class BarChartView: BarLineChartViewBase, BarChartDataProvider
}

// calculate axis range (min / max) according to provided data
_leftAxis.calculate(
leftAxis.calculate(
min: data.getYMin(axis: .left),
max: data.getYMax(axis: .left))
_rightAxis.calculate(
rightAxis.calculate(
min: data.getYMin(axis: .right),
max: data.getYMax(axis: .right))
}
Expand Down
171 changes: 67 additions & 104 deletions Source/Charts/Charts/BarLineChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,28 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
/// **default**: false
@objc open var keepPositionOnRotation: Bool = false

/// the object representing the left y-axis
internal var _leftAxis: YAxis!
/// The left y-axis object. In the horizontal bar-chart, this is the
/// top axis.
@objc open internal(set) var leftAxis = YAxis(position: .left)

/// the object representing the right y-axis
internal var _rightAxis: YAxis!
/// The right y-axis object. In the horizontal bar-chart, this is the
/// bottom axis.
@objc open internal(set) var rightAxis = YAxis(position: .right)

/// The left Y axis renderer. This is a read-write property so you can set your own custom renderer here.
/// **default**: An instance of YAxisRenderer
@objc open lazy var leftYAxisRenderer = YAxisRenderer(viewPortHandler: _viewPortHandler, yAxis: leftAxis, transformer: _leftAxisTransformer)

internal var _leftYAxisRenderer: YAxisRenderer!
internal var _rightYAxisRenderer: YAxisRenderer!
/// The right Y axis renderer. This is a read-write property so you can set your own custom renderer here.
/// **default**: An instance of YAxisRenderer
@objc open lazy var rightYAxisRenderer = YAxisRenderer(viewPortHandler: _viewPortHandler, yAxis: rightAxis, transformer: _rightAxisTransformer)

internal var _leftAxisTransformer: Transformer!
internal var _rightAxisTransformer: Transformer!

internal var _xAxisRenderer: XAxisRenderer!
/// The X axis renderer. This is a read-write property so you can set your own custom renderer here.
/// **default**: An instance of XAxisRenderer
@objc open lazy var xAxisRenderer = XAxisRenderer(viewPortHandler: _viewPortHandler, xAxis: _xAxis, transformer: _leftAxisTransformer)

internal var _tapGestureRecognizer: NSUITapGestureRecognizer!
internal var _doubleTapGestureRecognizer: NSUITapGestureRecognizer!
Expand Down Expand Up @@ -99,18 +108,10 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
internal override func initialize()
{
super.initialize()

_leftAxis = YAxis(position: .left)
_rightAxis = YAxis(position: .right)


_leftAxisTransformer = Transformer(viewPortHandler: _viewPortHandler)
_rightAxisTransformer = Transformer(viewPortHandler: _viewPortHandler)

_leftYAxisRenderer = YAxisRenderer(viewPortHandler: _viewPortHandler, yAxis: _leftAxis, transformer: _leftAxisTransformer)
_rightYAxisRenderer = YAxisRenderer(viewPortHandler: _viewPortHandler, yAxis: _rightAxis, transformer: _rightAxisTransformer)

_xAxisRenderer = XAxisRenderer(viewPortHandler: _viewPortHandler, xAxis: _xAxis, transformer: _leftAxisTransformer)

self.highlighter = ChartHighlighter(chart: self)

_tapGestureRecognizer = NSUITapGestureRecognizer(target: self, action: #selector(tapGestureRecognized(_:)))
Expand Down Expand Up @@ -178,43 +179,43 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
autoScale()
}

if _leftAxis.isEnabled
if leftAxis.isEnabled
{
_leftYAxisRenderer?.computeAxis(min: _leftAxis._axisMinimum, max: _leftAxis._axisMaximum, inverted: _leftAxis.isInverted)
leftYAxisRenderer.computeAxis(min: leftAxis._axisMinimum, max: leftAxis._axisMaximum, inverted: leftAxis.isInverted)
}

if _rightAxis.isEnabled
if rightAxis.isEnabled
{
_rightYAxisRenderer?.computeAxis(min: _rightAxis._axisMinimum, max: _rightAxis._axisMaximum, inverted: _rightAxis.isInverted)
rightYAxisRenderer.computeAxis(min: rightAxis._axisMinimum, max: rightAxis._axisMaximum, inverted: rightAxis.isInverted)
}

if _xAxis.isEnabled
{
_xAxisRenderer?.computeAxis(min: _xAxis._axisMinimum, max: _xAxis._axisMaximum, inverted: false)
xAxisRenderer.computeAxis(min: _xAxis._axisMinimum, max: _xAxis._axisMaximum, inverted: false)
}

_xAxisRenderer?.renderAxisLine(context: context)
_leftYAxisRenderer?.renderAxisLine(context: context)
_rightYAxisRenderer?.renderAxisLine(context: context)
xAxisRenderer.renderAxisLine(context: context)
leftYAxisRenderer.renderAxisLine(context: context)
rightYAxisRenderer.renderAxisLine(context: context)

// The renderers are responsible for clipping, to account for line-width center etc.
_xAxisRenderer?.renderGridLines(context: context)
_leftYAxisRenderer?.renderGridLines(context: context)
_rightYAxisRenderer?.renderGridLines(context: context)
xAxisRenderer.renderGridLines(context: context)
leftYAxisRenderer.renderGridLines(context: context)
rightYAxisRenderer.renderGridLines(context: context)

if _xAxis.isEnabled && _xAxis.isDrawLimitLinesBehindDataEnabled
{
_xAxisRenderer?.renderLimitLines(context: context)
xAxisRenderer.renderLimitLines(context: context)
}

if _leftAxis.isEnabled && _leftAxis.isDrawLimitLinesBehindDataEnabled
if leftAxis.isEnabled && leftAxis.isDrawLimitLinesBehindDataEnabled
{
_leftYAxisRenderer?.renderLimitLines(context: context)
leftYAxisRenderer.renderLimitLines(context: context)
}

if _rightAxis.isEnabled && _rightAxis.isDrawLimitLinesBehindDataEnabled
if rightAxis.isEnabled && rightAxis.isDrawLimitLinesBehindDataEnabled
{
_rightYAxisRenderer?.renderLimitLines(context: context)
rightYAxisRenderer.renderLimitLines(context: context)
}

// make sure the data cannot be drawn outside the content-rect
Expand All @@ -234,22 +235,22 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD

if _xAxis.isEnabled && !_xAxis.isDrawLimitLinesBehindDataEnabled
{
_xAxisRenderer?.renderLimitLines(context: context)
xAxisRenderer.renderLimitLines(context: context)
}

if _leftAxis.isEnabled && !_leftAxis.isDrawLimitLinesBehindDataEnabled
if leftAxis.isEnabled && !leftAxis.isDrawLimitLinesBehindDataEnabled
{
_leftYAxisRenderer?.renderLimitLines(context: context)
leftYAxisRenderer.renderLimitLines(context: context)
}

if _rightAxis.isEnabled && !_rightAxis.isDrawLimitLinesBehindDataEnabled
if rightAxis.isEnabled && !rightAxis.isDrawLimitLinesBehindDataEnabled
{
_rightYAxisRenderer?.renderLimitLines(context: context)
rightYAxisRenderer.renderLimitLines(context: context)
}

_xAxisRenderer.renderAxisLabels(context: context)
_leftYAxisRenderer.renderAxisLabels(context: context)
_rightYAxisRenderer.renderAxisLabels(context: context)
xAxisRenderer.renderAxisLabels(context: context)
leftYAxisRenderer.renderAxisLabels(context: context)
rightYAxisRenderer.renderAxisLabels(context: context)

if clipValuesToContentEnabled
{
Expand Down Expand Up @@ -287,29 +288,29 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD

// calculate axis range (min / max) according to provided data

if _leftAxis.isEnabled
if leftAxis.isEnabled
{
_leftAxis.calculate(min: data.getYMin(axis: .left), max: data.getYMax(axis: .left))
leftAxis.calculate(min: data.getYMin(axis: .left), max: data.getYMax(axis: .left))
}

if _rightAxis.isEnabled
if rightAxis.isEnabled
{
_rightAxis.calculate(min: data.getYMin(axis: .right), max: data.getYMax(axis: .right))
rightAxis.calculate(min: data.getYMin(axis: .right), max: data.getYMax(axis: .right))
}

calculateOffsets()
}

internal func prepareValuePxMatrix()
{
_rightAxisTransformer.prepareMatrixValuePx(chartXMin: _xAxis._axisMinimum, deltaX: CGFloat(xAxis.axisRange), deltaY: CGFloat(_rightAxis.axisRange), chartYMin: _rightAxis._axisMinimum)
_leftAxisTransformer.prepareMatrixValuePx(chartXMin: xAxis._axisMinimum, deltaX: CGFloat(xAxis.axisRange), deltaY: CGFloat(_leftAxis.axisRange), chartYMin: _leftAxis._axisMinimum)
_rightAxisTransformer.prepareMatrixValuePx(chartXMin: _xAxis._axisMinimum, deltaX: CGFloat(xAxis.axisRange), deltaY: CGFloat(rightAxis.axisRange), chartYMin: rightAxis._axisMinimum)
_leftAxisTransformer.prepareMatrixValuePx(chartXMin: xAxis._axisMinimum, deltaX: CGFloat(xAxis.axisRange), deltaY: CGFloat(leftAxis.axisRange), chartYMin: leftAxis._axisMinimum)
}

internal func prepareOffsetMatrix()
{
_rightAxisTransformer.prepareMatrixOffset(inverted: _rightAxis.isInverted)
_leftAxisTransformer.prepareMatrixOffset(inverted: _leftAxis.isInverted)
_rightAxisTransformer.prepareMatrixOffset(inverted: rightAxis.isInverted)
_leftAxisTransformer.prepareMatrixOffset(inverted: leftAxis.isInverted)
}

open override func notifyDataSetChanged()
Expand All @@ -318,12 +319,12 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD

calcMinMax()

_leftYAxisRenderer?.computeAxis(min: _leftAxis._axisMinimum, max: _leftAxis._axisMaximum, inverted: _leftAxis.isInverted)
_rightYAxisRenderer?.computeAxis(min: _rightAxis._axisMinimum, max: _rightAxis._axisMaximum, inverted: _rightAxis.isInverted)
leftYAxisRenderer.computeAxis(min: leftAxis._axisMinimum, max: leftAxis._axisMaximum, inverted: leftAxis.isInverted)
rightYAxisRenderer.computeAxis(min: rightAxis._axisMinimum, max: rightAxis._axisMaximum, inverted: rightAxis.isInverted)

if let data = _data
{
_xAxisRenderer?.computeAxis(
xAxisRenderer.computeAxis(
min: _xAxis._axisMinimum,
max: _xAxis._axisMaximum,
inverted: false)
Expand All @@ -345,8 +346,8 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
_xAxis.calculate(min: _data?.xMin ?? 0.0, max: _data?.xMax ?? 0.0)

// calculate axis range (min / max) according to provided data
_leftAxis.calculate(min: _data?.getYMin(axis: .left) ?? 0.0, max: _data?.getYMax(axis: .left) ?? 0.0)
_rightAxis.calculate(min: _data?.getYMin(axis: .right) ?? 0.0, max: _data?.getYMax(axis: .right) ?? 0.0)
leftAxis.calculate(min: _data?.getYMin(axis: .left) ?? 0.0, max: _data?.getYMax(axis: .left) ?? 0.0)
rightAxis.calculate(min: _data?.getYMin(axis: .right) ?? 0.0, max: _data?.getYMax(axis: .right) ?? 0.0)
}

internal func calculateLegendOffsets(offsetLeft: inout CGFloat, offsetTop: inout CGFloat, offsetRight: inout CGFloat, offsetBottom: inout CGFloat)
Expand Down Expand Up @@ -1716,28 +1717,17 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
/// if the chart is fully zoomed out, return true
@objc open var isFullyZoomedOut: Bool { return _viewPortHandler.isFullyZoomedOut }

/// - returns: The left y-axis object. In the horizontal bar-chart, this is the
/// top axis.
@objc open var leftAxis: YAxis
{
return _leftAxis
}

/// - returns: The right y-axis object. In the horizontal bar-chart, this is the
/// bottom axis.
@objc open var rightAxis: YAxis { return _rightAxis }

/// - returns: The y-axis object to the corresponding AxisDependency. In the
/// horizontal bar-chart, LEFT == top, RIGHT == BOTTOM
@objc open func getAxis(_ axis: YAxis.AxisDependency) -> YAxis
{
if axis == .left
{
return _leftAxis
return leftAxis
}
else
{
return _rightAxis
return rightAxis
}
}

Expand Down Expand Up @@ -1781,33 +1771,6 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
/// - returns: `true` if both drag offsets (x and y) are zero or smaller.
@objc open var hasNoDragOffset: Bool { return _viewPortHandler.hasNoDragOffset }

/// The X axis renderer. This is a read-write property so you can set your own custom renderer here.
/// **default**: An instance of XAxisRenderer
/// - returns: The current set X axis renderer
@objc open var xAxisRenderer: XAxisRenderer
{
get { return _xAxisRenderer }
set { _xAxisRenderer = newValue }
}

/// The left Y axis renderer. This is a read-write property so you can set your own custom renderer here.
/// **default**: An instance of YAxisRenderer
/// - returns: The current set left Y axis renderer
@objc open var leftYAxisRenderer: YAxisRenderer
{
get { return _leftYAxisRenderer }
set { _leftYAxisRenderer = newValue }
}

/// The right Y axis renderer. This is a read-write property so you can set your own custom renderer here.
/// **default**: An instance of YAxisRenderer
/// - returns: The current set right Y axis renderer
@objc open var rightYAxisRenderer: YAxisRenderer
{
get { return _rightYAxisRenderer }
set { _rightYAxisRenderer = newValue }
}

open override var chartYMax: Double
{
return max(leftAxis._axisMaximum, rightAxis._axisMaximum)
Expand All @@ -1821,7 +1784,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
/// - returns: `true` if either the left or the right or both axes are inverted.
@objc open var isAnyAxisInverted: Bool
{
return _leftAxis.isInverted || _rightAxis.isInverted
return leftAxis.isInverted || rightAxis.isInverted
}

/// flag that indicates if auto scaling on the y axis is enabled.
Expand All @@ -1841,11 +1804,11 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
{
if axis == .left
{
_leftAxis.minWidth = width
leftAxis.minWidth = width
}
else
{
_rightAxis.minWidth = width
rightAxis.minWidth = width
}
}

Expand All @@ -1855,11 +1818,11 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
{
if axis == .left
{
return _leftAxis.minWidth
return leftAxis.minWidth
}
else
{
return _rightAxis.minWidth
return rightAxis.minWidth
}
}
/// Sets a maximum width to the specified y axis.
Expand All @@ -1868,11 +1831,11 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
{
if axis == .left
{
_leftAxis.maxWidth = width
leftAxis.maxWidth = width
}
else
{
_rightAxis.maxWidth = width
rightAxis.maxWidth = width
}
}

Expand All @@ -1884,11 +1847,11 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
{
if axis == .left
{
return _leftAxis.maxWidth
return leftAxis.maxWidth
}
else
{
return _rightAxis.maxWidth
return rightAxis.maxWidth
}
}

Expand All @@ -1897,11 +1860,11 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD
{
if axis == .left
{
return _leftAxis.requiredSize().width
return leftAxis.requiredSize().width
}
else
{
return _rightAxis.requiredSize().width
return rightAxis.requiredSize().width
}
}

Expand Down
Loading