Graph::Template::Container::Graph - Graph::Template::Container::Graph


Graph-Template documentation Contained in the Graph-Template distribution.

Index


Code Index:

NAME

Top

Graph::Template::Container::Graph - Graph::Template::Container::Graph

PURPOSE

Top

The root node

NODE NAME

Top

GRAPH

INHERITANCE

Top

Graph::Template::Container

ATTRIBUTES

Top

* X_WIDTH / Y_WIDTH / SIZE

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.

* TYPE

This is the chart type. You can choose from the following:

* vert_bars (default)

Bar chart with the bars going vertically (from bottom to top)

* horiz_bars

Bar chart with the bars going horizontally (from left to right)

* line_graph

A graph with lines going from one point to another (similar to geometry class)

* point_graph

A graph with unconnected points

* line_point

A graph with points connected by lines

* pie

A standard pie-chart

* mixed (Currently unsupported)

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.)

* FORMAT

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.)

CHILDREN

Top

None

EFFECTS

Top

None

DEPENDENCIES

Top

None

USAGE

Top

  <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

AUTHOR

Top

Rob Kinyon (rkinyon@columbus.rr.com)

SEE ALSO

Top

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__