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

Constant Summary

Constants inherited from TiogaElement

TiogaElement::StyleBaseOptions

Instance Attribute Summary collapse

Attributes inherited from TiogaElement

#clipped, #depth, #hidden, #location, #object_classes, #object_id, #object_parent, #parent

Instance Method Summary collapse

Methods inherited from TiogaElement

all_styles, base_style, #check_styled, define_style, find_object, find_objects, #get_style, #has_style?, inherited, #inspect, register_object, register_style, #setup_style, #style_class, style_class, style_name, #style_name, styled_classes, #update_style

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(parent, root, options) ⇒ Container

Creates an empty new Container with the given parent.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# 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

Instance Attribute Details

#elementsObject

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



30
31
32
# File 'lib/ctioga2/graphics/elements/containers.rb', line 30

def elements
  @elements
end

#gp_cacheObject

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.



56
57
58
# File 'lib/ctioga2/graphics/elements/containers.rb', line 56

def gp_cache
  @gp_cache
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.



42
43
44
# File 'lib/ctioga2/graphics/elements/containers.rb', line 42

def legend_area
  @legend_area
end

#legend_item_targetObject

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



50
51
52
# File 'lib/ctioga2/graphics/elements/containers.rb', line 50

def legend_item_target
  @legend_item_target
end

#legend_storageObject

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



46
47
48
# File 'lib/ctioga2/graphics/elements/containers.rb', line 46

def legend_storage
  @legend_storage
end

#root_objectObject

A reference to the RootObject



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

def root_object
  @root_object
end

#subframeObject

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



34
35
36
# File 'lib/ctioga2/graphics/elements/containers.rb', line 34

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.



99
100
101
# File 'lib/ctioga2/graphics/elements/containers.rb', line 99

def actual_subframe(t)
  return @subframe
end

#add_element(element) ⇒ Object

Adds an element



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# 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) ⇒ Object

Adds a legend item to the current storage



125
126
127
# File 'lib/ctioga2/graphics/elements/containers.rb', line 125

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

#do(t) ⇒ Object



85
86
87
88
89
# 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) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# 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) ⇒ Object

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



133
134
135
136
137
138
139
140
# 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

#sizeObject

Returns the number of child elements



92
93
94
# File 'lib/ctioga2/graphics/elements/containers.rb', line 92

def size
  return @elements.size
end