class CTioga2::Graphics::Elements::Container

A Container is a drawable object that contains several others, its elements.

Attributes

elements[RW]

All drawable Element contained in this object. It may contain other Container subobjects.

gp_cache[RW]

A general-purpose cache that objects may use.

It is a hash, and its contents are reset at the beginning of each invocation of do.

legend_area[RW]

The Legends::LegendArea dedicated to the display of the legend of this object and its children, or nil if the parent should handle the display.

legend_item_target[RW]

The current legend container to which legend items are added. Defaults to the legend_storage, but it can be changed

legend_storage[RW]

The Legends::LegendStorage that holds all the legends of the object

root_object[RW]

A reference to the RootObject

subframe[RW]

The subframe position of this element with respect to its parent. It is a Types::Box object.

Public Class Methods

new(parent, root, options) click to toggle source

Creates an empty new Container with the given parent.

Calls superclass method
# File lib/ctioga2/graphics/elements/containers.rb, line 63
def initialize(parent, root, options)
  super()
  @parent = parent

  setup_style(parent, options)
  
  # elements to be given to tioga
  @elements = []

  # By default the frame takes up all the space.
  @subframe = Types::MarginsBox.new(0, 0, 0, 0)

  @root_object = root

  @legend_storage = Legends::LegendStorage.new
  
  @legend_item_target = @legend_storage

  # By default, don't display legends.
  @legend_area = nil
end

Public Instance Methods

actual_subframe(t) click to toggle source

Sometimes, the value of the subframe is nil and determined during the plot. This function is guaranteed to return the correct value. It takes a reference to a FigureMaker object.

# File lib/ctioga2/graphics/elements/containers.rb, line 99
def actual_subframe(t)
  return @subframe
end
add_element(element) click to toggle source

Adds an element

# File lib/ctioga2/graphics/elements/containers.rb, line 104
def add_element(element)
  element.parent = self
  @elements << element
  
  # If the element has a curve_style, we add it as a
  # CurveLegend
  if element.respond_to?(:curve_style) and 
      element.curve_style.has_legend?
    add_legend_item(Legends::CurveLegend.new(element.curve_style))
  elsif element.is_a? Container
    add_legend_item(element)
  end

  # We call LocationStyle#finalize! if possible
  if(self.respond_to?(:style) and element.respond_to?(:location))
    element.location.finalize!(self.style)
  end
end
add_legend_item(item) click to toggle source

Adds a legend item to the current storage

# File lib/ctioga2/graphics/elements/containers.rb, line 125
def add_legend_item(item)
  @legend_item_target.add_item(item)
end
do(t) click to toggle source
Calls superclass method
# File lib/ctioga2/graphics/elements/containers.rb, line 85
def do(t)
  # reset the cache
  @gp_cache = {}
  super
end
each_item(leaf_only = true, recursive = false, tl = true, &blk) click to toggle source
# File lib/ctioga2/graphics/elements/containers.rb, line 142
def each_item(leaf_only = true, recursive = false, tl = true, &blk)
  if (!recursive && !tl)
    return              # We're at the bottom level
  end
  for el in @elements
    if el.respond_to? :each_item
      if ! leaf_only
        blk.call(el)
      end
      el.each_item(leaf_only, recursive, false, &blk)
    else
      blk.call(el)
    end
  end
end
enter_legend_subcontainer(sub) click to toggle source

Adds a legend item to the current storage and make that item the next target for legend items.

If @a sub is nil, then switch back to the top

# File lib/ctioga2/graphics/elements/containers.rb, line 133
def enter_legend_subcontainer(sub)
  if sub
    add_legend_item(sub)
    @legend_item_target = sub
  else
    @legend_item_target = @legend_storage
  end
end
size() click to toggle source

Returns the number of child elements

# File lib/ctioga2/graphics/elements/containers.rb, line 92
def size
  return @elements.size
end

Protected Instance Methods

real_do(t) click to toggle source

Creates the appropriate subfigure and draws all its elements within.

# File lib/ctioga2/graphics/elements/containers.rb, line 164
def real_do(t)
  t.subfigure(@subframe.to_frame_margins(t)) do 
    for el in @elements
      el.do(t)
    end
  end
end