Method: Bio::Graphics::Ruler#draw

Defined in:
lib/bio/graphics/ruler.rb

#draw(panel_drawing) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/bio/graphics/ruler.rb', line 64

def draw(panel_drawing)
  ruler_drawing = Cairo::Context.new(panel_drawing)

  # Draw line
  ruler_drawing.move_to(0,10)
  ruler_drawing.line_to(panel.width, 10)
  ruler_drawing.stroke

  # Draw ticks
  #  * And start drawing the rest.
  first_tick_position.step(@panel.display_stop, @minor_tick_distance) do |tick|
    tick_pixel_position = (tick - panel.display_start) / @panel.rescale_factor
    ruler_drawing.move_to(tick_pixel_position.floor, @min_pixels_per_tick)
    if tick.modulo(@major_tick_distance) == 0
      ruler_drawing.rel_line_to(0, 3*@tick_height)
      
      # Draw tick number
      ruler_drawing.select_font_face(*Bio::Graphics::FONT)
      ruler_drawing.set_font_size(@tick_text_height)
      ruler_drawing.move_to(tick_pixel_position.floor, 4*@tick_height + @tick_text_height)
      ruler_drawing.show_text(tick.to_i.to_s)
    else
      ruler_drawing.rel_line_to(0, @tick_height)
      
    end
    ruler_drawing.stroke
  end

  @height = 5*@tick_height + @tick_text_height          
end