Thomas Fuchs
Hi, I'm Thomas Fuchs. I'm the author of Zepto.js, of script.aculo.us, and I'm a Ruby on Rails core alumnus. With Amy Hoy I'm building cheerful software, like Noko Time Tracking and Every Time Zone and write books like Retinafy.me.
   Want me to speak at your conference? Contact me!

Pure Ruby Sparklines

September 17th, 2005

Update 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:

Pure Ruby sparkline example

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:


                                                +++++
                                                +++++
                                                ++#++         +                       +--
                                                ++#++        ---                     -- --+
                                                +++#+        - -                     +
                                      +          + -        +   +     +-             -
                                    -- -         +  -      -     -  -- -+-          -
                              +--  --   -       --  -      -     - --    -+         -
                            --  --+     -       -    -    +       +        --      -
  +++++       +            --            -      +    +  --                  --     +
       --   -- +         -+               +     -    ----                     +-- --
        -- --   +      -+-                 -   --     +                         --+
          +      +  --+-                   -   +
                  +--                       +  +

                                              -