From 4599e4295fc3ee74e3d05c36a237f18975ee4ddf Mon Sep 17 00:00:00 2001 From: Daniel Cohen Gindi Date: Wed, 16 Dec 2015 21:59:13 +0200 Subject: [PATCH] Removed ambiguity of _dataNotSet (Fixes #585) We can just check for _data being null, knowing that this is the situation defined as "no data" --- Charts/Classes/Charts/BarChartView.swift | 2 +- .../Classes/Charts/BarLineChartViewBase.swift | 20 +++++++++---------- Charts/Classes/Charts/ChartViewBase.swift | 9 ++------- .../Charts/HorizontalBarChartView.swift | 2 +- Charts/Classes/Charts/PieChartView.swift | 4 ++-- .../Charts/PieRadarChartViewBase.swift | 2 +- Charts/Classes/Charts/RadarChartView.swift | 4 ++-- 7 files changed, 19 insertions(+), 24 deletions(-) diff --git a/Charts/Classes/Charts/BarChartView.swift b/Charts/Classes/Charts/BarChartView.swift index 5501c2fac8..b397a53a33 100644 --- a/Charts/Classes/Charts/BarChartView.swift +++ b/Charts/Classes/Charts/BarChartView.swift @@ -63,7 +63,7 @@ public class BarChartView: BarLineChartViewBase, BarChartDataProvider /// - returns: the Highlight object (contains x-index and DataSet index) of the selected value at the given touch point inside the BarChart. public override func getHighlightByTouchPoint(pt: CGPoint) -> ChartHighlight? { - if (_dataNotSet || _data === nil) + if _data === nil { print("Can't select by touch. No data set.", terminator: "\n") return nil diff --git a/Charts/Classes/Charts/BarLineChartViewBase.swift b/Charts/Classes/Charts/BarLineChartViewBase.swift index 1a27fb692a..ba9a48ed32 100644 --- a/Charts/Classes/Charts/BarLineChartViewBase.swift +++ b/Charts/Classes/Charts/BarLineChartViewBase.swift @@ -134,7 +134,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar { super.drawRect(rect) - if (_dataNotSet) + if _data === nil { return } @@ -261,7 +261,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar public override func notifyDataSetChanged() { - if (_dataNotSet) + if _data === nil { return } @@ -614,7 +614,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar @objc private func tapGestureRecognized(recognizer: UITapGestureRecognizer) { - if (_dataNotSet) + if _data === nil { return } @@ -640,14 +640,14 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar @objc private func doubleTapGestureRecognized(recognizer: UITapGestureRecognizer) { - if (_dataNotSet) + if _data === nil { return } if (recognizer.state == UIGestureRecognizerState.Ended) { - if (!_dataNotSet && _doubleTapToZoomEnabled) + if _data !== nil && _doubleTapToZoomEnabled { var location = recognizer.locationInView(self) location.x = location.x - _viewPortHandler.offsetLeft @@ -673,7 +673,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar { stopDeceleration() - if (!_dataNotSet && (_pinchZoomEnabled || _scaleXEnabled || _scaleYEnabled)) + if _data !== nil && (_pinchZoomEnabled || _scaleXEnabled || _scaleYEnabled) { _isScaling = true @@ -763,7 +763,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar { stopDeceleration() - if _dataNotSet + if _data === nil { // If we have no data, we have nothing to pan and no data to highlight return; } @@ -943,7 +943,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar if (gestureRecognizer == _panGestureRecognizer) { - if _dataNotSet || !_dragEnabled || + if _data === nil || !_dragEnabled || (self.hasNoDragOffset && self.isFullyZoomedOut && !self.isHighlightPerDragEnabled) { return false @@ -954,7 +954,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar #if !os(tvOS) if (gestureRecognizer == _pinchGestureRecognizer) { - if (_dataNotSet || (!_pinchZoomEnabled && !_scaleXEnabled && !_scaleYEnabled)) + if _data === nil || (!_pinchZoomEnabled && !_scaleXEnabled && !_scaleYEnabled) { return false } @@ -1387,7 +1387,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar /// - returns: the Highlight object (contains x-index and DataSet index) of the selected value at the given touch point inside the Line-, Scatter-, or CandleStick-Chart. public func getHighlightByTouchPoint(pt: CGPoint) -> ChartHighlight? { - if (_dataNotSet || _data === nil) + if _data === nil { print("Can't select by touch. No data set.", terminator: "\n") return nil diff --git a/Charts/Classes/Charts/ChartViewBase.swift b/Charts/Classes/Charts/ChartViewBase.swift index 22fdc5579c..dee6c5cd1b 100755 --- a/Charts/Classes/Charts/ChartViewBase.swift +++ b/Charts/Classes/Charts/ChartViewBase.swift @@ -73,9 +73,6 @@ public class ChartViewBase: UIView, ChartDataProvider, ChartAnimatorDelegate /// description text that appears in the bottom right corner of the chart public var descriptionText = "Description" - /// flag that indicates if the chart has been fed with data yet - internal var _dataNotSet = true - /// if true, units are drawn next to the values in the chart internal var _drawUnitInChart = false @@ -197,7 +194,6 @@ public class ChartViewBase: UIView, ChartDataProvider, ChartAnimatorDelegate return } - _dataNotSet = false _offsetsCalculated = false _data = newValue @@ -212,7 +208,6 @@ public class ChartViewBase: UIView, ChartDataProvider, ChartAnimatorDelegate public func clear() { _data = nil - _dataNotSet = true _indicesToHighlight.removeAll() setNeedsDisplay() } @@ -297,8 +292,8 @@ public class ChartViewBase: UIView, ChartDataProvider, ChartAnimatorDelegate let frame = self.bounds - if (_dataNotSet || _data === nil || _data.yValCount == 0) - { // check if there is data + if _data === nil + { CGContextSaveGState(context) diff --git a/Charts/Classes/Charts/HorizontalBarChartView.swift b/Charts/Classes/Charts/HorizontalBarChartView.swift index 56edbc416b..82e631058a 100644 --- a/Charts/Classes/Charts/HorizontalBarChartView.swift +++ b/Charts/Classes/Charts/HorizontalBarChartView.swift @@ -175,7 +175,7 @@ public class HorizontalBarChartView: BarChartView public override func getHighlightByTouchPoint(pt: CGPoint) -> ChartHighlight? { - if (_dataNotSet || _data === nil) + if _data === nil { print("Can't select by touch. No data set.", terminator: "\n") return nil diff --git a/Charts/Classes/Charts/PieChartView.swift b/Charts/Classes/Charts/PieChartView.swift index c880723614..4f3f3104c3 100755 --- a/Charts/Classes/Charts/PieChartView.swift +++ b/Charts/Classes/Charts/PieChartView.swift @@ -50,7 +50,7 @@ public class PieChartView: PieRadarChartViewBase { super.drawRect(rect) - if (_dataNotSet) + if _data === nil { return } @@ -81,7 +81,7 @@ public class PieChartView: PieRadarChartViewBase super.calculateOffsets() // prevent nullpointer when no data set - if (_dataNotSet) + if _data === nil { return } diff --git a/Charts/Classes/Charts/PieRadarChartViewBase.swift b/Charts/Classes/Charts/PieRadarChartViewBase.swift index f3bf950675..11c8f55e73 100755 --- a/Charts/Classes/Charts/PieRadarChartViewBase.swift +++ b/Charts/Classes/Charts/PieRadarChartViewBase.swift @@ -74,7 +74,7 @@ public class PieRadarChartViewBase: ChartViewBase public override func notifyDataSetChanged() { - if (_dataNotSet) + if _data === nil { return } diff --git a/Charts/Classes/Charts/RadarChartView.swift b/Charts/Classes/Charts/RadarChartView.swift index 6964fd0ee8..baa0bf532c 100644 --- a/Charts/Classes/Charts/RadarChartView.swift +++ b/Charts/Classes/Charts/RadarChartView.swift @@ -138,7 +138,7 @@ public class RadarChartView: PieRadarChartViewBase public override func notifyDataSetChanged() { - if (_dataNotSet) + if _data === nil { return } @@ -164,7 +164,7 @@ public class RadarChartView: PieRadarChartViewBase { super.drawRect(rect) - if (_dataNotSet) + if _data === nil { return }