Pure Ruby Sparklines
September 17th, 2005Update October 5, 2009: This is some REALLY old code, but I managed to salvage it recently and put it on Github at http://github.com/madrobby/spark_pr. Please download the code from there!
In Weed, we use Sparklines for displaying web site stats. But, you have to go through the rather tedious process (depending on your setup) of installing RMagick to generate them.
To get rid of the RMagick dependency, I came up with a pure ruby solution, based on why’s excellent Bumpspark and on Geoffrey’s hip gem. The solution currently supports the “smooth” type Sparklines, but i’ll eventually hope to add all types that Geoffrey’s gem supports.
So, you can now have nice “smooth-style” sparklines, just one ruby file required:
Drawing is done with alpha-blending and antialiased lines.
Grab the source at the Weed collaboa (and consider it beta quality only!).
Update: It now supports ASCII output too, for the GUI challenged:
+++++
+++++
++#++ + +--
++#++ --- -- --+
+++#+ - - +
+ + - + + +- -
-- - + - - - -- -+- -
+-- -- - -- - - - -- -+ -
-- --+ - - - + + -- -
+++++ + -- - + + -- -- +
-- -- + -+ + - ---- +-- --
-- -- + -+- - -- + --+
+ + --+- - +
+-- + +
-
Tweet