ChartDirector Ver 4.1 (C++ Edition)

Zooming and Scrolling Framework


Introduction

When talking about "zooming", it is common to think about zooming like a digital photograph, in which everything is magnified, but is otherwise exactly the same. The zoom ratio is usually a few times and the same data (the photograph) are used at all zoom levels.

There is a much more powerful type of zooming, like zooming in a map. For example, one may start with a world map, and zoom all the way down to seeing the streets and buildings within a city. The zoom ratio can be in the order of 500000 - 1000000 times. Different presentation method may be used at different scales. For example, the world map may show only terrain information, while at highest zoom ratio the map may show the names of individual streets.

The ChartDirector Zooming and Scrolling Framework is designed based on the second model or zooming. The key features are:

The View Port

The ChartDirector Zooming and Scrolling framework is based on the concept of a view port.

A view port can be imagined as a rectangular window of an underlying rectangular surface. For example, a chart that has 10 years of data can be imagined as a very long chart. If one only displays one of the year, we can say the view port covers only 10% of the underlying chart.

With the view port concept, scrolling can be handled as moving the view port, while zooming in and out can be handled as changing the view port size.

The CVN_ViewPortChanged Message

The CChartViewer control may update the view port based on mouse actions on the plot area. The supported mouse actions are drag to scroll, drag to select a region to zoom into, click to zoom in, and click to zoom out. The handling of mouse actions is configured by using CChartViewer.setMouseUsage.

When the view port is updated by mouse actions, CChartViewer will send the CVN_ViewPortChanged message to its parent container. It is expected the message handler will update the chart and other controls as necessary.

During drag to scroll, as the mouse is being dragged, CChartViewer will repeatedly update the view port and sends CVN_ViewPortChanged message:+s. This allows the chart to be updated continuous to reflect the moving view port. However, for these updates, it is not necessary to update the image map (if any is used) associated with the chart. The image map only needs to be updated when the drag is completed, that is, when the mouse button is released.

In the CVN_ViewPortChanged message handler, CChartViewer.needUpdateChart and CChartViewer.needUpdateImageMap may be used to determine if the chart and/or image map needs to be updated for the current message.

Updating View Port with External Controls

The ChartDirector Zooming and Scrolling framework allows external controls, such as scroll bars, slide bars, date/time picker controls, text and combo boxes, buttons, etc, to control zooming and scrolling. This is by allowing them to query and modify the view port through various getViewPortNNN and setViewPortNNN methods of the CChartViewer object. After modifying the view port, these controls can send the CVN_ViewPortChanged message by using CChartViewer.updateViewPort.

CVN_ViewPortChanged Message Handler

The primary function of the CVN_ViewPortChanged message handler is to draw the chart based on the current view port settings.

A typical structure of the draw chart code will be like:

Apart from drawing the chart, the CVN_ViewPortChanged message handler may also need to update external controls to reflect the view port. For example, when the user drags to zoom into a region, one may need to modify the date shown in an external date/time picker control to reflect the updated start date, and similarly update external scroll bars, etc.