Class: CTioga2::Graphics::Legends::LegendLine

Inherits:
LegendItem
  • Object
show all
Defined in:
lib/ctioga2/graphics/legends/items.rb

Overview

A class representing the style of a single legend line (unrelated to a curve)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text = "", style = {}) ⇒ LegendLine

Returns a new instance of LegendLine.



84
85
86
87
88
89
90
# File 'lib/ctioga2/graphics/legends/items.rb', line 84

def initialize(text = "", style = {})
  super()
  @text = text
  @style = Styles::FullTextStyle.from_hash(style)
  @style.justification ||= Tioga::FigureConstants::LEFT_JUSTIFIED

end

Instance Attribute Details

#styleObject

The style of the text, a Styles.FullTextStyle object.



82
83
84
# File 'lib/ctioga2/graphics/legends/items.rb', line 82

def style
  @style
end

#textObject

The text of the line



79
80
81
# File 'lib/ctioga2/graphics/legends/items.rb', line 79

def text
  @text
end

Instance Method Details

#draw(t, legend_style, x, y) ⇒ Object

Draw one single text line.



93
94
95
96
# File 'lib/ctioga2/graphics/legends/items.rb', line 93

def draw(t, legend_style, x, y)
  y = get_baseline_y(t, legend_style, y) 
  @style.draw_text(t, @text, x, y, legend_name)
end

#size(t, legend_style) ⇒ Object

Computes the size of the line. Height should always be accurate, but width can be 0 sometimes…



100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/ctioga2/graphics/legends/items.rb', line 100

def size(t, legend_style)
  height = legend_style.dy.to_figure(t)

  width = 0.0

  info = t.get_text_size(legend_name)
  
  if info.key? 'width'
    width += t.convert_output_to_figure_dx(10*info['width'])
  end

  return [ width, height ]
end