Topic: Vertical x-axis labels in Gruff

Hi,
I am trying to display vertical x-axis labels in Gruff-generated graphs, I googled and found some code snippet (http://www.ruby-forum.com/topic/72462#831745) to add (code snippet pasted below).
This is my first time to modify an existing ruby-class, so I am not sure where to put it. I tried this way:

I saved the code in a file under the 'lib' directory: lib/gruff_fix_patch.rb
Then, tried to call 'require' in environment.rb (below my other requires):
require 'gruff'
...
require 'gruff_fix_patch'

But no luck. The added code does not seem to have any effect on my rails project (e.g. on the generated graphs).

It would be great if anyone could answer this:
Exactly where am I supposed to add/put the code? How do I tell my controllers/views to include that change?

Thanks in advance..!

Note: there was these two lines in the webpage where I found the code:
    # init.rb
    require 'gruff_fix_patch'
    Issue.send(:include, GruffFixPatch)
But I don't know either where the init.rb file lives...

=============================================================================================================
# Saved in lib/gruff_fix_patch.rb

class Gruff::Base
     def setup_graph_measurements
       # TODO Separate horizontal lines from line number labels so they can be shown or hidden independently
       # TODO Get width of longest left-hand vertical text label and space left margin accordingly
       unless @hide_line_markers
         @graph_left = 130.0 # TODO Calculate based on string width of labels
         @graph_right_margin = 80.0 # TODO see previous line
         @graph_bottom_margin = 400.0
       else
         @graph_left = @graph_right_margin = @graph_bottom_margin =  40
       end

       @graph_right = @raw_columns - @graph_right_margin

       @graph_width = @raw_columns - @graph_left - @graph_right_margin

       @graph_top = 150.0
       @graph_bottom = @raw_rows - @graph_bottom_margin
       @graph_height = @graph_bottom - @graph_top
     end

     def draw_label(x_offset, index)
       return if @hide_line_markers

       if !@labels[index].nil? && @labels_seen[index].nil?
           #@d.fill = @marker_color
         @d.font = @font if @font
         @d.stroke = 'transparent'
        @d.rotation = 90
        @d.text_align( LeftAlign)
         @d.font_weight = NormalWeight
         @d.pointsize = scale_fontsize(@marker_font_size)
         @d.gravity = NorthWestGravity #CenterGravity
         @d = @d.annotate_scaled(@base_image,
                                 1, 1000,
                                 x_offset, @raw_rows -
                                (@graph_bottom_margin - 30),
                                 @labels[index], @scale)
        @d.rotation = -90
         @labels_seen[index] = 1
       end
     end
end
==========================================================================

Re: Vertical x-axis labels in Gruff

this might help
[code=]Attributes
additional_line_values      [RW]      Experimental
bottom_margin      [RW]      Blank space below the graph
center_labels_over_point      [RW]      Used internally for spacing.

By default, labels are centered over the point they represent.
colors      [RW]      Get or set the list of colors that will be used to draw the bars or lines.
font      [R]      Font used for titles, labels, etc. Works best if you provide the full path to the TTF font file. RMagick must be built with the Freetype libraries for this to work properly.

Tries to find Bitstream Vera (Vera.ttf) in the location specified by ENV[

Last edited by ajibanda (2009-08-07 04:30:32)