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
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.
-
DebConf24 to be Held in South Korea
Busan will be the location of the latest DebConf running July 28 through August 4
-
Fedora Unleashes Atomic Desktops
Fedora has combined its solid distribution with rpm-ostree system to make it possible to deliver a new family of Fedora spins, called Fedora Atomic Desktops.
-
Bootloader Vulnerability Affects Nearly All Linux Distributions
The developers of shim have released a version to fix numerous security flaws, including one that could enable remote control execution of malicious code under certain circumstances.