Topic: Vertical x-axis labels in Gruff
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):
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:
But I don't know either where the init.rb file lives...
# Saved in lib/gruff_fix_patch.rb
# 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
@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
@graph_left = @graph_right_margin = @graph_bottom_margin = 40
@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
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.font_weight = NormalWeight
@d.pointsize = scale_fontsize(@marker_font_size)
@d.gravity = NorthWestGravity #CenterGravity
@d = @d.annotate_scaled(@base_image,
x_offset, @raw_rows -
(@graph_bottom_margin - 30),
@d.rotation = -90
@labels_seen[index] = 1