Pure Ruby Sparklines
September 17th, 2005 by Thomas Fuchs, Comments OffUpdate 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 This Post
Digg This Post
Share on Facebook








Do you run a web site or web application? Do your users a favor, and grab our ebook on JavaScript performance. Profit from our knowledge gathered in over 15 years of working with the Web and JavaScript and make your sites ultra-fast and your users ultra-happy.