Charts icon indicating copy to clipboard operation
Charts copied to clipboard

Fix chart only drawing first entry

Open FelixHerrmann opened this issue 2 years ago • 2 comments

Issue Link :link:

#4819 #4792 #4753 #4739 #4722 #4699 (and possibly a lot more)

Goals :soccer:

Fixing line chart only drawing first entry when spaceMax on xAxis is not 0. This will fix the candle stick chart only drawing first value as well!

Implementation Details :construction:

With the addition of the swift-algorithms package in v4.0.0 many search algorithms have changed, including the one in ChartDataSet.entryIndex(x:closestToY:rounding:).

It turns out that partitioningIndex works different in one situation: when the given value is greater than the greatest value in the array. Screen Shot 2022-05-26 at 23 39 32

Because of that, we need some kind of check that ensures we don't get an index out of bounds. #4577 #4721 and the initial implementation #4497 do those checks, but wrong. The initial implementation is the best, the index is just one too high as shown in the screenshot above. We simply need to return the last possible index if a higher value is requested. Returning -1 in this situation will result in only drawing the first value!

In addition to that, I replaced all the raw index manipulation with the standard lib APIs and fixed Package.resolved to reflect the versions from the Package.swift!

Testing Details :mag:

I tested in the demo projects and my personal one.

Before Fix After Fix
Simulator Screen Shot - iPhone 13 Pro - 2022-05-26 at 22 24 17 Simulator Screen Shot - iPhone 13 Pro - 2022-05-26 at 22 25 51
Simulator Screen Shot - iPhone 13 Pro - 2022-05-26 at 22 24 52 Simulator Screen Shot - iPhone 13 Pro - 2022-05-26 at 22 25 32

FelixHerrmann avatar May 26 '22 22:05 FelixHerrmann

I've tested our apps' graphs with the results from this PR and I can confirm this solves our problem. Good job! I'll pull the updated version in our app as soon as it get available in a release.

TKZwo avatar Jun 21 '22 05:06 TKZwo

It would be highly appreciated if this fix can make it to the next release.

artalejo avatar Jun 27 '22 14:06 artalejo

Any thoughts on when this fix might be merged?

bzeeman avatar Aug 01 '22 22:08 bzeeman

Maybe @pmairoldi can tell us when we can expect this fix to be merged?

FelixHerrmann avatar Aug 02 '22 20:08 FelixHerrmann

Any word on when this can move forward @pmairoldi ? We ran into this same issue and can confirm this change fixes it.

morluna avatar Aug 25 '22 15:08 morluna

Hi @FelixHerrmann this totally solves my problem. In my case I had a lineChart combined with two other lineCharts configured to not show the lines, but just relevant points (mins a maxs detected with my algorithm) IMG_2190 IMG_2189

So yes that would be great to have this merged with master. Thanks!

cbalsalobre avatar Aug 26 '22 14:08 cbalsalobre

Awesome @cbalsalobre, thanks for confirming!

FelixHerrmann avatar Aug 26 '22 14:08 FelixHerrmann

A note for the Collaborators: #4839 and #4844 try to fix the same problem but they don't resolve the root cause of the issue

FelixHerrmann avatar Aug 28 '22 16:08 FelixHerrmann

We are waiting for merging this for a long time.

417-72KI avatar Aug 29 '22 02:08 417-72KI

@fumoboy007 I think if you edit your comment to 'approve' the 'open discussion' will be closed and this PR will be pulled in.

TKZwo avatar Aug 29 '22 06:08 TKZwo

Thanks for the contribution. Will be out with the next version for Xcode 14

pmairoldi avatar Aug 29 '22 13:08 pmairoldi

Hello @pmairoldi

Do you know when the next release of this lib will be available?

Thanks

santieduardo avatar Sep 09 '22 09:09 santieduardo