Class: CTioga2::Graphics::RootObject
- Inherits:
-
Object
- Object
- CTioga2::Graphics::RootObject
- Defined in:
- lib/ctioga2/graphics/root.rb
Overview
The root object of the plot. The PlotMaker has one object like that. It is the real object drawing the plot.
Instance Attribute Summary collapse
-
#count_legend_in_page ⇒ Object
Whether top-level legends are part of the “real size” of the graph or outside the graph (easier to align anything).
-
#current_container ⇒ Object
The current Elements::Container of the object.
-
#legend_area ⇒ Object
The top-level Legends::LegendArea.
-
#page_size ⇒ Object
The page size of the graph, a [width,height] array.
Instance Method Summary collapse
-
#current_legend_area ⇒ Object
Returns the legend_area in charge of the current container.
-
#current_plot ⇒ Object
Returns the current Elements::Container, or create an Elements::Subplot if there isn’t.
-
#draw_root_object(t) ⇒ Object
Draws this object onto an appropriate FigureMaker object.
-
#draw_top_level_legend? ⇒ Boolean
Whether we are drawing a top-level legend.
-
#empty? ⇒ Boolean
Returns true if not a single drawable object has been pushed unto the RootObject yet.
-
#enter_gradient ⇒ Object
This function is the companion of #subplot, but for GradientRegion objects.
-
#enter_region ⇒ Object
This function is the companion of #subplot, but for Region objects.
-
#enter_subobject(new_object) ⇒ Object
Enters into a new Elements::Container, new_object.
-
#initialize ⇒ RootObject
constructor
A new instance of RootObject.
-
#leave_subobject ⇒ Object
Leaves a subobject.
-
#set_page_size(size) ⇒ Object
Sets the page of the object, from a pure text object, such as “12cmx12cm”.
-
#setup_page(t) ⇒ Object
Sets up the page width and other parameters for the given FigureMaker object.
-
#subplot ⇒ Object
Creates a subplot of the current plot.
-
#top_level_container ⇒ Object
The only top-level container of the graph.
Constructor Details
#initialize ⇒ RootObject
Returns a new instance of RootObject.
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ctioga2/graphics/root.rb', line 46 def initialize @current_container = nil @container_stack = [] @legend_area = Legends::LegendArea.new @count_legend_in_page = false # @count_legend_in_page = true # Page size: set_page_size("12cmx12cm") # Same as old ctioga end |
Instance Attribute Details
#count_legend_in_page ⇒ Object
Whether top-level legends are part of the “real size” of the graph or outside the graph (easier to align anything)
40 41 42 |
# File 'lib/ctioga2/graphics/root.rb', line 40 def count_legend_in_page @count_legend_in_page end |
#current_container ⇒ Object
The current Elements::Container of the object.
32 33 34 |
# File 'lib/ctioga2/graphics/root.rb', line 32 def current_container @current_container end |
#legend_area ⇒ Object
The top-level Legends::LegendArea. This one gets necessarily displayed on one of the sides of the graph.
36 37 38 |
# File 'lib/ctioga2/graphics/root.rb', line 36 def legend_area @legend_area end |
#page_size ⇒ Object
The page size of the graph, a [width,height] array.
43 44 45 |
# File 'lib/ctioga2/graphics/root.rb', line 43 def page_size @page_size end |
Instance Method Details
#current_legend_area ⇒ Object
Returns the legend_area in charge of the current container.
211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/ctioga2/graphics/root.rb', line 211 def current_legend_area area = nil for el in @container_stack if el.respond_to?(:legend_area) and el.legend_area area = el.legend_area end end if ! area area = @legend_area end return area end |
#current_plot ⇒ Object
Returns the current Elements::Container, or create an Elements::Subplot if there isn’t.
This function should be used by all functions that add Elements::TiogaElement to plots (or modify plot’s data, such as title, axes…).
66 67 68 69 70 71 72 73 74 |
# File 'lib/ctioga2/graphics/root.rb', line 66 def current_plot if @current_container return @current_container else subplot = Elements::Subplot.new(nil, self, nil) enter_subobject(subplot) return subplot end end |
#draw_root_object(t) ⇒ Object
Draws this object onto an appropriate FigureMaker object.
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/ctioga2/graphics/root.rb', line 176 def draw_root_object(t) setup_page(t) if top_level_container plot_margins, legend_margins = if draw_top_level_legend? @legend_area.partition_frame(t, top_level_container) else [[0, 0, 0, 0], nil] end t.context do t.set_subframe(plot_margins) top_level_container.do(t) end # Draw the legend only when applicable. if legend_margins t.context do t.set_subframe(legend_margins) @legend_area.display_legend(t, top_level_container) end end else raise "The root object should not be drawn empty ?" end end |
#draw_top_level_legend? ⇒ Boolean
Whether we are drawing a top-level legend
205 206 207 208 |
# File 'lib/ctioga2/graphics/root.rb', line 205 def draw_top_level_legend? return (! top_level_container.legend_area) && ( top_level_container.legend_storage.harvest_contents.size > 0) end |
#empty? ⇒ Boolean
Returns true if not a single drawable object has been pushed unto the RootObject yet.
171 172 173 |
# File 'lib/ctioga2/graphics/root.rb', line 171 def empty? return @current_container.nil? end |
#enter_gradient ⇒ Object
This function is the companion of #subplot, but for GradientRegion objects. Returns the newly created GradientRegion
160 161 162 163 164 165 166 167 |
# File 'lib/ctioga2/graphics/root.rb', line 160 def enter_gradient if ! @current_container subplot end region = Elements::GradientRegion.new(@current_container, self) enter_subobject(region) return region end |
#enter_region ⇒ Object
This function is the companion of #subplot, but for Region objects. Returns the newly created Region.
149 150 151 152 153 154 155 156 |
# File 'lib/ctioga2/graphics/root.rb', line 149 def enter_region if ! @current_container subplot end region = Elements::Region.new(@current_container, self) enter_subobject(region) return region end |
#enter_subobject(new_object) ⇒ Object
Enters into a new Elements::Container, new_object.
77 78 79 80 81 82 83 |
# File 'lib/ctioga2/graphics/root.rb', line 77 def enter_subobject(new_object) if @current_container @current_container.add_element(new_object) end @current_container = new_object @container_stack << @current_container end |
#leave_subobject ⇒ Object
Leaves a subobject.
86 87 88 89 90 91 92 93 94 |
# File 'lib/ctioga2/graphics/root.rb', line 86 def leave_subobject if @container_stack.size == 1 raise "Trying to leave top-level object" end if @container_stack.pop != @current_container raise "We have a serious problem here" end @current_container = @container_stack.last end |
#set_page_size(size) ⇒ Object
Sets the page of the object, from a pure text object, such as “12cmx12cm”
103 104 105 106 107 |
# File 'lib/ctioga2/graphics/root.rb', line 103 def set_page_size(size) @page_size = size.split(/\s*x\s*/).collect {|s| Tioga::Utils::tex_dimension_to_bp(s) } end |
#setup_page(t) ⇒ Object
Sets up the page width and other parameters for the given FigureMaker object. Must be within a figure object, so that potential modifications to the page size due to text objects (legends) can be taken into account.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/ctioga2/graphics/root.rb', line 114 def setup_page(t) if @count_legend_in_page or ! draw_top_level_legend? effective_size = @page_size else effective_size = @legend_area. enlarged_page_size(t, top_level_container, *@page_size) end t.page_setup(*effective_size) t.set_frame_sides(0,1,1,0) # Setting label and title scale to 1 t.title_scale = 1 t.xlabel_scale = 1 t.ylabel_scale = 1 # \todo I think this is mostly useless. Check. end |
#subplot ⇒ Object
Creates a subplot of the current plot. If @current_container is null, create it as a Elements::Container: this will make it easy to create complex graphs (no need to disable axes and other kinds of stuff on the main plot).
For the sake of convenience, returns the newly created Elements::Subplot
138 139 140 141 142 143 144 145 |
# File 'lib/ctioga2/graphics/root.rb', line 138 def subplot() if ! @current_container enter_subobject(Elements::Container.new(nil, self)) end subplot = Elements::Subplot.new(@current_container, self, nil) enter_subobject(subplot) return subplot end |
#top_level_container ⇒ Object
The only top-level container of the graph.
97 98 99 |
# File 'lib/ctioga2/graphics/root.rb', line 97 def top_level_container return @container_stack.first end |