Class: CTioga::CurveLegend

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

Overview

The class handling the drawing of one 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(style) ⇒ CurveLegend

Returns a new instance of CurveLegend.



110
111
112
113
# File 'lib/CTioga/legends/item.rb', line 110

def initialize(style)
  super()
  @curve_style = style
end

Instance Attribute Details

#curve_styleObject

Returns the value of attribute curve_style.



108
109
110
# File 'lib/CTioga/legends/item.rb', line 108

def curve_style
  @curve_style
end

Instance Method Details

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

Draw one single text line



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/CTioga/legends/item.rb', line 116

def draw(t, legend_style, x, y)
  y = get_baseline_y(t, legend_style, y) 
  t.context do 
    # Position specification for the legend pictogram
    margin_specs = { 'left' => x,
      'right' => 1 - x - legend_style.picto_width.to_figure(t, :x),
      'bottom' => y,
      'top' => 1 - y - legend_style.picto_height.to_figure(t, :y)
    }
    debug "Legend margins for '#{@curve_style.legend}' : #{margin_specs.inspect}"
    t.subfigure(margin_specs) do
      # We scale the text back to normal so the markers have the right
      # size
      # t.line_width = 0.1
      # t.stroke_rect(0,0,1,1)
      t.rescale_text(1/legend_style.text_scale)
      @curve_style.output_legend_pictogram(t)
    end
  end
  t.show_text('x' => x + 
              legend_style.picto_width.to_figure(t, :x) + 
              legend_style.picto_to_text.to_figure(t, :x), 
              'y' => y, 'text' => @curve_style.legend,
              'measure' => legend_name,
              'justification' => LEFT_JUSTIFIED)
end

#size(t, legend_style) ⇒ Object

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



145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/CTioga/legends/item.rb', line 145

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

  width = legend_style.picto_width.to_figure(t, :x) + 
    legend_style.picto_to_text.to_figure(t, :x) 

  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