a ruby sparkline showing variation
Back in May’s Carnival of the Agilists I referenced a post by Clarke Ching in which he suggests we can learn a lot about variation in a complex process by simply flipping coins. When I tried the simulation a few times with Excel I found, as expected, that heads and tails don’t always occur in equal measure. But that was a pain to do, so I’ve made it easier. I’ve written a little Ruby program that simulates 1000 coin tosses; you can get it from github.
The simulation generates SVG images; if you can view those in your browser, you can see three consecutive runs here, here and here.
(Disclaimer: The images are SVG. It works fine in Firefox, but if you use IE you may need to install some kind of viewer.)





There is a kind of sparklines gem here:
http://nubyonrails.com/pages/sparklines
I added a histogram (bar chart) function to that library, and colored bars that were above a given threshold (like the rest of the drawing styles do). I don’t think that code went into the reworked version, although I was told it would be.
Anyway, things I like:
1) diverse set of drawing styles
2) not too rails-y, or rails oriented; nice generic Ruby (yay!) library is great
3) SVG is fine, since there’s lots of convertered (RMagick works fine for people trying to get things done, counter-propaganda aside)
Nice sparkline though :)
Actually I tried all of the existing gems and libraries, both for sparklines and for SVG — and in the end I just wrote a bunch of code that spits out SVG as text. Maybe I should tidy it up and put it up on RAA sometime…
[...] one downside to all this is that I no longer have somewhere to host my simulation of coin tossing. Well, that’s a shame, but not the end of the world. If you want to try it you can clone the [...]