Scruffy 0.2.0 has been released, and with it comes some significant changes. However, I said the majority of the changes would affect only the rendering system, and for the most part I stuck to that.
The result of these large changes is a pretty nifty rendering/layout engine that allows you to make your graphs look pretty much however you want. In addition, all elements on the graph have been made into components. You can move anything anywhere on the graph with ease.
To demonstate the capabilities of the renderers, I created a couple different layouts that are included with Scruffy. You can use them, or create your own.
Still no piecharts, but yes, those are coming, as are a few more chart types that I personally need.
The documentation is out of date at the moment. I will fix that in the next day or two to reflect the changes. The API for using the graph hasn’t changed much and is fairly simple. Below is a collection of code of resulting images.
Installing
1 2 |
gem install scruffy
|
Using
1 2 3 4 5 |
require 'scruffy'
graph = Scruffy::Graph.new
(...)
|
Split Graph
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
graph = Scruffy::Graph.new
graph.title = "Long-term Comparisons"
graph.value_formatter = Scruffy::Formatters::Currency.new(:special_negatives => true,
:negative_color => '#ff7777')
graph.renderer = Scruffy::Renderers::Split.new(:split_label => 'Northeastern (Top) / Central (Bottom)')
graph.add :area, 'Jeff', [20, -5, 100, 70, 30, 106, 203, 100, 50, 203, 289, 20], :category => :top
graph.add :area, 'Jerry', [-10, 70, 20, 102, 201, 26, 30, 106, 203, 100, 50, 39], :category => :top
graph.add :bar, 'Jack', [30, 0, 49, 29, 100, 203, 70, 20, 102, 201, 26, 130], :category => :bottom
graph.add :line, 'Brasten', [42, 10, 75, 150, 130, 70, -10, -20, 50, 92, -21, 19], :categories => [:top, :bottom]
graph.add :line, 'Jim', [-10, -20, 50, 92, -21, 56, 92, 84, 82, 100, 39, 120], :categories => [:top, :bottom]
graph.point_markers = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
… generates …
Stacking Graph Types
1 2 3 4 5 6 7 8 9 10 |
graph = Scruffy::Graph.new
graph.title = "Comparative Agent Performance"
graph.value_formatter = Scruffy::Formatters::Percentage.new(:precision => 0)
graph.add :stacked do |stacked|
stacked.add :bar, 'Jack', [30, 60, 49, 29, 100, 120]
stacked.add :bar, 'Jill', [120, 240, 0, 100, 140, 20]
stacked.add :bar, 'Hill', [10, 10, 90, 20, 40, 10]
end
graph.point_markers = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
|
… generates …
Multi-viewport Multi-layered (This was Fun)
1 2 3 4 5 6 7 8 9 10 11 |
graph = Scruffy::Graph.new
graph.title = "Some Kind of Information"
graph.renderer = Scruffy::Renderers::Cubed.new
graph.add :area, 'Jeff', [20, -5, 100, 70, 30, 106], :categories => [:top_left, :bottom_right]
graph.add :area, 'Jerry', [-10, 70, 20, 102, 201, 26], :categories => [:bottom_left, :buttom_right]
graph.add :bar, 'Jack', [30, 0, 49, 29, 100, 203], :categories => [:bottom_left, :top_right]
graph.add :line, 'Brasten', [42, 10, 75, 150, 130, 70], :categories => [:top_right, :bottom_left]
graph.add :line, 'Jim', [-10, -20, 50, 92, -21, 56], :categories => [:top_left, :bottom_right]
graph.point_markers = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
|
… generates …
August 15th, 2006 at 02:46 AM Hi Brasten, I am looking at your graph engine and it looks wonderful. Can I save the graph as a pdf file or a jpeg? Joe Alotta
August 15th, 2006 at 04:00 AM Looks great! Maybe we could combine our efforts? I was hoping to incorporate SVG support into Gruff, but haven't done it yet.
August 15th, 2006 at 10:00 AM Joe- graph.render(:width => 800, :as => 'JPG') The :as option is passed directly to rmagick, so it supports anything imagemagick does. I THINK that includes PDF. Your best bet it just to try :as => 'PDF' and see what happens. :) (And come back and let me know, too!) topfunky- Absolutely! Do you attend the Seattle.rb meetings? I haven't made it to one yet but I intend to. If so, we could chat then.
August 16th, 2006 at 09:07 AM I definitely attend the Seattle.rb meetings. I'll see you there.
August 17th, 2006 at 04:51 PM It cant draw a pie chart ?
August 18th, 2006 at 02:56 AM topfunky and brasten... just don't call your combined effort "Sgruffy" :D
August 18th, 2006 at 04:33 AM There ya go. :) As it is, 'Scruffy' is just a word that starts coming out of your mouth when you've been saying 'Gruff SVG' all weekend trying to explain what you're working on. broker- Soon. In fact I just got an email from A.J. Ostman who's working on the pie charts. Apparently basic pie charts are functional. He's working on some advanced pie charting capabilities now and we should be seeing that code soon. I'd guess we'll have pie charts in an official release sometime next week.
August 18th, 2006 at 09:56 AM after doing a gem install scruffy i can't seem to use the library (crashes on require 'scruffy') happens on both my linux and mac box
August 18th, 2006 at 04:53 PM jserver- Please send me any errors you're getting to my email address.. brasten -at- nagilum.com I'll take a look at it.
August 21st, 2006 at 06:07 PM #7 great! Thanks a lot, I will wait for the pie charts.
August 21st, 2006 at 11:17 PM #7 great! Thanks a lot, I will wait for the pie charts.
August 23rd, 2006 at 10:35 PM Great graphing library - thanks! I've noticed a small y-axis labelling bug: for graphs that cover only a very small range, the y-axis labels will repeat the same integer multiple times. http://dib.deefa.com/line.svg has an example of the ouput.
August 25th, 2006 at 11:06 PM Thanks - great stuff. I have one query though: Would it be possible to position the legend labels at differing heights - values on the y-axis that correspond with the last x value? Essentially, this would eliminate the use of a legend in line graphs (if desired). Have been searching high and low for such a feature and would love to find it in my own backyard (RoR). Interested in your thoughts on this. The flexibility that scruffy provides has been much needed. Well done.
August 30th, 2006 at 02:36 AM In the stacked graph example I have found that if you remove one of the bars so there are just two it errors. For example:
September 8th, 2006 at 05:32 AM sorry, åtopfunky, sorry gruff sucks, please allow it to die and use scruffy instead
May 5th, 2007 at 08:22 PM
You may want to note here that you may have to ‘require ‘rubygems” before require ‘scruffy’ thanks!
May 5th, 2007 at 08:31 PM
from http://scruffy.rubyforge.org/doc/classes/Scruffy/Graph.html
Here’s how to save it to a file… graph.render(:width => 700, :as => ‘PNG’, :to => ’<filename>’)
This quite confused me. Thanks!
May 8th, 2007 at 05:32 PM
Great stuff but I cannot seem to make it work. I have Macos X running Locomotive with RMagick bundle. I also have XTools and X11 libraries. I have created a controller such as;
class GraphController < ApplicationController
def index require 'rubygems' require 'scruffy'
end end
But it give me error. SyntaxError in GraphController#index
/Users/opsitunes/scruffy/app/controllers/graph_controller.rb:17: syntax error, unexpected kEND, expecting ‘)’ RAILS_ROOT: /Users/opsitunes/scruffy/config/..
Any ideas?
June 1st, 2007 at 05:02 PM
brasten – looks awesome! I’m running into one small problem. Using the exact example in your post, the generated graph has all the labels (legend, x-axis, and y-axis labels, but NOT the title) offset down and to the right of where they should be. For example, “Feb” is under the second bar, and the y-axis label “10” is midway between 0 and the first horizontal line, as well as positioned to far to the right (similar horizontal offset to the “Feb” label).
Any suggestions? Thanks!
June 7th, 2007 at 12:22 PM
Brasten, I really like the tool you’ve created, great job. One question: Is it possible to create a stacked bar graph with more than three bars? I have a project that requires me to have four data points per bar, and when I add the fouth I get an error regarding size.
July 10th, 2007 at 09:30 AM
Great stuff! Enjoyed using so far… Just need to work out how to tweek appearance :)
July 13th, 2007 at 09:10 AM
Any word on the next revision or any updates for us? Pie charts?
August 1st, 2007 at 03:06 PM
C:\rally>ruby scruffy.rb scruffy.rb:1: uninitialized constant Scruffy (NameError)
C:\rally>ruby scruffy.rb ./scruffy.rb:5: uninitialized constant Scruffy (NameError) from c:/ruby/lib/ruby/siteruby/1.8/rubygems/customrequire.rb:27:in
ge m_original_require’ from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:inre quire’ from scruffy.rb:2August 6th, 2007 at 03:00 AM
Is it possible to rotate the labels on the x axis, I have quite a lot of dates and they are all overlapping… Many thanks in advance!
October 25th, 2007 at 12:53 AM
Hi,
Scruffy looks like a nice tool. So far I have had trouble with a few things though:
Cheers,
Burnce
PS: It would be nice if you could add the “point_markers” line to the example in the rdoc (Scruffy::Graph). I spent some time figuring that one out.
October 29th, 2007 at 02:54 PM
A nice toolset. I have two questions: Is it possible to decouple the point markers from the data being graphed? I need to graph time on the x-axis with a reasonable number of evenly-spaced tics for a large number of data points.
October 30th, 2007 at 07:29 PM
Much nicer than gruff… however, i notice that you use relative sizes for stroke-width, font-size, etc… is there a way to override these settings w/ my own?
October 31st, 2007 at 02:49 AM
Hi, your tool is amazing. I’ve a little issue. I first copied one of the examples you showed here and I tried to render it but nothing was visualized on my web page (nothing appears in the page source code). Instead if I save the render on a file I can obtain the result I expect. Where I’m wrong? Thank you in advance
October 31st, 2007 at 10:29 AM
Hi,
Looks like stefano and I are having the same problem! In my case I’m using the sample directly from a rails view. Will this work?
Chris
January 11th, 2008 at 06:06 PM
Hi! I’m working on a Ruby on Rails application with Scruffy :) and I was wondering how to get the smiley faces that are in the third graph on th Scruffy site http://scruffy.rubyforge.org/? i need to submit this application very soon, so please help me out if you can :)
January 25th, 2008 at 08:53 AM
Two best practices:
The y-axis often doesn’t display the values you would like to see there. e.g. if you create a line graph where the highest value is 10, you would see values on the y-axis of 0, 3, 5, 8, 10 (so a difference of 3, 2, 3, 2). Setting :max_value to a multiple of 4 which is just higher than the highest value of the array solves this problem. i.e.:
def multiple_of_4(ar) (ar.max / 4.to_f).ceil * 4 end
in which ar is the array with the values in the graph you try to add. When calling render set :max_value to the value this function returns. Now the y-axis would show something like: 0, 3, 6, 9, 12 and the highest point on the graph is still 10.
The second best practice is to set :min_value to 0 when calling render if you have no negative values. If you want to display a value of 0 it will otherwise render a negative value on the y-axis (which you don’t want).
Hope this helps for all.
January 28th, 2008 at 08:14 AM
Scruffy doesn’t work on Mac with rmagick 2.x and ImageMagick 6.3.8. It fails on the following line in rmagickrasterizer: “image = Magick::Image::fromblob(svg)[0]” on line 16. I’m not sure why it fails, but after 12 hours of searching and thinking it was an ImageMagick problem, it clearly is a Scruffy/RMagick issue.
February 8th, 2008 at 03:29 PM
Just wanted to let you know that I love scruffy! Getting it to work in a Rails environment took a little work, but it wasn’t very difficult at all. I love it and hope you add pi charts soon!
February 16th, 2008 at 04:54 PM
Hi all, I’ve just finished setting Scruffy up in one of my rails apps, and it looks great!! Tks Brasten for this nice tool :) I don’t master it and I’m missing lots of options; I’ve actually not found too much documentation. Any full guide of params, options,..? cheers!
April 22nd, 2008 at 04:37 AM
Hello all, I am using scruffy for bar graphs on a soon-to-be public site on heroku. It works beautifully on localhost – thanks, Brasten! – but the deployment is to a headless server, requiring that certain public resources such as fonts be copied to a location available to the application. Where is the path to such resources obtained by gem scruffy? Thanks … I will post a link to our interesting energy-conservation site after I get it deployed!
April 26th, 2008 at 01:55 PM
what do include veiw file ?
May 6th, 2008 at 06:23 PM
Hi, I’m using scruffy to generate graphs, but I’m a newbee to ruby. I got the graphs working, but I have a question about rendering the graph.
Right now I’m rendering the graph as a PNG image (in the controller) to the public/images folder, and loading it with an IMG tag in the view.
This could give problems when 2 users ask for their graph at the same time (yes, they are personal). But also people could just refresh the URL for the graph and look at other peoples values.
I’d like to know how to render the graph directly to the browserscreen without saving it in a public place.
I’ve tried to render the graph in the view, but this just gave the PNG in hex on my screen.
Can anyone help me ?
Thx
May 6th, 2008 at 08:21 PM
Hello, I’d like to know how to reder the graph directly to the browserscreen without saving it somewhere in a public folder.
I used the reder function in the view, this gave me the HEX index of the PNG graph.
Can anyone tell me how to change that HEX code to a jpg redered to the screen
June 4th, 2008 at 02:31 PM
Nice Site! http://google.com
June 7th, 2008 at 11:56 AM
Very Nice Site! Thanx! 0 balence transfers balance transfer deals for visa balance transfer industry chase visa balance transger free balance transfers blue 0 balance transferes 0ºlance transfer no transfer fee best lifetime balance transfer 2.99 on life of balance transfer wamu mastercard balance transfer
June 24th, 2008 at 08:03 AM
tcm: if you don’t know, best not to comment.
Niels:
In the graph.render command, you need to write the image to a file (so that your browser has something to work with).
graph.render(:width => 600, :as => ‘JPG’,:to => “public/images/yourfile.jpg”)
Clearly, replace the :width value with your desired width, JPG with the mime type you want to use, and yourfile.jpg with a file name of your choosing.
Once render has been called, you will have a (permanent, until you overwrite it) file called “yourfile.jpg” in your images directory. As such, this code can be used in a controller, partial or view (even a model, though I wouldn’t recommend that!)…. so long as the code gets executed before you need to display it on the page. To show it in your view, just use an image tag:
<%= image_tag(“yourfile.jpg”) %>
Hope that helped!
July 23rd, 2008 at 04:21 PM
Hi Brasten, all. first of all , thanks for all the work done in Scruffy. I am using the version 0.2.2 and discovered that there is no way to put in the same bar graph multiple series of data by side and not stacked. I just developed a working extension of the bar to add support for multiple series in a bar graph, I called it multibar :-) Working with the code I was able to identify a couple of very little changes to add how can I submit this work to the community? is the development on the rubyforge project stopped? BR Giuseppe
July 30th, 2008 at 06:11 AM
This is really cool. I installed scruffy, however, I have not been able to find version 0.2.3 for download. Where is it available? Rubyforge only has 0.2.2.
September 29th, 2008 at 04:26 PM
LOL that doesn’t even make any sense!
October 2nd, 2008 at 07:41 AM
Is there ability to create a chart with 2 or more y-axis on different unit, for example: I have wireless data: call attempts: 100000, 200000, the drop calls rate: 2%, 1%, when I show it in the chart with double y-axis: all the drop call rate line chart is not readable.