Skip to content
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

Data disappearing while zooming/panning when y-values are not ordered by x #130

Closed
gjpc opened this issue Jun 5, 2015 · 17 comments
Closed

Comments

@gjpc
Copy link

gjpc commented Jun 5, 2015

Modify the Scatter plot demo thus:

add a line 99:

    double xv = (double) (arc4random_uniform(count)) + 3;

modify the next line which is now 100:

    [yVals1 addObject:[[ChartDataEntry alloc] initWithValue:val xIndex: xv]];

Start panning and zooming and many of the data points will not be rendered. Also, the value labels are frequently not rendered.

The problem is in ScatterChartRenderer.swift this code appears in two places:

            if (!viewPortHandler.isInBoundsRight(point.x))
            {
                break;
            }

This code at lines 91 and 217 assume that the X data is ordered. Removing the conditional break's fixes the problem.
in fork: https://github.com/gjpc/ios-charts

Patch:

diff --git a/Charts/Classes/Renderers/ScatterChartRenderer.swift b/Charts/Classes/Renderers/ScatterChartRenderer.swift
index 073e45c..f688630 100644
--- a/Charts/Classes/Renderers/ScatterChartRenderer.swift
+++ b/Charts/Classes/Renderers/ScatterChartRenderer.swift
@@ -87,12 +87,7 @@ public class ScatterChartRenderer: ChartDataRendererBase
             point.x = CGFloat(e.xIndex);
             point.y = CGFloat(e.value) * phaseY;
             point = CGPointApplyAffineTransform(point, valueToPixelMatrix);            
