-
-
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
[Pending rebase] Some lines in line chart not rendering for sparse data #713
Conversation
…d for data sets with sparse x-indexes For sparse data sets (that is, if there is not an entry for every x-index), when zoomed in and panning around, sometimes the outer lines of the line chart would disappear. In fact, ChartRendererBase took precautions to set _minX and _maxX to be always outside of the visible viewport, however, if the data set is sparse, this is not enough: If there is no entry at _minX, dataSet.entryForXIndex(_minX) will often return an entry with xIndex > _minX (not always, though, because of the nature of binary search). Fixed this by adding two more entry query functions to ChartDataSet: entryBeforeXIndex and entryAfterXIndex, which are guaranteed to return entries with a lower/higher x-index (if they exist).
I saw the same issue on my side, but pending fix. |
Oh, sorry, I overlooked the braces for the while loop. Fixed. Regarding the conflict: I've intentionally based by branch on the last stable tag (2.1.6), because I use the fork myself and didn't want the latest unstable Realm-stuff in master. But you're right, I should probably merge master for the PR. |
@liuxuan30 Just tried to rebase this onto master, but I noticed that there are fundamental changes to the data sets due to Realm (different implementations with base/interface). I currently don't have a lot of experience with Realm and, to be honest, not the time to implement the necessary changes to the |
Your fix does not touches the Realm stuff, just how the entries should be fetched; so should be easy to port the fix; Realm is just a DB, and defined the interfaces; |
Yes, you'd need to port the |
I'll try to work with this soon. If somebody has the time and wants to rebase this before I get to - that's also nice... One thing bothers me: The first/last points to draw have been proven to be some kind of a bottleneck in the past, in other situations. Have you tested the performance implications of this change? |
I have not explicitly profiled the code. However, the change is actually very minimal from a performance point of view. The heavy lifting is still done by the binary search (the new methods delegate to |
This looks really good. Did you stop working on this? I'm having the same problem and tried your fix (+ some refactoring) and it works great. |
@ylibatsya I created this pull request while v2.1.6 was the latest stable release, so my fix is based on that. In the meantime, a lot has changed, especially due to the Realm integration, so someone (read: someone with more Realm experience than me), should rebase this PR onto the current master, which would require to port my fix to the Realm-based dataset implementation, too. Other than that, it is "finished". |
@danielr it's just redefined the data portion interfaces, so we have common interfaces, so realm and standard can have their own implementation. I'm thinking your added methods should be in the common interfaces, nothing to do with the realm details? It should not be hard to adapt your change to the new architecture. |
I think that this PR is irrelevant anymore. Can't reproduce. |
For sparse data sets (that is, if there is not an entry for every x-index), when zoomed in and panning around, sometimes the outer lines of the line chart would disappear.
See this (sorry for the mediocre quality, I thought GIF is more appropriate here than a video):
In this demo, I use 15-minute intervals for the x-values, but there is not an entry for every x-index (thus "sparse data set").
I've had a look at the code and also fixed the issue. The following is an in-depth explanation of the issue at the code level:
In fact, ChartRendererBase took precautions to set _minX and _maxX to be always outside of the visible viewport, however, if the data set is sparse, this is not enough: If there is no entry at _minX, dataSet.entryForXIndex(_minX) will often return an entry with xIndex > _minX (not always, though, because of the nature of binary search). Fixed this by adding two more entry query functions to ChartDataSet: entryBeforeXIndex and entryAfterXIndex, which are guaranteed to return entries with a lower/higher x-index (if they exist).