Class: CTioga::LegendLine

Inherits:
LegendItem show all
Defined in:
lib/CTioga/legends/item.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from LegendItem

#get_baseline_y, #legend_name

Methods included from Log

#identify, #init_logger, #logger, #logger_options, #spawn

Methods included from Debug

#debug_figmaker, #debug_patterns, #debug_puts, #figmaker_options, #test_pattern, #test_pattern_right

Constructor Details

#initialize(text = "") ⇒ LegendLine

Returns a new instance of LegendLine.



74
75
76
77
# File 'lib/CTioga/legends/item.rb', line 74

def initialize(text = "")
  super()
  @text = text
end

Instance Attribute Details

#textObject

The text of the line



72
73
74
# File 'lib/CTioga/legends/item.rb', line 72

def text
  @text
end

Instance Method Details

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

Draw one single text line



80
81
82
83
84
85
86
87
# File 'lib/CTioga/legends/item.rb', line 80

def draw(t, legend_style, x, y)
  y = get_baseline_y(t, legend_style, y) 
  t.show_text('x' => x, 'y' => y, 
              'text' => @text,
              'justification' => LEFT_JUSTIFIED,
              'measure' => 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…



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/CTioga/legends/item.rb', line 91

def size(t, legend_style)
  height = legend_style.dy.to_figure(t, :y)
  info = t.get_text_size(legend_name)
  if info.key? 'width'
    width = t.convert_output_to_figure_dx(10*info['width'])
  else
    width = 0
  end

  return [ width, height ]
end