| Graph-Template documentation | Contained in the Graph-Template distribution. |
Graph::Template::Container::Graph - Graph::Template::Container::Graph
The root node
GRAPH
Graph::Template::Container
These are the width of the final graph. The defaults for both X_WIDTH and Y_WIDTH are 400. If SIZE is set, then that will be used instead of 400.
This is the chart type. You can choose from the following:
Bar chart with the bars going vertically (from bottom to top)
Bar chart with the bars going horizontally (from left to right)
A graph with lines going from one point to another (similar to geometry class)
A graph with unconnected points
A graph with points connected by lines
A standard pie-chart
This will allow mixed graphs, once I figure out a nice way for the template to specify it. (If you have any ideas, please let me know.)
Most of the types can support more than one dataset in the Y axis. The only exception is 'pie'. (q.v. the POD for DATAPOINT for more details on this.)
This is the output format. You can choose from any format your current version of GD allows. The default is the return value from GD::Graph->export_format() (This will be either png or gif, depending on if your version of GD supports gif or not. Please see the GD and GD::Graph documentation for more details.)
None
None
None
<graph type="horiz_bars" format="jpeg" size="$graph_size">
... Children here ...
</graph>
This will give you a jpeg of a chart with horizontal bars and a size set by the graph_size parameter
Rob Kinyon (rkinyon@columbus.rr.com)
GD, GD::Graph
| Graph-Template documentation | Contained in the Graph-Template distribution. |
package Graph::Template::Container::Graph; use strict; BEGIN { use vars qw(@ISA); @ISA = qw( Graph::Template::Container ); use Graph::Template::Container; } use Graph::Template::Constants qw( %GraphTypes ); sub render { my $self = shift; my ($context) = @_; $self->{SIZE} ||= 400; $self->{X_WIDTH} ||= $self->{SIZE}; $self->{Y_WIDTH} ||= $self->{SIZE}; $self->{TYPE} ||= 'vert_bars'; my $type = $context->get($self, 'TYPE'); my $class = $GraphTypes{$type} || die "'$type' is not a legal graph type.\n"; eval { (my $filename = "GD::Graph::$class") =~ s!::!/!g; require "$filename.pm"; "GD::Graph::$class"->import; }; if ($@) { die "Internal Error: Cannot compile 'GD::Graph::$class'!: $!\n"; } my $graph = "GD::Graph::$class"->new(@{$self}{qw( X_WIDTH Y_WIDTH )}); $self->{FORMAT} ||= $graph->export_format; for ($context) { $_->graph($graph); $_->format($self->{FORMAT}); } return $self->SUPER::render($context);; } 1; __END__