Chapter 5. Working with the Multigraph Source Code

Table of Contents

5.1. Adding New Renderers
5.2. The Flex Scene Graph

Multigraph is an open source project. Anyone is welcome to download the source code and modify it. You can download the source code from http://www.multigraph.org/download.

Multigraph is written in ActionScript, which is the language of the Adobe Flash player. The Multigraph source code is organized as a project for the Flex Builder Eclipse (http://www.eclipse.org) plugin from Adobe, which is available from http://www.adobe.com/products/flex. The Multigraph source code zip file includes the Eclipse project files, so importing the project into your copy of Eclipse should be straightforward. The Flex Builder plugin is unfortunately not free, but you can download a free 60-day trial version from the above web page. Also, it IS free for use in academic institutions (https://freeriatools.adobe.com/flex), and there is an alpha version for Linux that is free to anyone (http://labs.adobe.com/technologies/flex/flexbuilder_linux).

In addition to Flex Builder, it is also possible to compile Multigraph with Adobe's free SDK compiler, which is available from http://www.adobe.com/products/flex/flexdownloads/index.html. If you are going to do much work with the Multigraph source code, though, you will probably want to get Flex Builder.

If you have any questions about working with the Multigraph source code, send an email to the multigraph-users mailing list, which is described in Chapter 8, Obtaining Support / Mailing List.

5.1. Adding New Renderers

"Renderers" are objects in the multigraph source code that are responsible for drawing data plots. As described in Section 4.4, “Plots”, the renderer element for each plot in a mugl file indicates which renderer multigraph should use for drawing that plot. New renderers that implement new plot styles can be added to multigraph by creating a new ActionScript class. This section describes how to do that.

Multigraph's renderer objects are located in the "renderer" package in the "src" folder. The "Renderer" class is an abstract base class from which all renderers descend. To create a renderer to implement a new plot style, you need to create a new subclass of the "Renderer" class. The easiest way to do that is to copy one of the existing renderer subclasses and modify it. Or at least use and existing one as a guide.

The general idea behind the "Renderer" class design is that each subclass should:

  1. Define a constructor that takes two Axis arguments, calls the superclass constructor with these arguments, and does whatever else is needed in the subclass constructor.
  2. Define the 3 public static string variables "keyword", "description", and "options"; these are used to autogenerate the documentation for the renderer; they are described below.
  3. Define private variables corresponding to the options for this renderer, and corresponding getter/setter methods for those variables.
  4. Override the 3 methods "begin()", "dataPoint()", and "end()". These are the methods that do the actual plotting; they are described below.
  5. Add the name of the new subclass to the list of renderer subclasses in the "rendererList()" function definition in the file "Renderer.as".

The variables "keyword", "description", and "options" are used to autogenerate documentation for the renderer. The "keyword" variable is used by Multigraph's XML parser as the keyword for the renderer --- it is the word that should appear as the value of the type attribute of the renderer element when you want to use this renderer in a plot. The "description" string should be a short phrase that describes what this renderer does, and the "options" string should be an HTML-formatted list giving each option for the renderer, and its meaning.

The methods "begin()", "dataPoint()", and "end()" contain the code that does the actual plotting. When Multigraph is preparing to draw a plot using a renderer, it calls the renderer's "begin()" method once. It then calls the "dataPoint()" method once for each data point to be plotted. After all the data points to be plotted have been given by calls to "dataPoint()", Multigraph calls the "end()" method once. The "begin()" method is where the renderer can do any prep work that is needed before drawing a plot, and the "end()" method is where any needed cleanup work happens. In a simple renderer, the "dataPoint()" method might just plot the specified point, and the "begin()" and "end()" methods might not do anything (in which case they can be omitted from the renderer subclass). In general, however, the actual plotting can happen in any combintation of the "begin()", "dataPoint()", and "end()" methods. For example, in a more sophisticated renderer, the "begin()" method might initialize an array of points to be empty, the "dataPoint()" method could append each given point to that array, and the "end()" method could then loop through the points in the array, making some kind of plot that encorporates all the points at once.