Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

New Graphing Module

by aplonis (Pilgrim)
on Aug 02, 2006 at 01:52 UTC ( #565126=CUFP: print w/replies, xml ) Need Help??

There is one important instance where GD::Graph::lines does not suffice. That is the case where you require two Y axes (left & right) with more than two data curves to trace.

So I have cobbled together a module (my first ever OO) which covers that instance where GD::Graph::lines is lacking. May it serve as a tide-over until the day (month?, year?) when GD::Graph::lines shall be repaired.

This is a self-actualizing demo of the module, part of a utility I'm working on to graph strain gage rosette data. It generates fake data, saves it to a file, reads it back in, adds some calcualted-result channels, graphs it both in GD as *.png and in PostScript as an *.eps file

That's right, the output is PostScript. So you'll need a viewer (gv on UNIX, GSView on Win32) to view it. Running the file also calls up whichever of those is appropriate for your OS to display the graph.

It only does line graphs but does them quite prettily...except for the example given...which is deliberately hideous to show off user options for colors, fonts, etc. (I'm not really color-blind.)

Graphing Module Demo

There isn't any real Perl magic here, though. It's PostScript which performs all the tricks. I dredged up an old standalone PostScript graphing program which I'd written way back in 1992, tidied it a bit, broke it into pieces and married those pieces to Perl to make this happen.

You can choose any web safe color for back- and fore-grounds, lines, etc. You can choose any of the 35 fonts. And it auto-reconciles the Y1 and Y2 axes for best resolution of the data traces. That is to say, for each axis, at least one trace will course nearly the whole vertical area.

Its one big flaw is that no single data trace may number more than 65,535 data points. This is due to PostScript's internal addressing limitation...which I have yet to creatively overcome. At some point later on, after I've tinkered with it a bit more, I'll put in in CPAN. For now it's embeded in the demo script.

Gan Uesli Starling
Kalamazoo MI USA

Replies are listed 'Best First'.
Re: New Graphing Module
by ChemBoy (Priest) on Aug 02, 2006 at 15:25 UTC

    May it serve as a tide-over until the day (month?, year?) when GD::Graph::lines shall be repaired.

    Which I'm sure it will be, because of course you've reported this bug to the maintainers. Right?

    If God had meant us to fly, he would *never* have given us the railroads.
        --Michael Flanders

      My prior reply was from work at my new job. This addenda is from home. I have searched the home PC for my last communication with Martien Verbruggen to no avail. I had hoped to quote verbatim from that exchange. But I fear it must have been from work at my old job.

      I've actually been waiting for multi-data set graphs to work in dual Y-axis line graphs for more than three years. They sort of work now but the Y2 tick marks often times get out of control. And results are unprofessional until that gets sorted out, which I'm sure Mr. Verbruggen will get to eventually. But it is not top of his list, this being a rarely used feature. Meanwhile I needed something now. I'm not trying to compete, just share what I've got...such as it is.

      On the other hand, I don't very much like how GD::Graph::lines force-aligns both Y1 and Y2 to share a common zero because it scrunches the vertical resolution should all data sets for a given Y axis be on same side of zero. It is this very same beef with respect to another software product in 1992 that spurred me to write the original PostScript program which I grafted piecemeal to Perl for this present module.

      I'm not bucking GD::Graph in general. It's wonderful for every other use except this one, admittedly unusual, case in particular. My cool use for Perl was only to resurrect an otherwise user-unfriendly PostScript program to temporarily solve a vexing graph-related roadblock so that I could get on with a project.

      The maintainer is long since aware, as I read his responses to others who reported it prior to my own discovery.

      He said any potential fix would be "not trivial" and indicated no target date. It is, admittedly, a feature seldom (if ever) required by the vast majority of users.

Re: New Graphing Module
by aplonis (Pilgrim) on Aug 23, 2006 at 19:14 UTC

    A much updated version of this utility is now a CPAN module.

    Find it on CPAN as Chart::EPS_graph

    Gan Uesli Starling

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://565126]
Approved by McDarren
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2022-10-06 08:39 GMT
Find Nodes?
    Voting Booth?
    My preferred way to holiday/vacation is:

    Results (26 votes). Check out past polls.