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
context, counts, debug, error, fatal, #format_exception, #identify, info, init_logger, log_to, logger, set_level, #spawn, warn
Constructor Details
#initialize(style) ⇒ CurveLegend
Returns a new instance of CurveLegend.
137 138 139 140 |
# File 'lib/ctioga2/graphics/legends/items.rb', line 137 def initialize(style) super() @curve_style = style end |
Instance Attribute Details
#curve_style ⇒ Object
Returns the value of attribute curve_style.
135 136 137 |
# File 'lib/ctioga2/graphics/legends/items.rb', line 135 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.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# 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) ⇒ Object
Computes the size of the line. Height should always be accurate, but width can be 0 sometimes…
175 176 177 178 179 180 181 182 183 184 185 |
# 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 |