SVG::T...HeatMap(3pm)
π¦ NAME π¦
SVG::TT::Graph::HeatMap β bestie, it makes presentation quality SVG HeatMap graphs out of XYZ data points, and it makes it look easy. Which it is. Because it is. π
This is the Perl doc page for it (a User Contributed Perl Documentation page, iykyk), so likeβ¦ let's get into it. β¨
πΈ SYNOPSIS πΈ
use SVG::TT::Graph::HeatMap;
my @data_cpu = (
{ x => x_point1,
y_point1 => 10,
y_point2 => 200,
y_point3 => 1000,
},
{ x => x_point2,
y_point1 => 100,
y_point2 => 400,
y_point3 => 500,
},
{ x => x_point3,
y_point1 => 1000,
y_point2 => 600,
y_point3 => 0,
},
);
my $graph = SVG::TT::Graph::HeatMap->new(
{ block_height => 24,
block_width => 24,
gutter_width => 1,
} );
$graph->add_data(
{ 'data' => \@data_cpu,
'title' => 'CPU',
} );
print "Content-type: image/svg+xml\n\n";
print $graph->burn();
okay so like β make the object, feed it the data, burn() it, print the SVG. That's the whole plot. π
π DESCRIPTION π
This object exists so you can easily create high quality SVG HeatMap graphs of XYZ data. Obsessed, honestly. You can either use the default style sheet, or bring your own β your call, no pressure, main character energy either way. π«Ά
β οΈ real talk: the height and width of the final image is computed from the size of the labels,block_height/block_withandgutter_size. So like, the image sizes itself, you don't get to just declare it. (And yes bestie, those typos are literally in the original, I'm not touching them. π«£)
π METHODS π
β new()
use SVG::TT::Graph::HeatMap;
my $graph = SVG::TT::Graph::HeatMap->new({
# Optional - defaults shown
block_height => 24,
block_width => 24,
gutter_width => 1,
'y_axis_order' => [],
});
The constructor takes a hash reference, and every value defaults to the ones shown above β except style_sheet, which defaults to using the internal style sheet. β¨
β add_data()
You can feed it data as a big ol' array of hashes, like this:
my @data_cpu = (
{ x => x_point1,
y_point1 => 10,
y_point2 => 200,
y_point3 => 1000,
},
{ x => x_point2,
y_point1 => 100,
y_point2 => 400,
y_point3 => 500,
},
{ x => x_point3,
y_point1 => 1000,
y_point2 => 600,
y_point3 => 0,
},
);
or as a 2D matrix, like this:
my @data_cpu = ( ['x', 'y_point1', 'y_point2', 'y_point3'],
['x_point1', 10, 200, 5],
['x_point2', 100, 400, 1000],
['x_point3', 1000, 600, 0],
);
and then:
$graph->add_data({
'data' => \@data_cpu,
'title' => 'CPU',
});
This method is how you add data to the graph object, periodt. π The data is expected to be either an array of hashes or a 2D matrix (array of arrays) β with the Y-axis as the first arrayref, and the X-axis values sitting in the first element of the subsequent arrayrefs. π
β clear_data()
my $graph->clear_data();
Removes all the data from the object so you can reuse it to build a whole new graph while keeping the same config options. Recycling! We love her. π±
β burn()
print $graph->burn();
This method processes the template with the data and config that's been set, and returns the resulting SVG. π₯ (hence the name, burn, slay, etc.)
π Heads up: this method will croak unless at least one data set has been added to the graph object. No data = no graph = no mercy.
β config methods
my $value = $graph->method();
my $confirmed_new_value = $graph->method($value);
Here's the whole list of methods you can use to change the config of the graph object after it's been created. Go wild. π
πΈ compress()
Whether or not to compress the content of the SVG file. (Requires Compress::Zlib.)
πΈ tidy()
Whether or not to tidy the content of the SVG file. (Requires XML::Tidy.)
πΈ block_width()
The width of the blocks, in px. π
πΈ block_height()
The height of the blocks, in px. π
πΈ gutter()
The space between the blocks, in px. (The little breathing room, bestie, we all need it.) π«§
πΈ y_axis_order()
This is the order the columns are presented on the y-axis. If the data is in an Array of hashes, this has to be set β no setting it, no vibes. However, if the data is in a 2D matrix (array of arrays), it will use the order presented in the header array.
π And if the data is given in a 2D matrix andy_axis_orderis set, theny_axis_orderwill takeprescience. Yes,prescience. That's the word in the original. Foresight. Prophecy. The config has main character energy and it wins. (sic)
β¨ EXAMPLES β¨
For examples, look at the project home page:
http://leo.cuckoo.org/projects/SVG-TT-Graph/
π EXPORT π
None by default. Ngl, nothing gets exported. You asked for it, you call it. π
π¦ SEE ALSO π¦
SVG::TT::GraphSVG::TT::Graph::LineSVG::TT::Graph::BarSVG::TT::Graph::BarHorizontalSVG::TT::Graph::BarLineSVG::TT::Graph::PieSVG::TT::Graph::BubbleCompress::ZlibXML::Tidy
π That's the whole page, bestie! This was perl v5.36.0, dated 2022-11-19, from the User Contributed Perl Documentation collection β go forth and heatmap. πβ¨π
π¦ 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