Skip to content

Commit

Permalink
Removed ambiguity of _dataNotSet (Fixes #585)
Browse files Browse the repository at this point in the history
We can just check for _data being null,
knowing that this is the situation defined as "no data"
  • Loading branch information
danielgindi committed Dec 16, 2015
1 parent 0ada417 commit 4599e42
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Charts/Classes/Charts/BarChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions Charts/Classes/Charts/BarLineChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar
{
super.drawRect(rect)

if (_dataNotSet)
if _data === nil
{
return
}
Expand Down Expand Up @@ -261,7 +261,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar

public override func notifyDataSetChanged()
{
if (_dataNotSet)
if _data === nil
{
return
}
Expand Down Expand Up @@ -614,7 +614,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar

@objc private func tapGestureRecognized(recognizer: UITapGestureRecognizer)
{
if (_dataNotSet)
if _data === nil
{
return
}
Expand All @@ -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
Expand All @@ -673,7 +673,7 @@ public class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChar
{
stopDeceleration()

if (!_dataNotSet && (_pinchZoomEnabled || _scaleXEnabled || _scaleYEnabled))
if _data !== nil && (_pinchZoomEnabled || _scaleXEnabled || _scaleYEnabled)
{
_isScaling = true

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions Charts/Classes/Charts/ChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -197,7 +194,6 @@ public class ChartViewBase: UIView, ChartDataProvider, ChartAnimatorDelegate
return
}

_dataNotSet = false
_offsetsCalculated = false
_data = newValue

Expand All @@ -212,7 +208,6 @@ public class ChartViewBase: UIView, ChartDataProvider, ChartAnimatorDelegate
public func clear()
{
_data = nil
_dataNotSet = true
_indicesToHighlight.removeAll()
setNeedsDisplay()
}
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Charts/HorizontalBarChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Charts/Classes/Charts/PieChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class PieChartView: PieRadarChartViewBase
{
super.drawRect(rect)

if (_dataNotSet)
if _data === nil
{
return
}
Expand Down Expand Up @@ -81,7 +81,7 @@ public class PieChartView: PieRadarChartViewBase
super.calculateOffsets()

// prevent nullpointer when no data set
if (_dataNotSet)
if _data === nil
{
return
}
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Charts/PieRadarChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class PieRadarChartViewBase: ChartViewBase

public override func notifyDataSetChanged()
{
if (_dataNotSet)
if _data === nil
{
return
}
Expand Down
4 changes: 2 additions & 2 deletions Charts/Classes/Charts/RadarChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public class RadarChartView: PieRadarChartViewBase

public override func notifyDataSetChanged()
{
if (_dataNotSet)
if _data === nil
{
return
}
Expand All @@ -164,7 +164,7 @@ public class RadarChartView: PieRadarChartViewBase
{
super.drawRect(rect)

if (_dataNotSet)
if _data === nil
{
return
}
Expand Down

0 comments on commit 4599e42

Please sign in to comment.