On 4/17/07, Nigel Metheringham <[EMAIL PROTECTED]> wrote:
I have an existing application which I want to add some basic data graphing operations to.
*snip*
My initial inclination would be to have a wrapper URL which generates pretty much a HTML frame and a IMG tag in it pointing to another cat URL (with the same parameters passed as to the wrapper) which generates data into a View based on Chart::Lines.
*snip*
This means I do most of the DB queries twice (ie once in the wrapper invocation, and again in the image generation), which appears messy.
My method for doing this (which is a pet-project that I seem to reimplement in every language and framework I learn) has always been to create objects that represent the 'line' and use them in a seperate controller to generate an image (which was detailed by Alexander already). IOW, I make an object called Element (for an Element in the Chart) and give it accessors like name, start_date, end_date, max, min, etc, etc. Then I write a controller that translates parameters: elem1=Lemmings,2007-01-01,2007-02-01,100,0&elem2=... into said Objects and adds them to an array and subsequently to the stash. Then the view translates the Objects into an image using the charting API of your choice. So my 'first' controller creates the parameter string and uses that to populate the img tag. The img tag makes a request to the 'parameters to objects' controller and it returns image data. Your database only queries the data for charting once.
I'd love some suggestions as to good alternative methods - I do have sessions set up, but dumping the graph (or data for it) into the session store seems a little bizarre. I have seen a java graphing applet which would allow me to just generate it in one go with the graph data done as params within the applet call (the applet did not appear to be very sophisticated unfortunately).
I think my way is the most flexible, as it doesn't tie you to a charting library and has the side benefit of allowing you to call the 'charting' controller seperately. FWIW, I have a small app that does exactly this, but uses my charting library (which I will not plug, as I rarely work on it anymore): http://www.onemogin.com/blog/531-my-little-side-project-telemetry.html -- Cory 'G' Watson http://www.onemogin.com _______________________________________________ List: [email protected] Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[email protected]/ Dev site: http://dev.catalyst.perl.org/
