Some new patches around zooming and panning

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
uvoigt
Posts: 168
Joined: Mon Aug 23, 2004 10:50 am
Location: Germany

Some new patches around zooming and panning

Post by uvoigt » Mon May 12, 2014 2:38 pm

Hi,

I have posted some patches that improve zooming and panning.
As a main new feature the patches allow to zoom and pan single axis (instead of zooming and panning all axes).

The patches are:
Panning of single axis: https://sourceforge.net/p/jfreechart/patches/303/
Small bugfix for panning in Combined plots: https://sourceforge.net/p/jfreechart/patches/304/
Zoom single axis by mouse wheel: https://sourceforge.net/p/jfreechart/patches/305/
Zoom single axis by mouse drag: https://sourceforge.net/p/jfreechart/patches/306/

If required I can also post one patch that contains all changes in one patch file.

I would be happy to get some feedback and hopefully it can be integrated into JFreeChart.
Please let me know about any change requests. I am willing to do the fine tuning on the patches :)

Uli

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Some new patches around zooming and panning

Post by david.gilbert » Wed May 14, 2014 10:11 pm

Thanks!

I looked at the first two patches and they look great so far (the first one doesn't handle CategoryPlot, but that is easily fixed). I didn't commit anything yet, I'll wait till I get to the other two patches.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

uvoigt
Posts: 168
Joined: Mon Aug 23, 2004 10:50 am
Location: Germany

Re: Some new patches around zooming and panning

Post by uvoigt » Thu May 15, 2014 9:17 am

Great!

I have uploaded a second path for the mouse wheel zoom handler. It now supports FastScatterPlots and CombinedXXPlots.

uvoigt
Posts: 168
Joined: Mon Aug 23, 2004 10:50 am
Location: Germany

Re: Some new patches around zooming and panning

Post by uvoigt » Thu May 15, 2014 9:21 am

I have also uploaded a small fix for the FastScatterPlot:
https://sourceforge.net/p/jfreechart/patches/307/

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Some new patches around zooming and panning

Post by paradoxoff » Thu May 15, 2014 1:25 pm

Just saw uvoigts patch and this post.
I have patched my local JFreeChart version and added the folllwing options:
- Zooming/Panning can be disabled for selected axes. This was achieved by additional flags panEnabled and zoomEnabled in the ValueAxis class and check for the status of these flags during the zoom process.
- Panning by a mouse drag along an axis. Key idea was to add an addional entity interface DraggableEntity and make a) ValueAxis return an instance of that entity and b) make ChartPanel to treat that entity in a special way. One further use of this new entity class that I have in mind is a DraggableLegendTitle that only occupies one row/column and only exposes a subset of the legend item of its LegendItemSources.
- Zoom of only one axis by the mouse wheel. This was also realized by a new interface ZoomableEntity.

Would it be ok if I pack those extension into a single patch?

uvoigt
Posts: 168
Joined: Mon Aug 23, 2004 10:50 am
Location: Germany

Re: Some new patches around zooming and panning

Post by uvoigt » Thu May 15, 2014 2:13 pm

It sounds like we have implemented those features in parallel :-)

Can you try to merge our patches? It's ok for me (and it's obviously easier) to have a single patch. It's also ok for me if you use your implementation instead of mine. Anyhow it would be great if the complete functionality is available.

I like your idea to create something like a ZoomableEntity and DraggableEntity. Without having this my code blowed up significantly!

Please have a look at the patch 303. It introduces a PanHandler interface which is used by the ChartPanel.
This has two advantages:
  • Code in the ChartPanel becomes easier
  • PanHandler could be used to modify when a pan action is started, e.g. press Alt instead of Ctrl.
For the same reasons it would also be good to introduce a ZoomHandler likewise.

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Some new patches around zooming and panning

Post by paradoxoff » Sun May 18, 2014 8:27 pm

I have uploaded a patch, patch no. 309.
The only thing that is missing is an individual zoom for a specific axis that is triggered by a mouse drag ant not by a mouse wheel action. It should be possible to integrate that functionality, and delegate the zoom to an eventual ZoomableEntity, but before I need to better understand all the different cases that become relevant in case of zooming.
Delegating mouse actions to pluggable PanHandlers and ZoomHandlers would certainly simplify the code. The question is whether it is well invested time to change the architecture of the ChartPanel class. The future state edition seems to have significantly extended the features of ChartPanel with regard to mouse action handling. Why not wait until that is ready for publication?

uvoigt
Posts: 168
Joined: Mon Aug 23, 2004 10:50 am
Location: Germany

Re: Some new patches around zooming and panning

Post by uvoigt » Sun May 18, 2014 9:26 pm

