Class: CTioga2::Graphics::Legends::CurveLegend
- Inherits:
-
LegendItem
- Object
- LegendItem
- CTioga2::Graphics::Legends::CurveLegend
- Includes:
- Log
- Defined in:
- lib/ctioga2/graphics/legends/items.rb
Overview
The legend of a curve object, or rather, the legend corresponding to a given
todo finish to adapt: use FullTextStyle to draw the objects.
Instance Attribute Summary collapse
-
#curve_style ⇒ Object
Returns the value of attribute curve_style.
Instance Method Summary collapse
-
#draw(t, legend_style, x, y) ⇒ Object
Draw one single text line.
-
#initialize(style) ⇒ CurveLegend
constructor
A new instance of CurveLegend.
-
#size(t, legend_style) ⇒ Object
Computes the size of the line.
Methods included from Log
debug, error, fatal, #format_exception, #identify, info, init_logger, logger, set_level, #spawn, warn
Constructor Details
#initialize(style) ⇒ CurveLegend
Returns a new instance of CurveLegend.
126 127 128 129 |
# File 'lib/ctioga2/graphics/legends/items.rb', line 126 def initialize(style) super() @curve_style = style end |
Instance Attribute Details
#curve_style ⇒ Object
Returns the value of attribute curve_style.
124 125 126 |
# File 'lib/ctioga2/graphics/legends/items.rb', line 124 def curve_style @curve_style end |
Instance Method Details
#draw(t, legend_style, x, y) ⇒ Object
Draw one single text line
todo adapt here !
todo x and y are not taken into account the way they should be.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/ctioga2/graphics/legends/items.rb', line 136 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) @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) end |
#size(t, legend_style) ⇒ Object
Computes the size of the line. Height should always be accurate, but width can be 0 sometimes…
163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/ctioga2/graphics/legends/items.rb', line 163 def size(t, legend_style) height = legend_style.dy.to_figure(t) width = legend_style.picto_width.to_figure(t) + legend_style.picto_to_text.to_figure(t) 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 |