Class: CTioga2::Graphics::Elements::Subplot
- Inherits:
-
Container
- Object
- TiogaElement
- Container
- CTioga2::Graphics::Elements::Subplot
- Defined in:
- lib/ctioga2/graphics/elements/subplot.rb
Overview
A subplot. It features:
-
inclusion of curves
-
legends
-
a way to set/get its figure boundaries.
Constant Summary
Constants inherited from TiogaElement
TiogaElement::StyleBaseOptions
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, #hidden, #location, #object_classes, #object_id, #object_parent, #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, opts) ⇒ 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
all_styles, base_style, #check_styled, define_style, #do, 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, opts) ⇒ Subplot
Returns a new instance of Subplot.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ctioga2/graphics/elements/subplot.rb', line 42 def initialize(parent, root, opts) super(parent, root, opts) @subframe = Types::MarginsBox.new("2.8dy", "2.8dy", "2.8dy", "2.8dy") @subframe = nil # Automatic by default. @prev_subframe = nil @style = Styles::PlotStyle.new(self) @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.
40 41 42 |
# File 'lib/ctioga2/graphics/elements/subplot.rb', line 40 def computed_boundaries @computed_boundaries end |
#style ⇒ Object
Various stylistic aspects of the plot, as a Styles::PlotStyle object.
31 32 33 |
# File 'lib/ctioga2/graphics/elements/subplot.rb', line 31 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
35 36 37 |
# File 'lib/ctioga2/graphics/elements/subplot.rb', line 35 def user_boundaries @user_boundaries end |
Instance Method Details
#actual_subframe(t) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ctioga2/graphics/elements/subplot.rb', line 85 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.
100 101 102 |
# File 'lib/ctioga2/graphics/elements/subplot.rb', line 100 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.
74 75 76 77 |
# File 'lib/ctioga2/graphics/elements/subplot.rb', line 74 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.
66 67 68 |
# File 'lib/ctioga2/graphics/elements/subplot.rb', line 66 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:
80 81 82 83 |
# File 'lib/ctioga2/graphics/elements/subplot.rb', line 80 def set_user_boundaries(axis, bounds) key = @style.get_axis_key(axis) @user_boundaries[key] = Types::SimpleRange.new(bounds) end |