paradoxoff wrote:I have uploaded a patch, patch no. 309.
Is the patch complete? At least I cannot find PannableEntity (class, interface?).
paradoxoff wrote:The only thing that is missing is an individual zoom for a specific axis that is triggered by a mouse drag ant not by a mouse wheel action. It should be possible to integrate that functionality, and delegate the zoom to an eventual ZoomableEntity, but before I need to better understand all the different cases that become relevant in case of zooming.
Delegating mouse actions to pluggable PanHandlers and ZoomHandlers would certainly simplify the code. The question is whether it is well invested time to change the architecture of the ChartPanel class.
PanHandler is already implemented. Please check my patch.
paradoxoff wrote:The future state edition seems to have significantly extended the features of ChartPanel with regard to mouse action handling. Why not wait until that is ready for publication?
Referring to the future state edition does not satisfy me. Activity on this edition was not very high in the last months so I wonder when the first more or less stable version will be released. So from my point of view it's not an alternative to wait for it.

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Some new patches around zooming and panning

Post by paradoxoff » Mon May 19, 2014 9:16 am

uvoigt wrote: Is the patch complete? At least I cannot find PannableEntity (class, interface?).
No, it is not. I have created the patch file using the built in patch generator of Netbeans 7.4 and apparently did something wrong. All the new files are missing (interfaces PannableEntity and ZoomableEntity and the class ValueAxisEntity). I will have a look at that again this evening.
uvoigt wrote: PanHandler is already implemented. Please check my patch.
I have seen that. It is certainly a good way to shorten the source code of ChartPanel. I was just wondering whether using that approach is flexible enough to handle future needs that one might have, such as data point selection, adding annotations and markers, dragging annotations and markers, etc. Changing the panMask could be realized by simply making that field public and provide a setter.

uvoigt
Posts: 168
Joined: Mon Aug 23, 2004 10:50 am
Location: Germany

Re: Some new patches around zooming and panning

Post by uvoigt » Mon May 19, 2014 10:05 am

paradoxoff wrote:
uvoigt wrote: PanHandler is already implemented. Please check my patch.
I have seen that. It is certainly a good way to shorten the source code of ChartPanel. I was just wondering whether using that approach is flexible enough to handle future needs that one might have, such as data point selection, adding annotations and markers, dragging annotations and markers, etc. Changing the panMask could be realized by simply making that field public and provide a setter.
You might not only want to change the panMask but also want to switch between zooming and panning by toggle buttons in the application. I don't know either if the interface is designed well enough to handle other use cases. But it's a try to put more and more stuff into the ChartPanel class which makes it code a bit clumsy.

I don't mind not to use the PanHandler interface or to change the implementation drastically.
But I would not be happy if the functionality of single axis panning and zooming is not realized.

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Some new patches around zooming and panning

Post by paradoxoff » Wed May 21, 2014 8:48 pm

I have integrated the single axis zoom by dragging the mouse around in the axis area. The new files are now included. Since I could´t get Git and NetBeans to work for me as intended (when I have more time I will setup my IDE properly), I have used diff from UnxUtils.

uvoigt
Posts: 168
Joined: Mon Aug 23, 2004 10:50 am
Location: Germany

Re: Some new patches around zooming and panning

Post by uvoigt » Thu May 22, 2014 9:30 am

Thanks!
I managed to use your patch. It works for me.

I have some minor comments:
  • Combined plots seems to be not supported yet
  • When zooming with the mouse on a single axis the mouse movement should only be evaluated in x direction for domain axes and y direction for range axes. This matters for the zoom out detection triggered by a negative sized mouse movement.
  • The zoom window should better mark the whole y range (domain axis) or x range (range axis) of the axis and not the exact mouse movement (see my patch 306)
  • Can you explain a situation where it is reasonable to use the isGloballyPannable/Zoomable flag?
    I find it more understandable to have an isSingleAxisPannable/Zoomable flag of the ChartPanel (or Chart?) instead. At the moment it is possible to set all isGlobally* flags to false (the defaults), set the setXXPannable/Zoomable flags to true. It is then possible to create the zoom window with the mouse within the plot but nothing happens. Zooming on the axis works.
    I think it is easier to understand if all range/domain axis can be zoomed/pannable alltogether only or individually and altogether. Being able to zoom/pan individually but not altogether is unexpected.
  • I have seen some effects when using the mouse wheel on the left range axis of the MultipleAxisDemo4. When zooming in so that only values in range 90-95 are visible the chart seems to resize too often. Maybe that's not a problem of your patch.
I am looking forward to land this new features for JFreeChart 1.0.18?!?
Uli

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Some new patches around zooming and panning

Post by paradoxoff » Fri May 23, 2014 8:17 am

