Graphing

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.

Exit mobile version