class CTioga2::Graphics::Legends::LegendItem

All items that can be displayed in a legend derive from this one.

Public Class Methods

new() click to toggle source

Initializes the LegendItem. Children must call super to make sure the numbering is dealt with properly.

# File lib/ctioga2/graphics/legends/items.rb, line 35
def initialize
  @legend_number = @@legend_item_numbering
  @@legend_item_numbering += 1
end

Public Instance Methods

draw(t, legend_style, x, y) click to toggle source

Draws the legend at the given top left position (x,y) in figure coordinates.

# File lib/ctioga2/graphics/legends/items.rb, line 51
def draw(t, legend_style, x, y)
end
size(t, legend_style) click to toggle source

Returns the (width, height) in figure coordinates of the legend element with the given Styles::LegendStyle and FigureMaker reference objects.

The returned values can be inaccurate to some extent.

# File lib/ctioga2/graphics/legends/items.rb, line 45
def size(t, legend_style)
  return [0, 0]
end

Protected Instance Methods

get_baseline_y(t, legend_style, y) click to toggle source

Returns the y value for the baseline of the text in terms of figure coordinates.

This is plain wrong, I think…

# File lib/ctioga2/graphics/legends/items.rb, line 67
def get_baseline_y(t, legend_style, y)
  w , h = size(t, legend_style)
  return y - h          # This is wrong, but not as bad ;-)...
end
legend_name() click to toggle source

The internal name for the legend - one we can use in a get_text_size query.

# File lib/ctioga2/graphics/legends/items.rb, line 59
def legend_name
  return "legend-#{@legend_number}"
end
text_size(t, legend_style) click to toggle source

Computes the text size

# File lib/ctioga2/graphics/legends/items.rb, line 73
def text_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(t.scaling_factor*info['width'])

    h = t.convert_output_to_figure_dy(t.scaling_factor*info['height'])
    if h > height
      height = h
    end
  end

  return [ width, height ]
end