Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Seeking GD::Graph like goal-thermometer graph

by mattr (Curate)
on Dec 19, 2006 at 06:20 UTC ( #590610=note: print w/replies, xml ) Need Help??

in reply to Seeking GD::Graph like goal-thermometer graph

Hi! I'd like to point you to a GPL thermometer image, alert you to a problem with a module mentioned in this thread, and mention how to do it easily in GD or (probably more quickly) with rsvg. (the image mentioned is available as both PNG and SVG).

First, I tried GD-Dashboard mentioned above many moons ago, on a bug that was 2 years old at the time. I decided instead to roll my own GD-based Gantt-like workflow scheduler and I was very happy with plain GD. So, if you want to try Dashboard note that CPAN says it fails to build and you may have to debug it.

I would say use plain GD, but I also found a neat SVG one.

First, with GD: First find a free thermometer graphic or draw your own. Then use Gimp or another drawing program to find the coordinates of the red rectangle you need to draw to fill the thermometer, and adjust its height based on the thermometer's value. Also make some space above the thermometer to display a big XXX% label (maybe at the top of the thermometer) and get the coordinates of that rectangle too. The rest is pretty straightforward.

As for the graphic and the SVG one I found, I googled for thermometer gpl image (also open clipart might work). Check out this page which provides a script that uses rsvg to rasterize an svg image into a png file. This looks pretty easy to perlize, if you are on linux and install rsvg. At the very least, you can use the png image they show here as a template for your own GD-based thermometer if you don't want to use svg. If you can't view SVG you can get one here at Adobe. It will install an ActiveX component that lets you see the other thermometer in that site’s svg chemistry set on this page though it is more chemistry and less PR style.

Here is something like what you need for the svg one for your info (untested but syntax checked) though if you already are using GD then maybe you just want to use the PNG file on the same page. It is nice and easy to read.

# Usage: perl 12000 # in case you are at the 12000 mark. open(IN,"thermometer_tmpl.svg"); my $buf = <IN>; close(IN); my $amt = $ARGV[0]; my $height = 20000; $n = 10 * $amt/$height; # floating point 0-10 my ($min,$mid,$max) = ('$0','$10,000','$20,000'); $buf =~ s/height="10"/height="$n"/; $buf =~ s/Foo/$min/; $buf =~ s/Bar/$mid/; $buf =~ s/Baz/$max/; open(OUT,"thermo_live.svg"); print OUT $buf; close(OUT); system("rsvg-convert -o thermometer.png thermo_live.svg");

Anyway in the bash script provided replace sed with s/// in perl, and use the system command to run rsvg and it should be doable really in 5 minutes. This will let you easily make a web form or config file to painlessly update the thermometer perhaps automatically. Watch out for when you exceed the boiling point though!

Oh some more links found in some later google results, which you can bend to your purposes.. ugly gd thermometer from php, webthermometer is gpl and has a nice thermo. gif image you can use

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://590610]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2017-02-26 22:02 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (376 votes). Check out past polls.