WWPlot
$graph = new WWPlot(400,400); # creates a graph 400 pixels by 400 pixels
$graph->fn($fun1, $fun2); # installs functions $fun1 and $fun2 in $graph
$image_binary = $graph->draw(); # creates the gif/png image of the functions installed in the graph
This module creates a graph object -- a canvas on which to draw functions, labels, and other symbols. The graph can be drawn with an axis, with a grid, and/or with an axis with tick marks. The position of the axes and the granularity of the grid and tick marks can be specified.
$graph = new WWPlot(400,400);
Creates a graph object 400 pixels by 400 pixels. The size is required.
These determine the world co-ordinates of the graph. The constructions
$new_xmin = $graph->xmin($new_xmin);
and
$current_xmin = $graph->xmin();
set and read the values.
These arrays contain references to the functions (fn), the labels (lb) and the stamped images (stamps) such as open or closed circles which will drawn when the graph is asked to draw itself. Since each of these objects is expected to draw itself, there is not a strong difference between the different arrays of objects. The principle difference is the order in which they are drawn. The axis and grids are drawn first, followed by the functions, then the labels, then the stamps.
You can add a function with either of the commands
@fn = $graph->fn($new_fun_ref1, $new_fun_ref2);
@fn = $graph->install($new_fun_ref1, $new_fun_ref2);
the constructions for labels and stamps are respectively:
@labels = $graph->lb($new_label);
@stamps = $graph->stamps($new_stamp);
while
@functions = $graph->fn();
will give a list of the current functions (similary for labels and stamps).
Either of the commands
$graph->fn('reset');
$graph->fn('erase');
will erase the array containing the functions and similary for the label and stamps arrays.
$h_axis_coordinate = $graph -> h_axis();
$new_axis = $grpah -> h_axis($new_axis);
Respectively read and set the vertical coordinate value in real world coordinates where the horizontal axis intersects the vertical one. The same construction reads and sets the coordinate value for the vertical axis. The axis is drawn more darkly than the grids.
@h_ticks = $graph -> h_ticks();
@h_ticks = $graph -> h_ticks( $tick1, $tick2, $tick3, $tick4 );
reads and sets the coordinates for the tick marks along the horizontal axis. The values $tick1, etc are the real world coordinate values for each of the tick marks.
@h_grid = $graph -> h_grid();
@h_grid = $graph -> h_grid( $grid1, $grid2, $grid3, $grid4 );
reads and sets the verical coordinates for the horizontal grid lines. The values $grid1, etc are the real world coordinate values where the horizontal grid meets the vertical axis.
$image = $graph ->draw();
Draws the image of the graph.
($horizontal_pixels, $vertical_pixels) = @{$graph ->size()};
Reads the size of the graph image in pixels. This cannot be reset. It is defined by the new constructor and cannot be changed.
%colors =$graph->colors();
Returns the hash containing the colors known to the graph. The keys are the names of the colors and the values are the color indices used by the graph.
$graph->new_color('white', 255,255,255);
defines a new color named white with red, green and blue densities 255.
$GD_image = $graph->im();
Allows access to the GD image object contained in the graph object. You can use this to access methods defined in GD but not supported directly by WWPlot. (See the documentation for GD.)
$graph->moveTo($x,$y);
$graph->lineTo($x,$y,$color);
$graph->lineTo($x,$y,$color,$thickness);
$graph->lineTo($x,$y,$color,$thickness,'dashed');
$graph->arrowTo($x,$y,$color);
$graph->arrowTo($x,$y,$color,$thickness);
$graph->arrowTo($x,$y,$color,$thickness,'dashed');
Moves to the point ($x, $y) (defined in real world coordinates) or draws a line or arrow from the current position to the specified point ($x, $y) using the color $color. $color is the name, e.g. 'white', of the color, not an index value or RGB specification. $thickness gives the thickness of the line or arrow to draw. If 'dashed' is specified, the line or arrow is rendered with a dashed line. These are low level call back routines used by the function, label and stamp objects to draw themselves.
These functions translate from real world to pixel coordinates.
$pixels_down_from_top = $graph -> jj($y);