Hu Uli, thanks for trying the patch and for the feedback.
uvoigt wrote: Combined plots seems to be not supported yet
I just discovered that the logic to detect zoom and pan events is broken for subplots. I will need to change the order of checks in the mousePressed method and to first check whether the mouse event occured within the area of a ZoomableEntity and then whether it occurs within the data area. At present, it is the other way round. With the present order, it will not be possible to reach ZoomableEntities that are within the data area.
uvoigt wrote: When zooming with the mouse on a single axis the mouse movement should only be evaluated in x direction for domain axes and y direction for range axes. This matters for the zoom out detection triggered by a negative sized mouse movement.
If the ZoomableEntity is in fact an instance of ValueAxisEntity, you are definitely right. If the ZoomableEntity is of another type, the behaviour described may or may not the desired or intuitive one. I see two approaches to this issue:
1. In the mouseDragged method, check whether the ZoomableEntity is an instance of ValueAxisEntity, and if yes, check its positions realtive to the data area and draw the zoom rectangle accordingly.
2. Delegate the calculation of the zooom rectangle to the ZoomableEntity. Personally, I prefer the second approach, as this would allow to add further ZoomableEntities without having to teach ChartPanel how to draw an appropriate zoom rectangle.
uvoigt wrote:Can you explain a situation where it is reasonable to use the isGloballyPannable/Zoomable flag?
I find it more understandable to have an isSingleAxisPannable/Zoomable flag of the ChartPanel (or Chart?) instead. At the moment it is possible to set all isGlobally* flags to false (the defaults), set the setXXPannable/Zoomable flags to true. It is then possible to create the zoom window with the mouse within the plot but nothing happens. Zooming on the axis works.
One use case is the visualization of the response of a process over time which is dependent on some process variables. In such a case, the process variables (which are defined by a user and changed in a controlled way in regular intervals) are rerpesented by separate datasets and plotted on secondary y axes. The "outcome" of the process and the time are plotted on the primary y and on the x axis, respectively. In such a case, it is highly desirable, to leave the ranges for the y axes showing the process parameters constant and only zoom/pan the axes for the time and the process outcome.
But you are right that the behaviour during a zoom action if all axes have the globalXXXable flags set to false is irritating. I will change the isDomain/RangePannable/Zoomable methods of XYPlot and CategoryPlot to not directly return true or false, but to check the respective globalXXX flags of their domain and range axes and return a more appropriate flag.

Regarding the behaviour that you observed for the MultipleAxisDemo4: I will need to check that, but I think that this probably comes from the frequent change of the tick unit and variable lengths of the tick marks.

uvoigt
Posts: 168
Joined: Mon Aug 23, 2004 10:50 am
Location: Germany

Re: Some new patches around zooming and panning

Post by uvoigt » Mon May 26, 2014 2:41 pm

paradoxoff wrote:
uvoigt wrote:Can you explain a situation where it is reasonable to use the isGloballyPannable/Zoomable flag?
I find it more understandable to have an isSingleAxisPannable/Zoomable flag of the ChartPanel (or Chart?) instead. At the moment it is possible to set all isGlobally* flags to false (the defaults), set the setXXPannable/Zoomable flags to true. It is then possible to create the zoom window with the mouse within the plot but nothing happens. Zooming on the axis works.
One use case is the visualization of the response of a process over time which is dependent on some process variables. In such a case, the process variables (which are defined by a user and changed in a controlled way in regular intervals) are rerpesented by separate datasets and plotted on secondary y axes. The "outcome" of the process and the time are plotted on the primary y and on the x axis, respectively. In such a case, it is highly desirable, to leave the ranges for the y axes showing the process parameters constant and only zoom/pan the axes for the time and the process outcome.
But you are right that the behaviour during a zoom action if all axes have the globalXXXable flags set to false is irritating. I will change the isDomain/RangePannable/Zoomable methods of XYPlot and CategoryPlot to not directly return true or false, but to check the respective globalXXX flags of their domain and range axes and return a more appropriate flag.
Ok, I think I understood.

I wonder if it is required to have a isPannable/isZoomable method on the axis that returns four values:
DISABLED (no zoom/pan at all)
LOCAL_ONLY (zoom/pan on this single axis only but no global zoom/pan)
GLOBAL_ONLY (global zoom/pan on this axis only but not local on this axis)
GLOBAL_AND_LOCAL (zoom/pan always enabled - both global and local)

I don't know if you meant that with your last sentence?

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Some new patches around zooming and panning

Post by paradoxoff » Wed Jun 11, 2014 8:22 pm

Finally, the patch now seems to be working also for combined plots.
Getting this to work required to dig a little deeper into the JFreeChart internals than I had thought. In order to get combined plots to work, I had to change how matching PlotRenderingInfos for a given coordinate are found: they are now detected based on whether the plot area (not the data area) of the info contains the coordinates, and if an info object has subplots and none of the subplots plot area contains the coordinate, it is checked whether the plot area of the main info object contains the point.
uvoigt wrote: I wonder if it is required to have a isPannable/isZoomable method on the axis that returns four values:
DISABLED (no zoom/pan at all)
LOCAL_ONLY (zoom/pan on this single axis only but no global zoom/pan)
GLOBAL_ONLY (global zoom/pan on this axis only but not local on this axis)
GLOBAL_AND_LOCAL (zoom/pan always enabled - both global and local)

I don't know if you meant that with your last sentence?
Regarding the four different values: I do not think that it needs to be that complicated. The main motivation behing the globalPannable and globalZoomable flags was to keep axes from getting zoomed is the user dragged the mouse on the data area. I do not see a reason why the option to suppress zooming if a user is dragging along an axis. IMHO, if the user is doing that, he knows what he is doing.
Regarding my "last sentence" above: Have a look at the patch. :)

Locked