module DYI::Chart::Legend
@since 0.0.0
Private Class Methods
included(klass)
click to toggle source
# File lib/dyi/chart/legend.rb, line 73 def included(klass) klass.__send__(:opt_accessor, :show_legend, :type => :boolean, :default => true) klass.__send__(:opt_accessor, :legend_font, :type => :font) klass.__send__(:opt_accessor, :legend_format, :type => :string, :default_method => :default_legend_format) klass.__send__(:opt_accessor, :legend_point, :type => :point, :default_method => :default_legend_point) klass.__send__(:opt_accessor, :legend_css_class, :type => :string) end
Private Instance Methods
default_legend_format()
click to toggle source
# File lib/dyi/chart/legend.rb, line 65 def default_legend_format "{name}" end
default_legend_point()
click to toggle source
# File lib/dyi/chart/legend.rb, line 61 def default_legend_point Coordinate.new(0,0) end
draw_legend(names, shapes=nil, records=nil, colors=nil)
click to toggle source
# File lib/dyi/chart/legend.rb, line 30 def draw_legend(names, shapes=nil, records=nil, colors=nil) legend_canvas.translate(legend_point.x, legend_point.y) if show_legend? pen = Drawing::Pen.black_pen(:font => legend_font) brush = Drawing::Brush.new names.each_with_index do |name, index| y = legend_font_size * (1.2 * (index + 1)) group = Shape::ShapeGroup.draw_on(legend_canvas) case shapes && shapes[index] when Shape::Base shapes[index].draw_on(group) when NilClass brush.color = colors && colors[index] || chart_color(index) brush.draw_rectangle( group, Coordinate.new(legend_font_size * 0.2, y - legend_font_size * 0.8), legend_font_size * 0.8, legend_font_size * 0.8) end pen.draw_text( group, Coordinate.new(legend_font_size * 0.2 + legend_font_size, y), name) end end end
legend_font_size()
click to toggle source
# File lib/dyi/chart/legend.rb, line 57 def legend_font_size legend_font ? legend_font.draw_size : Font::DEFAULT_SIZE end