SVG::T...HeatMap(3pm)

πŸ“¦
version 1.04 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ¦‹ 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_with and gutter_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 and y_axis_order is set, then y_axis_order will take prescience. 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::Graph
  • SVG::TT::Graph::Line
  • SVG::TT::Graph::Bar
  • SVG::TT::Graph::BarHorizontal
  • SVG::TT::Graph::BarLine
  • SVG::TT::Graph::Pie
  • SVG::TT::Graph::Bubble
  • Compress::Zlib
  • XML::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