Skip to content

Commit

Permalink
Fixed crash when phaseX causes entryForIndex to go out of bounds (#726)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Apr 13, 2016
1 parent 3938d5b commit 833d982
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions Charts/Classes/Renderers/BubbleChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class BubbleChartRenderer: ChartDataRendererBase

let trans = dataProvider.getTransformer(dataSet.axisDependency)

let phaseX = animator.phaseX
let phaseX = max(0.0, min(1.0, animator.phaseX))
let phaseY = animator.phaseY

let entryCount = dataSet.entryCount
Expand Down Expand Up @@ -153,7 +153,7 @@ public class BubbleChartRenderer: ChartDataRendererBase
{
guard let dataSets = bubbleData.dataSets as? [IBubbleChartDataSet] else { return }

let phaseX = animator.phaseX
let phaseX = max(0.0, min(1.0, animator.phaseX))
let phaseY = animator.phaseY

var pt = CGPoint()
Expand Down Expand Up @@ -236,7 +236,7 @@ public class BubbleChartRenderer: ChartDataRendererBase

CGContextSaveGState(context)

let phaseX = animator.phaseX
let phaseX = max(0.0, min(1.0, animator.phaseX))
let phaseY = animator.phaseY

for indice in indices
Expand Down
4 changes: 2 additions & 2 deletions Charts/Classes/Renderers/CandleStickChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class CandleStickChartRenderer: LineScatterCandleRadarChartRenderer
animator = animator
else { return }

let phaseX = animator.phaseX
let phaseX = max(0.0, min(1.0, animator.phaseX))
let phaseY = animator.phaseY
let barSpace = dataSet.barSpace
let showCandleBar = dataSet.showCandleBar
Expand Down Expand Up @@ -257,7 +257,7 @@ public class CandleStickChartRenderer: LineScatterCandleRadarChartRenderer
{
var dataSets = candleData.dataSets

let phaseX = animator.phaseX
let phaseX = max(0.0, min(1.0, animator.phaseX))
let phaseY = animator.phaseY

var pt = CGPoint()
Expand Down
24 changes: 12 additions & 12 deletions Charts/Classes/Renderers/LineChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public class LineChartRenderer: LineRadarChartRenderer
let minx = max(dataSet.entryIndex(entry: entryFrom) - diff - 1, 0)
let maxx = min(max(minx + 2, dataSet.entryIndex(entry: entryTo) + 1), entryCount)

let phaseX = animator.phaseX
let phaseX = max(0.0, min(1.0, animator.phaseX))
let phaseY = animator.phaseY

// get the color that is specified for this position from the DataSet
Expand Down Expand Up @@ -138,7 +138,7 @@ public class LineChartRenderer: LineRadarChartRenderer
// let the spline start
CGPathMoveToPoint(cubicPath, &valueToPixelMatrix, CGFloat(cur.xIndex), CGFloat(cur.value) * phaseY)

for j in minx + 1 ..< min(size, entryCount)
for j in (minx + 1).stride(to: min(size, entryCount), by: 1)
{
prevPrev = prev
prev = cur
Expand Down Expand Up @@ -198,7 +198,7 @@ public class LineChartRenderer: LineRadarChartRenderer
let minx = max(dataSet.entryIndex(entry: entryFrom) - diff - 1, 0)
let maxx = min(max(minx + 2, dataSet.entryIndex(entry: entryTo) + 1), entryCount)

let phaseX = animator.phaseX
let phaseX = max(0.0, min(1.0, animator.phaseX))
let phaseY = animator.phaseY

// get the color that is specified for this position from the DataSet
Expand All @@ -221,7 +221,7 @@ public class LineChartRenderer: LineRadarChartRenderer
// let the spline start
CGPathMoveToPoint(cubicPath, &valueToPixelMatrix, CGFloat(cur.xIndex), CGFloat(cur.value) * phaseY)

for j in minx + 1 ..< min(size, entryCount)
for j in (minx + 1).stride(to: min(size, entryCount), by: 1)
{
prev = cur
cur = dataSet.entryForIndex(j)
Expand Down Expand Up @@ -305,7 +305,7 @@ public class LineChartRenderer: LineRadarChartRenderer
let isDrawSteppedEnabled = dataSet.mode == .Stepped
let pointsPerEntryPair = isDrawSteppedEnabled ? 4 : 2

let phaseX = animator.phaseX
let phaseX = max(0.0, min(1.0, animator.phaseX))
let phaseY = animator.phaseY

guard let
Expand All @@ -330,7 +330,7 @@ public class LineChartRenderer: LineRadarChartRenderer
}

let count = Int(ceil(CGFloat(maxx - minx) * phaseX + CGFloat(minx)))
for j in minx ..< count
for j in minx.stride(to: count, by: 1)
{
if (count > 1 && j == count - 1)
{ // Last point, we have already drawn a line to this point
Expand Down Expand Up @@ -407,7 +407,7 @@ public class LineChartRenderer: LineRadarChartRenderer
let count = Int(ceil(CGFloat(maxx - minx) * phaseX + CGFloat(minx)))

var j = 0
for x in (count > 1 ? minx + 1 : minx) ..< count
for x in (count > 1 ? minx + 1 : minx).stride(to: count, by: 1)
{
e1 = dataSet.entryForIndex(x == 0 ? 0 : (x - 1))
e2 = dataSet.entryForIndex(x)
Expand Down Expand Up @@ -485,7 +485,7 @@ public class LineChartRenderer: LineRadarChartRenderer
/// Generates the path that is used for filled drawing.
private func generateFilledPath(dataSet dataSet: ILineChartDataSet, fillMin: CGFloat, from: Int, to: Int, matrix: CGAffineTransform) -> CGPath
{
let phaseX = animator?.phaseX ?? 1.0
let phaseX = max(0.0, min(1.0, animator?.phaseX ?? 1.0))
let phaseY = animator?.phaseY ?? 1.0
let isDrawSteppedEnabled = dataSet.mode == .Stepped
var matrix = matrix
Expand Down Expand Up @@ -538,7 +538,7 @@ public class LineChartRenderer: LineRadarChartRenderer
{
var dataSets = lineData.dataSets

let phaseX = animator.phaseX
let phaseX = max(0.0, min(1.0, animator.phaseX))
let phaseY = animator.phaseY

var pt = CGPoint()
Expand Down Expand Up @@ -578,7 +578,7 @@ public class LineChartRenderer: LineRadarChartRenderer
let minx = max(dataSet.entryIndex(entry: entryFrom) - diff, 0)
let maxx = min(max(minx + 2, dataSet.entryIndex(entry: entryTo) + 1), entryCount)

for j in minx ..< Int(ceil(CGFloat(maxx - minx) * phaseX + CGFloat(minx)))
for j in minx.stride(to: Int(ceil(CGFloat(maxx - minx) * phaseX + CGFloat(minx))), by: 1)
{
guard let e = dataSet.entryForIndex(j) else { break }

Expand Down Expand Up @@ -621,7 +621,7 @@ public class LineChartRenderer: LineRadarChartRenderer
animator = animator
else { return }

let phaseX = animator.phaseX
let phaseX = max(0.0, min(1.0, animator.phaseX))
let phaseY = animator.phaseY

let dataSets = lineData.dataSets
Expand Down Expand Up @@ -660,7 +660,7 @@ public class LineChartRenderer: LineRadarChartRenderer
let minx = max(dataSet.entryIndex(entry: entryFrom) - diff, 0)
let maxx = min(max(minx + 2, dataSet.entryIndex(entry: entryTo) + 1), entryCount)

for j in minx ..< Int(ceil(CGFloat(maxx - minx) * phaseX + CGFloat(minx)))
for j in minx.stride(to: Int(ceil(CGFloat(maxx - minx) * phaseX + CGFloat(minx))), by: 1)
{
guard let e = dataSet.entryForIndex(j) else { break }

Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Renderers/ScatterChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public class ScatterChartRenderer: LineScatterCandleRadarChartRenderer
{
guard let dataSets = scatterData.dataSets as? [IScatterChartDataSet] else { return }

let phaseX = animator.phaseX
let phaseX = max(0.0, min(1.0, animator.phaseX))
let phaseY = animator.phaseY

var pt = CGPoint()
Expand Down

0 comments on commit 833d982

Please sign in to comment.