Enable persistent, reusable sparklines

lambert - March 3, 2007 - 22:23
Project:Sparkline generator and filter
Version:HEAD
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

It would be better to have a way to incorporate arbitrary sparkline PHP files (e.g., all/modules/sparkline/sparkline-php-0.2/samples/baseball.php) into content, both for greater functionality, and to be able to have the same sparkline appear in more than one node.

If there's a generic way to do this from within Drupal, I don't know what it is.

#1

fractile81 - March 27, 2007 - 14:12

This is an interesting idea, being able to call the same data forward when needed. My only thought would be to allow users to define sparkline data through a configure form and give it a named shortcut (e.g. they enter the data and the shortcut is set to 'baseball'). Retaining a GUI (albeit a form) would probably help non-power-users out a lot. Then, there's also no worries about arbitrary code execution through Sparkline.

I realize I'm kind of changing the idea of this a little, but it'd still function the same way, just a different way to storing/pulling data. So the tag would either be [sparkline bar 1,2,3,4,5] or [sparkline baseball] (or something to that effect).

Any other thoughts?

#2

shunting - March 27, 2007 - 15:26

I like the idea of mapping name to URL through the admin interface much better than embedding the URL in content.

Mathfilter has the embedding functionality:

http://www.universalpantograph.com/equations-using-tex

but not the naming idea.

Although I wish there was some sort of standard for these proliferating microformats in Drupal. They are all great, but we soon clashes will begin as the namespace gets more and more crowded....

#3

Chris Johnson - March 28, 2007 - 14:39

I'm definitely interested in making sparkline allow the same sparkline to appear in more than one place. I think that's a matter of getting the right API and persistence model.

I don't know that I'd consider allowing arbitrary PHP to be called. That's like providing an author with the PHP input format capability, which gives one all the rope necessary to hang oneself, crash the site, or create a huge security problem.

#4

shunting - March 29, 2007 - 00:16

I see your point on the PHP. With the TeX model there isn't a general purpose engine, so the security issues aren't as great.

Could the PHP be compiled? Could a JavaScript library be used?

Possibly the microformat data itself could be stored -- but that seems awfully limiting.

#5

fractile81 - March 29, 2007 - 17:11

Could the PHP be compiled? Could a JavaScript library be used?

I didn't quite follow the direction of these questions. Are we talking about simply reflecting what the Sparkline filter currently does but in a multi-use way, or opening up the Sparkline library's interface to be more usable via the module?

If it's the former, then compiled PHP or JavaScript, I believe, would be over-kill. It's only data that's being worked with, and shifting the data to code seems needless to me. The data simply needs a method to be stored and retrieved.

If it's the latter, then it's a matter of how to resolve cached Sparklines that have been created elsewhere (in-code or via a GUI?). Additionally, it's adopting the proper interface for exposing the Sparkline library's functionality, which seems to be a little out-of-scope of this module to me (at this point, anyway).

Or am I missing the mark here?

#6

fm - February 25, 2008 - 20:43

I would love to implement dynamically created sparklines on my site. PHP seems to be the way to do this, but as a novice programmer it is not at all clear to me how I'd accomplish it. An interface that walked me through the creation of each dynamic sparkline would be terrific. If that's not possible, step-by-step instructions on how to insert php into a sparkline tag, along with accompanying examples, would be welcome.

#7

Chris Johnson - October 24, 2008 - 14:46
Title:Call PHP code from within the [sparkline] tag» Enable persistent, reusable sparklines
Version:4.7.x-1.x-dev» HEAD

Retitled to fit the feature request I'm willing to implement. A module developer or someone with node PHP access can already call the sparkline routines directly, if so desired. I'm not interested in providing some other sort of PHP access, due to all of the security and implementation considerations. However, the ability to reuse the same sparkline in multiple places is a good idea.

#8

shunting - November 2, 2008 - 22:21

Great! That's really my requirement. It's re-usability that I want.

#9

NikLP - November 3, 2008 - 14:39

Isn't a simple method of storing cached files the way forward? Imagecache has been doing this successfully for quite some time now. Multiple references to the same image all render the same "thumbnails" for example.

Then you could simply store the sparkline files at (eg) /sites/<default>/files/sparklines - right?

#10

shunting - November 4, 2008 - 15:20

It's up to the implementor, of course, but for myself, I'd always rather separate the concerns of data and rendition and render on the fly. What if I'm generating the sparkline dynamically? Then I have to manage the files directory too...

#11

fm - November 4, 2008 - 16:07

... render on the fly.

I agree.

#12

NikLP - November 4, 2008 - 17:29

So, if 50,000 (edit: site-registered) people hit your new article which contains a sparkline, you don't want that cached and delivered from a static source or a content delivery network??

I think you probably do!

#13

fm - November 4, 2008 - 19:22

meh. good point.

#14

shunting - November 12, 2008 - 01:39

Won't the cache layer handle this? And then clear if the sparkline is updated?

I was reacting to what I thought was a proposal to store the rendered sparkline on the file system.

#15

NikLP - November 12, 2008 - 13:19

You can't just create an image on the fly and expect it to exist in cache somewhere! If the image is dynamically generated, even with the same name the browser cache will deem the image out of date and force recreation of the image every page load.

In order for any kind of performance increase, the image needs to be written to disk. Then the Drupal caching mechanism can churn out these images as part of a cached page. Other than that, the only way to speed things up is to use css sprites or a content delivery network, both of which aren't really relevant to this kind of use case unless the cache age can be quite high.

#16

Chris Johnson - November 18, 2008 - 02:52

There is some generated sparkline image file caching already going on in the current code, by the way.

I'm open to patches to implement these suggested features.

I'm not currently working on any sparkline projects, so probably won't spend much time on this module until I need to use it again.

 
 

Drupal is a registered trademark of Dries Buytaert.