Class: CTioga2::Graphics::Elements::Container

Inherits:
TiogaElement
  • Object
show all
Defined in:
lib/ctioga2/graphics/elements/containers.rb

Overview

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

Direct Known Subclasses

RedirectingContainer, Subplot

Instance Attribute Summary collapse

Attributes inherited from TiogaElement

#location, #parent

Instance Method Summary collapse

Methods inherited from TiogaElement

#do, #inspect

Methods included from Log

debug, error, fatal, #format_exception, #identify, info, init_logger, logger, set_level, #spawn, warn

Constructor Details

#initialize(parent = nil, root = nil) ⇒ Container

Creates an empty new Container with the given parent.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ctioga2/graphics/elements/containers.rb', line 51

def initialize(parent = nil, root = nil)
  @parent = parent
  
  # 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

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

Instance Attribute Details

#elementsObject

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



32
33
34
# File 'lib/ctioga2/graphics/elements/containers.rb', line 32

def elements
  @elements
end

#legend_areaObject

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.



44
45
46
# File 'lib/ctioga2/graphics/elements/containers.rb', line 44

def legend_area
  @legend_area
end

#legend_storageObject

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



48
49
50
# File 'lib/ctioga2/graphics/elements/containers.rb', line 48

def legend_storage
  @legend_storage
end

#root_objectObject

A reference to the RootObject



39
40
41
# File 'lib/ctioga2/graphics/elements/containers.rb', line 39

def root_object
  @root_object
end

#subframeObject

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



36
37
38
# File 'lib/ctioga2/graphics/elements/containers.rb', line 36

def subframe
  @subframe
end

Instance Method Details

#actual_subframe(t) ⇒ Object

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.



76
77
78
# File 'lib/ctioga2/graphics/elements/containers.rb', line 76

def actual_subframe(t)
  return @subframe
end

#add_element(element) ⇒ Object

Adds an element



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/ctioga2/graphics/elements/containers.rb', line 81

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) ⇒ Object

Adds a legend item to the #associated_legend_storage



102
103
104
# File 'lib/ctioga2/graphics/elements/containers.rb', line 102

def add_legend_item(item)
  @legend_storage.add_item(item)
end

#sizeObject

Returns the number of child elements



69
70
71
# File 'lib/ctioga2/graphics/elements/containers.rb', line 69

def size
  return @elements.size
end