Class: CTioga::SimpleLayout

Inherits:
Layout
  • Object
show all
Defined in:
lib/CTioga/layout.rb

Overview

This class takes care of simple plots. All children are considered for computing the extension of the plots, but they won’t receive anything else than a default full frame.

For now, the legend is not taken into consideration – and the children as well ;-) !!

The SimpleLayout class is also meant as a base class for any layout that would need to know its extensions, but that will not get positionned at all in the same way.

Direct Known Subclasses

FixedLayout, GridItemLayout, GridLayout

Instance Attribute Summary collapse

Attributes inherited from Layout

#child_layouts, #object, #parent

Instance Method Summary collapse

Methods inherited from Layout

#add_child, #compute_padding, #convert_layout, #legend_extension, #legend_only_specs, #update_extension_with_object, #update_extensions

Methods included from Log

#identify, #init_logger, #logger, #logger_options, #spawn

Constructor Details

#initialize(ro, ch = [], children = []) ⇒ SimpleLayout

Returns a new instance of SimpleLayout.



287
288
289
290
# File 'lib/CTioga/layout.rb', line 287

def initialize(ro, ch = [], children = [] )
  super
  @bounding_box = [0.0, 0.0, 0.0, 0.0]
end

Instance Attribute Details

#bounding_boxObject

A hash setting the ‘bounding box’ for the plot. It is relative to the Container#outer_frame. Defaults to 0: the object occupies all the frame.



285
286
287
# File 'lib/CTioga/layout.rb', line 285

def bounding_box
  @bounding_box
end

Instance Method Details

#extension(t) ⇒ Object

Returns this layout’s extension. By default, it also includes the children’s extensions, unless the



329
330
331
332
333
334
335
336
337
338
339
# File 'lib/CTioga/layout.rb', line 329

def extension(t)
  # We use the simple extensions computation from Layout
  a = super
  # We update it with the children's informations:
  unless @ignore_children_extensions
    for f in @child_layouts
      update_extensions(a, f.extension(t))
    end
  end
  return a
end

#legend_specs(t = nil) ⇒ Object

Returns the object’s frame.



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/CTioga/layout.rb', line 293

def legend_specs(t = nil)
  a = extension(t)
  frames = @object.outer_frame(t)
  padding = Dimension.absolute_to_relative(a, frames)

  padding_prefs = 
    LayoutPreferences.padding_relative_values(compute_padding(@object), 
                                              frames)

  update_extensions(padding, padding_prefs)
  
  # If we display a legend, add the legend to the side.
  if @object.display_legend?
    a = Dimension.absolute_to_relative(legend_extension(t),frames)
    4.times do |i|
      padding[i] += a[i]
    end
  end
  
  specs = {}
  i = 0
  for side in %w(left right top bottom)
    specs["plot_#{side}_margin"] = padding[i] + @bounding_box[i]
    i += 1
  end
  if @object.display_legend?
    a = legend_only_specs(t, padding)
    return specs.merge(a)
  else
    return specs
  end
end