This Time Self-Hosted
dark mode light mode Search


If you remember an old post of mine I was looking for a way to graph some statistics about bindings and other issues related to that. Even though Philipp Janert did send me a PDF copy of his book, I haven’t been able to proceed on that because of my health issues which did set back a lot of stuff in my TODO list (that was long enough at the time).

The other day I wanted to graph something else, in particular I wanted to graph the EAPI usage in tree; as a start, a simple piechart to show the proportion between the three currently-used EAPI was what I had in mind. How difficult could it be to draw a piechart with free tools, I thought. Well a bit more than I expected before starting.

For starting, gnuplot does not produce piecharts; and at the same time, the piechart tool they suggest is a bit old, rusty and bitrotting. But it does not seem to have so much drawing logic in it at first glance, so I decided to see if I could reimplement it in Ruby. My choice of target was first SVG, but since it’s not so easy to do it in SVG (even though Scribus has some doc about the calculations that are needed to find the right coordinates for the angles), I ended up doing something much easier and as much interesting: I used Cairo.

Cairo is a very nice library that somehow reminds me of LOGO, since it also accepts movement and draw commands. I used the Ruby bindings, but I could have as well used the C bindings to do the whole thing, but since I don’t need the speed, Ruby will work just fine for me. The basic results are acceptable, even though writing text with Pango and Cairo is slightly a mess. I guess it’d be easier to implement some less-primitive graphing support over Cairo, but that’s beside our point here (hey does anybody know if anybody tried to write a LOGO interpreter using Cairo for display? would make a nice example usage of it for average-complexity matters, and I would like to have something like that for my nephew to start playing with a computer).

After doing a very rough script that only interpreted whatever I needed, I thought that the most easy way to handle this would have been to write a library that could create the pie chart for me, starting from the data, using just Ruby and Cairo. But today while looking at something entirely different, I found gruff that seems to be doing almost what I need. It uses RMagick (and thus ImageMagick) instead of Cairo for the primitives though, and it doesn’t support SVG output yet (which I use to make the thumbnail and would love to have as source for the images).

This brings me to a quite interesting thought for the next few days to relax myself by shifting almost everything else down in the TODO line: porting gruff so that instead of using RMagick it would use Cairo. A bit of work but the primitives are more or less the same (maybe I could just write an RMagick-workalike using Cairo) and it would have the nice advantage of having SVG and PDF support out of the box.

My main reason to be willing to write this is that it would make my bindings’ grapher script much easier, since then I’d just have to graph something like this:

{ "First try" => { "Module 1" => [ 12, 144 ], "Module 2" => [ 13, 12445 ] },
  "Second try" => { { "Module 1" => [ 0, 12 ], "Module 2" => [ 0, 134 ] }

in a viewable graph to show the differences.

And similarly, it would help me show other ELF-related statistics, so that what I write on the blog wouldn’t be just numbers any longer, and could be noticed by people. If just there was an easy way to interface Ruby and Python, it would be nice to have access to Portage’s information on my Ruby scripts..

Oh well, a new project to start, maybe.

Comments 5
  1. I point you to openflashchart, simple api, little bit of javascript, fairly nice. If you want more, write a nice little numerical adapter for python & use matplotlib, or for the more adventurous, rpy.cheers

  2. How difficult could it be to draw a piechart with free tools, I thought.

    The “free” in there means free as in speech, not free as in beer. I don’t intend replying on Google’s services for this.Nor on Flash for what matters since I don’t use it at all myself.Unfortunately my Python is very bad or I’d be using just that; instead my scripting language of choice is Ruby, so I think I’ll stick with that… I’ll check out matplotlib later though, maybe it does what I need and has Ruby bindings.

  3. M-x R?pieNote: Pie charts are a very bad way of displaying information. The eye is good at judging linear measures and bad at judging relative areas. A bar chart or dot chart is a preferable way of displaying this type of data. Cleveland (1985), page 264: “Data that can be shown by pie charts always can be shown by a dot chart. This means that judgements of position along a common scale can be made instead of the less accurate angle judgements.” This statement is based on the empirical investigations of Cleveland and McGill as well as investigations by perceptual psychologists.:)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.