halfhp / androidplot

Charts and plots for Android
http://androidplot.com
Apache License 2.0
505 stars 159 forks source link

PanZoom enhanced #33

Closed phisi closed 7 years ago

phisi commented 7 years ago

Adds ZoomLimit flag to PanZoom If the flag is set to PanZoom.MIN_TICKS PanZoom.calculateZoom( ...) will be limited not to zoom in beyond one visible grid line (if applicable).

Default behavior is not changed. Should not break any existing code using this class.

phisi commented 7 years ago

I must admit I did not look into XYPlot.innerLimits. To understand the way the grid is drawn I looked at XYGraphWidget.drawGrid(). I don't see how innerLimits would change the outcome of that function.

halfhp commented 7 years ago

Hmm perhaps I've misunderstood the purpose of this change. The basic intent appears to be to provide a new way of specifying a zoom limit to work with the StepModel changes.

This PR contains this new logic:

// make sure we do not zoom in too far (there should be at least one grid line visible)
if (plot.getDomainStepValue() > (scale*span)) {...}

Which determines whether or not to operate on a zoom event using a new algorithm. The intent of innerLimits and outerLimits however is that these are the only two values that PanZoom needs to worry about to determine whether or not to prevent pan/zoom as a result of hitting a limit

Rather than making these calculations on every zoom event, I wonder if we can instead calculate and set the appropriate innerLimit one time up front, either when we attach the PanZoom instance or perhaps when we add the StepModelFit instance. The former is probably cleaner, however the later would have the benefit that it would recalculate any time the StepModel changes.

phisi commented 7 years ago

I played around a little with the innerLimits and could get some of the functionality I want. The problem is that the innerLimits also interfere with the framing model (that is the only code where they are realy used). To get everything I propably would have to mess around there too...

To clarify the desired functionality: Lets say we start with the PanZoomDemo Range 0-1000 Domain 0-3000 now you can zoom in and pan around. The limits are the outer limits (can not pan outside those) with the commit there is an additional limit on the zoom (not pan) the range/domain on display can not be smaller than a certain value (currently the getStepValue() but could be anything). So you could for example view the range 103-104 (min. step 1) at domain 2452-2462 (min. step 10).

phisi commented 7 years ago

I added a stub javadoc. Please fell free to expand. Thanks

halfhp commented 7 years ago

Thanks - merged!