diff --git a/Source/Charts/Animation/Animator.swift b/Source/Charts/Animation/Animator.swift index cec0987572..042012b1ba 100644 --- a/Source/Charts/Animation/Animator.swift +++ b/Source/Charts/Animation/Animator.swift @@ -39,23 +39,23 @@ open class Animator: NSObject /// the phase that is animated and influences the drawn values on the y-axis @objc open var phaseY: Double = 1.0 - fileprivate var _startTimeX: TimeInterval = 0.0 - fileprivate var _startTimeY: TimeInterval = 0.0 - fileprivate var _displayLink: NSUIDisplayLink? + private var _startTimeX: TimeInterval = 0.0 + private var _startTimeY: TimeInterval = 0.0 + private var _displayLink: NSUIDisplayLink? - fileprivate var _durationX: TimeInterval = 0.0 - fileprivate var _durationY: TimeInterval = 0.0 + private var _durationX: TimeInterval = 0.0 + private var _durationY: TimeInterval = 0.0 - fileprivate var _endTimeX: TimeInterval = 0.0 - fileprivate var _endTimeY: TimeInterval = 0.0 - fileprivate var _endTime: TimeInterval = 0.0 + private var _endTimeX: TimeInterval = 0.0 + private var _endTimeY: TimeInterval = 0.0 + private var _endTime: TimeInterval = 0.0 - fileprivate var _enabledX: Bool = false - fileprivate var _enabledY: Bool = false - - fileprivate var _easingX: ChartEasingFunctionBlock? - fileprivate var _easingY: ChartEasingFunctionBlock? + private var _enabledX: Bool = false + private var _enabledY: Bool = false + private var _easingX: ChartEasingFunctionBlock? + private var _easingY: ChartEasingFunctionBlock? + public override init() { super.init() @@ -68,11 +68,10 @@ open class Animator: NSObject @objc open func stop() { - guard let _displayLink = _displayLink else { - return - } - _displayLink.remove(from: RunLoop.main, forMode: RunLoopMode.commonModes) - self._displayLink = nil + guard _displayLink != nil else { return } + + _displayLink?.remove(from: .main, forMode: .commonModes) + _displayLink = nil _enabledX = false _enabledY = false @@ -91,7 +90,7 @@ open class Animator: NSObject stopBlock?() } - fileprivate func updateAnimationPhases(_ currentTime: TimeInterval) + private func updateAnimationPhases(_ currentTime: TimeInterval) { if _enabledX { @@ -103,7 +102,7 @@ open class Animator: NSObject elapsed = duration } - phaseX = _easingX?(elapsed, duration) ?? Double(elapsed / duration) + phaseX = _easingX?(elapsed, duration) ?? elapsed / duration } if _enabledY @@ -115,26 +114,18 @@ open class Animator: NSObject { elapsed = duration } - - if let _easingY = _easingY - { - phaseY = _easingY(elapsed, duration) - } - else - { - phaseY = Double(elapsed / duration) - } + + phaseY = _easingY?(elapsed, duration) ?? elapsed / duration } } - @objc fileprivate func animationLoop() + @objc private func animationLoop() { let currentTime: TimeInterval = CACurrentMediaTime() updateAnimationPhases(currentTime) delegate?.animatorUpdated(self) - updateBlock?() if currentTime >= _endTime @@ -202,20 +193,11 @@ open class Animator: NSObject /// - parameter xAxisDuration: duration for animating the x axis /// - parameter yAxisDuration: duration for animating the y axis /// - parameter easingOption: the easing function for the animation - @objc open func animate(xAxisDuration: TimeInterval, yAxisDuration: TimeInterval, easingOption: ChartEasingOption) + @objc open func animate(xAxisDuration: TimeInterval, yAxisDuration: TimeInterval, easingOption: ChartEasingOption = .easeInOutSine) { animate(xAxisDuration: xAxisDuration, yAxisDuration: yAxisDuration, easing: easingFunctionFromOption(easingOption)) } - - /// Animates the drawing / rendering of the chart on both x- and y-axis with the specified animation time. - /// If `animate(...)` is called, no further calling of `invalidate()` is necessary to refresh the chart. - /// - parameter xAxisDuration: duration for animating the x axis - /// - parameter yAxisDuration: duration for animating the y axis - @objc open func animate(xAxisDuration: TimeInterval, yAxisDuration: TimeInterval) - { - animate(xAxisDuration: xAxisDuration, yAxisDuration: yAxisDuration, easingOption: .easeInOutSine) - } - + /// Animates the drawing / rendering of the chart the x-axis with the specified animation time. /// If `animate(...)` is called, no further calling of `invalidate()` is necessary to refresh the chart. /// - parameter xAxisDuration: duration for animating the x axis @@ -233,13 +215,11 @@ open class Animator: NSObject // Take care of the first frame if rendering is already scheduled... updateAnimationPhases(_startTimeX) - if _enabledX || _enabledY + if _enabledX || _enabledY, + _displayLink == nil { - if _displayLink == nil - { - _displayLink = NSUIDisplayLink(target: self, selector: #selector(animationLoop)) - _displayLink?.add(to: RunLoop.main, forMode: RunLoopMode.commonModes) - } + _displayLink = NSUIDisplayLink(target: self, selector: #selector(animationLoop)) + _displayLink?.add(to: .main, forMode: .commonModes) } } @@ -247,19 +227,11 @@ open class Animator: NSObject /// If `animate(...)` is called, no further calling of `invalidate()` is necessary to refresh the chart. /// - parameter xAxisDuration: duration for animating the x axis /// - parameter easingOption: the easing function for the animation - @objc open func animate(xAxisDuration: TimeInterval, easingOption: ChartEasingOption) + @objc open func animate(xAxisDuration: TimeInterval, easingOption: ChartEasingOption = .easeInOutSine) { animate(xAxisDuration: xAxisDuration, easing: easingFunctionFromOption(easingOption)) } - - /// Animates the drawing / rendering of the chart the x-axis with the specified animation time. - /// If `animate(...)` is called, no further calling of `invalidate()` is necessary to refresh the chart. - /// - parameter xAxisDuration: duration for animating the x axis - @objc open func animate(xAxisDuration: TimeInterval) - { - animate(xAxisDuration: xAxisDuration, easingOption: .easeInOutSine) - } - + /// Animates the drawing / rendering of the chart the y-axis with the specified animation time. /// If `animate(...)` is called, no further calling of `invalidate()` is necessary to refresh the chart. /// - parameter yAxisDuration: duration for animating the y axis @@ -277,13 +249,11 @@ open class Animator: NSObject // Take care of the first frame if rendering is already scheduled... updateAnimationPhases(_startTimeY) - if _enabledX || _enabledY + if _enabledX || _enabledY, + _displayLink == nil { - if _displayLink == nil - { - _displayLink = NSUIDisplayLink(target: self, selector: #selector(animationLoop)) - _displayLink?.add(to: RunLoop.main, forMode: RunLoopMode.commonModes) - } + _displayLink = NSUIDisplayLink(target: self, selector: #selector(animationLoop)) + _displayLink?.add(to: .main, forMode: .commonModes) } } @@ -291,16 +261,8 @@ open class Animator: NSObject /// If `animate(...)` is called, no further calling of `invalidate()` is necessary to refresh the chart. /// - parameter yAxisDuration: duration for animating the y axis /// - parameter easingOption: the easing function for the animation - @objc open func animate(yAxisDuration: TimeInterval, easingOption: ChartEasingOption) + @objc open func animate(yAxisDuration: TimeInterval, easingOption: ChartEasingOption = .easeInOutSine) { animate(yAxisDuration: yAxisDuration, easing: easingFunctionFromOption(easingOption)) } - - /// Animates the drawing / rendering of the chart the y-axis with the specified animation time. - /// If `animate(...)` is called, no further calling of `invalidate()` is necessary to refresh the chart. - /// - parameter yAxisDuration: duration for animating the y axis - @objc open func animate(yAxisDuration: TimeInterval) - { - animate(yAxisDuration: yAxisDuration, easingOption: .easeInOutSine) - } } diff --git a/Source/Charts/Charts/BarChartView.swift b/Source/Charts/Charts/BarChartView.swift index 685cac6150..16d7ed1674 100644 --- a/Source/Charts/Charts/BarChartView.swift +++ b/Source/Charts/Charts/BarChartView.swift @@ -16,10 +16,10 @@ import CoreGraphics open class BarChartView: BarLineChartViewBase, BarChartDataProvider { /// if set to true, all values are drawn above their bars, instead of below their top - fileprivate var _drawValueAboveBarEnabled = true + private var _drawValueAboveBarEnabled = true /// if set to true, a grey area is drawn behind each bar that indicates the maximum value - fileprivate var _drawBarShadowEnabled = false + private var _drawBarShadowEnabled = false internal override func initialize() { diff --git a/Source/Charts/Charts/BarLineChartViewBase.swift b/Source/Charts/Charts/BarLineChartViewBase.swift index 135b707728..1f07a19084 100644 --- a/Source/Charts/Charts/BarLineChartViewBase.swift +++ b/Source/Charts/Charts/BarLineChartViewBase.swift @@ -21,18 +21,18 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD { /// the maximum number of entries to which values will be drawn /// (entry numbers greater than this value will cause value-labels to disappear) - @objc internal var _maxVisibleCount = 100 + internal var _maxVisibleCount = 100 /// flag that indicates if auto scaling on the y axis is enabled - fileprivate var _autoScaleMinMaxEnabled = false + private var _autoScaleMinMaxEnabled = false - fileprivate var _pinchZoomEnabled = false - fileprivate var _doubleTapToZoomEnabled = true - fileprivate var _dragXEnabled = true - fileprivate var _dragYEnabled = true + private var _pinchZoomEnabled = false + private var _doubleTapToZoomEnabled = true + private var _dragXEnabled = true + private var _dragYEnabled = true - fileprivate var _scaleXEnabled = true - fileprivate var _scaleYEnabled = true + private var _scaleXEnabled = true + private var _scaleYEnabled = true /// the color for the background of the chart-drawing area (everything behind the grid lines). @objc open var gridBackgroundColor = NSUIColor(red: 240/255.0, green: 240/255.0, blue: 240/255.0, alpha: 1.0) @@ -58,28 +58,28 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD @objc open var keepPositionOnRotation: Bool = false /// the object representing the left y-axis - @objc internal var _leftAxis: YAxis! + internal var _leftAxis: YAxis! /// the object representing the right y-axis - @objc internal var _rightAxis: YAxis! + internal var _rightAxis: YAxis! - @objc internal var _leftYAxisRenderer: YAxisRenderer! - @objc internal var _rightYAxisRenderer: YAxisRenderer! + internal var _leftYAxisRenderer: YAxisRenderer! + internal var _rightYAxisRenderer: YAxisRenderer! - @objc internal var _leftAxisTransformer: Transformer! - @objc internal var _rightAxisTransformer: Transformer! + internal var _leftAxisTransformer: Transformer! + internal var _rightAxisTransformer: Transformer! - @objc internal var _xAxisRenderer: XAxisRenderer! + internal var _xAxisRenderer: XAxisRenderer! - @objc internal var _tapGestureRecognizer: NSUITapGestureRecognizer! - @objc internal var _doubleTapGestureRecognizer: NSUITapGestureRecognizer! + internal var _tapGestureRecognizer: NSUITapGestureRecognizer! + internal var _doubleTapGestureRecognizer: NSUITapGestureRecognizer! #if !os(tvOS) - @objc internal var _pinchGestureRecognizer: NSUIPinchGestureRecognizer! + internal var _pinchGestureRecognizer: NSUIPinchGestureRecognizer! #endif - @objc internal var _panGestureRecognizer: NSUIPanGestureRecognizer! + internal var _panGestureRecognizer: NSUIPanGestureRecognizer! /// flag that indicates if a custom viewport offset has been set - fileprivate var _customViewPortEnabled = false + private var _customViewPortEnabled = false public override init(frame: CGRect) { @@ -156,7 +156,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD } else { - let _ = viewPortHandler.refresh(newMatrix: viewPortHandler.touchMatrix, chart: self, invalidate: true) + viewPortHandler.refresh(newMatrix: viewPortHandler.touchMatrix, chart: self, invalidate: true) } } @@ -272,11 +272,11 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD drawMarkers(context: context) } - fileprivate var _autoScaleLastLowestVisibleX: Double? - fileprivate var _autoScaleLastHighestVisibleX: Double? + private var _autoScaleLastLowestVisibleX: Double? + private var _autoScaleLastHighestVisibleX: Double? /// Performs auto scaling of the axis by recalculating the minimum and maximum y-values based on the entries currently in view. - @objc internal func autoScale() + internal func autoScale() { guard let data = _data else { return } @@ -300,13 +300,13 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD calculateOffsets() } - @objc internal func prepareValuePxMatrix() + 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) } - @objc internal func prepareOffsetMatrix() + internal func prepareOffsetMatrix() { _rightAxisTransformer.prepareMatrixOffset(inverted: _rightAxis.isInverted) _leftAxisTransformer.prepareMatrixOffset(inverted: _leftAxis.isInverted) @@ -468,7 +468,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD } /// draws the grid background - @objc internal func drawGridBackground(context: CGContext) + internal func drawGridBackground(context: CGContext) { if drawGridBackgroundEnabled || drawBordersEnabled { @@ -497,27 +497,27 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD // MARK: - Gestures - fileprivate enum GestureScaleAxis + private enum GestureScaleAxis { case both case x case y } - fileprivate var _isDragging = false - fileprivate var _isScaling = false - fileprivate var _gestureScaleAxis = GestureScaleAxis.both - fileprivate var _closestDataSetToTouch: IChartDataSet! - fileprivate var _panGestureReachedEdge: Bool = false - fileprivate weak var _outerScrollView: NSUIScrollView? + private var _isDragging = false + private var _isScaling = false + private var _gestureScaleAxis = GestureScaleAxis.both + private var _closestDataSetToTouch: IChartDataSet! + private var _panGestureReachedEdge: Bool = false + private weak var _outerScrollView: NSUIScrollView? - fileprivate var _lastPanPoint = CGPoint() /// This is to prevent using setTranslation which resets velocity + private var _lastPanPoint = CGPoint() /// This is to prevent using setTranslation which resets velocity - fileprivate var _decelerationLastTime: TimeInterval = 0.0 - fileprivate var _decelerationDisplayLink: NSUIDisplayLink! - fileprivate var _decelerationVelocity = CGPoint() + private var _decelerationLastTime: TimeInterval = 0.0 + private var _decelerationDisplayLink: NSUIDisplayLink! + private var _decelerationVelocity = CGPoint() - @objc fileprivate func tapGestureRecognized(_ recognizer: NSUITapGestureRecognizer) + @objc private func tapGestureRecognized(_ recognizer: NSUITapGestureRecognizer) { if _data === nil { @@ -543,7 +543,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD } } - @objc fileprivate func doubleTapGestureRecognized(_ recognizer: NSUITapGestureRecognizer) + @objc private func doubleTapGestureRecognized(_ recognizer: NSUITapGestureRecognizer) { if _data === nil { @@ -572,7 +572,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD } #if !os(tvOS) - @objc fileprivate func pinchGestureRecognized(_ recognizer: NSUIPinchGestureRecognizer) + @objc private func pinchGestureRecognized(_ recognizer: NSUIPinchGestureRecognizer) { if recognizer.state == NSUIGestureRecognizerState.began { @@ -648,7 +648,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD matrix = _viewPortHandler.touchMatrix.concatenating(matrix) - let _ = _viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: true) + _viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: true) if delegate !== nil { @@ -662,7 +662,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD } #endif - @objc fileprivate func panGestureRecognized(_ recognizer: NSUIPanGestureRecognizer) + @objc private func panGestureRecognized(_ recognizer: NSUIPanGestureRecognizer) { if recognizer.state == NSUIGestureRecognizerState.began && recognizer.nsuiNumberOfTouches() > 0 { @@ -783,7 +783,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD } } - fileprivate func performPanChange(translation: CGPoint) -> Bool + private func performPanChange(translation: CGPoint) -> Bool { var translation = translation @@ -815,7 +815,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD return matrix.tx != originalMatrix.tx || matrix.ty != originalMatrix.ty } - fileprivate func isTouchInverted() -> Bool + private func isTouchInverted() -> Bool { return isAnyAxisInverted && _closestDataSetToTouch !== nil && @@ -831,7 +831,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD } } - @objc fileprivate func decelerationLoop() + @objc private func decelerationLoop() { let currentTime = CACurrentMediaTime() @@ -864,13 +864,15 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD } } - fileprivate func nsuiGestureRecognizerShouldBegin(_ gestureRecognizer: NSUIGestureRecognizer) -> Bool + private func nsuiGestureRecognizerShouldBegin(_ gestureRecognizer: NSUIGestureRecognizer) -> Bool { if gestureRecognizer == _panGestureRecognizer { - if _data === nil || - !isDragEnabled || - (self.hasNoDragOffset && self.isFullyZoomedOut && !self.isHighlightPerDragEnabled) + let velocity = _panGestureRecognizer.velocity(in: self) + if _data === nil || !isDragEnabled || + (self.hasNoDragOffset && self.isFullyZoomedOut && !self.isHighlightPerDragEnabled) || + (!_dragYEnabled && fabs(velocity.y) > fabs(velocity.x)) || + (!_dragXEnabled && fabs(velocity.y) < fabs(velocity.x)) { return false } @@ -913,30 +915,27 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD open func gestureRecognizer(_ gestureRecognizer: NSUIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: NSUIGestureRecognizer) -> Bool { #if !os(tvOS) - if ((gestureRecognizer.isKind(of: NSUIPinchGestureRecognizer.self) && - otherGestureRecognizer.isKind(of: NSUIPanGestureRecognizer.self)) || - (gestureRecognizer.isKind(of: NSUIPanGestureRecognizer.self) && - otherGestureRecognizer.isKind(of: NSUIPinchGestureRecognizer.self))) + if ((gestureRecognizer is NSUIPinchGestureRecognizer && otherGestureRecognizer is NSUIPanGestureRecognizer) || + (gestureRecognizer is NSUIPanGestureRecognizer && otherGestureRecognizer is NSUIPinchGestureRecognizer)) { return true } #endif - if (gestureRecognizer.isKind(of: NSUIPanGestureRecognizer.self) && - otherGestureRecognizer.isKind(of: NSUIPanGestureRecognizer.self) && ( - gestureRecognizer == _panGestureRecognizer - )) + if gestureRecognizer is NSUIPanGestureRecognizer, + otherGestureRecognizer is NSUIPanGestureRecognizer, + gestureRecognizer == _panGestureRecognizer { var scrollView = self.superview - while !(scrollView?.isKind(of: NSUIScrollView.self) ?? true) + while scrollView != nil && !(scrollView is NSUIScrollView) { scrollView = scrollView?.superview } // If there is two scrollview together, we pick the superview of the inner scrollview. // In the case of UITableViewWrepperView, the superview will be UITableView - if let superViewOfScrollView = scrollView?.superview - , superViewOfScrollView.isKind(of: NSUIScrollView.self) + if let superViewOfScrollView = scrollView?.superview, + superViewOfScrollView is NSUIScrollView { scrollView = superViewOfScrollView } @@ -971,7 +970,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD let center = _viewPortHandler.contentCenter let matrix = _viewPortHandler.zoomIn(x: center.x, y: -center.y) - let _ = _viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: false) + _viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: false) // Range might have changed, which means that Y-axis labels could have changed in size, affecting Y-axis size. So we need to recalculate offsets. calculateOffsets() @@ -984,7 +983,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD let center = _viewPortHandler.contentCenter let matrix = _viewPortHandler.zoomOut(x: center.x, y: -center.y) - let _ = _viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: false) + _viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: false) // Range might have changed, which means that Y-axis labels could have changed in size, affecting Y-axis size. So we need to recalculate offsets. calculateOffsets() @@ -995,7 +994,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD @objc open func resetZoom() { let matrix = _viewPortHandler.resetZoom() - let _ = _viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: false) + _viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: false) // Range might have changed, which means that Y-axis labels could have changed in size, affecting Y-axis size. So we need to recalculate offsets. calculateOffsets() @@ -1016,7 +1015,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD y: CGFloat) { let matrix = _viewPortHandler.zoom(scaleX: scaleX, scaleY: scaleY, x: x, y: -y) - let _ = _viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: false) + _viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: false) // Range might have changed, which means that Y-axis labels could have changed in size, affecting Y-axis size. So we need to recalculate offsets. calculateOffsets() @@ -1067,7 +1066,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD scaleY: scaleY, x: center.x, y: -center.y) - let _ = viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: false) + viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: false) } /// Zooms by the specified scale factor to the specified values on the specified axis. @@ -1157,7 +1156,7 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD @objc open func fitScreen() { let matrix = _viewPortHandler.fitScreen() - let _ = _viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: false) + _viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: false) calculateOffsets() setNeedsDisplay() diff --git a/Source/Charts/Charts/ChartViewBase.swift b/Source/Charts/Charts/ChartViewBase.swift index 0c79db9d74..41426689b6 100755 --- a/Source/Charts/Charts/ChartViewBase.swift +++ b/Source/Charts/Charts/ChartViewBase.swift @@ -48,26 +48,26 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate } /// The default IValueFormatter that has been determined by the chart considering the provided minimum and maximum values. - @objc internal var _defaultValueFormatter: IValueFormatter? = DefaultValueFormatter(decimals: 0) + internal var _defaultValueFormatter: IValueFormatter? = DefaultValueFormatter(decimals: 0) /// object that holds all data that was originally set for the chart, before it was modified or any filtering algorithms had been applied - @objc internal var _data: ChartData? + internal var _data: ChartData? /// Flag that indicates if highlighting per tap (touch) is enabled - fileprivate var _highlightPerTapEnabled = true + private var _highlightPerTapEnabled = true /// If set to true, chart continues to scroll after touch up @objc open var dragDecelerationEnabled = true /// Deceleration friction coefficient in [0 ; 1] interval, higher values indicate that speed will decrease slowly, for example if it set to 0, it will stop immediately. /// 1 is an invalid value, and will be converted to 0.999 automatically. - fileprivate var _dragDecelerationFrictionCoef: CGFloat = 0.9 + private var _dragDecelerationFrictionCoef: CGFloat = 0.9 /// if true, units are drawn next to the values in the chart - @objc internal var _drawUnitInChart = false + internal var _drawUnitInChart = false /// The object representing the labels on the x-axis - @objc internal var _xAxis: XAxis! + internal var _xAxis: XAxis! /// The `Description` object of the chart. /// This should have been called just "description", but @@ -126,7 +126,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate } /// The legend object containing all data associated with the legend - @objc internal var _legend: Legend! + internal var _legend: Legend! /// delegate to receive chart events @objc open weak var delegate: ChartViewDelegate? @@ -140,7 +140,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate /// color of the no data text @objc open var noDataTextColor: NSUIColor = NSUIColor.black - @objc internal var _legendRenderer: LegendRenderer! + internal var _legendRenderer: LegendRenderer! /// object responsible for rendering the data @objc open var renderer: DataRenderer? @@ -148,16 +148,16 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate @objc open var highlighter: IHighlighter? /// object that manages the bounds and drawing constraints of the chart - @objc internal var _viewPortHandler: ViewPortHandler! + internal var _viewPortHandler: ViewPortHandler! /// object responsible for animations - @objc internal var _animator: Animator! + internal var _animator: Animator! /// flag that indicates if offsets calculation has already been done or not - fileprivate var _offsetsCalculated = false + private var _offsetsCalculated = false /// array of Highlight objects that reference the highlighted slices in the chart - @objc internal var _indicesToHighlight = [Highlight]() + internal var _indicesToHighlight = [Highlight]() /// `true` if drawing the marker is enabled when tapping on values /// (use the `marker` property to specify a marker) @@ -170,7 +170,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate /// The marker that is displayed when a value is clicked on the chart @objc open var marker: IMarker? - fileprivate var _interceptTouchEvents = false + private var _interceptTouchEvents = false /// An extra offset to be appended to the viewport's top @objc open var extraTopOffset: CGFloat = 0.0 @@ -212,7 +212,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate self.removeObserver(self, forKeyPath: "frame") } - @objc internal func initialize() + internal func initialize() { #if os(iOS) self.backgroundColor = NSUIColor.clear @@ -221,8 +221,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate _animator = Animator() _animator.delegate = self - _viewPortHandler = ViewPortHandler() - _viewPortHandler.setChartDimens(width: bounds.size.width, height: bounds.size.height) + _viewPortHandler = ViewPortHandler(width: bounds.size.width, height: bounds.size.height) chartDescription = Description() @@ -311,19 +310,19 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate } /// Calculates the offsets of the chart to the border depending on the position of an eventual legend or depending on the length of the y-axis and x-axis labels and their position - @objc internal func calculateOffsets() + internal func calculateOffsets() { fatalError("calculateOffsets() cannot be called on ChartViewBase") } /// calcualtes the y-min and y-max value and the y-delta and x-delta value - @objc internal func calcMinMax() + internal func calcMinMax() { fatalError("calcMinMax() cannot be called on ChartViewBase") } /// calculates the required number of digits for the values that might be drawn in the chart (if enabled), and creates the default value formatter - @objc internal func setupDefaultFormatter(min: Double, max: Double) + internal func setupDefaultFormatter(min: Double, max: Double) { // check if a custom formatter is set or not var reference = Double(0.0) @@ -384,7 +383,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate } /// Draws the description text in the bottom right corner of the chart (per default) - @objc internal func drawDescription(context: CGContext) + internal func drawDescription(context: CGContext) { // check if description should be drawn guard @@ -587,7 +586,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate // MARK: - Markers /// draws all MarkerViews on the highlighted positions - @objc internal func drawMarkers(context: CGContext) + internal func drawMarkers(context: CGContext) { // if there is no marker view or drawing marker is disabled guard @@ -886,7 +885,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate return true } - @objc internal var _viewportJobs = [ViewPortJob]() + internal var _viewportJobs = [ViewPortJob]() open override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { diff --git a/Source/Charts/Charts/CombinedChartView.swift b/Source/Charts/Charts/CombinedChartView.swift index eef738f58b..ead6c3d130 100644 --- a/Source/Charts/Charts/CombinedChartView.swift +++ b/Source/Charts/Charts/CombinedChartView.swift @@ -16,7 +16,7 @@ import CoreGraphics open class CombinedChartView: BarLineChartViewBase, CombinedChartDataProvider { /// the fill-formatter used for determining the position of the fill-line - @objc internal var _fillFormatter: IFillFormatter! + internal var _fillFormatter: IFillFormatter! /// enum that allows to specify the order in which the different data objects for the combined-chart are drawn @objc(CombinedChartDrawOrder) diff --git a/Source/Charts/Charts/PieChartView.swift b/Source/Charts/Charts/PieChartView.swift index 7316c2fe03..046253b424 100755 --- a/Source/Charts/Charts/PieChartView.swift +++ b/Source/Charts/Charts/PieChartView.swift @@ -20,57 +20,57 @@ import CoreGraphics open class PieChartView: PieRadarChartViewBase { /// rect object that represents the bounds of the piechart, needed for drawing the circle - fileprivate var _circleBox = CGRect() + private var _circleBox = CGRect() /// flag indicating if entry labels should be drawn or not - fileprivate var _drawEntryLabelsEnabled = true + private var _drawEntryLabelsEnabled = true /// array that holds the width of each pie-slice in degrees - fileprivate var _drawAngles = [CGFloat]() + private var _drawAngles = [CGFloat]() /// array that holds the absolute angle in degrees of each slice - fileprivate var _absoluteAngles = [CGFloat]() + private var _absoluteAngles = [CGFloat]() /// if true, the hole inside the chart will be drawn - fileprivate var _drawHoleEnabled = true + private var _drawHoleEnabled = true - fileprivate var _holeColor: NSUIColor? = NSUIColor.white + private var _holeColor: NSUIColor? = NSUIColor.white /// Sets the color the entry labels are drawn with. - fileprivate var _entryLabelColor: NSUIColor? = NSUIColor.white + private var _entryLabelColor: NSUIColor? = NSUIColor.white /// Sets the font the entry labels are drawn with. - fileprivate var _entryLabelFont: NSUIFont? = NSUIFont(name: "HelveticaNeue", size: 13.0) + private var _entryLabelFont: NSUIFont? = NSUIFont(name: "HelveticaNeue", size: 13.0) /// if true, the hole will see-through to the inner tips of the slices - fileprivate var _drawSlicesUnderHoleEnabled = false + private var _drawSlicesUnderHoleEnabled = false /// if true, the values inside the piechart are drawn as percent values - fileprivate var _usePercentValuesEnabled = false + private var _usePercentValuesEnabled = false /// variable for the text that is drawn in the center of the pie-chart - fileprivate var _centerAttributedText: NSAttributedString? + private var _centerAttributedText: NSAttributedString? /// the offset on the x- and y-axis the center text has in dp. - fileprivate var _centerTextOffset: CGPoint = CGPoint() + private var _centerTextOffset: CGPoint = CGPoint() /// indicates the size of the hole in the center of the piechart /// /// **default**: `0.5` - fileprivate var _holeRadiusPercent = CGFloat(0.5) + private var _holeRadiusPercent = CGFloat(0.5) - fileprivate var _transparentCircleColor: NSUIColor? = NSUIColor(white: 1.0, alpha: 105.0/255.0) + private var _transparentCircleColor: NSUIColor? = NSUIColor(white: 1.0, alpha: 105.0/255.0) /// the radius of the transparent circle next to the chart-hole in the center - fileprivate var _transparentCircleRadiusPercent = CGFloat(0.55) + private var _transparentCircleRadiusPercent = CGFloat(0.55) /// if enabled, centertext is drawn - fileprivate var _drawCenterTextEnabled = true + private var _drawCenterTextEnabled = true - fileprivate var _centerTextRadiusPercent: CGFloat = 1.0 + private var _centerTextRadiusPercent: CGFloat = 1.0 /// maximum angle for this pie - fileprivate var _maxAngle: CGFloat = 360.0 + private var _maxAngle: CGFloat = 360.0 public override init(frame: CGRect) { @@ -175,14 +175,14 @@ open class PieChartView: PieRadarChartViewBase let offset = drawAngles[entryIndex] / 2.0 // calculate the text position - let x: CGFloat = (r * cos(((rotationAngle + absoluteAngles[entryIndex] - offset) * CGFloat(_animator.phaseY)) * ChartUtils.Math.FDEG2RAD) + center.x) - let y: CGFloat = (r * sin(((rotationAngle + absoluteAngles[entryIndex] - offset) * CGFloat(_animator.phaseY)) * ChartUtils.Math.FDEG2RAD) + center.y) + let x: CGFloat = (r * cos(((rotationAngle + absoluteAngles[entryIndex] - offset) * CGFloat(_animator.phaseY)).DEG2RAD) + center.x) + let y: CGFloat = (r * sin(((rotationAngle + absoluteAngles[entryIndex] - offset) * CGFloat(_animator.phaseY)).DEG2RAD) + center.y) return CGPoint(x: x, y: y) } /// calculates the needed angles for the chart slices - fileprivate func calcAngles() + private func calcAngles() { _drawAngles = [CGFloat]() _absoluteAngles = [CGFloat]() @@ -247,13 +247,13 @@ open class PieChartView: PieRadarChartViewBase } /// calculates the needed angle for a given value - fileprivate func calcAngle(_ value: Double) -> CGFloat + private func calcAngle(_ value: Double) -> CGFloat { return calcAngle(value: value, yValueSum: (_data as! PieChartData).yValueSum) } /// calculates the needed angle for a given value - fileprivate func calcAngle(value: Double, yValueSum: Double) -> CGFloat + private func calcAngle(value: Double, yValueSum: Double) -> CGFloat { return CGFloat(value) / CGFloat(yValueSum) * _maxAngle } @@ -267,7 +267,7 @@ open class PieChartView: PieRadarChartViewBase open override func indexForAngle(_ angle: CGFloat) -> Int { // take the current angle of the chart into consideration - let a = ChartUtils.normalizedAngleFromAngle(angle - self.rotationAngle) + let a = (angle - self.rotationAngle).normalizedAngle for i in 0 ..< _absoluteAngles.count { if _absoluteAngles[i] > a diff --git a/Source/Charts/Charts/PieRadarChartViewBase.swift b/Source/Charts/Charts/PieRadarChartViewBase.swift index b45e2157d3..5d6f22fac8 100755 --- a/Source/Charts/Charts/PieRadarChartViewBase.swift +++ b/Source/Charts/Charts/PieRadarChartViewBase.swift @@ -20,10 +20,10 @@ import CoreGraphics open class PieRadarChartViewBase: ChartViewBase { /// holds the normalized version of the current rotation angle of the chart - fileprivate var _rotationAngle = CGFloat(270.0) + private var _rotationAngle = CGFloat(270.0) /// holds the raw version of the current rotation angle of the chart - fileprivate var _rawRotationAngle = CGFloat(270.0) + private var _rawRotationAngle = CGFloat(270.0) /// flag that indicates if rotation is enabled or not @objc open var rotationEnabled = true @@ -32,11 +32,11 @@ open class PieRadarChartViewBase: ChartViewBase @objc open var minOffset = CGFloat(0.0) /// iOS && OSX only: Enabled multi-touch rotation using two fingers. - fileprivate var _rotationWithTwoFingers = false + private var _rotationWithTwoFingers = false - fileprivate var _tapGestureRecognizer: NSUITapGestureRecognizer! + private var _tapGestureRecognizer: NSUITapGestureRecognizer! #if !os(tvOS) - fileprivate var _rotationGestureRecognizer: NSUIRotationGestureRecognizer! + private var _rotationGestureRecognizer: NSUIRotationGestureRecognizer! #endif public override init(frame: CGRect) @@ -226,7 +226,7 @@ open class PieRadarChartViewBase: ChartViewBase var minOffset = self.minOffset - if (self.isKind(of: RadarChartView.self)) + if self is RadarChartView { let x = self.xAxis @@ -255,7 +255,7 @@ open class PieRadarChartViewBase: ChartViewBase let length = sqrt(tx * tx + ty * ty) let r = acos(ty / length) - var angle = r * ChartUtils.Math.RAD2DEG + var angle = r.RAD2DEG if x > c.x { @@ -278,8 +278,8 @@ open class PieRadarChartViewBase: ChartViewBase /// from the center, and the angle of the position around the center. @objc open func getPosition(center: CGPoint, dist: CGFloat, angle: CGFloat) -> CGPoint { - return CGPoint(x: center.x + dist * cos(angle * ChartUtils.Math.FDEG2RAD), - y: center.y + dist * sin(angle * ChartUtils.Math.FDEG2RAD)) + return CGPoint(x: center.x + dist * cos(angle.DEG2RAD), + y: center.y + dist * sin(angle.DEG2RAD)) } /// - returns: The distance of a certain point on the chart to the center of the chart. @@ -336,7 +336,7 @@ open class PieRadarChartViewBase: ChartViewBase set { _rawRotationAngle = newValue - _rotationAngle = ChartUtils.normalizedAngleFromAngle(newValue) + _rotationAngle = newValue.normalizedAngle setNeedsDisplay() } } @@ -366,14 +366,14 @@ open class PieRadarChartViewBase: ChartViewBase } /// - returns: The required offset for the chart legend. - @objc internal var requiredLegendOffset: CGFloat + internal var requiredLegendOffset: CGFloat { fatalError("requiredLegendOffset cannot be called on PieRadarChartViewBase") } /// - returns: The base offset needed for the chart without calculating the /// legend size. - @objc internal var requiredBaseOffset: CGFloat + internal var requiredBaseOffset: CGFloat { fatalError("requiredBaseOffset cannot be called on PieRadarChartViewBase") } @@ -426,7 +426,7 @@ open class PieRadarChartViewBase: ChartViewBase // MARK: - Animation - fileprivate var _spinAnimator: Animator! + private var _spinAnimator: Animator! /// Applys a spin animation to the Chart. @objc open func spin(duration: TimeInterval, fromAngle: CGFloat, toAngle: CGFloat, easing: ChartEasingFunctionBlock?) @@ -465,23 +465,23 @@ open class PieRadarChartViewBase: ChartViewBase // MARK: - Gestures - fileprivate var _rotationGestureStartPoint: CGPoint! - fileprivate var _isRotating = false - fileprivate var _startAngle = CGFloat(0.0) + private var _rotationGestureStartPoint: CGPoint! + private var _isRotating = false + private var _startAngle = CGFloat(0.0) - fileprivate struct AngularVelocitySample + private struct AngularVelocitySample { var time: TimeInterval var angle: CGFloat } - fileprivate var _velocitySamples = [AngularVelocitySample]() + private var _velocitySamples = [AngularVelocitySample]() - fileprivate var _decelerationLastTime: TimeInterval = 0.0 - fileprivate var _decelerationDisplayLink: NSUIDisplayLink! - fileprivate var _decelerationAngularVelocity: CGFloat = 0.0 + private var _decelerationLastTime: TimeInterval = 0.0 + private var _decelerationDisplayLink: NSUIDisplayLink! + private var _decelerationAngularVelocity: CGFloat = 0.0 - @objc internal final func processRotationGestureBegan(location: CGPoint) + internal final func processRotationGestureBegan(location: CGPoint) { self.resetVelocity() @@ -495,7 +495,7 @@ open class PieRadarChartViewBase: ChartViewBase _rotationGestureStartPoint = location } - @objc internal final func processRotationGestureMoved(location: CGPoint) + internal final func processRotationGestureMoved(location: CGPoint) { if isDragDecelerationEnabled { @@ -518,7 +518,7 @@ open class PieRadarChartViewBase: ChartViewBase } } - @objc internal final func processRotationGestureEnded(location: CGPoint) + internal final func processRotationGestureEnded(location: CGPoint) { if isDragDecelerationEnabled { @@ -537,7 +537,7 @@ open class PieRadarChartViewBase: ChartViewBase } } - @objc internal final func processRotationGestureCancelled() + internal final func processRotationGestureCancelled() { if _isRotating { @@ -661,12 +661,12 @@ open class PieRadarChartViewBase: ChartViewBase } #endif - fileprivate func resetVelocity() + private func resetVelocity() { _velocitySamples.removeAll(keepingCapacity: false) } - fileprivate func sampleVelocity(touchLocation: CGPoint) + private func sampleVelocity(touchLocation: CGPoint) { let currentTime = CACurrentMediaTime() @@ -691,7 +691,7 @@ open class PieRadarChartViewBase: ChartViewBase } } - fileprivate func calculateVelocity() -> CGFloat + private func calculateVelocity() -> CGFloat { if _velocitySamples.isEmpty { @@ -750,7 +750,7 @@ open class PieRadarChartViewBase: ChartViewBase } /// sets the starting angle of the rotation, this is only used by the touch listener, x and y is the touch position - fileprivate func setGestureStartAngle(x: CGFloat, y: CGFloat) + private func setGestureStartAngle(x: CGFloat, y: CGFloat) { _startAngle = angleForPoint(x: x, y: y) @@ -759,7 +759,7 @@ open class PieRadarChartViewBase: ChartViewBase } /// updates the view rotation depending on the given touch position, also takes the starting angle into consideration - fileprivate func updateGestureRotation(x: CGFloat, y: CGFloat) + private func updateGestureRotation(x: CGFloat, y: CGFloat) { self.rotationAngle = angleForPoint(x: x, y: y) - _startAngle } @@ -773,7 +773,7 @@ open class PieRadarChartViewBase: ChartViewBase } } - @objc fileprivate func decelerationLoop() + @objc private func decelerationLoop() { let currentTime = CACurrentMediaTime() @@ -792,7 +792,7 @@ open class PieRadarChartViewBase: ChartViewBase } /// - returns: The distance between two points - fileprivate func distance(eventX: CGFloat, startX: CGFloat, eventY: CGFloat, startY: CGFloat) -> CGFloat + private func distance(eventX: CGFloat, startX: CGFloat, eventY: CGFloat, startY: CGFloat) -> CGFloat { let dx = eventX - startX let dy = eventY - startY @@ -800,7 +800,7 @@ open class PieRadarChartViewBase: ChartViewBase } /// - returns: The distance between two points - fileprivate func distance(from: CGPoint, to: CGPoint) -> CGFloat + private func distance(from: CGPoint, to: CGPoint) -> CGFloat { let dx = from.x - to.x let dy = from.y - to.y @@ -808,9 +808,9 @@ open class PieRadarChartViewBase: ChartViewBase } /// reference to the last highlighted object - fileprivate var _lastHighlight: Highlight! + private var _lastHighlight: Highlight! - @objc fileprivate func tapGestureRecognized(_ recognizer: NSUITapGestureRecognizer) + @objc private func tapGestureRecognized(_ recognizer: NSUITapGestureRecognizer) { if recognizer.state == NSUIGestureRecognizerState.ended { @@ -824,7 +824,7 @@ open class PieRadarChartViewBase: ChartViewBase } #if !os(tvOS) - @objc fileprivate func rotationGestureRecognized(_ recognizer: NSUIRotationGestureRecognizer) + @objc private func rotationGestureRecognized(_ recognizer: NSUIRotationGestureRecognizer) { if recognizer.state == NSUIGestureRecognizerState.began { @@ -835,14 +835,14 @@ open class PieRadarChartViewBase: ChartViewBase if recognizer.state == NSUIGestureRecognizerState.began || recognizer.state == NSUIGestureRecognizerState.changed { - let angle = ChartUtils.Math.FRAD2DEG * recognizer.nsuiRotation + let angle = recognizer.nsuiRotation.RAD2DEG self.rotationAngle = _startAngle + angle setNeedsDisplay() } else if recognizer.state == NSUIGestureRecognizerState.ended { - let angle = ChartUtils.Math.FRAD2DEG * recognizer.nsuiRotation + let angle = recognizer.nsuiRotation.RAD2DEG self.rotationAngle = _startAngle + angle setNeedsDisplay() @@ -851,7 +851,7 @@ open class PieRadarChartViewBase: ChartViewBase { stopDeceleration() - _decelerationAngularVelocity = ChartUtils.Math.FRAD2DEG * recognizer.velocity + _decelerationAngularVelocity = recognizer.velocity.RAD2DEG if _decelerationAngularVelocity != 0.0 { diff --git a/Source/Charts/Charts/RadarChartView.swift b/Source/Charts/Charts/RadarChartView.swift index 232d59492f..2182df6e15 100644 --- a/Source/Charts/Charts/RadarChartView.swift +++ b/Source/Charts/Charts/RadarChartView.swift @@ -36,13 +36,13 @@ open class RadarChartView: PieRadarChartViewBase @objc open var drawWeb = true /// modulus that determines how many labels and web-lines are skipped before the next is drawn - fileprivate var _skipWebLineCount = 0 + private var _skipWebLineCount = 0 /// the object reprsenting the y-axis labels - fileprivate var _yAxis: YAxis! + private var _yAxis: YAxis! - @objc internal var _yAxisRenderer: YAxisRendererRadarChart! - @objc internal var _xAxisRenderer: XAxisRendererRadarChart! + internal var _yAxisRenderer: YAxisRendererRadarChart! + internal var _xAxisRenderer: XAxisRendererRadarChart! public override init(frame: CGRect) { @@ -163,7 +163,7 @@ open class RadarChartView: PieRadarChartViewBase open override func indexForAngle(_ angle: CGFloat) -> Int { // take the current angle of the chart into consideration - let a = ChartUtils.normalizedAngleFromAngle(angle - self.rotationAngle) + let a = (angle - self.rotationAngle).normalizedAngle let sliceAngle = self.sliceAngle diff --git a/Source/Charts/Components/AxisBase.swift b/Source/Charts/Components/AxisBase.swift index 0f6c86580d..fbab2c0f71 100644 --- a/Source/Charts/Components/AxisBase.swift +++ b/Source/Charts/Components/AxisBase.swift @@ -22,7 +22,7 @@ open class AxisBase: ComponentBase } /// Custom formatter that is used instead of the auto-formatter if set - fileprivate var _axisValueFormatter: IAxisValueFormatter? + private var _axisValueFormatter: IAxisValueFormatter? @objc open var labelFont = NSUIFont.systemFont(ofSize: 10.0) @objc open var labelTextColor = NSUIColor.black @@ -44,7 +44,7 @@ open class AxisBase: ComponentBase /// flag that indicates of the labels of this axis should be drawn or not @objc open var drawLabelsEnabled = true - fileprivate var _centerAxisLabelsEnabled = false + private var _centerAxisLabelsEnabled = false /// Centers the axis labels instead of drawing them at their original position. /// This is useful especially for grouped BarChart. @@ -60,7 +60,7 @@ open class AxisBase: ComponentBase } /// array of limitlines that can be set for the axis - fileprivate var _limitLines = [ChartLimitLine]() + private var _limitLines = [ChartLimitLine]() /// Are the LimitLines drawn behind the data or in front of the data? /// @@ -82,7 +82,7 @@ open class AxisBase: ComponentBase /// the number of label entries the axis should have /// /// **default**: 6 - fileprivate var _labelCount = Int(6) + private var _labelCount = Int(6) /// the number of decimal digits to use (for the default formatter @objc open var decimals: Int = 0 @@ -93,7 +93,7 @@ open class AxisBase: ComponentBase /// If using granularity this could be avoided by having fewer axis values visible. @objc open var granularityEnabled = false - fileprivate var _granularity = Double(1.0) + private var _granularity = Double(1.0) /// The minimum interval between axis values. /// This can be used to avoid label duplicating when zooming in. @@ -195,20 +195,20 @@ open class AxisBase: ComponentBase @objc open var spaceMax: Double = 0.0 /// Flag indicating that the axis-min value has been customized - @objc internal var _customAxisMin: Bool = false + internal var _customAxisMin: Bool = false /// Flag indicating that the axis-max value has been customized - @objc internal var _customAxisMax: Bool = false + internal var _customAxisMax: Bool = false /// Do not touch this directly, instead, use axisMinimum. /// This is automatically calculated to represent the real min value, /// and is used when calculating the effective minimum. - @objc internal var _axisMinimum = Double(0) + internal var _axisMinimum = Double(0) /// Do not touch this directly, instead, use axisMaximum. /// This is automatically calculated to represent the real max value, /// and is used when calculating the effective maximum. - @objc internal var _axisMaximum = Double(0) + internal var _axisMaximum = Double(0) /// the total range of values this axis covers @objc open var axisRange = Double(0) diff --git a/Source/Charts/Components/ChartLimitLine.swift b/Source/Charts/Components/ChartLimitLine.swift index 8bfd91ccce..d0d2249888 100644 --- a/Source/Charts/Components/ChartLimitLine.swift +++ b/Source/Charts/Components/ChartLimitLine.swift @@ -29,7 +29,7 @@ open class ChartLimitLine: ComponentBase /// limit / maximum (the y-value or xIndex) @objc open var limit = Double(0.0) - fileprivate var _lineWidth = CGFloat(2.0) + private var _lineWidth = CGFloat(2.0) @objc open var lineColor = NSUIColor(red: 237.0/255.0, green: 91.0/255.0, blue: 91.0/255.0, alpha: 1.0) @objc open var lineDashPhase = CGFloat(0.0) @objc open var lineDashLengths: [CGFloat]? diff --git a/Source/Charts/Components/Legend.swift b/Source/Charts/Components/Legend.swift index d2d6a1bcf8..992342a329 100644 --- a/Source/Charts/Components/Legend.swift +++ b/Source/Charts/Components/Legend.swift @@ -101,7 +101,7 @@ open class Legend: ComponentBase /// Are the legend labels/colors a custom value or auto calculated? If false, then it's auto, if true, then custom. /// /// **default**: false (automatic legend) - fileprivate var _isLegendCustom = false + private var _isLegendCustom = false /// This property is deprecated - Use `horizontalAlignment`, `verticalAlignment`, `orientation`, `drawInside`, `direction`. @objc @available(*, deprecated: 1.0, message: "Use `horizontalAlignment`, `verticalAlignment`, `orientation`, `drawInside`, `direction`.") diff --git a/Source/Charts/Components/YAxis.swift b/Source/Charts/Components/YAxis.swift index 605a69876d..cfe520776e 100644 --- a/Source/Charts/Components/YAxis.swift +++ b/Source/Charts/Components/YAxis.swift @@ -74,7 +74,7 @@ open class YAxis: AxisBase @objc open var labelPosition = LabelPosition.outsideChart /// the side this axis object represents - fileprivate var _axisDependency = AxisDependency.left + private var _axisDependency = AxisDependency.left /// the minimum width that the axis should take /// diff --git a/Source/Charts/Data/Implementations/ChartBaseDataSet.swift b/Source/Charts/Data/Implementations/ChartBaseDataSet.swift index ea282ffdd1..7136f2f04b 100644 --- a/Source/Charts/Data/Implementations/ChartBaseDataSet.swift +++ b/Source/Charts/Data/Implementations/ChartBaseDataSet.swift @@ -270,7 +270,7 @@ open class ChartBaseDataSet: NSObject, IChartDataSet open var isHighlightEnabled: Bool { return highlightEnabled } /// Custom formatter that is used instead of the auto-formatter if set - @objc internal var _valueFormatter: IValueFormatter? + internal var _valueFormatter: IValueFormatter? /// Custom formatter that is used instead of the auto-formatter if set open var valueFormatter: IValueFormatter? diff --git a/Source/Charts/Data/Implementations/Standard/BarChartDataEntry.swift b/Source/Charts/Data/Implementations/Standard/BarChartDataEntry.swift index 89243992ad..23fec77eb8 100644 --- a/Source/Charts/Data/Implementations/Standard/BarChartDataEntry.swift +++ b/Source/Charts/Data/Implementations/Standard/BarChartDataEntry.swift @@ -14,16 +14,16 @@ import Foundation open class BarChartDataEntry: ChartDataEntry { /// the values the stacked barchart holds - fileprivate var _yVals: [Double]? + private var _yVals: [Double]? /// the ranges for the individual stack values - automatically calculated - fileprivate var _ranges: [Range]? + private var _ranges: [Range]? /// the sum of all negative values this entry (if stacked) contains - fileprivate var _negativeSum: Double = 0.0 + private var _negativeSum: Double = 0.0 /// the sum of all positive values this entry (if stacked) contains - fileprivate var _positiveSum: Double = 0.0 + private var _positiveSum: Double = 0.0 public required init() { @@ -240,7 +240,7 @@ open class BarChartDataEntry: ChartDataEntry /// /// - parameter vals: /// - returns: - fileprivate static func calcSum(values: [Double]?) -> Double + private static func calcSum(values: [Double]?) -> Double { guard let values = values else { return 0.0 } diff --git a/Source/Charts/Data/Implementations/Standard/BarChartDataSet.swift b/Source/Charts/Data/Implementations/Standard/BarChartDataSet.swift index ceb5ccb8af..27ed7a5722 100644 --- a/Source/Charts/Data/Implementations/Standard/BarChartDataSet.swift +++ b/Source/Charts/Data/Implementations/Standard/BarChartDataSet.swift @@ -15,7 +15,7 @@ import CoreGraphics open class BarChartDataSet: BarLineScatterCandleBubbleChartDataSet, IBarChartDataSet { - fileprivate func initialize() + private func initialize() { self.highlightColor = NSUIColor.black @@ -39,14 +39,14 @@ open class BarChartDataSet: BarLineScatterCandleBubbleChartDataSet, IBarChartDat /// the maximum number of bars that are stacked upon each other, this value /// is calculated from the Entries that are added to the DataSet - fileprivate var _stackSize = 1 + private var _stackSize = 1 /// the overall entry count, including counting each stack-value individually - fileprivate var _entryCountStacks = 0 + private var _entryCountStacks = 0 /// Calculates the total number of entries this DataSet represents, including /// stacks. All values belonging to a stack are calculated separately. - fileprivate func calcEntryCountIncludingStacks(entries: [BarChartDataEntry]) + private func calcEntryCountIncludingStacks(entries: [BarChartDataEntry]) { _entryCountStacks = 0 @@ -64,7 +64,7 @@ open class BarChartDataSet: BarLineScatterCandleBubbleChartDataSet, IBarChartDat } /// calculates the maximum stacksize that occurs in the Entries array of this DataSet - fileprivate func calcStackSize(entries: [BarChartDataEntry]) + private func calcStackSize(entries: [BarChartDataEntry]) { for i in 0 ..< entries.count { diff --git a/Source/Charts/Data/Implementations/Standard/BubbleChartDataSet.swift b/Source/Charts/Data/Implementations/Standard/BubbleChartDataSet.swift index 6041bb94d3..cdc3567e69 100644 --- a/Source/Charts/Data/Implementations/Standard/BubbleChartDataSet.swift +++ b/Source/Charts/Data/Implementations/Standard/BubbleChartDataSet.swift @@ -17,7 +17,7 @@ open class BubbleChartDataSet: BarLineScatterCandleBubbleChartDataSet, IBubbleCh { // MARK: - Data functions and accessors - @objc internal var _maxSize = CGFloat(0.0) + internal var _maxSize = CGFloat(0.0) open var maxSize: CGFloat { return _maxSize } @objc open var normalizeSizeEnabled: Bool = true diff --git a/Source/Charts/Data/Implementations/Standard/CandleChartDataSet.swift b/Source/Charts/Data/Implementations/Standard/CandleChartDataSet.swift index d4da90d69f..852e65d385 100644 --- a/Source/Charts/Data/Implementations/Standard/CandleChartDataSet.swift +++ b/Source/Charts/Data/Implementations/Standard/CandleChartDataSet.swift @@ -75,7 +75,7 @@ open class CandleChartDataSet: LineScatterCandleRadarChartDataSet, ICandleChartD /// the space between the candle entries /// /// **default**: 0.1 (10%) - fileprivate var _barSpace = CGFloat(0.1) + private var _barSpace = CGFloat(0.1) /// the space that is left out on the left and right side of each candle, /// **default**: 0.1 (10%), max 0.45, min 0.0 diff --git a/Source/Charts/Data/Implementations/Standard/ChartData.swift b/Source/Charts/Data/Implementations/Standard/ChartData.swift index 411643d67f..3b9851a43c 100644 --- a/Source/Charts/Data/Implementations/Standard/ChartData.swift +++ b/Source/Charts/Data/Implementations/Standard/ChartData.swift @@ -13,16 +13,16 @@ import Foundation open class ChartData: NSObject { - @objc internal var _yMax: Double = -Double.greatestFiniteMagnitude - @objc internal var _yMin: Double = Double.greatestFiniteMagnitude - @objc internal var _xMax: Double = -Double.greatestFiniteMagnitude - @objc internal var _xMin: Double = Double.greatestFiniteMagnitude - @objc internal var _leftAxisMax: Double = -Double.greatestFiniteMagnitude - @objc internal var _leftAxisMin: Double = Double.greatestFiniteMagnitude - @objc internal var _rightAxisMax: Double = -Double.greatestFiniteMagnitude - @objc internal var _rightAxisMin: Double = Double.greatestFiniteMagnitude + 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 internal var _dataSets = [IChartDataSet]() + internal var _dataSets = [IChartDataSet]() public override init() { @@ -45,7 +45,7 @@ open class ChartData: NSObject self.init(dataSets: dataSet === nil ? nil : [dataSet!]) } - @objc internal func initialize(dataSets: [IChartDataSet]) + internal func initialize(dataSets: [IChartDataSet]) { notifyDataChanged() } @@ -350,7 +350,7 @@ open class ChartData: NSObject /// - 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. - @objc internal func getDataSetIndexByLabel(_ label: String, ignorecase: Bool) -> Int + internal func getDataSetIndexByLabel(_ label: String, ignorecase: Bool) -> Int { if ignorecase { @@ -381,7 +381,7 @@ open class ChartData: NSObject } /// - returns: The labels of all DataSets as a string array. - @objc internal func dataSetLabels() -> [String] + internal func dataSetLabels() -> [String] { var types = [String]() diff --git a/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift b/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift index b829f630e1..c55ee6fd3d 100644 --- a/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift +++ b/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift @@ -55,19 +55,19 @@ open class ChartDataSet: ChartBaseDataSet // MARK: - Data functions and accessors /// the entries that this dataset represents / holds together - @objc internal var _values: [ChartDataEntry]! + internal var _values: [ChartDataEntry]! /// maximum y-value in the value array - @objc internal var _yMax: Double = -Double.greatestFiniteMagnitude + internal var _yMax: Double = -Double.greatestFiniteMagnitude /// minimum y-value in the value array - @objc internal var _yMin: Double = Double.greatestFiniteMagnitude + internal var _yMin: Double = Double.greatestFiniteMagnitude /// maximum x-value in the value array - @objc internal var _xMax: Double = -Double.greatestFiniteMagnitude + internal var _xMax: Double = -Double.greatestFiniteMagnitude /// minimum x-value in the value array - @objc internal var _xMin: Double = Double.greatestFiniteMagnitude + internal var _xMin: Double = Double.greatestFiniteMagnitude /// * /// - note: Calls `notifyDataSetChanged()` after setting a new value. @@ -158,7 +158,7 @@ open class ChartDataSet: ChartBaseDataSet /// Updates the min and max x and y value of this DataSet based on the given Entry. /// /// - parameter e: - @objc internal func calcMinMax(entry e: ChartDataEntry) + internal func calcMinMax(entry e: ChartDataEntry) { calcMinMaxX(entry: e) calcMinMaxY(entry: e) diff --git a/Source/Charts/Data/Implementations/Standard/CombinedChartData.swift b/Source/Charts/Data/Implementations/Standard/CombinedChartData.swift index 9492f64de9..9e2342a200 100644 --- a/Source/Charts/Data/Implementations/Standard/CombinedChartData.swift +++ b/Source/Charts/Data/Implementations/Standard/CombinedChartData.swift @@ -13,11 +13,11 @@ import Foundation open class CombinedChartData: BarLineScatterCandleBubbleChartData { - fileprivate var _lineData: LineChartData! - fileprivate var _barData: BarChartData! - fileprivate var _scatterData: ScatterChartData! - fileprivate var _candleData: CandleChartData! - fileprivate var _bubbleData: BubbleChartData! + private var _lineData: LineChartData! + private var _barData: BarChartData! + private var _scatterData: ScatterChartData! + private var _candleData: CandleChartData! + private var _bubbleData: BubbleChartData! public override init() { diff --git a/Source/Charts/Data/Implementations/Standard/LineChartDataSet.swift b/Source/Charts/Data/Implementations/Standard/LineChartDataSet.swift index eae20419cb..357d29604f 100644 --- a/Source/Charts/Data/Implementations/Standard/LineChartDataSet.swift +++ b/Source/Charts/Data/Implementations/Standard/LineChartDataSet.swift @@ -24,7 +24,7 @@ open class LineChartDataSet: LineRadarChartDataSet, ILineChartDataSet case horizontalBezier } - fileprivate func initialize() + private func initialize() { // default color circleColors.append(NSUIColor(red: 140.0/255.0, green: 234.0/255.0, blue: 255.0/255.0, alpha: 1.0)) @@ -51,7 +51,7 @@ open class LineChartDataSet: LineRadarChartDataSet, ILineChartDataSet /// **default**: Linear open var mode: Mode = Mode.linear - fileprivate var _cubicIntensity = CGFloat(0.2) + private var _cubicIntensity = CGFloat(0.2) /// Intensity for cubic lines (min = 0.05, max = 1) /// @@ -176,7 +176,7 @@ open class LineChartDataSet: LineRadarChartDataSet, ILineChartDataSet open var lineCapType = CGLineCap.butt /// formatter for customizing the position of the fill-line - fileprivate var _fillFormatter: IFillFormatter = DefaultFillFormatter() + private var _fillFormatter: IFillFormatter = DefaultFillFormatter() /// Sets a custom IFillFormatter to the chart that handles the position of the filled-line for each DataSet. Set this to null to use the default logic. open var fillFormatter: IFillFormatter? diff --git a/Source/Charts/Data/Implementations/Standard/LineRadarChartDataSet.swift b/Source/Charts/Data/Implementations/Standard/LineRadarChartDataSet.swift index 4fe67697e9..be934257f1 100644 --- a/Source/Charts/Data/Implementations/Standard/LineRadarChartDataSet.swift +++ b/Source/Charts/Data/Implementations/Standard/LineRadarChartDataSet.swift @@ -20,7 +20,7 @@ open class LineRadarChartDataSet: LineScatterCandleRadarChartDataSet, ILineRadar // MARK: - Styling functions and accessors /// The color that is used for filling the line surface area. - fileprivate var _fillColor = NSUIColor(red: 140.0/255.0, green: 234.0/255.0, blue: 255.0/255.0, alpha: 1.0) + private var _fillColor = NSUIColor(red: 140.0/255.0, green: 234.0/255.0, blue: 255.0/255.0, alpha: 1.0) /// The color that is used for filling the line surface area. open var fillColor: NSUIColor @@ -41,7 +41,7 @@ open class LineRadarChartDataSet: LineScatterCandleRadarChartDataSet, ILineRadar /// **default**: 0.33 open var fillAlpha = CGFloat(0.33) - fileprivate var _lineWidth = CGFloat(1.0) + private var _lineWidth = CGFloat(1.0) /// line width of the chart (min = 0.0, max = 10) /// diff --git a/Source/Charts/Data/Implementations/Standard/PieChartDataSet.swift b/Source/Charts/Data/Implementations/Standard/PieChartDataSet.swift index f7fd919046..af4aa617d0 100644 --- a/Source/Charts/Data/Implementations/Standard/PieChartDataSet.swift +++ b/Source/Charts/Data/Implementations/Standard/PieChartDataSet.swift @@ -21,7 +21,7 @@ open class PieChartDataSet: ChartDataSet, IPieChartDataSet case outsideSlice } - fileprivate func initialize() + private func initialize() { self.valueTextColor = NSUIColor.white self.valueFont = NSUIFont.systemFont(ofSize: 13.0) @@ -46,7 +46,7 @@ open class PieChartDataSet: ChartDataSet, IPieChartDataSet // MARK: - Styling functions and accessors - fileprivate var _sliceSpace = CGFloat(0.0) + private var _sliceSpace = CGFloat(0.0) /// the space in pixels between the pie-slices /// **default**: 0 diff --git a/Source/Charts/Data/Implementations/Standard/RadarChartDataSet.swift b/Source/Charts/Data/Implementations/Standard/RadarChartDataSet.swift index fcb3134fba..67b4730a28 100644 --- a/Source/Charts/Data/Implementations/Standard/RadarChartDataSet.swift +++ b/Source/Charts/Data/Implementations/Standard/RadarChartDataSet.swift @@ -15,7 +15,7 @@ import CoreGraphics open class RadarChartDataSet: LineRadarChartDataSet, IRadarChartDataSet { - fileprivate func initialize() + private func initialize() { self.valueFont = NSUIFont.systemFont(ofSize: 13.0) } diff --git a/Source/Charts/Filters/DataApproximator.swift b/Source/Charts/Filters/DataApproximator.swift index 6bc0ee1bd0..6cd5338ff7 100644 --- a/Source/Charts/Filters/DataApproximator.swift +++ b/Source/Charts/Filters/DataApproximator.swift @@ -96,7 +96,7 @@ open class DataApproximator: NSObject } // else don't keep the point... } - fileprivate class Line + private class Line { var sxey: CGFloat var exsy: CGFloat diff --git a/Source/Charts/Formatters/DefaultValueFormatter.swift b/Source/Charts/Formatters/DefaultValueFormatter.swift index 0e238bf7a7..b3fff70ac9 100644 --- a/Source/Charts/Formatters/DefaultValueFormatter.swift +++ b/Source/Charts/Formatters/DefaultValueFormatter.swift @@ -24,7 +24,7 @@ open class DefaultValueFormatter: NSObject, IValueFormatter @objc open var hasAutoDecimals: Bool = false - fileprivate var _formatter: NumberFormatter? + private var _formatter: NumberFormatter? @objc open var formatter: NumberFormatter? { get { return _formatter } @@ -35,7 +35,7 @@ open class DefaultValueFormatter: NSObject, IValueFormatter } } - fileprivate var _decimals: Int? + private var _decimals: Int? open var decimals: Int? { get { return _decimals } diff --git a/Source/Charts/Highlight/ChartHighlighter.swift b/Source/Charts/Highlight/ChartHighlighter.swift index d8e1d0bc4d..719f44e757 100644 --- a/Source/Charts/Highlight/ChartHighlighter.swift +++ b/Source/Charts/Highlight/ChartHighlighter.swift @@ -102,7 +102,7 @@ open class ChartHighlighter : NSObject, IHighlighter } /// - returns: An array of `Highlight` objects corresponding to the selected xValue and dataSetIndex. - @objc internal func buildHighlights( + internal func buildHighlights( dataSet set: IChartDataSet, dataSetIndex: Int, xValue: Double, @@ -166,7 +166,7 @@ open class ChartHighlighter : NSObject, IHighlighter } /// - returns: The minimum distance from a touch-y-value (in pixels) to the closest y-value (in pixels) that is displayed in the chart. - @objc internal func getMinimumDistance( + internal func getMinimumDistance( closestValues: [Highlight], y: CGFloat, axis: YAxis.AxisDependency) -> CGFloat @@ -190,17 +190,17 @@ open class ChartHighlighter : NSObject, IHighlighter return distance } - @objc internal func getHighlightPos(high: Highlight) -> CGFloat + internal func getHighlightPos(high: Highlight) -> CGFloat { return high.yPx } - @objc internal func getDistance(x1: CGFloat, y1: CGFloat, x2: CGFloat, y2: CGFloat) -> CGFloat + internal func getDistance(x1: CGFloat, y1: CGFloat, x2: CGFloat, y2: CGFloat) -> CGFloat { return hypot(x1 - x2, y1 - y2) } - @objc internal var data: ChartData? + internal var data: ChartData? { return chart?.data } diff --git a/Source/Charts/Highlight/CombinedHighlighter.swift b/Source/Charts/Highlight/CombinedHighlighter.swift index 86e841993c..f7ca82f71c 100644 --- a/Source/Charts/Highlight/CombinedHighlighter.swift +++ b/Source/Charts/Highlight/CombinedHighlighter.swift @@ -16,7 +16,7 @@ import CoreGraphics open class CombinedHighlighter: ChartHighlighter { /// bar highlighter for supporting stacked highlighting - fileprivate var barHighlighter: BarHighlighter? + private var barHighlighter: BarHighlighter? @objc public init(chart: CombinedChartDataProvider, barDataProvider: BarChartDataProvider) { diff --git a/Source/Charts/Highlight/Highlight.swift b/Source/Charts/Highlight/Highlight.swift index 80778f7663..a33127b8ba 100644 --- a/Source/Charts/Highlight/Highlight.swift +++ b/Source/Charts/Highlight/Highlight.swift @@ -22,10 +22,10 @@ open class Highlight: NSObject fileprivate var _y = Double.nan /// the x-pixel of the highlight - fileprivate var _xPx = CGFloat.nan + private var _xPx = CGFloat.nan /// the y-pixel of the highlight - fileprivate var _yPx = CGFloat.nan + private var _yPx = CGFloat.nan /// the index of the data object - in case it refers to more than one @objc open var dataIndex = Int(-1) @@ -39,7 +39,7 @@ open class Highlight: NSObject fileprivate var _stackIndex = Int(-1) /// the axis the highlighted value belongs to - fileprivate var _axis: YAxis.AxisDependency = YAxis.AxisDependency.left + private var _axis: YAxis.AxisDependency = YAxis.AxisDependency.left /// the x-position (pixels) on which this highlight object was last drawn @objc open var drawX: CGFloat = 0.0 diff --git a/Source/Charts/Highlight/RadarHighlighter.swift b/Source/Charts/Highlight/RadarHighlighter.swift index 6e25ac20d1..8df2d3195a 100644 --- a/Source/Charts/Highlight/RadarHighlighter.swift +++ b/Source/Charts/Highlight/RadarHighlighter.swift @@ -44,7 +44,7 @@ open class RadarHighlighter: PieRadarHighlighter /// The Highlight objects give information about the value at the selected index and DataSet it belongs to. /// /// - parameter index: - @objc internal func getHighlights(forIndex index: Int) -> [Highlight] + internal func getHighlights(forIndex index: Int) -> [Highlight] { var vals = [Highlight]() diff --git a/Source/Charts/Jobs/AnimatedMoveViewJob.swift b/Source/Charts/Jobs/AnimatedMoveViewJob.swift index b2dc5d2205..b6ea8c28e5 100644 --- a/Source/Charts/Jobs/AnimatedMoveViewJob.swift +++ b/Source/Charts/Jobs/AnimatedMoveViewJob.swift @@ -18,28 +18,6 @@ import CoreGraphics open class AnimatedMoveViewJob: AnimatedViewPortJob { - public override init( - viewPortHandler: ViewPortHandler, - xValue: Double, - yValue: Double, - transformer: Transformer, - view: ChartViewBase, - xOrigin: CGFloat, - yOrigin: CGFloat, - duration: TimeInterval, - easing: ChartEasingFunctionBlock?) - { - super.init(viewPortHandler: viewPortHandler, - xValue: xValue, - yValue: yValue, - transformer: transformer, - view: view, - xOrigin: xOrigin, - yOrigin: yOrigin, - duration: duration, - easing: easing) - } - internal override func animationUpdate() { guard diff --git a/Source/Charts/Jobs/AnimatedViewPortJob.swift b/Source/Charts/Jobs/AnimatedViewPortJob.swift index dbde0bf4b1..7b2cd3e175 100644 --- a/Source/Charts/Jobs/AnimatedViewPortJob.swift +++ b/Source/Charts/Jobs/AnimatedViewPortJob.swift @@ -18,16 +18,16 @@ import CoreGraphics open class AnimatedViewPortJob: ViewPortJob { - @objc internal var phase: CGFloat = 1.0 - @objc internal var xOrigin: CGFloat = 0.0 - @objc internal var yOrigin: CGFloat = 0.0 + internal var phase: CGFloat = 1.0 + internal var xOrigin: CGFloat = 0.0 + internal var yOrigin: CGFloat = 0.0 - fileprivate var _startTime: TimeInterval = 0.0 - fileprivate var _displayLink: NSUIDisplayLink! - fileprivate var _duration: TimeInterval = 0.0 - fileprivate var _endTime: TimeInterval = 0.0 + private var _startTime: TimeInterval = 0.0 + private var _displayLink: NSUIDisplayLink! + private var _duration: TimeInterval = 0.0 + private var _endTime: TimeInterval = 0.0 - fileprivate var _easing: ChartEasingFunctionBlock? + private var _easing: ChartEasingFunctionBlock? @objc public init( viewPortHandler: ViewPortHandler, @@ -71,52 +71,40 @@ open class AnimatedViewPortJob: ViewPortJob updateAnimationPhase(_startTime) _displayLink = NSUIDisplayLink(target: self, selector: #selector(animationLoop)) - _displayLink.add(to: RunLoop.main, forMode: RunLoopMode.commonModes) + _displayLink.add(to: .main, forMode: .commonModes) } @objc open func stop(finish: Bool) { - if _displayLink != nil + guard _displayLink != nil else { return } + + _displayLink.remove(from: .main, forMode: .commonModes) + _displayLink = nil + + if finish { - _displayLink.remove(from: RunLoop.main, forMode: RunLoopMode.commonModes) - _displayLink = nil - - if finish + if phase != 1.0 { - if phase != 1.0 - { - phase = 1.0 - phase = 1.0 - - animationUpdate() - } - - animationEnd() + phase = 1.0 + animationUpdate() } + + animationEnd() } } - fileprivate func updateAnimationPhase(_ currentTime: TimeInterval) + private func updateAnimationPhase(_ currentTime: TimeInterval) { - let elapsedTime: TimeInterval = currentTime - _startTime - let duration: TimeInterval = _duration - var elapsed: TimeInterval = elapsedTime - if elapsed > duration - { - elapsed = duration - } - - if _easing != nil - { - phase = CGFloat(_easing!(elapsed, duration)) - } - else - { - phase = CGFloat(elapsed / duration) - } + let elapsedTime = currentTime - _startTime + let duration = _duration + var elapsed = elapsedTime + + elapsed = min(elapsed, duration) + + phase = CGFloat(_easing?(elapsed, duration) ?? elapsed / duration) } - @objc fileprivate func animationLoop() + @objc private func animationLoop() { let currentTime: TimeInterval = CACurrentMediaTime() @@ -130,13 +118,13 @@ open class AnimatedViewPortJob: ViewPortJob } } - @objc internal func animationUpdate() + internal func animationUpdate() { - // Override this + fatalError("`animationUpdate()` must be overriden by subclasses") } - @objc internal func animationEnd() + internal func animationEnd() { - // Override this + fatalError("`animationEnd()` must be overriden by subclasses") } } diff --git a/Source/Charts/Jobs/AnimatedZoomViewJob.swift b/Source/Charts/Jobs/AnimatedZoomViewJob.swift index 3ad1959cfc..4e9d5fd981 100644 --- a/Source/Charts/Jobs/AnimatedZoomViewJob.swift +++ b/Source/Charts/Jobs/AnimatedZoomViewJob.swift @@ -14,14 +14,14 @@ import CoreGraphics open class AnimatedZoomViewJob: AnimatedViewPortJob { - @objc internal var yAxis: YAxis? - @objc internal var xAxisRange: Double = 0.0 - @objc internal var scaleX: CGFloat = 0.0 - @objc internal var scaleY: CGFloat = 0.0 - @objc internal var zoomOriginX: CGFloat = 0.0 - @objc internal var zoomOriginY: CGFloat = 0.0 - @objc internal var zoomCenterX: CGFloat = 0.0 - @objc internal var zoomCenterY: CGFloat = 0.0 + internal var yAxis: YAxis? + internal var xAxisRange: Double = 0.0 + internal var scaleX: CGFloat = 0.0 + internal var scaleY: CGFloat = 0.0 + internal var zoomOriginX: CGFloat = 0.0 + internal var zoomOriginY: CGFloat = 0.0 + internal var zoomCenterX: CGFloat = 0.0 + internal var zoomCenterY: CGFloat = 0.0 @objc public init( viewPortHandler: ViewPortHandler, @@ -72,7 +72,7 @@ open class AnimatedZoomViewJob: AnimatedViewPortJob let scaleY = yOrigin + (self.scaleY - yOrigin) * phase var matrix = viewPortHandler.setZoom(scaleX: scaleX, scaleY: scaleY) - let _ = viewPortHandler.refresh(newMatrix: matrix, chart: view, invalidate: false) + viewPortHandler.refresh(newMatrix: matrix, chart: view, invalidate: false) let valsInView = CGFloat(yAxis?.axisRange ?? 0.0) / viewPortHandler.scaleY let xsInView = CGFloat(xAxisRange) / viewPortHandler.scaleX @@ -85,7 +85,7 @@ open class AnimatedZoomViewJob: AnimatedViewPortJob transformer.pointValueToPixel(&pt) matrix = viewPortHandler.translate(pt: pt) - let _ = viewPortHandler.refresh(newMatrix: matrix, chart: view, invalidate: true) + viewPortHandler.refresh(newMatrix: matrix, chart: view, invalidate: true) } internal override func animationEnd() diff --git a/Source/Charts/Jobs/MoveViewJob.swift b/Source/Charts/Jobs/MoveViewJob.swift index b175b1707e..acc8165d39 100644 --- a/Source/Charts/Jobs/MoveViewJob.swift +++ b/Source/Charts/Jobs/MoveViewJob.swift @@ -18,22 +18,7 @@ import CoreGraphics @objc(MoveChartViewJob) open class MoveViewJob: ViewPortJob -{ - public override init( - viewPortHandler: ViewPortHandler, - xValue: Double, - yValue: Double, - transformer: Transformer, - view: ChartViewBase) - { - super.init( - viewPortHandler: viewPortHandler, - xValue: xValue, - yValue: yValue, - transformer: transformer, - view: view) - } - +{ open override func doJob() { guard @@ -43,8 +28,8 @@ open class MoveViewJob: ViewPortJob else { return } var pt = CGPoint( - x: CGFloat(xValue), - y: CGFloat(yValue) + x: xValue, + y: yValue ) transformer.pointValueToPixel(&pt) diff --git a/Source/Charts/Jobs/ViewPortJob.swift b/Source/Charts/Jobs/ViewPortJob.swift index 42f9b76783..c52562ed53 100644 --- a/Source/Charts/Jobs/ViewPortJob.swift +++ b/Source/Charts/Jobs/ViewPortJob.swift @@ -16,12 +16,12 @@ import CoreGraphics @objc(ChartViewPortJob) open class ViewPortJob: NSObject { - @objc internal var point: CGPoint = CGPoint() - @objc internal weak var viewPortHandler: ViewPortHandler? - @objc internal var xValue: Double = 0.0 - @objc internal var yValue: Double = 0.0 - @objc internal weak var transformer: Transformer? - @objc internal weak var view: ChartViewBase? + internal var point: CGPoint = CGPoint() + internal weak var viewPortHandler: ViewPortHandler? + internal var xValue: Double = 0.0 + internal var yValue: Double = 0.0 + internal weak var transformer: Transformer? + internal weak var view: ChartViewBase? @objc public init( viewPortHandler: ViewPortHandler, @@ -41,6 +41,6 @@ open class ViewPortJob: NSObject @objc open func doJob() { - // Override this + fatalError("`doJob()` must be overridden by subclasses") } } diff --git a/Source/Charts/Jobs/ZoomViewJob.swift b/Source/Charts/Jobs/ZoomViewJob.swift index 7a6c8d8911..7bd805c425 100644 --- a/Source/Charts/Jobs/ZoomViewJob.swift +++ b/Source/Charts/Jobs/ZoomViewJob.swift @@ -19,9 +19,9 @@ import CoreGraphics @objc(ZoomChartViewJob) open class ZoomViewJob: ViewPortJob { - @objc internal var scaleX: CGFloat = 0.0 - @objc internal var scaleY: CGFloat = 0.0 - @objc internal var axisDependency: YAxis.AxisDependency = YAxis.AxisDependency.left + internal var scaleX: CGFloat = 0.0 + internal var scaleY: CGFloat = 0.0 + internal var axisDependency: YAxis.AxisDependency = .left @objc public init( viewPortHandler: ViewPortHandler, @@ -54,20 +54,20 @@ open class ZoomViewJob: ViewPortJob else { return } var matrix = viewPortHandler.setZoom(scaleX: scaleX, scaleY: scaleY) - let _ = viewPortHandler.refresh(newMatrix: matrix, chart: view, invalidate: false) + viewPortHandler.refresh(newMatrix: matrix, chart: view, invalidate: false) let yValsInView = (view as! BarLineChartViewBase).getAxis(axisDependency).axisRange / Double(viewPortHandler.scaleY) let xValsInView = (view as! BarLineChartViewBase).xAxis.axisRange / Double(viewPortHandler.scaleX) var pt = CGPoint( - x: CGFloat(xValue - xValsInView / 2.0), - y: CGFloat(yValue + yValsInView / 2.0) + x: CGFloat(xValue - xValsInView) / 2.0, + y: CGFloat(yValue + yValsInView) / 2.0 ) transformer.pointValueToPixel(&pt) matrix = viewPortHandler.translate(pt: pt) - let _ = viewPortHandler.refresh(newMatrix: matrix, chart: view, invalidate: false) + viewPortHandler.refresh(newMatrix: matrix, chart: view, invalidate: false) (view as! BarLineChartViewBase).calculateOffsets() view.setNeedsDisplay() diff --git a/Source/Charts/Renderers/AxisRendererBase.swift b/Source/Charts/Renderers/AxisRendererBase.swift index 52a234e011..bd1c6aa466 100644 --- a/Source/Charts/Renderers/AxisRendererBase.swift +++ b/Source/Charts/Renderers/AxisRendererBase.swift @@ -20,13 +20,8 @@ open class AxisRendererBase: Renderer /// transformer to transform values to screen pixels and return @objc open var transformer: Transformer? - - public override init() - { - super.init() - } - - @objc public init(viewPortHandler: ViewPortHandler?, transformer: Transformer?, axis: AxisBase?) + + @objc public init(viewPortHandler: ViewPortHandler, transformer: Transformer?, axis: AxisBase?) { super.init(viewPortHandler: viewPortHandler) @@ -68,23 +63,20 @@ open class AxisRendererBase: Renderer if let transformer = self.transformer { // calculate the starting and entry point of the y-labels (depending on zoom / contentrect bounds) - if let viewPortHandler = viewPortHandler + if viewPortHandler.contentWidth > 10.0 && !viewPortHandler.isFullyZoomedOutY { - if viewPortHandler.contentWidth > 10.0 && !viewPortHandler.isFullyZoomedOutY + let p1 = transformer.valueForTouchPoint(CGPoint(x: viewPortHandler.contentLeft, y: viewPortHandler.contentTop)) + let p2 = transformer.valueForTouchPoint(CGPoint(x: viewPortHandler.contentLeft, y: viewPortHandler.contentBottom)) + + if !inverted + { + min = Double(p2.y) + max = Double(p1.y) + } + else { - let p1 = transformer.valueForTouchPoint(CGPoint(x: viewPortHandler.contentLeft, y: viewPortHandler.contentTop)) - let p2 = transformer.valueForTouchPoint(CGPoint(x: viewPortHandler.contentLeft, y: viewPortHandler.contentBottom)) - - if !inverted - { - min = Double(p2.y) - max = Double(p1.y) - } - else - { - min = Double(p1.y) - max = Double(p2.y) - } + min = Double(p1.y) + max = Double(p2.y) } } } diff --git a/Source/Charts/Renderers/BarChartRenderer.swift b/Source/Charts/Renderers/BarChartRenderer.swift index 8aa3bc9b0a..3621ddbf9c 100644 --- a/Source/Charts/Renderers/BarChartRenderer.swift +++ b/Source/Charts/Renderers/BarChartRenderer.swift @@ -18,14 +18,14 @@ import CoreGraphics open class BarChartRenderer: BarLineScatterCandleBubbleRenderer { - fileprivate class Buffer + private class Buffer { var rects = [CGRect]() } @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) @@ -33,7 +33,7 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer } // [CGRect] per dataset - fileprivate var _buffers = [Buffer]() + private var _buffers = [Buffer]() open override func initBuffers() { @@ -68,12 +68,11 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer } } - fileprivate func prepareBuffer(dataSet: IBarChartDataSet, index: Int) + private func prepareBuffer(dataSet: IBarChartDataSet, index: Int) { guard let dataProvider = dataProvider, - let barData = dataProvider.barData, - let animator = animator + let barData = dataProvider.barData else { return } let barWidthHalf = barData.barWidth / 2.0 @@ -204,14 +203,11 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer } } - fileprivate var _barShadowRectBuffer: CGRect = CGRect() + private var _barShadowRectBuffer: CGRect = CGRect() @objc open func drawDataSet(context: CGContext, dataSet: IBarChartDataSet, index: Int) { - guard - let dataProvider = dataProvider, - let viewPortHandler = self.viewPortHandler - else { return } + guard let dataProvider = dataProvider else { return } let trans = dataProvider.getTransformer(forAxis: dataSet.axisDependency) @@ -227,10 +223,7 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer // 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 @@ -347,7 +340,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) @@ -357,18 +350,16 @@ 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 let valueOffsetPlus: CGFloat = 4.5 var posOffset: CGFloat var negOffset: CGFloat let drawValueAboveBar = dataProvider.isDrawValueAboveBarEnabled - + for dataSetIndex in 0 ..< barData.dataSetCount { guard let dataSet = dataSets[dataSetIndex] as? IBarChartDataSet else { continue } @@ -693,7 +684,7 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer } /// Sets the drawing position of the highlight object based on the riven bar-rect. - @objc internal func setHighlightDrawPos(highlight high: Highlight, barRect: CGRect) + internal func setHighlightDrawPos(highlight high: Highlight, barRect: CGRect) { high.setDraw(x: barRect.midX, y: barRect.origin.y) } diff --git a/Source/Charts/Renderers/BarLineScatterCandleBubbleRenderer.swift b/Source/Charts/Renderers/BarLineScatterCandleBubbleRenderer.swift index 796c757290..4ba1b5fac7 100644 --- a/Source/Charts/Renderers/BarLineScatterCandleBubbleRenderer.swift +++ b/Source/Charts/Renderers/BarLineScatterCandleBubbleRenderer.swift @@ -17,24 +17,16 @@ 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) } /// Checks if the provided entry object is in bounds for drawing considering the current animation phase. - @objc internal func isInBoundsX(entry e: ChartDataEntry, dataSet: IBarLineScatterCandleBubbleChartDataSet) -> Bool + internal func isInBoundsX(entry e: ChartDataEntry, dataSet: IBarLineScatterCandleBubbleChartDataSet) -> Bool { let entryIndex = dataSet.entryIndex(entry: e) - - if Double(entryIndex) >= Double(dataSet.entryCount) * (animator?.phaseX ?? 1.0) - { - return false - } - else - { - return true - } + 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. @@ -47,7 +39,7 @@ open class BarLineScatterCandleBubbleRenderer: DataRenderer } /// - returns: `true` if the DataSet values should be drawn, `false` if not. - @objc internal func shouldDrawValues(forDataSet set: IChartDataSet) -> Bool + internal func shouldDrawValues(forDataSet set: IChartDataSet) -> Bool { return set.isVisible && (set.isDrawValuesEnabled || set.isDrawIconsEnabled) } @@ -94,5 +86,4 @@ open class BarLineScatterCandleBubbleRenderer: DataRenderer range = Int(Double(self.max - self.min) * phaseX) } } - } diff --git a/Source/Charts/Renderers/BubbleChartRenderer.swift b/Source/Charts/Renderers/BubbleChartRenderer.swift index 4f4265db3b..8498070c17 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) @@ -35,16 +35,13 @@ open class BubbleChartRenderer: BarLineScatterCandleBubbleRenderer let bubbleData = dataProvider.bubbleData else { return } - for set in bubbleData.dataSets as! [IBubbleChartDataSet] + for set in bubbleData.dataSets as! [IBubbleChartDataSet] where set.isVisible { - if set.isVisible - { - drawDataSet(context: context, dataSet: set) - } + drawDataSet(context: context, dataSet: set) } } - fileprivate func getShapeSize( + private func getShapeSize( entrySize: CGFloat, maxSize: CGFloat, reference: CGFloat, @@ -57,16 +54,12 @@ open class BubbleChartRenderer: BarLineScatterCandleBubbleRenderer return shapeSize } - fileprivate var _pointBuffer = CGPoint() - fileprivate var _sizeBuffer = [CGPoint](repeating: CGPoint(), count: 2) + private var _pointBuffer = CGPoint() + private var _sizeBuffer = [CGPoint](repeating: CGPoint(), count: 2) @objc open func drawDataSet(context: CGContext, dataSet: IBubbleChartDataSet) { - guard - let dataProvider = dataProvider, - let viewPortHandler = self.viewPortHandler, - let animator = animator - else { return } + guard let dataProvider = dataProvider else { return } let trans = dataProvider.getTransformer(forAxis: dataSet.axisDependency) @@ -84,6 +77,7 @@ open class BubbleChartRenderer: BarLineScatterCandleBubbleRenderer trans.pointValuesToPixel(&_sizeBuffer) context.saveGState() + defer { context.restoreGState() } let normalizeSize = dataSet.isNormalizeSizeEnabled @@ -103,21 +97,13 @@ open class BubbleChartRenderer: BarLineScatterCandleBubbleRenderer let shapeSize = getShapeSize(entrySize: entry.size, maxSize: dataSet.maxSize, reference: referenceSize, normalizeSize: normalizeSize) let shapeHalf = shapeSize / 2.0 - if !viewPortHandler.isInBoundsTop(_pointBuffer.y + shapeHalf) - || !viewPortHandler.isInBoundsBottom(_pointBuffer.y - shapeHalf) - { - continue - } - - if !viewPortHandler.isInBoundsLeft(_pointBuffer.x + shapeHalf) - { - continue - } - - if !viewPortHandler.isInBoundsRight(_pointBuffer.x - shapeHalf) - { - break - } + guard + viewPortHandler.isInBoundsTop(_pointBuffer.y + shapeHalf), + viewPortHandler.isInBoundsBottom(_pointBuffer.y - shapeHalf), + viewPortHandler.isInBoundsLeft(_pointBuffer.x + shapeHalf) + else { continue } + + guard viewPortHandler.isInBoundsRight(_pointBuffer.x - shapeHalf) else { break } let color = dataSet.color(atIndex: Int(entry.x)) @@ -131,100 +117,86 @@ open class BubbleChartRenderer: BarLineScatterCandleBubbleRenderer context.setFillColor(color.cgColor) context.fillEllipse(in: rect) } - - context.restoreGState() } open override func drawValues(context: CGContext) { guard 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 } - - // if values are drawn - if isDrawingValuesAllowed(dataProvider: dataProvider) + + let phaseX = max(0.0, min(1.0, animator.phaseX)) + let phaseY = animator.phaseY + + var pt = CGPoint() + + for i in 0.. Bool { - guard let data = dataProvider?.data - else { return false } - return data.entryCount < Int(CGFloat(dataProvider?.maxVisibleCount ?? 0) * (self.viewPortHandler?.scaleX ?? 1.0)) + guard let data = dataProvider?.data else { return false } + return data.entryCount < Int(CGFloat(dataProvider?.maxVisibleCount ?? 0) * viewPortHandler.scaleX) } } diff --git a/Source/Charts/Renderers/CombinedChartRenderer.swift b/Source/Charts/Renderers/CombinedChartRenderer.swift index 72cb1f14d2..d38ccb5f7a 100644 --- a/Source/Charts/Renderers/CombinedChartRenderer.swift +++ b/Source/Charts/Renderers/CombinedChartRenderer.swift @@ -22,11 +22,11 @@ open class CombinedChartRenderer: DataRenderer /// if set to true, a grey area is drawn behind each bar that indicates the maximum value @objc open var drawBarShadowEnabled = false - @objc internal var _renderers = [DataRenderer]() + internal var _renderers = [DataRenderer]() internal var _drawOrder: [CombinedChartView.DrawOrder] = [.bar, .bubble, .line, .candle, .scatter] - @objc public init(chart: CombinedChartView?, animator: Animator, viewPortHandler: ViewPortHandler?) + @objc public init(chart: CombinedChartView, animator: Animator, viewPortHandler: ViewPortHandler) { super.init(animator: animator, viewPortHandler: viewPortHandler) @@ -36,15 +36,11 @@ open class CombinedChartRenderer: DataRenderer } /// Creates the renderers needed for this combined-renderer in the required order. Also takes the DrawOrder into consideration. - @objc internal func createRenderers() + internal func createRenderers() { _renderers = [DataRenderer]() - guard let - chart = chart, - let animator = animator, - let viewPortHandler = self.viewPortHandler - else { return } + guard let chart = chart else { return } for order in drawOrder { diff --git a/Source/Charts/Renderers/HorizontalBarChartRenderer.swift b/Source/Charts/Renderers/HorizontalBarChartRenderer.swift index 2de854df43..23925c4d60 100644 --- a/Source/Charts/Renderers/HorizontalBarChartRenderer.swift +++ b/Source/Charts/Renderers/HorizontalBarChartRenderer.swift @@ -19,18 +19,18 @@ import CoreGraphics open class HorizontalBarChartRenderer: BarChartRenderer { - fileprivate class Buffer + private class Buffer { 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) } // [CGRect] per dataset - fileprivate var _buffers = [Buffer]() + private var _buffers = [Buffer]() open override func initBuffers() { @@ -65,12 +65,11 @@ open class HorizontalBarChartRenderer: BarChartRenderer } } - fileprivate func prepareBuffer(dataSet: IBarChartDataSet, index: Int) + private func prepareBuffer(dataSet: IBarChartDataSet, index: Int) { guard let dataProvider = dataProvider, - let barData = dataProvider.barData, - let animator = animator + let barData = dataProvider.barData else { return } let barWidthHalf = barData.barWidth / 2.0 @@ -178,14 +177,11 @@ open class HorizontalBarChartRenderer: BarChartRenderer } } - fileprivate var _barShadowRectBuffer: CGRect = CGRect() + private var _barShadowRectBuffer: CGRect = CGRect() open override func drawDataSet(context: CGContext, dataSet: IBarChartDataSet, index: Int) { - guard let - dataProvider = dataProvider, - let viewPortHandler = self.viewPortHandler - else { return } + guard let dataProvider = dataProvider else { return } let trans = dataProvider.getTransformer(forAxis: dataSet.axisDependency) @@ -201,10 +197,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 +292,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) @@ -309,9 +302,7 @@ open class HorizontalBarChartRenderer: BarChartRenderer { guard let dataProvider = dataProvider, - let barData = dataProvider.barData, - let animator = animator, - let viewPortHandler = self.viewPortHandler + let barData = dataProvider.barData else { return } var dataSets = barData.dataSets @@ -610,7 +601,7 @@ open class HorizontalBarChartRenderer: BarChartRenderer { guard let data = dataProvider?.data else { return false } - return data.entryCount < Int(CGFloat(dataProvider?.maxVisibleCount ?? 0) * (self.viewPortHandler?.scaleY ?? 1.0)) + return data.entryCount < Int(CGFloat(dataProvider?.maxVisibleCount ?? 0) * self.viewPortHandler.scaleY) } /// Sets the drawing position of the highlight object based on the riven bar-rect. diff --git a/Source/Charts/Renderers/LegendRenderer.swift b/Source/Charts/Renderers/LegendRenderer.swift index aab91b24ad..38c3648537 100755 --- a/Source/Charts/Renderers/LegendRenderer.swift +++ b/Source/Charts/Renderers/LegendRenderer.swift @@ -22,7 +22,7 @@ open class LegendRenderer: Renderer /// the legend object this renderer renders @objc open var legend: Legend? - @objc public init(viewPortHandler: ViewPortHandler?, legend: Legend?) + @objc public init(viewPortHandler: ViewPortHandler, legend: Legend?) { super.init(viewPortHandler: viewPortHandler) @@ -32,10 +32,7 @@ open class LegendRenderer: Renderer /// Prepares the legend and calculates all needed forms, labels and colors. @objc open func computeLegend(data: ChartData) { - guard - let legend = legend, - let viewPortHandler = self.viewPortHandler - else { return } + guard let legend = legend else { return } if !legend.isLegendCustom { @@ -194,10 +191,7 @@ open class LegendRenderer: Renderer @objc open func renderLegend(context: CGContext) { - guard - let legend = legend, - let viewPortHandler = self.viewPortHandler - else { return } + guard let legend = legend else { return } if !legend.enabled { @@ -494,7 +488,7 @@ open class LegendRenderer: Renderer } } - fileprivate var _formLineSegmentsBuffer = [CGPoint](repeating: CGPoint(), count: 2) + private var _formLineSegmentsBuffer = [CGPoint](repeating: CGPoint(), count: 2) /// Draws the Legend-form at the given position with the color at the given index. @objc open func drawForm( diff --git a/Source/Charts/Renderers/LineChartRenderer.swift b/Source/Charts/Renderers/LineChartRenderer.swift index fbb1f7be30..24c5fdf285 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) @@ -288,15 +282,11 @@ open class LineChartRenderer: LineRadarRenderer } } - fileprivate var _lineSegments = [CGPoint](repeating: CGPoint(), count: 2) + private var _lineSegments = [CGPoint](repeating: CGPoint(), count: 2) @objc open func drawLinear(context: CGContext, dataSet: ILineChartDataSet) { - guard - let dataProvider = dataProvider, - let animator = animator, - let viewPortHandler = self.viewPortHandler - else { return } + guard let dataProvider = dataProvider else { return } let trans = dataProvider.getTransformer(forAxis: dataSet.axisDependency) @@ -463,9 +453,9 @@ 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 + private 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 @@ -509,11 +499,9 @@ open class LineChartRenderer: LineRadarRenderer { guard let dataProvider = dataProvider, - let lineData = dataProvider.lineData, - let animator = animator, - let viewPortHandler = self.viewPortHandler + let lineData = dataProvider.lineData else { return } - + if isDrawingValuesAllowed(dataProvider: dataProvider) { var dataSets = lineData.dataSets @@ -601,17 +589,15 @@ open class LineChartRenderer: LineRadarRenderer drawCircles(context: context) } - fileprivate func drawCircles(context: CGContext) + private func drawCircles(context: CGContext) { guard let dataProvider = dataProvider, - let lineData = dataProvider.lineData, - let animator = animator, - let viewPortHandler = self.viewPortHandler + let lineData = dataProvider.lineData else { return } let phaseY = animator.phaseY - + let dataSets = lineData.dataSets var pt = CGPoint() @@ -714,8 +700,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..6b02825053 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) } @@ -23,8 +23,6 @@ open class LineRadarRenderer: LineScatterCandleRadarRenderer /// Draws the provided path in filled mode with the provided drawable. @objc open func drawFilledPath(context: CGContext, path: CGPath, fill: Fill, fillAlpha: CGFloat) { - guard let viewPortHandler = self.viewPortHandler - else { return } context.saveGState() context.beginPath() diff --git a/Source/Charts/Renderers/LineScatterCandleRadarRenderer.swift b/Source/Charts/Renderers/LineScatterCandleRadarRenderer.swift index 2d3379960d..05203caf9c 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) } @@ -27,9 +27,6 @@ open class LineScatterCandleRadarRenderer: BarLineScatterCandleBubbleRenderer /// :param: vertical @objc open func drawHighlightLines(context: CGContext, point: CGPoint, set: ILineScatterCandleRadarChartDataSet) { - guard let - viewPortHandler = self.viewPortHandler - else { return } // draw vertical highlight lines if set.isVerticalHighlightIndicatorEnabled diff --git a/Source/Charts/Renderers/PieChartRenderer.swift b/Source/Charts/Renderers/PieChartRenderer.swift old mode 100755 new mode 100644 index 327cbc8503..a363da290d --- 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) @@ -58,12 +58,12 @@ open class PieChartRenderer: DataRenderer let angleMiddle = startAngle + sweepAngle / 2.0 // Other point of the arc - let arcEndPointX = center.x + radius * cos((startAngle + sweepAngle) * ChartUtils.Math.FDEG2RAD) - let arcEndPointY = center.y + radius * sin((startAngle + sweepAngle) * ChartUtils.Math.FDEG2RAD) + let arcEndPointX = center.x + radius * cos((startAngle + sweepAngle).DEG2RAD) + let arcEndPointY = center.y + radius * sin((startAngle + sweepAngle).DEG2RAD) // Middle point on the arc - let arcMidPointX = center.x + radius * cos(angleMiddle * ChartUtils.Math.FDEG2RAD) - let arcMidPointY = center.y + radius * sin(angleMiddle * ChartUtils.Math.FDEG2RAD) + let arcMidPointX = center.x + radius * cos(angleMiddle.DEG2RAD) + let arcMidPointY = center.y + radius * sin(angleMiddle.DEG2RAD) // This is the base of the contained triangle let basePointsDistance = sqrt( @@ -74,7 +74,7 @@ open class PieChartRenderer: DataRenderer // the angle of the contained triangle should stay the same. // So let's find out the height of that triangle. let containedTriangleHeight = (basePointsDistance / 2.0 * - tan((180.0 - angle) / 2.0 * ChartUtils.Math.FDEG2RAD)) + tan((180.0 - angle).DEG2RAD / 2.0)) // Now we subtract that from the radius var spacedRadius = radius - containedTriangleHeight @@ -92,7 +92,6 @@ open class PieChartRenderer: DataRenderer { guard dataSet.automaticallyDisableSliceSpacing, - let viewPortHandler = self.viewPortHandler, let data = chart?.data as? PieChartData else { return dataSet.sliceSpace } @@ -108,10 +107,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 @@ -158,7 +154,7 @@ open class PieChartRenderer: DataRenderer let sliceSpaceAngleOuter = visibleAngleCount == 1 ? 0.0 : - sliceSpace / (ChartUtils.Math.FDEG2RAD * radius) + sliceSpace / radius.DEG2RAD let startAngleOuter = rotationAngle + (angle + sliceSpaceAngleOuter / 2.0) * CGFloat(phaseY) var sweepAngleOuter = (sliceAngle - sliceSpaceAngleOuter) * CGFloat(phaseY) if sweepAngleOuter < 0.0 @@ -166,15 +162,15 @@ open class PieChartRenderer: DataRenderer sweepAngleOuter = 0.0 } - let arcStartPointX = center.x + radius * cos(startAngleOuter * ChartUtils.Math.FDEG2RAD) - let arcStartPointY = center.y + radius * sin(startAngleOuter * ChartUtils.Math.FDEG2RAD) + let arcStartPointX = center.x + radius * cos(startAngleOuter.DEG2RAD) + let arcStartPointY = center.y + radius * sin(startAngleOuter.DEG2RAD) let path = CGMutablePath() path.move(to: CGPoint(x: arcStartPointX, y: arcStartPointY)) - path.addRelativeArc(center: center, radius: radius, startAngle: startAngleOuter * ChartUtils.Math.FDEG2RAD, delta: sweepAngleOuter * ChartUtils.Math.FDEG2RAD) + path.addRelativeArc(center: center, radius: radius, startAngle: startAngleOuter.DEG2RAD, delta: sweepAngleOuter.DEG2RAD) if drawInnerArc && (innerRadius > 0.0 || accountForSliceSpacing) @@ -198,7 +194,7 @@ open class PieChartRenderer: DataRenderer let sliceSpaceAngleInner = visibleAngleCount == 1 || innerRadius == 0.0 ? 0.0 : - sliceSpace / (ChartUtils.Math.FDEG2RAD * innerRadius) + sliceSpace / innerRadius.DEG2RAD let startAngleInner = rotationAngle + (angle + sliceSpaceAngleInner / 2.0) * CGFloat(phaseY) var sweepAngleInner = (sliceAngle - sliceSpaceAngleInner) * CGFloat(phaseY) if sweepAngleInner < 0.0 @@ -209,10 +205,10 @@ open class PieChartRenderer: DataRenderer path.addLine( to: CGPoint( - x: center.x + innerRadius * cos(endAngleInner * ChartUtils.Math.FDEG2RAD), - y: center.y + innerRadius * sin(endAngleInner * ChartUtils.Math.FDEG2RAD))) + x: center.x + innerRadius * cos(endAngleInner.DEG2RAD), + y: center.y + innerRadius * sin(endAngleInner.DEG2RAD))) - path.addRelativeArc(center: center, radius: innerRadius, startAngle: endAngleInner * ChartUtils.Math.FDEG2RAD, delta: -sweepAngleInner * ChartUtils.Math.FDEG2RAD) + path.addRelativeArc(center: center, radius: innerRadius, startAngle: endAngleInner.DEG2RAD, delta: -sweepAngleInner.DEG2RAD) } else { @@ -230,8 +226,8 @@ open class PieChartRenderer: DataRenderer startAngle: startAngleOuter, sweepAngle: sweepAngleOuter) - let arcEndPointX = center.x + sliceSpaceOffset * cos(angleMiddle * ChartUtils.Math.FDEG2RAD) - let arcEndPointY = center.y + sliceSpaceOffset * sin(angleMiddle * ChartUtils.Math.FDEG2RAD) + let arcEndPointX = center.x + sliceSpaceOffset * cos(angleMiddle.DEG2RAD) + let arcEndPointY = center.y + sliceSpaceOffset * sin(angleMiddle.DEG2RAD) path.addLine( to: CGPoint( @@ -262,8 +258,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 @@ -339,7 +334,7 @@ open class PieChartRenderer: DataRenderer let sliceAngle = drawAngles[xIndex] let sliceSpace = getSliceSpace(dataSet: dataSet) - let sliceSpaceMiddleAngle = sliceSpace / (ChartUtils.Math.FDEG2RAD * labelRadius) + let sliceSpaceMiddleAngle = sliceSpace / labelRadius.DEG2RAD // offset needed to center the drawn text in the slice let angleOffset = (sliceAngle - sliceSpaceMiddleAngle / 2.0) / 2.0 @@ -355,8 +350,8 @@ open class PieChartRenderer: DataRenderer dataSetIndex: i, viewPortHandler: viewPortHandler) - let sliceXBase = cos(transformedAngle * ChartUtils.Math.FDEG2RAD) - let sliceYBase = sin(transformedAngle * ChartUtils.Math.FDEG2RAD) + let sliceXBase = cos(transformedAngle.DEG2RAD) + let sliceYBase = sin(transformedAngle.DEG2RAD) let drawXOutside = drawEntryLabels && xValuePosition == .outsideSlice let drawYOutside = drawValues && yValuePosition == .outsideSlice @@ -388,7 +383,7 @@ open class PieChartRenderer: DataRenderer } let polyline2Length = dataSet.valueLineVariableLength - ? labelRadius * valueLineLength2 * abs(sin(transformedAngle * ChartUtils.Math.FDEG2RAD)) + ? labelRadius * valueLineLength2 * abs(sin(transformedAngle.DEG2RAD)) : labelRadius * valueLineLength2 let pt0 = CGPoint( @@ -557,12 +552,9 @@ open class PieChartRenderer: DataRenderer } /// draws the hole in the center of the chart and the transparent circle / hole - fileprivate func drawHole(context: CGContext) + private func drawHole(context: CGContext) { - guard - let chart = chart, - let animator = animator - else { return } + guard let chart = chart else { return } if chart.drawHoleEnabled { @@ -616,7 +608,7 @@ open class PieChartRenderer: DataRenderer } /// draws the description text in the center of the pie chart makes most sense when center-hole is enabled - fileprivate func drawCenterText(context: CGContext) + private func drawCenterText(context: CGContext) { guard let chart = chart, @@ -668,8 +660,7 @@ open class PieChartRenderer: DataRenderer { guard let chart = chart, - let data = chart.data, - let animator = animator + let data = chart.data else { return } context.saveGState() @@ -737,11 +728,11 @@ open class PieChartRenderer: DataRenderer let sliceSpaceAngleOuter = visibleAngleCount == 1 ? 0.0 : - sliceSpace / (ChartUtils.Math.FDEG2RAD * radius) + sliceSpace / radius.DEG2RAD let sliceSpaceAngleShifted = visibleAngleCount == 1 ? 0.0 : - sliceSpace / (ChartUtils.Math.FDEG2RAD * highlightedRadius) + sliceSpace / highlightedRadius.DEG2RAD let startAngleOuter = rotationAngle + (angle + sliceSpaceAngleOuter / 2.0) * CGFloat(phaseY) var sweepAngleOuter = (sliceAngle - sliceSpaceAngleOuter) * CGFloat(phaseY) @@ -759,11 +750,11 @@ open class PieChartRenderer: DataRenderer let path = CGMutablePath() - path.move(to: CGPoint(x: center.x + highlightedRadius * cos(startAngleShifted * ChartUtils.Math.FDEG2RAD), - y: center.y + highlightedRadius * sin(startAngleShifted * ChartUtils.Math.FDEG2RAD))) + path.move(to: CGPoint(x: center.x + highlightedRadius * cos(startAngleShifted.DEG2RAD), + y: center.y + highlightedRadius * sin(startAngleShifted.DEG2RAD))) - path.addRelativeArc(center: center, radius: highlightedRadius, startAngle: startAngleShifted * ChartUtils.Math.FDEG2RAD, - delta: sweepAngleShifted * ChartUtils.Math.FDEG2RAD) + path.addRelativeArc(center: center, radius: highlightedRadius, startAngle: startAngleShifted.DEG2RAD, + delta: sweepAngleShifted.DEG2RAD) var sliceSpaceRadius: CGFloat = 0.0 if accountForSliceSpacing @@ -772,8 +763,8 @@ open class PieChartRenderer: DataRenderer center: center, radius: radius, angle: sliceAngle * CGFloat(phaseY), - arcStartPointX: center.x + radius * cos(startAngleOuter * ChartUtils.Math.FDEG2RAD), - arcStartPointY: center.y + radius * sin(startAngleOuter * ChartUtils.Math.FDEG2RAD), + arcStartPointX: center.x + radius * cos(startAngleOuter.DEG2RAD), + arcStartPointY: center.y + radius * sin(startAngleOuter.DEG2RAD), startAngle: startAngleOuter, sweepAngle: sweepAngleOuter) } @@ -793,7 +784,7 @@ open class PieChartRenderer: DataRenderer let sliceSpaceAngleInner = visibleAngleCount == 1 || innerRadius == 0.0 ? 0.0 : - sliceSpace / (ChartUtils.Math.FDEG2RAD * innerRadius) + sliceSpace / innerRadius.DEG2RAD let startAngleInner = rotationAngle + (angle + sliceSpaceAngleInner / 2.0) * CGFloat(phaseY) var sweepAngleInner = (sliceAngle - sliceSpaceAngleInner) * CGFloat(phaseY) if sweepAngleInner < 0.0 @@ -804,12 +795,12 @@ open class PieChartRenderer: DataRenderer path.addLine( to: CGPoint( - x: center.x + innerRadius * cos(endAngleInner * ChartUtils.Math.FDEG2RAD), - y: center.y + innerRadius * sin(endAngleInner * ChartUtils.Math.FDEG2RAD))) + x: center.x + innerRadius * cos(endAngleInner.DEG2RAD), + y: center.y + innerRadius * sin(endAngleInner.DEG2RAD))) path.addRelativeArc(center: center, radius: innerRadius, - startAngle: endAngleInner * ChartUtils.Math.FDEG2RAD, - delta: -sweepAngleInner * ChartUtils.Math.FDEG2RAD) + startAngle: endAngleInner.DEG2RAD, + delta: -sweepAngleInner.DEG2RAD) } else { @@ -817,8 +808,8 @@ open class PieChartRenderer: DataRenderer { let angleMiddle = startAngleOuter + sweepAngleOuter / 2.0 - let arcEndPointX = center.x + sliceSpaceRadius * cos(angleMiddle * ChartUtils.Math.FDEG2RAD) - let arcEndPointY = center.y + sliceSpaceRadius * sin(angleMiddle * ChartUtils.Math.FDEG2RAD) + let arcEndPointX = center.x + sliceSpaceRadius * cos(angleMiddle.DEG2RAD) + let arcEndPointY = center.y + sliceSpaceRadius * sin(angleMiddle.DEG2RAD) path.addLine( to: CGPoint( diff --git a/Source/Charts/Renderers/RadarChartRenderer.swift b/Source/Charts/Renderers/RadarChartRenderer.swift index 57068555f7..ab4890f646 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) @@ -53,12 +53,9 @@ open class RadarChartRenderer: LineRadarRenderer /// - parameter context: /// - parameter dataSet: /// - parameter mostEntries: the entry count of the dataset with the most entries - @objc internal func drawDataSet(context: CGContext, dataSet: IRadarChartDataSet, mostEntries: Int) + 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 @@ -222,7 +218,7 @@ open class RadarChartRenderer: LineRadarRenderer drawWeb(context: context) } - fileprivate var _webLineSegmentsBuffer = [CGPoint](repeating: CGPoint(), count: 2) + private var _webLineSegmentsBuffer = [CGPoint](repeating: CGPoint(), count: 2) @objc open func drawWeb(context: CGContext) { @@ -293,14 +289,13 @@ open class RadarChartRenderer: LineRadarRenderer context.restoreGState() } - fileprivate var _highlightPointBuffer = CGPoint() + private var _highlightPointBuffer = CGPoint() open override func drawHighlighted(context: CGContext, indices: [Highlight]) { guard let chart = chart, - let radarData = chart.data as? RadarChartData, - let animator = animator + let radarData = chart.data as? RadarChartData else { return } context.saveGState() @@ -380,7 +375,7 @@ open class RadarChartRenderer: LineRadarRenderer context.restoreGState() } - @objc internal func drawHighlightCircle( + internal func drawHighlightCircle( context: CGContext, atPoint point: CGPoint, innerRadius: CGFloat, diff --git a/Source/Charts/Renderers/Renderer.swift b/Source/Charts/Renderers/Renderer.swift index 86727524b3..5c929f28e0 100644 --- a/Source/Charts/Renderers/Renderer.swift +++ b/Source/Charts/Renderers/Renderer.swift @@ -16,17 +16,11 @@ import CoreGraphics open class Renderer: NSObject { /// the component that handles the drawing area of the chart and it's offsets - @objc open var viewPortHandler: ViewPortHandler? - - public override init() - { - super.init() - } - - @objc public init(viewPortHandler: ViewPortHandler?) + @objc open let viewPortHandler: ViewPortHandler + + @objc public init(viewPortHandler: ViewPortHandler) { - super.init() self.viewPortHandler = viewPortHandler + super.init() } } - diff --git a/Source/Charts/Renderers/ScatterChartRenderer.swift b/Source/Charts/Renderers/ScatterChartRenderer.swift index c9148caa7b..010ca16791 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) @@ -48,15 +48,11 @@ open class ScatterChartRenderer: LineScatterCandleRadarRenderer } } - fileprivate var _lineSegments = [CGPoint](repeating: CGPoint(), count: 2) + private var _lineSegments = [CGPoint](repeating: CGPoint(), count: 2) @objc open func drawDataSet(context: CGContext, dataSet: IScatterChartDataSet) { - guard - let dataProvider = dataProvider, - let animator = animator, - let viewPortHandler = self.viewPortHandler - else { return } + guard let dataProvider = dataProvider else { return } let trans = dataProvider.getTransformer(forAxis: dataSet.axisDependency) @@ -106,9 +102,7 @@ open class ScatterChartRenderer: LineScatterCandleRadarRenderer { guard let dataProvider = dataProvider, - let scatterData = dataProvider.scatterData, - let animator = animator, - let viewPortHandler = self.viewPortHandler + let scatterData = dataProvider.scatterData else { return } // if values are drawn @@ -204,8 +198,7 @@ open class ScatterChartRenderer: LineScatterCandleRadarRenderer { guard let dataProvider = dataProvider, - let scatterData = dataProvider.scatterData, - let animator = animator + let scatterData = dataProvider.scatterData else { return } context.saveGState() diff --git a/Source/Charts/Renderers/XAxisRenderer.swift b/Source/Charts/Renderers/XAxisRenderer.swift index bb75d25450..534e606dcf 100644 --- a/Source/Charts/Renderers/XAxisRenderer.swift +++ b/Source/Charts/Renderers/XAxisRenderer.swift @@ -19,17 +19,13 @@ import CoreGraphics @objc(ChartXAxisRenderer) open class XAxisRenderer: AxisRendererBase { - @objc public init(viewPortHandler: ViewPortHandler?, xAxis: XAxis?, transformer: Transformer?) + @objc public init(viewPortHandler: ViewPortHandler, xAxis: XAxis?, transformer: Transformer?) { super.init(viewPortHandler: viewPortHandler, transformer: transformer, axis: xAxis) } open override func computeAxis(min: Double, max: Double, inverted: Bool) { - guard let - viewPortHandler = self.viewPortHandler - else { return } - var min = min, max = max if let transformer = self.transformer @@ -87,10 +83,7 @@ open class XAxisRenderer: AxisRendererBase open override func renderAxisLabels(context: CGContext) { - guard let - xAxis = self.axis as? XAxis, - let viewPortHandler = self.viewPortHandler - else { return } + guard let xAxis = self.axis as? XAxis else { return } if !xAxis.isEnabled || !xAxis.isDrawLabelsEnabled { @@ -122,14 +115,11 @@ open class XAxisRenderer: AxisRendererBase } } - fileprivate var _axisLineSegmentsBuffer = [CGPoint](repeating: CGPoint(), count: 2) + private var _axisLineSegmentsBuffer = [CGPoint](repeating: CGPoint(), count: 2) open override func renderAxisLine(context: CGContext) { - guard - let xAxis = self.axis as? XAxis, - let viewPortHandler = self.viewPortHandler - else { return } + guard let xAxis = self.axis as? XAxis else { return } if !xAxis.isEnabled || !xAxis.isDrawAxisLineEnabled { @@ -179,7 +169,6 @@ open class XAxisRenderer: AxisRendererBase { guard let xAxis = self.axis as? XAxis, - let viewPortHandler = self.viewPortHandler, let transformer = self.transformer else { return } @@ -193,7 +182,7 @@ open class XAxisRenderer: AxisRendererBase let labelAttrs: [NSAttributedStringKey : Any] = [NSAttributedStringKey.font: xAxis.labelFont, NSAttributedStringKey.foregroundColor: xAxis.labelTextColor, NSAttributedStringKey.paragraphStyle: paraStyle] - let labelRotationAngleRadians = xAxis.labelRotationAngle * ChartUtils.Math.FDEG2RAD + let labelRotationAngleRadians = xAxis.labelRotationAngle.DEG2RAD let centeringEnabled = xAxis.isCenterAxisLabelsEnabled @@ -330,7 +319,7 @@ open class XAxisRenderer: AxisRendererBase @objc open var gridClippingRect: CGRect { - var contentRect = viewPortHandler?.contentRect ?? CGRect.zero + var contentRect = viewPortHandler.contentRect let dx = self.axis?.gridLineWidth ?? 0.0 contentRect.origin.x -= dx / 2.0 contentRect.size.width += dx @@ -339,10 +328,6 @@ open class XAxisRenderer: AxisRendererBase @objc open func drawGridLine(context: CGContext, x: CGFloat, y: CGFloat) { - guard - let viewPortHandler = self.viewPortHandler - else { return } - if x >= viewPortHandler.offsetLeft && x <= viewPortHandler.chartWidth { @@ -357,7 +342,6 @@ open class XAxisRenderer: AxisRendererBase { guard let xAxis = self.axis as? XAxis, - let viewPortHandler = self.viewPortHandler, let transformer = self.transformer else { return } @@ -400,9 +384,6 @@ open class XAxisRenderer: AxisRendererBase @objc open func renderLimitLineLine(context: CGContext, limitLine: ChartLimitLine, position: CGPoint) { - guard - let viewPortHandler = self.viewPortHandler - else { return } context.beginPath() context.move(to: CGPoint(x: position.x, y: viewPortHandler.contentTop)) @@ -424,9 +405,6 @@ open class XAxisRenderer: AxisRendererBase @objc open func renderLimitLineLabel(context: CGContext, limitLine: ChartLimitLine, position: CGPoint, yOffset: CGFloat) { - guard - let viewPortHandler = self.viewPortHandler - else { return } let label = limitLine.label diff --git a/Source/Charts/Renderers/XAxisRendererHorizontalBarChart.swift b/Source/Charts/Renderers/XAxisRendererHorizontalBarChart.swift index 97f0c56029..d2e0c29306 100644 --- a/Source/Charts/Renderers/XAxisRendererHorizontalBarChart.swift +++ b/Source/Charts/Renderers/XAxisRendererHorizontalBarChart.swift @@ -18,9 +18,9 @@ import CoreGraphics open class XAxisRendererHorizontalBarChart: XAxisRenderer { - @objc internal var chart: BarChartView? + internal weak var chart: BarChartView? - @objc public init(viewPortHandler: ViewPortHandler?, xAxis: XAxis?, transformer: Transformer?, chart: BarChartView?) + @objc public init(viewPortHandler: ViewPortHandler, xAxis: XAxis?, transformer: Transformer?, chart: BarChartView) { super.init(viewPortHandler: viewPortHandler, xAxis: xAxis, transformer: transformer) @@ -29,10 +29,6 @@ open class XAxisRendererHorizontalBarChart: XAxisRenderer open override func computeAxis(min: Double, max: Double, inverted: Bool) { - guard let - viewPortHandler = self.viewPortHandler - else { return } - var min = min, max = max if let transformer = self.transformer @@ -83,8 +79,7 @@ open class XAxisRendererHorizontalBarChart: XAxisRenderer open override func renderAxisLabels(context: CGContext) { guard - let xAxis = self.axis as? XAxis, - let viewPortHandler = self.viewPortHandler + let xAxis = self.axis as? XAxis else { return } if !xAxis.isEnabled || !xAxis.isDrawLabelsEnabled || chart?.data === nil @@ -122,13 +117,12 @@ open class XAxisRendererHorizontalBarChart: XAxisRenderer { guard let xAxis = self.axis as? XAxis, - let transformer = self.transformer, - let viewPortHandler = self.viewPortHandler + let transformer = self.transformer else { return } let labelFont = xAxis.labelFont let labelTextColor = xAxis.labelTextColor - let labelRotationAngleRadians = xAxis.labelRotationAngle * ChartUtils.Math.FDEG2RAD + let labelRotationAngleRadians = xAxis.labelRotationAngle.DEG2RAD let centeringEnabled = xAxis.isCenterAxisLabelsEnabled @@ -189,21 +183,17 @@ open class XAxisRendererHorizontalBarChart: XAxisRenderer open override var gridClippingRect: CGRect { - var contentRect = viewPortHandler?.contentRect ?? CGRect.zero + var contentRect = viewPortHandler.contentRect let dy = self.axis?.gridLineWidth ?? 0.0 contentRect.origin.y -= dy / 2.0 contentRect.size.height += dy return contentRect } - fileprivate var _gridLineSegmentsBuffer = [CGPoint](repeating: CGPoint(), count: 2) + private var _gridLineSegmentsBuffer = [CGPoint](repeating: CGPoint(), count: 2) open override func drawGridLine(context: CGContext, x: CGFloat, y: CGFloat) { - guard - let viewPortHandler = self.viewPortHandler - else { return } - if viewPortHandler.isInBoundsY(y) { context.beginPath() @@ -215,10 +205,7 @@ open class XAxisRendererHorizontalBarChart: XAxisRenderer open override func renderAxisLine(context: CGContext) { - guard - let xAxis = self.axis as? XAxis, - let viewPortHandler = self.viewPortHandler - else { return } + guard let xAxis = self.axis as? XAxis else { return } if !xAxis.isEnabled || !xAxis.isDrawAxisLineEnabled { @@ -265,7 +252,6 @@ open class XAxisRendererHorizontalBarChart: XAxisRenderer { guard let xAxis = self.axis as? XAxis, - let viewPortHandler = self.viewPortHandler, let transformer = self.transformer else { return } diff --git a/Source/Charts/Renderers/XAxisRendererRadarChart.swift b/Source/Charts/Renderers/XAxisRendererRadarChart.swift index 2f78ce2303..ab57149cce 100644 --- a/Source/Charts/Renderers/XAxisRendererRadarChart.swift +++ b/Source/Charts/Renderers/XAxisRendererRadarChart.swift @@ -20,7 +20,7 @@ open class XAxisRendererRadarChart: XAxisRenderer { @objc open weak var chart: RadarChartView? - @objc public init(viewPortHandler: ViewPortHandler?, xAxis: XAxis?, chart: RadarChartView?) + @objc public init(viewPortHandler: ViewPortHandler, xAxis: XAxis?, chart: RadarChartView) { super.init(viewPortHandler: viewPortHandler, xAxis: xAxis, transformer: nil) @@ -41,7 +41,7 @@ open class XAxisRendererRadarChart: XAxisRenderer let labelFont = xAxis.labelFont let labelTextColor = xAxis.labelTextColor - let labelRotationAngleRadians = xAxis.labelRotationAngle * ChartUtils.Math.FDEG2RAD + let labelRotationAngleRadians = xAxis.labelRotationAngle.RAD2DEG let drawLabelAnchor = CGPoint(x: 0.5, y: 0.25) let sliceangle = chart.sliceAngle diff --git a/Source/Charts/Renderers/YAxisRenderer.swift b/Source/Charts/Renderers/YAxisRenderer.swift index 511400a09d..e5b0802575 100644 --- a/Source/Charts/Renderers/YAxisRenderer.swift +++ b/Source/Charts/Renderers/YAxisRenderer.swift @@ -19,7 +19,7 @@ import CoreGraphics @objc(ChartYAxisRenderer) open class YAxisRenderer: AxisRendererBase { - @objc public init(viewPortHandler: ViewPortHandler?, yAxis: YAxis?, transformer: Transformer?) + @objc public init(viewPortHandler: ViewPortHandler, yAxis: YAxis?, transformer: Transformer?) { super.init(viewPortHandler: viewPortHandler, transformer: transformer, axis: yAxis) } @@ -27,10 +27,7 @@ open class YAxisRenderer: AxisRendererBase /// draws the y-axis labels to the screen open override func renderAxisLabels(context: CGContext) { - guard - let yAxis = self.axis as? YAxis, - let viewPortHandler = self.viewPortHandler - else { return } + guard let yAxis = self.axis as? YAxis else { return } if !yAxis.isEnabled || !yAxis.isDrawLabelsEnabled { @@ -85,10 +82,7 @@ open class YAxisRenderer: AxisRendererBase open override func renderAxisLine(context: CGContext) { - guard - let yAxis = self.axis as? YAxis, - let viewPortHandler = self.viewPortHandler - else { return } + guard let yAxis = self.axis as? YAxis else { return } if !yAxis.isEnabled || !yAxis.drawAxisLineEnabled { @@ -127,7 +121,7 @@ open class YAxisRenderer: AxisRendererBase } /// draws the y-labels on the specified x-position - @objc internal func drawYLabels( + internal func drawYLabels( context: CGContext, fixedPosition: CGFloat, positions: [CGPoint], @@ -207,7 +201,7 @@ open class YAxisRenderer: AxisRendererBase @objc open var gridClippingRect: CGRect { - var contentRect = viewPortHandler?.contentRect ?? CGRect.zero + var contentRect = viewPortHandler.contentRect let dy = self.axis?.gridLineWidth ?? 0.0 contentRect.origin.y -= dy / 2.0 contentRect.size.height += dy @@ -218,10 +212,6 @@ open class YAxisRenderer: AxisRendererBase context: CGContext, position: CGPoint) { - guard - let viewPortHandler = self.viewPortHandler - else { return } - context.beginPath() context.move(to: CGPoint(x: viewPortHandler.contentLeft, y: position.y)) context.addLine(to: CGPoint(x: viewPortHandler.contentRight, y: position.y)) @@ -255,7 +245,6 @@ open class YAxisRenderer: AxisRendererBase { guard let yAxis = self.axis as? YAxis, - let viewPortHandler = self.viewPortHandler, let transformer = self.transformer, let zeroLineColor = yAxis.zeroLineColor else { return } @@ -291,7 +280,6 @@ open class YAxisRenderer: AxisRendererBase { guard let yAxis = self.axis as? YAxis, - let viewPortHandler = self.viewPortHandler, let transformer = self.transformer else { return } diff --git a/Source/Charts/Renderers/YAxisRendererHorizontalBarChart.swift b/Source/Charts/Renderers/YAxisRendererHorizontalBarChart.swift index 15c1a1539f..ba7c51f17f 100644 --- a/Source/Charts/Renderers/YAxisRendererHorizontalBarChart.swift +++ b/Source/Charts/Renderers/YAxisRendererHorizontalBarChart.swift @@ -18,7 +18,7 @@ import CoreGraphics open class YAxisRendererHorizontalBarChart: YAxisRenderer { - public override init(viewPortHandler: ViewPortHandler?, yAxis: YAxis?, transformer: Transformer?) + public override init(viewPortHandler: ViewPortHandler, yAxis: YAxis?, transformer: Transformer?) { super.init(viewPortHandler: viewPortHandler, yAxis: yAxis, transformer: transformer) } @@ -26,10 +26,7 @@ open class YAxisRendererHorizontalBarChart: YAxisRenderer /// Computes the axis values. open override func computeAxis(min: Double, max: Double, inverted: Bool) { - guard - let viewPortHandler = self.viewPortHandler, - let transformer = self.transformer - else { return } + guard let transformer = self.transformer else { return } var min = min, max = max @@ -57,10 +54,7 @@ open class YAxisRendererHorizontalBarChart: YAxisRenderer /// draws the y-axis labels to the screen open override func renderAxisLabels(context: CGContext) { - guard - let yAxis = axis as? YAxis, - let viewPortHandler = self.viewPortHandler - else { return } + guard let yAxis = axis as? YAxis else { return } if !yAxis.isEnabled || !yAxis.isDrawLabelsEnabled { @@ -111,10 +105,7 @@ open class YAxisRendererHorizontalBarChart: YAxisRenderer open override func renderAxisLine(context: CGContext) { - guard - let yAxis = axis as? YAxis, - let viewPortHandler = self.viewPortHandler - else { return } + guard let yAxis = axis as? YAxis else { return } if !yAxis.isEnabled || !yAxis.drawAxisLineEnabled { @@ -183,7 +174,7 @@ open class YAxisRendererHorizontalBarChart: YAxisRenderer open override var gridClippingRect: CGRect { - var contentRect = viewPortHandler?.contentRect ?? CGRect.zero + var contentRect = viewPortHandler.contentRect let dx = self.axis?.gridLineWidth ?? 0.0 contentRect.origin.x -= dx / 2.0 contentRect.size.width += dx @@ -194,10 +185,6 @@ open class YAxisRendererHorizontalBarChart: YAxisRenderer context: CGContext, position: CGPoint) { - guard - let viewPortHandler = self.viewPortHandler - else { return } - context.beginPath() context.move(to: CGPoint(x: position.x, y: viewPortHandler.contentTop)) context.addLine(to: CGPoint(x: position.x, y: viewPortHandler.contentBottom)) @@ -231,7 +218,6 @@ open class YAxisRendererHorizontalBarChart: YAxisRenderer { guard let yAxis = self.axis as? YAxis, - let viewPortHandler = self.viewPortHandler, let transformer = self.transformer, let zeroLineColor = yAxis.zeroLineColor else { return } @@ -263,13 +249,12 @@ open class YAxisRendererHorizontalBarChart: YAxisRenderer context.drawPath(using: CGPathDrawingMode.stroke) } - fileprivate var _limitLineSegmentsBuffer = [CGPoint](repeating: CGPoint(), count: 2) + private var _limitLineSegmentsBuffer = [CGPoint](repeating: CGPoint(), count: 2) open override func renderLimitLines(context: CGContext) { guard let yAxis = axis as? YAxis, - let viewPortHandler = self.viewPortHandler, let transformer = self.transformer else { return } diff --git a/Source/Charts/Renderers/YAxisRendererRadarChart.swift b/Source/Charts/Renderers/YAxisRendererRadarChart.swift index cab45f7125..b23b987556 100644 --- a/Source/Charts/Renderers/YAxisRendererRadarChart.swift +++ b/Source/Charts/Renderers/YAxisRendererRadarChart.swift @@ -18,9 +18,9 @@ import CoreGraphics open class YAxisRendererRadarChart: YAxisRenderer { - fileprivate weak var chart: RadarChartView? + private weak var chart: RadarChartView? - @objc public init(viewPortHandler: ViewPortHandler?, yAxis: YAxis?, chart: RadarChartView?) + @objc public init(viewPortHandler: ViewPortHandler, yAxis: YAxis?, chart: RadarChartView) { super.init(viewPortHandler: viewPortHandler, yAxis: yAxis, transformer: nil) diff --git a/Source/Charts/Utils/ChartUtils.swift b/Source/Charts/Utils/ChartUtils.swift old mode 100755 new mode 100644 index a1c56ab477..d5b441e164 --- a/Source/Charts/Utils/ChartUtils.swift +++ b/Source/Charts/Utils/ChartUtils.swift @@ -16,9 +16,26 @@ import CoreGraphics import UIKit #endif +extension FloatingPoint { + var DEG2RAD: Self { + return self * .pi / 180 + } + + var RAD2DEG: Self { + return self * 180 / .pi + } + + /// - returns: An angle between 0.0 < 360.0 (not less than zero, less than 360) + /// NOTE: Value must be in degrees + var normalizedAngle: Self { + let angle = truncatingRemainder(dividingBy: 360) + return (sign == .minus) ? angle + 360 : angle + } +} + extension CGSize { func rotatedBy(degrees: CGFloat) -> CGSize { - let radians = ChartUtils.Math.FDEG2RAD * degrees + let radians = degrees.DEG2RAD return rotatedBy(radians: radians) } @@ -32,16 +49,8 @@ extension CGSize { open class ChartUtils { - fileprivate static var _defaultValueFormatter: IValueFormatter = ChartUtils.generateDefaultValueFormatter() - - internal struct Math - { - internal static let FDEG2RAD = CGFloat(Double.pi / 180.0) - internal static let FRAD2DEG = CGFloat(180.0 / Double.pi) - internal static let DEG2RAD = Double.pi / 180.0 - internal static let RAD2DEG = 180.0 / Double.pi - } - + private static var _defaultValueFormatter: IValueFormatter = ChartUtils.generateDefaultValueFormatter() + internal class func roundToNextSignificant(number: Double) -> Double { if number.isInfinite || number.isNaN || number == 0 @@ -89,8 +98,8 @@ open class ChartUtils internal class func getPosition(center: CGPoint, dist: CGFloat, angle: CGFloat) -> CGPoint { return CGPoint( - x: center.x + dist * cos(angle * Math.FDEG2RAD), - y: center.y + dist * sin(angle * Math.FDEG2RAD) + x: center.x + dist * cos(angle.DEG2RAD), + y: center.y + dist * sin(angle.DEG2RAD) ) } @@ -262,21 +271,8 @@ open class ChartUtils let rect = text.boundingRect(with: constrainedToSize, options: .usesLineFragmentOrigin, attributes: attributes, context: nil) drawMultilineText(context: context, text: text, knownTextSize: rect.size, point: point, attributes: attributes, constrainedToSize: constrainedToSize, anchor: anchor, angleRadians: angleRadians) } - - /// - returns: An angle between 0.0 < 360.0 (not less than zero, less than 360) - internal class func normalizedAngleFromAngle(_ angle: CGFloat) -> CGFloat - { - var angle = angle - - while (angle < 0.0) - { - angle += 360.0 - } - - return angle.truncatingRemainder(dividingBy: 360.0) - } - - fileprivate class func generateDefaultValueFormatter() -> IValueFormatter + + private class func generateDefaultValueFormatter() -> IValueFormatter { let formatter = DefaultValueFormatter(decimals: 1) return formatter diff --git a/Source/Charts/Utils/Fill.swift b/Source/Charts/Utils/Fill.swift index 58c6fe693e..1294b3efc0 100644 --- a/Source/Charts/Utils/Fill.swift +++ b/Source/Charts/Utils/Fill.swift @@ -27,16 +27,16 @@ public enum FillType: Int @objc(ChartFill) open class Fill: NSObject { - fileprivate var _type: FillType = FillType.empty - fileprivate var _color: CGColor? - fileprivate var _gradient: CGGradient? - fileprivate var _gradientAngle: CGFloat = 0.0 - fileprivate var _gradientStartOffsetPercent: CGPoint = CGPoint() - fileprivate var _gradientStartRadiusPercent: CGFloat = 0.0 - fileprivate var _gradientEndOffsetPercent: CGPoint = CGPoint() - fileprivate var _gradientEndRadiusPercent: CGFloat = 0.0 - fileprivate var _image: CGImage? - fileprivate var _layer: CGLayer? + private var _type: FillType = FillType.empty + private var _color: CGColor? + private var _gradient: CGGradient? + private var _gradientAngle: CGFloat = 0.0 + private var _gradientStartOffsetPercent: CGPoint = CGPoint() + private var _gradientStartRadiusPercent: CGFloat = 0.0 + private var _gradientEndOffsetPercent: CGPoint = CGPoint() + private var _gradientEndRadiusPercent: CGFloat = 0.0 + private var _image: CGImage? + private var _layer: CGLayer? // MARK: Properties @@ -273,7 +273,7 @@ open class Fill: NSObject case .linearGradient: - let radians = ChartUtils.Math.FDEG2RAD * (360.0 - _gradientAngle) + let radians = (360.0 - _gradientAngle).DEG2RAD let centerPoint = CGPoint(x: rect.midX, y: rect.midY) let xAngleDelta = cos(radians) * rect.width / 2.0 let yAngleDelta = sin(radians) * rect.height / 2.0 diff --git a/Source/Charts/Utils/Transformer.swift b/Source/Charts/Utils/Transformer.swift index 71110ec722..ca99fb2360 100644 --- a/Source/Charts/Utils/Transformer.swift +++ b/Source/Charts/Utils/Transformer.swift @@ -17,12 +17,12 @@ import CoreGraphics open class Transformer: NSObject { /// matrix to map the values to the screen pixels - @objc internal var _matrixValueToPx = CGAffineTransform.identity + internal var _matrixValueToPx = CGAffineTransform.identity /// matrix for handling the different offsets of the chart - @objc internal var _matrixOffset = CGAffineTransform.identity + internal var _matrixOffset = CGAffineTransform.identity - @objc internal var _viewPortHandler: ViewPortHandler + internal var _viewPortHandler: ViewPortHandler @objc public init(viewPortHandler: ViewPortHandler) { diff --git a/Source/Charts/Utils/ViewPortHandler.swift b/Source/Charts/Utils/ViewPortHandler.swift index 6e184e0b3f..db45d61cb3 100755 --- a/Source/Charts/Utils/ViewPortHandler.swift +++ b/Source/Charts/Utils/ViewPortHandler.swift @@ -17,47 +17,43 @@ import CoreGraphics open class ViewPortHandler: NSObject { /// matrix used for touch events - fileprivate var _touchMatrix = CGAffineTransform.identity + private var _touchMatrix = CGAffineTransform.identity /// this rectangle defines the area in which graph values can be drawn - fileprivate var _contentRect = CGRect() + private var _contentRect = CGRect() - fileprivate var _chartWidth = CGFloat(0.0) - fileprivate var _chartHeight = CGFloat(0.0) + private var _chartWidth = CGFloat(0.0) + private var _chartHeight = CGFloat(0.0) /// minimum scale value on the y-axis - fileprivate var _minScaleY = CGFloat(1.0) + private var _minScaleY = CGFloat(1.0) /// maximum scale value on the y-axis - fileprivate var _maxScaleY = CGFloat.greatestFiniteMagnitude + private var _maxScaleY = CGFloat.greatestFiniteMagnitude /// minimum scale value on the x-axis - fileprivate var _minScaleX = CGFloat(1.0) + private var _minScaleX = CGFloat(1.0) /// maximum scale value on the x-axis - fileprivate var _maxScaleX = CGFloat.greatestFiniteMagnitude + private var _maxScaleX = CGFloat.greatestFiniteMagnitude /// contains the current scale factor of the x-axis - fileprivate var _scaleX = CGFloat(1.0) + private var _scaleX = CGFloat(1.0) /// contains the current scale factor of the y-axis - fileprivate var _scaleY = CGFloat(1.0) + private var _scaleY = CGFloat(1.0) /// current translation (drag distance) on the x-axis - fileprivate var _transX = CGFloat(0.0) + private var _transX = CGFloat(0.0) /// current translation (drag distance) on the y-axis - fileprivate var _transY = CGFloat(0.0) + private var _transY = CGFloat(0.0) /// offset that allows the chart to be dragged over its bounds on the x-axis - fileprivate var _transOffsetX = CGFloat(0.0) + private var _transOffsetX = CGFloat(0.0) /// offset that allows the chart to be dragged over its bounds on the x-axis - fileprivate var _transOffsetY = CGFloat(0.0) - - public override init() - { - } + private var _transOffsetY = CGFloat(0.0) /// Constructor - don't forget calling setChartDimens(...) @objc public init(width: CGFloat, height: CGFloat) @@ -255,12 +251,11 @@ open class ViewPortHandler: NSObject let translateY = pt.y - offsetTop let matrix = _touchMatrix.concatenating(CGAffineTransform(translationX: -translateX, y: -translateY)) - - let _ = refresh(newMatrix: matrix, chart: chart, invalidate: true) + refresh(newMatrix: matrix, chart: chart, invalidate: true) } /// call this method to refresh the graph with a given matrix - @objc open func refresh(newMatrix: CGAffineTransform, chart: ChartViewBase, invalidate: Bool) -> CGAffineTransform + @objc @discardableResult open func refresh(newMatrix: CGAffineTransform, chart: ChartViewBase, invalidate: Bool) -> CGAffineTransform { _touchMatrix = newMatrix @@ -273,7 +268,7 @@ open class ViewPortHandler: NSObject } /// limits the maximum scale and X translation of the given matrix - fileprivate func limitTransAndScale(matrix: inout CGAffineTransform, content: CGRect?) + private func limitTransAndScale(matrix: inout CGAffineTransform, content: CGRect?) { // min scale-x is 1 _scaleX = min(max(_minScaleX, matrix.a), _maxScaleX)