Text-Layouts: WeblayoutZeitung3 Spalten

Sparklines & Statistics

First implementation of Sparklines.

Most recent update on this topic / official release: Sparkling

General Information:
Okay, it's done: I've just now finished the first real Sparklines implementation. Let's see what this tool can do: mainly it's about using inline statistic visuals, like this distribution of number of texts over the last years (2004-2007) spark_bar(data2004;34;2005;45;2006;23;2007;32,12,5,2,20,50,black,txtstats).

So, gathering the data for the graph above took me longer than "creating" it. I just wrote it down. Maybe I should just find another example ... ah, yeah, found one, which is Germany's total fertility rates over the last seven years spark_bar(data2000;1.38;2001;1.38;2002;1.39;2003;1.37;2004;1.38;2005;1.39;2006;1.39;2007;1.4,12,5,2,1,2,black,fert), a graph which is indeed quiet interesting (isn't it?). Okay, I must admit, it is really boring; the fertility rates is stable (minimum is 1.37, maximum is 1.4).

Okay, by now we've only included the sparks into the text directly, which means, that they maybe to small to provide real information. Maybe a line chart works out better here. Let's have a look at another way of visualizing the second chart simple_line(data1.38;1.38;1.39;1.37;1.38;1.39;1.39;1.4,fert2). Works better, doesn't it? This one looks especially great, if you have loas of data, for example, the distribution simple_line(data3;0;2;2;0;10;8;9;6;6;1;3;2;8;4;3;3;1;6;2;0;1;1;0;9;0;2;2;0;2;2;4;5;0;3;6;2;0;1;1;0;1;10;4,ex,100) of text on this page over the months from 2004 - 2007.

Now let's increase its' size and add some feature points: spark_line(data1.38;1.38;1.39;1.37;1.38;1.39;1.39;1.4,60,400,1,2,fert3,10,features0,1.38,black,5,2000;1,1.38,black,5,2001,3; 2,1.39,blue,5,2002 (1.39);3,1.37,red,5,2003 (1.37),4;4,1.38,black,5,2004;6,1.39,blue,5,2006;7,1.4,blue,5,2007,2)
Nice one? I think so!

This plug-in is available right now. Usage instructions for authors will follow soon.


Implementation Information:
Implementation was done via PHP, Reg-Ex and a modified Sparkline Lib. Usage looks similar to this "spark_line (parameters)" or "spark_bar (parameters)".

There were two bugs in the Original Sparklines Lib (v.2) I had to eradicate: The first one is a bug with the setFeaturePoint function. The coordinated for the feature points lack the same dataConversion function as the data points experience. The solution was quiet easy:

- Added at line 110:
for ($i = 0; $i < sizeof($this->featurePoint); $i ++)
$this->featurePoint$i"ptX" = $this->featurePoint$i"ptX" * $xBound /
sizeof($this->dataSeries$series);


- and modified line 170:
$pxX = $v'ptX';

Furthermore I think there's another bug in v.2, which is, that you have to either delete the variables $dataSeries, $dataSeriesStats, $dataSeriesConverted, $yMin and $yMax from the Sparkline object to use it in multiple instances. The reason might be, that the parent class "Sparkline" does calculate image sizes only the first time the object is called and data is provided.
The debug error I experienced, when not either deleting those variables or calling a new object with differing object names each time is:
could not create image; GD imagecreate functions unavailable.


RSS feed RSS RSS feed RSS (Kommentare)

Kommentare

patrick wrote on 2007-12-06 01:28:56

Usage instructions for authors is now available in the authors FAQs. Plus I've used sparks for activity monitors, available in the plug-ins scape.

Have a nice day.

patrick wrote on 2007-12-05 10:50:38

Today I've added another implementation, which calls "simple_line". It is a easy-to-use version of "spark_line". There's no formatting options except for "width" (optional), which allows faster and easier usage. Here's an example: simple_line(data2;5;6;1;4,simple2)...

Have a nice day.

* Why use my real name?


* Pflichtfelder