APLineChart icon indicating copy to clipboard operation
APLineChart copied to clipboard

APChartLine having points all with the same Y gives error: Assertion failed

Open kross50 opened this issue 10 years ago • 2 comments

Swift 1.2 / Xcode 6.3

for i:Int in 0...20{ x = x+1 + CGFloat(arc4random_uniform(10)) line.addPoint( CGPoint(x: x, y: 2)) // arbitrarily set to 2 to duplicate real life scenario

    }

Assertion failed: (CGFloatIsValid(x) && CGFloatIsValid(y)), function void CGPathMoveToPoint(CGMutablePathRef, const CGAffineTransform *, CGFloat, CGFloat), file Paths/CGPath.cc, line 254.

Error is in APCharLine: func drawLine() -> CAShapeLayer? { .. bpath.moveToPoint(CGPoint(x: dots[0].point.x, y: dots[0].point.y)) ... }

kross50 avatar Apr 11 '15 10:04 kross50

To fix it in APChartPoint I changed the function to instead be:

func updatePointY (factor:CGFloat, _ offset:CGFloat) -> CGFloat { var newY = offset - self * factor

    if (newY.isNaN) {
        newY = 0
    }

    return newY
}

kross50 avatar Apr 11 '15 11:04 kross50

fixed

tylyo avatar Apr 16 '15 19:04 tylyo