-
-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LineChartView.highlightValue causes CoreGraphics API errors #4043
Comments
I did some digging, and there's already a PR which addresses this #2568. But there looks to be some confusion about highlights being created with NaN Y values, however if you follow the code path from It's worth noting that using the result of |
sorry to wrongly link this issue from 4093 I need to know why it's NaN then we can decide how to fix for this issue |
OK so I took a look at your code and #2568.
will eventually fall into
and passing a nan for y value, because no one gives it. It should finally fall into open override func entryIndex(
x xValue: Double,
closestToY yValue: Double,
rounding: ChartDataSetRounding) -> Int
{ where it detects if yValue is NaN and do something: // Search by closest to y-value
if !yValue.isNaN
{
while closest > 0 && self[closest - 1].x == closestXValue
{
closest -= 1
}
var closestYValue = self[closest].y
var closestYIndex = closest
while true
{
closest += 1
if closest >= endIndex { break }
let value = self[closest]
if value.x != closestXValue { break }
if abs(value.y - yValue) <= abs(closestYValue - yValue)
{
closestYValue = yValue
closestYIndex = closest
}
}
closest = closestYIndex
} but like you said, it later calls |
it seems #2568 indeed is valid fix. Thanks for reporting! |
What did you do?
Called
LineChartView.highlightValue(x: Double, dataSetIndex: Int)
with a validx
&dataSetIndex
What did you expect to happen?
I expected the Chart to Highlight the appropriate X/Y point for the given X value
What happened instead?
Nothing was drawn, console spews out the error:
Error: this application, or a library it uses, has passed an invalid numeric value (NaN, or not-a-number) to CoreGraphics API and this value is being ignored. Please fix this problem.
Charts Environment
Charts version/Branch/Commit Number: 3.3.0
Xcode version: 10.2.1
Swift version: 5.0
Platform(s) running Charts: iOS 12.3.1
macOS version running Xcode: 10.14.4
Demo Project
Note: From my own digging the issue here is in the
LineChartRenderer.drawHighlighted
func. Specifically the following lines:Since
high.y
is NaN, the transformer attempts to transform a CGPoint where Y is NaN. This causes pt X & Y to both be NaN which is then passed todrawHighlightLines
resulting in CoreGraphics API errors.I believe a fix here would be to use the result from
set.entryForXValue
above? But i'm not sure what implications that would have on other highlighting funcs.The text was updated successfully, but these errors were encountered: