Class: Bio::Graphics::Panel::Ruler
- Inherits:
-
Object
- Object
- Bio::Graphics::Panel::Ruler
- Defined in:
- lib/bio/graphics/ruler.rb
Overview
The Bio::Graphics::Ruler class describes the ruler to be drawn on the graph. This is created automatically when creating the picture by using Bio::Graphics::Panel.to_svg. See BioExt::Graphics documentation for explanation of interplay between different classes. – TODO: the ruler might be implemented as a special case of a track, so it would inherit from it (class Ruler < Bio::Graphics::Panel::Track). But I haven’t really thought this through yet. ++
Instance Attribute Summary collapse
-
#colour ⇒ Object
Returns the value of attribute colour.
-
#height ⇒ Object
Returns the value of attribute height.
-
#major_tick_distance ⇒ Object
Returns the value of attribute major_tick_distance.
-
#minor_tick_distance ⇒ Object
Returns the value of attribute minor_tick_distance.
-
#name ⇒ Object
Returns the value of attribute name.
-
#panel ⇒ Object
Returns the value of attribute panel.
Instance Method Summary collapse
- #calculate_tick_distance ⇒ Object
- #draw(panel_drawing, vertical_offset) ⇒ Object
-
#initialize(panel, colour = [0,0,0]) ⇒ Ruler
constructor
Creates a new Bio::Graphics::Panel::Ruler object.
Constructor Details
#initialize(panel, colour = [0,0,0]) ⇒ Ruler
Creates a new Bio::Graphics::Panel::Ruler object.
Arguments:
- panel (required)
-
Bio::Graphics::Panel object that this ruler
belongs to
- colour
-
colour of the ruler. Default = ‘black’
- Returns
-
Bio::Graphics::Ruler object
28 29 30 31 32 |
# File 'lib/bio/graphics/ruler.rb', line 28 def initialize(panel, colour = [0,0,0]) @panel = panel @name = 'ruler' @colour = colour end |
Instance Attribute Details
#colour ⇒ Object
Returns the value of attribute colour.
33 34 35 |
# File 'lib/bio/graphics/ruler.rb', line 33 def colour @colour end |
#height ⇒ Object
Returns the value of attribute height.
33 34 35 |
# File 'lib/bio/graphics/ruler.rb', line 33 def height @height end |
#major_tick_distance ⇒ Object
Returns the value of attribute major_tick_distance.
33 34 35 |
# File 'lib/bio/graphics/ruler.rb', line 33 def major_tick_distance @major_tick_distance end |
#minor_tick_distance ⇒ Object
Returns the value of attribute minor_tick_distance.
33 34 35 |
# File 'lib/bio/graphics/ruler.rb', line 33 def minor_tick_distance @minor_tick_distance end |
#name ⇒ Object
Returns the value of attribute name.
33 34 35 |
# File 'lib/bio/graphics/ruler.rb', line 33 def name @name end |
#panel ⇒ Object
Returns the value of attribute panel.
33 34 35 |
# File 'lib/bio/graphics/ruler.rb', line 33 def panel @panel end |
Instance Method Details
#calculate_tick_distance ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bio/graphics/ruler.rb', line 35 def calculate_tick_distance min_tick_distance_requirement_met = false self.minor_tick_distance = 1 # in basepairs. while ! min_tick_distance_requirement_met if self.minor_tick_distance/panel.rescale_factor >= RULER_MIN_DISTANCE_TICKS_PIXEL min_tick_distance_requirement_met = true else self.minor_tick_distance = self.minor_tick_distance*5 end end self.major_tick_distance = self.minor_tick_distance * 10 end |
#draw(panel_drawing, vertical_offset) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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 |
# File 'lib/bio/graphics/ruler.rb', line 49 def draw(panel_drawing, vertical_offset) ruler_drawing = Cairo::Context.new(panel_drawing) self.calculate_tick_distance # Draw line ruler_drawing.move_to(0,10) ruler_drawing.line_to(panel.width, 10) ruler_drawing.stroke # Draw ticks # * Find position of first tick. # Most of the time, we don't want the first tick on the very first # basepair of the view. Suppose that would be position 333 in the # sequence. Then the numbers under the major tickmarks would be: # 343, 353, 363, 373 and so on. Instead, we want 350, 360, 370, 380. # So we want to find the position of the first tick. first_tick_position = panel.display_start while first_tick_position.modulo(minor_tick_distance) != 0 first_tick_position += 1 end # * 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, 5) if tick.modulo(major_tick_distance) == 0 ruler_drawing.rel_line_to(0, 15) # Draw tick number ruler_drawing.select_font_face(*(FONT)) ruler_drawing.set_font_size(RULER_TEXT_HEIGHT) ruler_drawing.move_to(tick_pixel_position.floor, 20 + RULER_TEXT_HEIGHT) ruler_drawing.show_text(tick.to_i.to_s) else ruler_drawing.rel_line_to(0, 5) end ruler_drawing.stroke end @height = 25 + RULER_TEXT_HEIGHT end |