Skip to content

Commit

Permalink
Final fix for highlights disappearing because of NaN values (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Jun 29, 2015
1 parent 24cda7e commit 8d74304
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
20 changes: 11 additions & 9 deletions Charts/Classes/Charts/BarLineChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1314,25 +1314,27 @@ public class BarLineChartViewBase: ChartViewBase, UIGestureRecognizerDelegate
{
var vals = [ChartSelectionDetail]();

var pt = CGPoint();

for (var i = 0, count = _data.dataSetCount; i < count; i++)
{
var pt = CGPoint();
var dataSet = _data.getDataSetByIndex(i);
{ var dataSet = _data.getDataSetByIndex(i);
if (dataSet === nil || !dataSet.isHighlightEnabled)
{
continue;
}

// extract all y-values from all DataSets at the given x-index
var yVal = dataSet!.yValForXIndex(xIndex);
let yVal = dataSet!.yValForXIndex(xIndex);
if (yVal.isNaN)
{
continue;
}

pt.y = CGFloat(yVal);

getTransformer(dataSet!.axisDependency).pointValueToPixel(&pt);

if (!isnan(pt.y))
{
vals.append(ChartSelectionDetail(value: Double(pt.y), dataSetIndex: i, dataSet: dataSet!));
}

vals.append(ChartSelectionDetail(value: Double(pt.y), dataSetIndex: i, dataSet: dataSet!));
}

return vals;
Expand Down
9 changes: 5 additions & 4 deletions Charts/Classes/Charts/PieRadarChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,13 @@ public class PieRadarChartViewBase: ChartViewBase
}
// extract all y-values from all DataSets at the given x-index
var yVal = dataSet!.yValForXIndex(xIndex);
if (!isnan(yVal))
let yVal = dataSet!.yValForXIndex(xIndex);
if (yVal.isNaN)
{
vals.append(ChartSelectionDetail(value: yVal, dataSetIndex: i, dataSet: dataSet!));
continue;
}
vals.append(ChartSelectionDetail(value: yVal, dataSetIndex: i, dataSet: dataSet!));
}
return vals;
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Renderers/LineChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ public class LineChartRenderer: ChartDataRendererBase
}

let yValue = set.yValForXIndex(xIndex);
if (isnan(yValue))
if (yValue.isNaN)
{
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions Charts/Classes/Renderers/ScatterChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,13 @@ public class ScatterChartRenderer: ChartDataRendererBase
continue;
}

let yValue = set.yValForXIndex(xIndex);
if (isnan(yValue))
let yVal = set.yValForXIndex(xIndex);
if (yVal.isNaN)
{
continue;
}

var y = CGFloat(yValue) * _animator.phaseY; // get the y-position
var y = CGFloat(yVal) * _animator.phaseY; // get the y-position

pts[0] = CGPoint(x: CGFloat(xIndex), y: CGFloat(chartYMax));
pts[1] = CGPoint(x: CGFloat(xIndex), y: CGFloat(chartYMin));
Expand Down

0 comments on commit 8d74304

Please sign in to comment.