3. Examples

Here are a few graphs from the gruff test suite, all made with RubyCocoa and CocoaMagick (trust me about that, I still haven’t gotten RMagick installed on my Mac!):

To generate these yourself, download gruff from rubyforge. Get the .tgz version and unpack it somewhere convenient. Put CocoaMagick.rb in the lib directory and then edit lib/gruff/base.rb to require CocoaMagick instead of RMagick. Then go up to the top-level gruff directory and run the tests.

For example, to generate the line graph examples, run this:
% ruby test/line_test.rb

If you need RubyCocoa, you can find directions for installing it here.

I’m sure there’s a lot that could be said and done to improve this. If you’d like to comment, please email me or post your thoughts on my nascent blog. Thanks!

Did you find an error? Is something missing? Post your comment or suggestion below!

Comments (2) post
  1. pig_farmer@earthlink.net Mon Sep 25 14:59:15 +0000 2006

    I’m new to ruby and rubycocoa and appreciate your tutorials. After installing gruff and CocoaMagick, I tried to run your first test example but it can’t find ‘height’ in the Type_Metrics class. Am I doing something wrong?

    ruby test/line_test.rb fails because type_metrics doesn’t have a height attribute:

    Started ...E.E.EEEEEEEE.EEEE.EEEEEE.EEE Finished in 2.694138 seconds. test_all_negative(TestGruffLine): NoMethodError: undefined method `height’ for # ./test/../lib/gruff/base.rb:875:in `calculate_caps_height’ ./test/../lib/gruff/base.rb:434:in `setup_graph_measurements’ ./test/../lib/gruff/base.rb:397:in `setup_drawing’ ./test/../lib/gruff/base.rb:376:in `draw’ ./test/../lib/gruff/line.rb:37:in `draw’ ./test/../lib/gruff/base.rb:357:in `write’ test/line_test.rb:346:in `test_all_negative’

    1) Error:

    (many more errors with same error.

    base.rb lines 873 to 876 def calculate_caps_height(font_size) @d.pointsize = font_size @d.get_type_metrics(@base_image, ‘X’).height end

    CocoaMagick Type_Metrics class: class TypeMetric attr_accessor :width def initialize @width = 50 end end NormalWeight = 400 BoldWeight = 700 WestGravity = :west EastGravity = :east CenterGravity = :center SouthGravity = :south NorthGravity = :north SouthWestGravity = :southwest NorthWestGravity = :northwest NorthEastGravity = :northeast SouthEastGravity = :southeast end

  2. Tim Mon Sep 25 16:20:12 +0000 2006

    Sorry, it looks like gruff has gotten ahead of us.  Perhaps you can fix this by adding a height method to CocoaMagic?  I’ll look into this soon.