|
C++ Zoom In with my own GUI Frameworks |
Posted by rstein on Dec-23-2016 18:26 |
|
Hi,
I am trying to understand how to develop the option to zoomIn, zoomOut, and rotate without using one of the chartViewer object - with no success.
I am looking in the help/guide, in section :
Using ChartDirector with Other GUI Frameworks - Handling View Port Interactions.
and I don't fully understand what I have to do.
In the last point in the instantiation it's written:
Redraw the chart based on the new view port position and size.
I have the position and size...
who will redraw the chart for me?
Does the zoomIn and zoomOut, just take the image as is, and make the image bigger and smaller ?
Or we generate the new image with the right values?
if we do generate new image, how do I do that?
Thanks,
Rachel. |
Re: C++ Zoom In with my own GUI Frameworks |
Posted by Peter Kwan on Dec-24-2016 00:05 |
|
Hi rstein,
Your own code will need to redraw the chart. Typically, you do not need to write any extra code, as you can use the same code that draws the chart in the first place.
In our own sample code, the drawChart routine just draws whatever data range the user has selected. When the user changes the selection (such as to drag a new rectangle in "zoom in" mode, or use the mouse wheel to zoom in/out, or drag the chart in "drag to scroll" mode, etc), the drawChart method is called again the update the chart.
In charting, zooming in and out usually means modifying the axis range. For example, if the axis range is initially one year, zooming in may mean the axis range becoming 6 months. Usually, most of the things in the chart would not change size. For example, the font size, line widths, etc. will stay the same. Instead, the chart shows a different data range. So the chart needs to be redrawn again, as it is effectively a chart with different data.
Now the user needs some user interface to allow it to scroll the chart and to zoom in/out. In our chart viewer implementation, it allows the user to use mouse clicks or drags or move wheels to change the "viewport", then the chart viewer will generate a "viewportchanged" event to notify other code that the user has changed the viewport. The other code can then calls drawChart to redraw the chart, and can also update other things that depend on the axis range. For example, in the "Zooming and Scrolling with Track Line (2) (Windows)" sample code, there are two date picker controls and a horizontal scrollbar that need to be updated when the viewport is changed.
If you are using your own GUI framework, in the simplest case, you may just use mouse wheel to control zooming and use an external horizontal scrollbar to control scrolling. Once you get it working, you can add more user interface methods, such as using clicking to zoom in/out, or dragging on the chart surface to scroll or drag a selection rectangle, etc.
Regards
Peter Kwan |
|