Class: CTioga::Container
- Inherits:
-
TiogaElement
- Object
- TiogaElement
- CTioga::Container
- Defined in:
- lib/CTioga/elements/containers.rb
Overview
A class that can hold several ‘child’ elements, such as the SubPlot class and the Region class. A missed funcall will result in a try to call the parent, if it exists.
Instance Attribute Summary collapse
-
#accept_legend ⇒ Object
If true, the plot will keep its legend element, and the ones communicated by the children for itself.
-
#disable_legend ⇒ Object
If this attribute is set, all legends here will be completely ignored.
-
#elements ⇒ Object
readonly
The various properties defining the class.
-
#force_position ⇒ Object
Override the layouts opinion about where the object should be placed.
-
#funcalls ⇒ Object
readonly
The various properties defining the class.
-
#layout ⇒ Object
The layout !!! This is the one handling the object, but that does not necessarily mean that self == layout.root_object.
-
#layout_preferences ⇒ Object
The layout preferences for the object, that is, useful information that will be used by the object to make decisions about layouts.
-
#rescale ⇒ Object
A rescale attribute.
-
#root_frame ⇒ Object
The frame of the element, if that element is the root.
-
#show_legend ⇒ Object
Whether or not to show legend for the current plot.
Attributes inherited from TiogaElement
Instance Method Summary collapse
- #add_elem(elem) ⇒ Object
- #add_funcall(funcall) ⇒ Object
-
#add_legend_info(info) ⇒ Object
If legends are disable, we drop the legend altogether.
-
#convert_layout(cls) ⇒ Object
Converts the current layout using Layout#convert_layout.
-
#display_legend? ⇒ Boolean
Whether or not we should display a legend.
-
#get_boundaries ⇒ Object
This function can be used by external objects to query the boundaries this object would like to report.
- #has_plots? ⇒ Boolean
-
#initialize(p = nil) ⇒ Container
constructor
A new instance of Container.
-
#internal_get_boundaries ⇒ Object
The internal_get_boundaries is the function responsible for doing the real work behind getting the boundaries for objects.
-
#make_funcalls(t) ⇒ Object
Do the funcalls and some other initialization as well.
-
#method_missing(meth, *args) ⇒ Object
We redirect missed funcall to the @parent.
Methods inherited from TiogaElement
Methods included from Log
#identify, #init_logger, #logger, #logger_options, #spawn
Methods included from Debug
#debug_figmaker, #debug_patterns, #debug_puts, #figmaker_options, #test_pattern, #test_pattern_right
Constructor Details
#initialize(p = nil) ⇒ Container
Returns a new instance of Container.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/CTioga/elements/containers.rb', line 71 def initialize(p = nil) @parent = p # elements to be given to tioga @elements = [] # Used to add initial function calls. @funcalls = [] # Used to store legends internally. It is an array of CurveStyle @legend_info = [] # Whether to accept legends or forward them to the parent @accept_legend = false # Whether or not to show them @show_legend = false # A rescale factor: @rescale = false # The root frame: @root_frame = nil @layout_preferences = LayoutPreferences.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
We redirect missed funcall to the @parent
182 183 184 185 186 187 188 189 |
# File 'lib/CTioga/elements/containers.rb', line 182 def method_missing(meth, *args) if @parent debug "Redirecting call #{meth} to parent" @parent.send(meth,*args) else raise NoMethodError.new("No such method: #{meth}",meth,args) end end |
Instance Attribute Details
#accept_legend ⇒ Object
If true, the plot will keep its legend element, and the ones communicated by the children for itself. If false, legend informations are sent to the parent and simply ignored otherwise.
69 70 71 |
# File 'lib/CTioga/elements/containers.rb', line 69 def accept_legend @accept_legend end |
#disable_legend ⇒ Object
If this attribute is set, all legends here will be completely ignored.
40 41 42 |
# File 'lib/CTioga/elements/containers.rb', line 40 def disable_legend @disable_legend end |
#elements ⇒ Object (readonly)
The various properties defining the class
30 31 32 |
# File 'lib/CTioga/elements/containers.rb', line 30 def elements @elements end |
#force_position ⇒ Object
Override the layouts opinion about where the object should be placed. Please note that there is no need for a layout in the case when this attribute is not nil and not empty. Used with care ;-) !
63 64 65 |
# File 'lib/CTioga/elements/containers.rb', line 63 def force_position @force_position end |
#funcalls ⇒ Object (readonly)
The various properties defining the class
30 31 32 |
# File 'lib/CTioga/elements/containers.rb', line 30 def funcalls @funcalls end |
#layout ⇒ Object
The layout !!! This is the one handling the object, but that does not necessarily mean that self == layout.root_object. This might even seldom be the case.
57 58 59 |
# File 'lib/CTioga/elements/containers.rb', line 57 def layout @layout end |
#layout_preferences ⇒ Object
The layout preferences for the object, that is, useful information that will be used by the object to make decisions about layouts.
52 53 54 |
# File 'lib/CTioga/elements/containers.rb', line 52 def layout_preferences @layout_preferences end |
#rescale ⇒ Object
A rescale attribute
33 34 35 |
# File 'lib/CTioga/elements/containers.rb', line 33 def rescale @rescale end |
#root_frame ⇒ Object
The frame of the element, if that element is the root. Expressed in big points. Supposedly, nothing should stick out of this frame. If the element is not root, this should be nil.
As usual, [left, right, top, bottom]
47 48 49 |
# File 'lib/CTioga/elements/containers.rb', line 47 def root_frame @root_frame end |
#show_legend ⇒ Object
Whether or not to show legend for the current plot
36 37 38 |
# File 'lib/CTioga/elements/containers.rb', line 36 def show_legend @show_legend end |
Instance Method Details
#add_elem(elem) ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/CTioga/elements/containers.rb', line 105 def add_elem(elem) elem.parent = self @elements << elem # If the element has a style, then we assume it is a curve, # and add legend accordingly if elem.respond_to?(:style) and elem.style.has_legend? add_legend_info(CurveLegend.new(elem.style)) end end |
#add_funcall(funcall) ⇒ Object
116 117 118 119 |
# File 'lib/CTioga/elements/containers.rb', line 116 def add_funcall(funcall) funcall.parent = self @funcalls << funcall end |
#add_legend_info(info) ⇒ Object
If legends are disable, we drop the legend altogether. If we accept legends, add the legend, if it is not false. Else, forward it to the parents.
info may be either a CurveStyle or a LegendLine object.
126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/CTioga/elements/containers.rb', line 126 def add_legend_info(info) return unless info.is_a?(LegendItem) return if @disable_legend if @accept_legend debug "Adding legend information #{info.inspect}" @legend_info << info if info elsif parent debug "Forwarding legend to the parent" parent.add_legend_info(info) else info "Legend information dropped - this might not be expected" end end |
#convert_layout(cls) ⇒ Object
Converts the current layout using Layout#convert_layout
97 98 99 100 101 102 103 |
# File 'lib/CTioga/elements/containers.rb', line 97 def convert_layout(cls) if @layout @layout = @layout.convert_layout(cls) else @layout = cls.new(self) end end |
#display_legend? ⇒ Boolean
Whether or not we should display a legend
192 193 194 |
# File 'lib/CTioga/elements/containers.rb', line 192 def display_legend? @show_legend && has_plots? && has_legends? && ( not @disable_legend) end |
#get_boundaries ⇒ Object
This function can be used by external objects to query the boundaries this object would like to report. The default behaviour is to not report anything to the parent.
176 177 178 |
# File 'lib/CTioga/elements/containers.rb', line 176 def get_boundaries return [0.0/0.0, 0.0/0.0, 0.0/0.0, 0.0/0.0] end |
#has_plots? ⇒ Boolean
148 149 150 151 152 153 154 155 156 |
# File 'lib/CTioga/elements/containers.rb', line 148 def has_plots? @elements.each {|e| return true if e.is_a?(Curve2D) if e.respond_to? :has_plots? and e.has_plots? return true end } return false end |
#internal_get_boundaries ⇒ Object
The internal_get_boundaries is the function responsible for doing the real work behind getting the boundaries for objects. Some objects might want to use some boundaries but report other to their parents; they can rely on internal_get_boundaries to give the right result for them and modify get_boundaries to suit their needs.
164 165 166 167 168 169 170 171 |
# File 'lib/CTioga/elements/containers.rb', line 164 def internal_get_boundaries bounds = [] @elements.each do |e| bounds.push(e.get_boundaries) if e.respond_to? :get_boundaries end b = Curve2D.compute_boundaries(bounds) return b end |
#make_funcalls(t) ⇒ Object
Do the funcalls and some other initialization as well
141 142 143 144 145 146 |
# File 'lib/CTioga/elements/containers.rb', line 141 def make_funcalls(t) t.rescale(@rescale) if @rescale for f in @funcalls f.do(t) end end |