Rob Kinyon > Graph-Template > Graph::Template

Download:
Graph-Template-0.05.tar.gz

Dependencies

Annotate this POD (2)

View/Report Bugs
Module Version: 0.05   Source  

NAME ^

Graph::Template - Graph::Template

SYNOPSIS ^

First, make a template. This is an XML file, describing the layout of the spreadsheet.

For example, test.xml:

  <graph>
      <title text="Testing Title"/>
      <xlabel text="X Label"/>
      <ylabel text="Y Label"/>
      <data name="test_data">
          <datapoint value="$x_point"/>
          <datapoint value="$y_point"/>
      </data>
  </workbook>

Now, create a small program to use it:

  #!/usr/bin/perl -w
  use Graph::Template

  # Create the Graph template
  my $template = Graph::Template->new(
      filename => 'test.xml',
  );

  my @data;
  for (1 .. 3)
  {
      push @data, {
          x_point => $_,
          y_point => 4 - $_,
      };
  }

  # Add a few parameters
  $template->param(
      test_data => \@data,
  );

  $template->write_file('test.png');

If everything worked, then you should have a graph in your work directory called test.png that looks something like:

           Testing Title
  5 +-------------------------+
    |                         |
    |                         |
  4 +                         |
    |                         |
    |                         |
  3 +   +-----+               |
    |   |     |               |
    |   |     |               |
  2 +   |     |-----+         |
    |   |     |     |         |
    |   |     |     |         |
  1 +   |     |     |-----+   |
    |   |     |     |     |   |
    |   |     |     |     |   |
  0 +---+-----+-----+-----+---+
           1     2     3

DESCRIPTION ^

This is a module used for templating Graph files. Its genesis came from the need to use the same datastructure as HTML::Template, but provide Graph files instead. The existing modules don't do the trick, as they require separate logic from what HTML::Template needs.

Currently, only a small subset of the planned features are supported. This is meant to be a test of the waters, to see what features people actually want.

MOTIVATION ^

I do a lot of Perl/CGI for reporting purposes. Usually, I've been asked for HTML, PDF, and Excel. Recently, I've been asked to do graphs, using the exact same data. Instead of writing graphing-specific code, I preferred to do it once in a template.

USAGE ^

new()

This creates a Graph::Template object. If passed a filename parameter, it will parse the template in the given file. (You can also use the parse() method, described below.)

param()

This method is exactly like HTML::Template's param() method. Although, I will be adding more to this section later, please see HTML::Template's description for info right now.

parse() / parse_xml()

This method actually parses the template file. It can either be called separately or through the new() call. It will die() if it cannot handle any situation.

write_file()

Create the Graph file and write it to the specified filename. This is when the actual merging of the template and the parameters occurs.

output()

It will act just like HTML::Template's output() method, returning the resultant file as a stream, usually for output to the web.

SUPPORTED NODES ^

This is just a list of nodes. See the other classes in for more details on specific parameters and the like.

BUGS ^

None, that I know of. (But there aren't many features, neither!)

SUPPORT ^

This is currently beta-quality software. It's built on the new PDF::Template technology, which was just released. The featureset is extremely limited, but I expect to be adding on to it very soon.

AUTHOR ^

    Rob Kinyon
    rkinyon@columbus.rr.com

COPYRIGHT ^

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

SEE ALSO ^

perl(1), HTML::Template, GD::Graph, GD.

syntax highlighting: