ChartDirector Ver 4.1 (PHP Edition 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.

WebChartViewer and JsChartViewer

The ChartDirector Zooming and Scrolling Framework for web applications is based on two controls:

In a typical web page with a zoomable and scrollable chart, the operation is like:

The last three steps may then repeat many times.

Partial Chart Update and Full Page Update

ChartDirector supports using AJAX (Asynchronous Javascript And XML) methods for the communication between the JsChartViewer and WebChartViewer. So the chart can be updated without refreshing the web page. In ChartDirector terminology, this is called a partial chart update.

The vast majority of the browsers nowadays support AJAX. However, it is still possible a user may be using a non-AJAX supporting browser. To handle these cases, ChartDirector also supports using traditional full page update method. In this method, the JsChartViewer updates the WebChartViewer by using HTTP POST or GET, and the WebChartViewer updates the browser display by updating the entire page.

JsChartViewer.canSupportPartialUpdate can be used to dynamically detect if a browser supports AJAX or not, so the JsChartViewer can determine which method to use to communicate with the WebChartViewer.

Integration with External Controls

It is not uncommon for a web page to be designed with multiple ways to control the axis range of the chart. For example, in a time based chart, in addition to using "drag to scroll" and "drag to select region" to select the time range of the chart, there may be text fields or drop down list boxes to allow the user to select the start time and end time directly.

Although the text fields or drop down list boxes are not part of the JsChartViewer, it would be ideal if these external controls can also use partial chart updates (AJAX requests), so the chart can be updated without the web page refreshing.

Also, if a user drags to scroll the chart using JsChartViewer, in addition to updating the chart, the text fields or drop down list boxes may also need to be updated to show the new time range.

To support external controls, JsChartViewer and WebChartViewer support custom attributes. Like other properties of JsChartViewer and WebChartViewer, custom attributes set on the browser side JsChartViewer will be accessible from the server side WebChartViewer, and vice versa.

For example, in the above case with external text fields for entering the start and end dates, the operation may be like:

Persistent State Storage

Apart from supporting external controls, another usage of custom attributes is to provide a persistent state storage across multiple chart update requests.

In a zoomable and scrollable, whenever the view port is updated, there will be a request sent to the server for an updated chart. It is often useful to have a storage that is persistent across multiple chart update requests. In other words, data set in a chart update request can be retrieved in subsequent chart update requests.

Custom attributes can serve this role because attributes set on the server side WebChartViewer will be transported to the browser side JsChartViewer. During chart update requests, these attributes will be transported back to the server side. So these custom attributes are preserved across chart update requests from both the server side and browser side point of view.

Typical Server Side Code Structure

The server side code may need to handle the following types of requests from the browser:

Note that one may always design a web page that only uses partial chart update or full page update, in which case only the corresponding request type needs to be implemented.

If a page only supports partial chart update, then very old browsers that do not support AJAX may be unable to zoom or scroll the chart, but they can still see the initial chart.

If a page only supports full page update, then it will work with all browsers, but each zooming or scrolling requests will result in updating the entire web page.

The typical code structure will be like:

Typical Browser Side Code Structure

On the browser side, the typical code structure will be like:

Library Files Required for Zoomable/Scrollable Charts

A zoomable/scrollable chart requires the following files. Please ensure you copy the necessary files to the proper directories (typically the same directory as the script) and reference them using the proper paths.

FileDescription
getchart.phpThe standard utility script used in the image url for retrieving the chart image from a session variable (see BaseChart.makeSession).
cdjcv.js
zoomin.cur
zoomout.cur
nozoom.cur
wait.gif
The script file for JsChartViewer, and the supporting cursor and image files. These files must be in the same directory.