by 

PlotJax Helper Object Developer's Guide

Note: this is a preliminary specification subject to change.

To facilitate customization of PlotJax rendering and (especially) interactivity, the PlotJax constructor supports a "Helper" object parameter. The PlotJax Helper object provides methods which are called prior to processing certain types of events:

A base class definition for PlotJaxHelper is specified below:

Constructor

The constructor is entirely application specific, as it is never called from within PlotJax. Note that the Helper must be created prior to creating the PlotJax container. A single Helper may be used for multiple PlotJax containers.

onload(plotjax, charts, balloon, gesture)

(Optional) Called after all charts have been loaded into a PlotJax container. This provides the Helper an opportunity to record the individual components prior to any rendering or other interaction.

onlayout(plotjax, chart)

(Optional) Called during the layout process for each chart in the container.

content = ondraw(plotjax, chart, id)

(Optional) Called during drawing for each element of each chart in the container.

onhover(plotjax, chart, id)

(Optional) Called when the mouse enters an individual element of a chart. Returns either text content to be inserted into the hover tooltip, or null, in which case the tooltip will not be shown.

onclick(plotjax, chart, id, x, y)

(Optional) Called when the mouse is clicked over an individual element of a chart

If no onclick is defined, or no Helper is defined, and the chart element has an associated tooltip property, a balloon tooltip will be opened and loaded with the tooltip property content (either static text or loaded via a URL).

oncapture(plotjax, chart, id)

(Optional) Called for each chart element that lies inside a capture gesture area. If no oncapture is defined, or no Helper is defined, a zoom operation will be applied to the chart element.

onflick(plotjax, chart, id)

(Optional) Called for each chart element that is covered by a flick gesture. If no onflick is defined, or no Helper is defined, the element is recoverably removed from the chart.

getBalloonContent(plotjax, chart, id)

(Optional) Called when a balloon tooltip might be opened. The method can retrieve any information it needs to generate the tooltip content using the chart object's accessors.

The returned value must be one of

E.g.,

function myHelper(url) {
	this.baseurl = url;
}

myHelper.prototype.getBalloonContent = function(plotjax, chart, elemid) {
	var datapt = chart.getChartElementValues(elemid);
	return this.baseurl + "plotnum=" + chart.getChartIndex() +
		"&plotkind=" + chart.getPlotKind() + "&x=" + datapt[0] + "&y=" + datapt[1];
}

var tooltipper = new myToolTipper("http://my.domain.com/cgi-bin/charttip.pl?");

var mychart = new PlotJax("mychart", 400, 400, contentJson, tooltipper);

PlotJax Chart Accessors

Each chart object contained within a PlotJax container provides the following accessor methods which can be used by Helper objects to determine a chart's properties:

getChartId()

Returns the unique identifier for the chart

getChartIndex()

Returns the ordinal index of the chart in the list of charts, starting at zero.

getPlotKind()

Returns the kind of plot (see PlotKind)

getChartElementBBox(id)

Returns the bounding box for the specified chart element. The bounding box is a 4-tuple consisting of the coordinates of the upper left and lower right corners of the box, relative to the containing canvas area.

getChartElementShape(id)

Returns the shape specification for the specified chart element.

getChartElementIcon(id)

Returns the icon URL for the specified chart element.

getChartElementValues(id)

Returns a list of values associated with the element; the returned list is dependent on the kind of chart; e.g., for a bubble chart, the list is [ x-value, y-value, size-value, intensity-value ].

getChartElementColor(id)

Returns the color of the specified chart element.

setChartElementShape(id)

Sets the shape specification for the specified chart element.

setChartElementIcon(id)

Sets the icon URL for the specified chart element.

setChartElementColor(id)

Sets the color of the specified chart element.

removeChartElement(id)

Removes the specified chart element from the chart. Once removed, the element cannot be recovered.

addChartElement(id, properties)

Adds an element to the chart. properties is an object of the same form as an individual PlotJax.Charts.Data element.