Draw Google diagrams from a Perl script
Professional Bric-a-Brac
To replace the plain white chart background with a more professional looking white to olive gradient, the fill option in line 42 sets the background to "LinearGradient". As you can read in the Colors section [3], you need a "c" value to fill the chart area; color1 and color2 expect two hex-encoded RGB colors. If the offset value is 0, the corresponding color is pure at the left of the chart and washed out at the right. A value of 1 lets the gradient run from right to left. The values in lines 46 through 51 thus define a chart background with a gradient from white on the left to full olive on the right. An angle of 45 degrees defines a gradient that runs diagonally from bottom left to top right.
The grid option (line 55) draws a grid in the chart, dividing the total elapsed time of approximately 36 hours in the X direction into three sections of 33 parts of 100. In the Y direction, horizontal lines are spaced 20 points apart. The axis labeling for the chart is defined by the axis parameter in line 60. The X axis is labeled with hour values from 1 to 36 at equal distances; the Y axis is labeled with the values 0 through 100 in steps of 25. Note that this labeling is entirely independent of the records you pass in; the data is normalized within a range of 1 through 100 for both axes.
The line colors for both sets of records are defined by the color option in line 75 in the order of data input. E6E9FD is a light blue, whereas 4D89F9 is more of a sky blue.
To allow the viewer to interpret the charts, legend in line 77 draws a legend on the right-hand side of the chart, depicting squares matching the line colors along with the name of the corresponding set of measurements.
To avoid the axes in the chart bumping against the edge of the image, the margin option in line 80 sets a border of 50 pixels in all directions. The last two values, both of which are 100, set the gap for the legend in the X direction from the right margin and the gap between the top of the graph and the automatically selected legend display location in the Y direction.
If you would like to see the individual data points drawn as crosses, you can set the marker option as shown in line 85. The first two elements in markerset define the appearance of the crosses for the first and second data sets, which you can specify as dataset => 0 and dataset => 1. If datapoint is set to -1, the chart service will draw every single data point, but you can use a selection instead. Markers with a priority of 1 are drawn last by graph-discharge, thus ensuring that the graph lines do not cover the crosses.
If the lines in the chart are below your aesthetic standards, because you prefer thicker lines, for example, you can use a marker setting here that is slightly non-intuitive. Instead of using 'x' as the marker_type, a 'D' entry sets line properties, such as thickness and color. In other words, if you prefer thicker lines in the chart, simply specify the same color as used previously with the color option in line 74 and set a marker thickness of 4. The -1 priority keeps the lines from obscuring any crosses by making sure they are drawn first.
Finally, the render_to_file method called in line 127 creates a URL as per Figure 4 and sends it to Google, which sends back the results in about one second as a PNG-formatted file that is stored on your disk under the specified file name.
Installation
The Google::Chart module is available from CPAN and requires the postmodern Moose object system (see the "Postmodern Programming" box), which in turn necessitates a whole rat-tail of dependencies; it is thus a good idea to use a CPAN shell or a package manager. When this issue went to print, Google::Chart was still lacking a couple of features, but after a short talk with the developers, they quickly took my patches from the GitHub.com [4] collaboration page and applied them to the 0.05014_01 developer version, which, along with the stable release, is available for download [5]. Long live GitHub: the dawn of a new age of open source collaboration!
Postmodern Computing
Larry Wall, creator of Perl, first expounded on Perl as a postmodern language in his 1999 Linux World talk [6]. Unlike modernism, which he says looks at things in isolation, postmodernism looks at the big picture. Modern computer languages take a concept (objects, stack code, parentheses) and drive it into the ground. Postmodern languages integrate many concepts, allowing each to work in its own way. "The Modernist believes in OR more than AND. Postmodernists believe in AND more than OR."
In short, he said, postmodernists choose, without the need to justify their choices, "what rules and what sucks." By extension, then, Linux and the open source movement are postmodern.
Infos
- Listings for this article: ftp://ftp.linux-magazin.com/pub/listings/magazine/105
- "Perl: Pinpointing Spammers" by Michael Schilli, Linux Pro Magazine, March 2009, pg. 74
- Google Chart API Developer's Guide: http://code.google.com/apis/chart
- GitHub project for the Google::Chart module: http://github.com/lestrrat/google-chart/tree/master
- CPAN version of the Google::Chart module (including 0.05014_01 trial version): http://search.cpan.org/dist/Google-Chart
- Perl, the first postmodern computer language: http://www.perl.com/lpt/a/109
« Previous 1 2 3
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs