iBrasten

My methods of calculating time are far superior to yours, in every way.

 

This is the blog of Brasten Sager, a freelance software developer, Mariners fan, guitarist, haphazard philosopher.

Getting Scruffy With It

August 10, 2006 @ 09:40 AM

So I’ve been up to some fun stuff lately with projects and such, and I’d like to give my blog readers a head start on my latest one.

This last weekend I found myself with two desires colliding into one project. I’d been tinkering with SVG for a little bit and wanted to explore the possibility of SVG-based graphs, and at the same time I needed some functionality out of a graphing library that Gruff didn’t provide out-of-the-box. So in standard Ruby fashion, I decided to roll my own graphing library. The result of that is the (http://scruffy.rubyforge.org) project.

What It Does, What It Will Do, Etc…

Keep in mind I haven’t officially released this yet, I hope to do that by this weekend. There are a couple features I want to throw in before it goes super public. At that time I will go into more detail with the whats and whys. Until then, here’s a quick summary:

Current Features
  • The graphs are built entirely using SVG. Whether or not you want to render to SVG is up to you, you will be able to render to another graphics format easily. But building the whole thing on SVG provided me with some fun capabilities as well as extremely clean, maintainable code.
  • It’s very easy to extend. The first release will include 5-8 graph types, most of which are only a few lines of code. Adding new graph types is extremely easy, so I’m hoping to see custom graphs popping up all over.
  • Very useable. For the most part, Scruffy doesn’t limit you if it doesn’t have to. Graphs can contain multiple types (line graph, area graph, etc) at the same time, and Scruffy doesn’t need to know what size your graph will be until the moment it’s rendered. And rendering doesn’t affect your graph in any way, you can continue adding data, changing colors, and re-rendering at any size with the same graph object.
Coming Soon (like, very soon)...
  • As of this writing, you can’t actually render the graphs to an image format other than SVG, at least not directly. This is a 5-line change, and I plan on adding that capability tonight. If you really need to see that working before tonight, you can use RMagick to transform the resulting SVG into a format of your choice.
  • Specifications. Yes, I do have specifications mostly finished for behavior testing Scruffy (should you wish to make any changes), and they will be checked in shortly.
Not Present in First Release
  • Pie charts will not be included in the first release. I know these are very important, and they will be done in short order, but I wanted to get Scruffy out there before I worked on these.
  1. Installation
Installing Scruffy is easy:
gem install scruffy
  1. Basic Example

You can find more detailed examples in the documentation.

  graph = Scruffy::Graph.new(:title => 'Sales')
  graph.add :line, 'Brasten', [100, 200, 140] 
  graph.add :area, 'Jeff',    [150, 100, 40]

  graph.render(:width => 1500)
  1. Documentation You can view documentation online at http://scruffy.rubyforge.org/doc

0 Responses to “Getting Scruffy With It”