|
ChartViewer for SWT |
Posted by Mark on Mar-10-2016 09:53 |
|
I have a mature app that uses SWT graphics package instead of SWING. I want to take advantage of ChartDirector6's new Zoom/Scroll and Track features, and it seems that the ChartViewer widget is needed to support the new capabilities. I suppose that there isn't a ChartViewer widget based on the SWT's Label widget like there is for SWING's JLabel widget, is there? Am I out of luck, or is there an alternative approach??
Mark |
Re: ChartViewer for SWT |
Posted by Peter Kwan on Mar-11-2016 04:16 |
|
Hi Mark,
The main function of the ChartViewer is to provide the user interface (eg. for dragging a selection box) and for book-keeping of the viewport. The actual chart and track cursor update is done by the ChartDirector core and not by the ChartViewer. So it should be possible to use SWT to support track cursor and zoom/scroll. You would just need to write some code to provide a similar user interface.
For track cursors, it needs the mouse move and mouse out events. Although I am not familiar with SWT, I believe SWT should have equivalent events. In the sample code, the exact event is "PlotAreaMouseMove" (the mouse moving on the plot area). In SWT, you may simply use the mouse move event, and use additional code to check if the mouse is over the plot area.
For zooming and scrolling, if you keep the user interface simple, it should not be hard to implement. For example, you can use mouse wheel for zooming (instead of dragging a selection rectangle which is harder to implement). The SWT may already have a built-in support for mouse wheel events. You just need to write some code to change the viewport size in the mouse wheel events, and then update the chart. The chart update itself does not involve the ChartViewer. It is just normal charting code.
For scrolling, you may use mouse drag for scrolling. A mouse drag is a mouse down, followed by mouse move, followed by mouse up. So for your case, you would need to keep track of how far the mouse has moved when the mouse button is down, and update the viewport position in the mouse move event, and then update the chart.
Also, for zooming and scrolling, in ChartDirector 4.1, the charting code also updates the "axis scale" to reflect zooming. In recent versions of ChartDirector, to simplify the code, there is a ChartViewer.syncLinearAxisWithViewPort method to automatically update the axis scale. As your code cannot use the ChartViewer, you may need to copy the code that updates the axis scale from ChartDirector 4.1 to your charting code to implement the same function.
Regards
Peter Kwan |
|