def draw_legend
if key
group = @root.add_element( "g" )
key_count = 0
for key_name in keys
y_offset = (KEY_BOX_SIZE * key_count) + (key_count * 5)
group.add_element( "rect", {
"x" => 0.to_s,
"y" => y_offset.to_s,
"width" => KEY_BOX_SIZE.to_s,
"height" => KEY_BOX_SIZE.to_s,
"class" => "key#{key_count+1}"
})
group.add_element( "text", {
"x" => (KEY_BOX_SIZE + 5).to_s,
"y" => (y_offset + KEY_BOX_SIZE).to_s,
"class" => "keyText"
}).text = key_name.to_s
key_count += 1
end
case key_position
when :right
x_offset = @graph_width + @border_left + 10
y_offset = @border_top + 20
when :bottom
x_offset = @border_left + 20
y_offset = @border_top + @graph_height + 5
if show_x_labels
max_x_label_height_px = (not rotate_x_labels) ?
x_label_font_size :
get_x_labels.max{|a,b|
a.to_s.length<=>b.to_s.length
}.to_s.length * x_label_font_size * 0.6
x_label_font_size
y_offset += max_x_label_height_px
y_offset += max_x_label_height_px + 5 if stagger_x_labels
end
y_offset += x_title_font_size + 5 if show_x_title
end
group.attributes["transform"] = "translate(#{x_offset} #{y_offset})"
end
end