SVG::TT::Graph(3pm)
π SVG::TT::Graph β the base module for generating SVG graphics π
Okay so this is SVG::TT::Graph(3pm), straight out of the User Contributed Perl Documentation, and it's the β¨ foundation β¨ that all the actual graph modules stand on. Bestie, if you're here to make a chart, you're in the wrong room β this is the backstage area. Stay anyway, it's iconic.
πΈ NAME πΈ
SVG::TT::Graph β the base module for generating SVG graphics. That's it, that's the name.
π SYNOPSIS π
Okay so here's how you'd build a new graph type on top of this bad boy. First, the module part β this is what a subclass looks like when you're writing one:
package SVG::TT::Graph::GRAPH_TYPE;
use SVG::TT::Graph;
use base qw(SVG::TT::Graph);
our $VERSION = $SVG::TT::Graph::VERSION;
our $TEMPLATE_FH = \*DATA;
sub _set_defaults {
my $self = shift;
my %default = (
'keys' => 'value',
);
while( my ($key,$value) = each %default ) {
$self->{config}->{$key} = $value;
}
}
# optional - called when object is created
sub _init {
my $self = shift;
# any testing you want to do.
}
...
1;
__DATA__
<!-- SVG Template goes here -->
Then, in your script, you actually use it like this β and yes, the template module ships its own template in __DATA__, that's the whole vibe:
use SVG::TT::Graph::GRAPH_TYPE;
my $width = '500',
my $heigh = '300';
my @fields = qw(field_1 field_2 field_3);
my $graph = SVG::TT::Graph::GRAPH_TYPE->new({
# Required for some graph types
'fields' => \@fields,
# .. other config options
'height' => '500',
});
my @data = qw(23 56 32);
$graph->add_data({
'data' => \@data,
'title' => 'Sales 2002',
});
# find a config options value
my $config_value = $graph->config_option();
# set a config option value
$graph->config_option($config_value);
# All graphs support SVGZ (compressed SVG) if
# Compress::Zlib is available. Use either the
# 'compress' => 1 config option, or:
$graph->compress(1);
# All graph SVGs can be tidied if XML::Tidy
# is installed. Use either the 'tidy' => 1
# config option, or:
$graph->tidy(1);
print "Content-type: image/svg+xml\n\n";
print $graph->burn();
Periodt. That's the whole flow β build it, feed it data, optionally squash it, optionally tidy it, then burn() it out to the browser. π₯
π¦ DESCRIPTION π¦
So this package is the base module for creating graphs in Scalable Vector Format (SVG). And here's the thing β do NOT use this module directly. It's giving scaffolding, not decoration. Instead, pick one of these actual plot-makers:
SVG::TT::Graph::LineSVG::TT::Graph::BarSVG::TT::Graph::BarHorizontalSVG::TT::Graph::BarLineSVG::TT::Graph::PieSVG::TT::Graph::TimeSeriesSVG::TT::Graph::XY
If XML::Tidy is installed, the SVG files you generate can be tidied (so pretty β¨). And if Compress::Zlib is available, the SVG files can also be compressed to SVGZ. Both optional, both cute.
π METHODS π
add_data()
my @data_sales_02 = qw(12 45 21);
$graph->add_data({
'data' => \@data_sales_02,
'title' => 'Sales 2002',
});
This method lets you add data to the graph object. And the best part? You can call it several times to stack more data sets in. Go off, multi-series queen. π
clear_data()
my $graph->clear_data();
Wipes all the data off the object so you can reuse it and make a whole new graph β but keeping the exact same config options. Recycle, but make it fashion. β»οΈ
get_template()
print $graph->get_template();
Returns the TT template that's used for making the graph. Handy if you wanna peek at the machinery.
burn()
print $graph->burn();
This one processes the template with all the data and config you've set, and hands you back the resulting SVG. It's the moment. The reveal. π¬
Careful though bestie β this method will croak unless at least one data set has been added to the graph object. No data, no graph, no mercy.
compress()
$graph->compress(1);
If Compress::Zlib is installed, the content of the SVG file can be compressed. This get/set method controls whether or not to compress. The default is 0 (off).
tidy()
$graph->tidy(1);
If XML::Tidy is installed, the content of the SVG file can be formatted in a prettier way. This get/set method controls whether or not to tidy. The default is 0 (off). Heads up: the limitations of tidy are described at this URL: <http://search.cpan.org/~pip/XML-Tidy-1.12.B55J2qn/Tidy.pm#tidy%28%29>
config methods
my $value = $graph->method();
$graph->method($value);
This object provides autoload methods for all the config options defined in the _set_default method within the inheriting object. So basically every config key becomes a getter/setter, iykyk.
See the SVG::TT::Graph::GRAPH_TYPE documentation for a list.
π EXAMPLES π
Want examples? Go look at the project home page: <http://leo.cuckoo.org/projects/SVG-TT-Graph/> β it's all there.
π EXPORT π
None by default. Nothing gets yeeted into your namespace unless you ask. Clean.
π«Ά ACKNOWLEDGEMENTS π«Ά
Thanks to Foxtons for letting us put this on CPAN, Todd Caine for heads up on reparsing the template (but not using atm), David Meibusch for TimeSeries and a load of other ideas, Stephen Morgan for creating the TT template and SVG, and thanks for all the patches by Andrew Ruthven and others. Genuinely a group project that ate. π
β¨ AUTHOR β¨
Leo Lapworth <LLAP@cuckoo.org>
π MAINTAINER π
Florent Angly <florent.angly@gmail.com>
π COPYRIGHT AND LICENSE π
Copyright (C) 2003, Leo Lapworth
This module is free software; you can redistribute it or modify it under the same terms as Perl itself.
π§ SEE ALSO π§
SVG::TT::Graph::LineSVG::TT::Graph::BarSVG::TT::Graph::BarHorizontalSVG::TT::Graph::BarLineSVG::TT::Graph::PieSVG::TT::Graph::TimeSeriesSVG::TT::Graph::XYCompress::ZlibXML::Tidy
Okay that's the whole page bestie, and this manual page is from perl v5.36.0, dated 2022-11-19 β so yes, the documentation is a lil vintage but the SVG graphs are still serving. π Go make something pretty. π¦β¨
π¦ where this page comes from
- debian bookworm: libsvg-tt-graph-perl 1.04-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libsvg-tt-graph-perl 1.04-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libsvg-tt-graph-perl 1.04-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libsvg-tt-graph-perl 1.04-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libsvg-tt-graph-perl 1.04-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms