Class: CTioga2::Graphics::Elements::Subplot
- Inherits:
-
Container
- Object
- TiogaElement
- Container
- CTioga2::Graphics::Elements::Subplot
- Defined in:
- lib/ctioga2/graphics/elements/subplot.rb
Overview
It would be interesting to feature several layers:
It would also be interesting to offer the possibility to
A subplot. It features:
-
inclusion of curves
-
legends
-
a way to set/get its figure boundaries.
background/normal/foreground, that could be addressed just using options to drawing commands
output non-clipped objects.
Instance Attribute Summary collapse
-
#computed_boundaries ⇒ Object
Computed boundaries.
-
#style ⇒ Object
Various stylistic aspects of the plot, as a Styles::PlotStyle object.
-
#user_boundaries ⇒ Object
User-specified boundaries.
Attributes inherited from Container
#elements, #gp_cache, #legend_area, #legend_item_target, #legend_storage, #root_object, #subframe
Attributes inherited from TiogaElement
#clipped, #depth, #location, #parent
Instance Method Summary collapse
- #actual_subframe(t) ⇒ Object
-
#count_boundaries? ⇒ Boolean
In general, subplot’s boundaries do not count for the parent plot.
-
#get_boundaries ⇒ Object
Returns the boundaries of the default axes.
-
#get_el_boundaries(el) ⇒ Object
Returns the boundaries that apply for the given curve – it reads the curve’s axes.
-
#initialize(parent, root, style) ⇒ Subplot
constructor
A new instance of Subplot.
-
#set_user_boundaries(axis, bounds) ⇒ Object
Sets the user boundaries for the given (named) axis:.
Methods inherited from Container
#add_element, #add_legend_item, #do, #each_item, #enter_legend_subcontainer, #size
Methods inherited from TiogaElement
Methods included from Log
context, debug, error, fatal, #format_exception, #identify, info, init_logger, log_to, logger, set_level, #spawn, warn
Constructor Details
#initialize(parent, root, style) ⇒ Subplot
Returns a new instance of Subplot.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ctioga2/graphics/elements/subplot.rb', line 49 def initialize(parent, root, style) super(parent, root) @subframe = Types::MarginsBox.new("2.8dy", "2.8dy", "2.8dy", "2.8dy") @subframe = nil # Automatic by default. @prev_subframe = nil @style = style || Styles::PlotStyle.new @user_boundaries = {} end |
Instance Attribute Details
#computed_boundaries ⇒ Object
Computed boundaries. It also is a hash axis -> SimpleRange, just as #user_boundaries. Its value is not defined as long as #real_do hasn’t been entered into.
47 48 49 |
# File 'lib/ctioga2/graphics/elements/subplot.rb', line 47 def computed_boundaries @computed_boundaries end |
#style ⇒ Object
Various stylistic aspects of the plot, as a Styles::PlotStyle object.
38 39 40 |
# File 'lib/ctioga2/graphics/elements/subplot.rb', line 38 def style @style end |
#user_boundaries ⇒ Object
User-specified boundaries. It is a hash axis -> SimpleRange, where the axis is a valid return value of PlotStyle#get_axis_key
42 43 44 |
# File 'lib/ctioga2/graphics/elements/subplot.rb', line 42 def user_boundaries @user_boundaries end |
Instance Method Details
#actual_subframe(t) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/ctioga2/graphics/elements/subplot.rb', line 92 def actual_subframe(t) if @subframe return @subframe else if @prev_subframe @style.compute_margins(t, @prev_subframe) else @prev_subframe = @style.estimate_margins(t) return @prev_subframe end end end |
#count_boundaries? ⇒ Boolean
In general, subplot’s boundaries do not count for the parent plot.
107 108 109 |
# File 'lib/ctioga2/graphics/elements/subplot.rb', line 107 def count_boundaries? return false end |
#get_boundaries ⇒ Object
Returns the boundaries of the default axes. Plotting functions may safely assume that they are drawn using these boundaries, unless they asked for being drawn onto different axes.
81 82 83 84 |
# File 'lib/ctioga2/graphics/elements/subplot.rb', line 81 def get_boundaries return get_given_boundaries(style.xaxis_location, style.yaxis_location) end |
#get_el_boundaries(el) ⇒ Object
Returns the boundaries that apply for the given curve – it reads the curve’s axes. #compute_boundaries must have been called beforehand, which means that it will only work from within #real_do.
todo This should not only apply to curves, but to any object. That also means that there should be a way to specify axes for them too.
73 74 75 |
# File 'lib/ctioga2/graphics/elements/subplot.rb', line 73 def get_el_boundaries(el) return get_given_boundaries(* el.location.get_axis_keys(style)) end |
#set_user_boundaries(axis, bounds) ⇒ Object
Sets the user boundaries for the given (named) axis:
87 88 89 90 |
# File 'lib/ctioga2/graphics/elements/subplot.rb', line 87 def set_user_boundaries(axis, bounds) key = @style.get_axis_key(axis) @user_boundaries[key] = Types::SimpleRange.new(bounds) end |