class CTioga2::Graphics::Legends::CurveLegend

The legend of a curve object, or rather, the legend corresponding to a given

todo finish to adapt: use FullTextStyle to draw the objects.

Attributes

curve_style[RW]

Public Class Methods

new(style) click to toggle source
# File lib/ctioga2/graphics/legends/items.rb, line 137
def initialize(style)
  super()
  @curve_style = style
end

Public Instance Methods

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

Draw one single text line

todo adapt here !

todo x and y are not taken into account the way they should be.

# File lib/ctioga2/graphics/legends/items.rb, line 147
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),
      'bottom' => y,
      'top' => 1 - y - legend_style.picto_height.to_figure(t)
    }
    debug { "Legend margins for '#{@curve_style.legend}' : #{margin_specs.inspect}" }
    t.subfigure(margin_specs) do
      # We make the markers slightly smaller than the text
      # around.
      t.rescale_text(0.8 * legend_style.symbol_scale)
      @curve_style.draw_legend_pictogram(t)
    end
  end
  t.show_text('x' => x + 
              legend_style.picto_width.to_figure(t) + 
              legend_style.picto_to_text.to_figure(t), 
              'y' => y, 'text' => @curve_style.legend,
              'measure' => legend_name,
              'justification' => Tioga::FigureConstants::LEFT_JUSTIFIED,
              'alignment' => Tioga::FigureConstants::ALIGNED_AT_BASELINE)
end
size(t, legend_style) click to toggle source

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

# File lib/ctioga2/graphics/legends/items.rb, line 175
def size(t, legend_style)
  width, height = text_size(t, legend_style)
  width += legend_style.picto_width.to_figure(t) + 
    legend_style.picto_to_text.to_figure(t) 
  lh = Types::Dimension.new(:dy, 1, :y).to_figure(t,:y)
  if lh > height
    height = lh
  end
    
  return [ width, height ]
end