Books I Like

Sunday, October 11, 2009

Easy Graph with Scruffy on Ruby


This weekend, I was going through the first chapter of the book Ruby in Practice. Kind of like it as of yet , although have read only 4-5 pages.

It shows an example of using the graphing library Scruffy. Thought to give it a try on my home PC (Vitsa).

This blog is to save your time, in case you want to use this nice library and run into configuration problem.

1. You need to install the "Scruffy" gems
gem install scruffy

2. Then I tried the example discussed at :- http://scruffy.rubyforge.org. However, was getting error, which made it clear, you need to install another gem - RMagick. Won't bother you with my trial and errors, so to cut long story short, RMagick in turn requires other graphing lib (for e.g., I opted for IMageMagick).

So, download http://rubyforge.org/frs/download.php/38052/RMagick-2.5.0-ImageMagick-6.4.1-5-Q8.zip

3. Extract this to a temp directory, and run the IMageMagick installer.

4. Follow the readme file, which mentions to update your gem and install the RMagick gem.

5.Now, the most important part. Reboot your machine [:)]. Don't forget it.

6.After this, the sample codes described here :- http://scruffy.rubyforge.org/ started to work, except the graphs being generated was exactly as it appears on this site (as of this writing, wonder why it hasn't been fixed ?), i.e. blank images.

7. One blog post which helped me to fix this was :- http://www.ruby-forum.com/topic/193988
It suggests to replace the line 35, of the base.rb (for me it is C:\Ruby\lib\ruby\gems\1.8\gems\scruffy-0.2.6\lib\scruffy\renderers\base.rb)with

svg.svg(:xmlns => "http://www.w3.org/2000/svg", 'xmlns:xlink' =>"http://www.w3.org/1999/xlink",:viewBox => "0 0 #{options[:size].first} #{options[:size].last}") {

After it, the graphs started working like a charm. Looking forward to explore it more. Hope, it saves your time.

4 comments:

Mat Schaffer said...

I commited that fix to scruffy just a few minutes ago. I feel like I should probably consult with one of the project admins before rolling a release though. In the mean time I've posted a snapshot release at http://dl.getdropbox.com/u/54805/scruffy-0.2.6-matschaffer.gem.

Hopefully scruffy 0.2.7 will include this fix.

Anshu said...

Thanks Mat !

giovanni said...

Thanks man!
Scruffy doesn't work out of the box due to its dependency on biulder gem and rmagick as you noticed, but the blank charts problem was weird!
Hope they'll fix it, or maybe we can fork the project to solve the problem.

Anonymous said...

Worked for me to! Thanks

Get at Amazon