APChartLine having points all with the same Y gives error: Assertion failed
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)) ... }
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
}
fixed