-            
-            if (!viewPortHandler.isInBoundsRight(point.x))
-            {
-                break;
-            }
-            
+                        
             if (!viewPortHandler.isInBoundsLeft(point.x) || !viewPortHandler.isInBoundsY(point.y))
             {
                 continue;
@@ -213,12 +208,7 @@ public class ScatterChartRenderer: ChartDataRendererBase
                 var lineHeight = valueFont.lineHeight;

                 for (var j = 0, count = Int(ceil(CGFloat(positions.count) * _animator.phaseX)); j < count; j++)
-                {
-                    if (!viewPortHandler.isInBoundsRight(positions[j].x))
-                    {
-                        break;
-                    }
-                    
+                {                   
                     // make sure the lines don't do shitty things outside bounds
                     if ((!viewPortHandler.isInBoundsLeft(positions[j].x)
                         || !viewPortHandler.isInBoundsY(positions[j].y)))
@gjpc gjpc changed the title pinch zooming and panning the scatter plot makes data dissapear pinch zooming and panning the scatter plot makes data dissapear -- SOLVED Jun 5, 2015
@gjpc gjpc changed the title pinch zooming and panning the scatter plot makes data dissapear -- SOLVED pinch zooming and panning the scatter plot makes data dissapear -- SOLVED contains patch Jun 8, 2015
@gjpc
Copy link
Author

gjpc commented Jun 9, 2015

Though the patch allows viewing and interaction with a non x ordered scatter data set, utility functions such as entryIndex expect ordered x data and fail. So the patch is only good if you are just displaying the data. There might be other package architectural dependencies on ordered x data. Anyone in the project care to comment?

However given issue #82 the bad behavior may be rooted in other bugs.

@gjpc gjpc changed the title pinch zooming and panning the scatter plot makes data dissapear -- SOLVED contains patch pinch zooming and panning the scatter plot makes data dissapear -- SOLVED in gjpc fork Jun 10, 2015
@danielgindi
Copy link
Collaborator

Actually, many functions in the project depends on the y values being ordered on the x axis. That's because in many places we know that we can stop at a certain point, and not loop through more data. This is done for either rendering or even just preventing calculations on data that's our of the viewport.

I'll continue a discussion on this with Phil, in the other issue on the MPAndroidChart repo. PhilJay/MPAndroidChart#718.

You can follow up on it there, and when we have a conclusion I'll give an update here.

@danielgindi danielgindi changed the title pinch zooming and panning the scatter plot makes data dissapear -- SOLVED in gjpc fork Data disappearing while zooming/panning when y-values are not ordered by x Jun 11, 2015
@gjpc
Copy link
Author

gjpc commented Jun 11, 2015

Yes, I have noticed that and I would think in many non-biological areas it would be fine, it's a good optimization. Perhaps setting a flag in a DataSet object's first scan of the data to let the renderers know it aint so. It may be advisable to to go ahead and set the flag when realtime data on the x axis manipulation occurs.

@danielgindi
Copy link
Collaborator

We've come to a conclusion that the values must be ordered - as it is considerably less expensive to sort the data by x-index before passing to the chart, than to loop over the whole data and do the bounds-checking for each and every point.

So this is going to be closed for now. If there's a request for a specific special feature please open a relevant issue :-)

@gjpc
Copy link
Author

gjpc commented Jun 23, 2015

If anyone wants a scatter chart that actually works they can go to my branch....

@danielgindi
Copy link
Collaborator

Or work correctly with the API. The scatter chart works.

@gjpc
Copy link
Author

gjpc commented Jun 23, 2015

It does not :P

@micnguyen
Copy link

@gjpc Hi, I've tried implementing your changes to remove the condition checking on my project that suffers this issue as well, but it does not seem to fix it either. Have any advice?

@gjpc
Copy link
Author

gjpc commented Aug 28, 2015

@micnguyen I need a bit more information before I may offer any advice.

@gjpc
Copy link
Author

gjpc commented Aug 29, 2015

@micnguyen I am not sure you implemented my changes or @danielgindi branch of my changes that may or may not contain my changes properly implemented. I just pushed a major enhancement to the Independent Scatter Chart demo to illustrate exactly what an Independent scatter plot does. Please go to my branch and see it that solves your problems.

@micnguyen
Copy link

@gjpc I basically created a time series charge with lots of x-axis intervals (spaced by 1 minute). So there will data points at say, interval 1 and another data point at interval 61 if they are an hour apart. The issue I have been seeing is if you zoom until a point is off the screen, the line that connects them disappears. I assumed your change of removing the conditionals on line 91 and 217 fixed that - or have you tackled another issue that I may be mistaking?

@gjpc
Copy link
Author

gjpc commented Aug 31, 2015

@micnguyen I chose not to draw a line unless both points are visible on the screen. I find it easier to zoom out to find the next dot's position, panning and then re-zooming a more natural mode of analysis. In a particularly dense data set I found too many lines running off the screen in so many different directions obscured the data under study. I'll consider adding a flag to allow a line to the off-screen points.

@micnguyen
Copy link

@gjpc Our testers and myself personally have found the disappearing lines odd behaviour. In our situation, we only have 1 data set that all have unique x-y values. The lines that connect said data points do provide some information to the user (especially if your data points do not have large explicit markers). I hope the changes to achieve that won't be too much work - thank you.

@gjpc
Copy link
Author

gjpc commented Aug 31, 2015

@micnguyen it is a trivial fix if you don't mind the line transversing to the off screen data point crossing the axis lines. It is more work to stop it at the axis, but there is a certain amount of positive feedback in indicating the data exists, but it is out of the view port.

What do you think?

screen shot 2015-08-30 at 7 51 56 pm

@micnguyen
Copy link

@gjpc It looks great! It appearing out of the axis lines is rather unfortunate and undesirable however. But if the lines and data points don't disappear when out of the viewport, that's great.

@gjpc
Copy link
Author

gjpc commented Aug 31, 2015

@micnguyen You are right, pickup the finish at https://github.com/gjpc/ios-charts
screen shot 2015-08-30 at 10 10 38 pm

@gjpc
Copy link
Author

gjpc commented Sep 2, 2015

@micnguyen I don't know if this will effect you, but I just did a rebase and force push to get rid of a previous commit error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants