Class: Plotrb::Axis
Overview
Axes provide axis lines, ticks, and labels to convey how a spatial range
represents a data range.
Constant Summary collapse
- TYPES =
%i(x y)
Instance Attribute Summary collapse
-
#format ⇒ String
The formatting pattern for axis labels.
-
#grid ⇒ Boolean
Whether gridlines should be created.
-
#offset ⇒ Integer
The offset by which to displace the axis from the edge of the enclosing group or data rectangle.
-
#orient ⇒ Symbol
The orientation of the axis.
-
#properties(element = nil, &block) ⇒ Hash
Optional mark property definitions for custom styling.
-
#scale ⇒ String
The name of the scale backing the axis.
-
#subdivide ⇒ Integer
The number of minor ticks between major ticks.
-
#tick_padding ⇒ Integer
The padding between ticks and text labels.
-
#tick_size ⇒ Integer
The size of major, minor, and end ticks.
-
#tick_size_end ⇒ Integer
The size of end ticks.
-
#tick_size_major ⇒ Integer
The size of major ticks.
-
#tick_size_minor ⇒ Integer
The size of minor ticks.
-
#ticks ⇒ Integer
A desired number of ticks.
-
#title ⇒ String
The title for the axis.
-
#tittle_offset ⇒ Integer
The offset from the axis at which to place the title.
-
#type ⇒ Symbol
Type of the axis, either :x or :y.
-
#values ⇒ Array
Explicitly set the visible axis tick values.
Instance Method Summary collapse
- #above(&block) ⇒ Object
- #above? ⇒ Boolean
- #below(&block) ⇒ Object
- #below? ⇒ Boolean
-
#initialize(type, &block) ⇒ Axis
constructor
A new instance of Axis.
- #method_missing(method, *args, &block) ⇒ Object
- #no_grid(&block) ⇒ Object
Methods included from Base
#add_attributes, #attributes, #classify, #collect_attributes, #define_boolean_attribute, #define_boolean_attributes, #define_multi_val_attribute, #define_multi_val_attributes, #define_single_val_attribute, #define_single_val_attributes, #defined_attributes, included, #set_attributes
Constructor Details
#initialize(type, &block) ⇒ Axis
Returns a new instance of Axis.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/plotrb/axes.rb', line 58 def initialize(type, &block) @type = type define_single_val_attributes(:scale, :orient, :title, :title_offset, :format, :ticks, :subdivide, :tick_padding, :tick_size, :tick_size_major, :tick_size_end, :tick_size_minor, :offset, :layer) define_boolean_attribute(:grid) define_multi_val_attributes(:values) self.singleton_class.class_eval { alias_method :from, :scale alias_method :offset_title_by, :title_offset alias_method :subdivide_by, :subdivide alias_method :major_tick_size, :tick_size_major alias_method :minor_tick_size, :tick_size_minor alias_method :end_tick_size, :tick_size_end alias_method :offset_by, :offset alias_method :show_grid, :grid alias_method :with_grid, :grid alias_method :show_grid?, :grid? alias_method :with_grid?, :grid? } self.instance_eval(&block) if block_given? ::Plotrb::Kernel.axes << self self end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/plotrb/axes.rb', line 123 def method_missing(method, *args, &block) case method.to_s when /^with_(\d+)_ticks$/ # set number of ticks. eg. in_20_ticks self.ticks($1.to_i, &block) when /^subdivide_by_(\d+)$/ # set subdivide of ticks self.subdivide($1.to_i, &block) when /^at_(top|bottom|left|right)$/ # set orient of the axis self.orient($1.to_sym, &block) when /^in_(front|back)$/ # set layer of the axis self.layer($1.to_sym, &block) else super end end |
Instance Attribute Details
#format ⇒ String
Returns the formatting pattern for axis labels.
53 54 55 56 |
# File 'lib/plotrb/axes.rb', line 53 add_attributes :type, :scale, :orient, :format, :ticks, :values, :subdivide, :tick_padding, :tick_size, :tick_size_major, :tick_size_minor, :tick_size_end, :offset, :layer, :properties, :title, :title_offset, :grid |
#grid ⇒ Boolean
Returns whether gridlines should be created.
53 54 55 56 |
# File 'lib/plotrb/axes.rb', line 53 add_attributes :type, :scale, :orient, :format, :ticks, :values, :subdivide, :tick_padding, :tick_size, :tick_size_major, :tick_size_minor, :tick_size_end, :offset, :layer, :properties, :title, :title_offset, :grid |
#offset ⇒ Integer
Returns the offset by which to displace the axis from the edge of the enclosing group or data rectangle.
53 54 55 56 |
# File 'lib/plotrb/axes.rb', line 53 add_attributes :type, :scale, :orient, :format, :ticks, :values, :subdivide, :tick_padding, :tick_size, :tick_size_major, :tick_size_minor, :tick_size_end, :offset, :layer, :properties, :title, :title_offset, :grid |
#orient ⇒ Symbol
Returns the orientation of the axis.
53 54 55 56 |
# File 'lib/plotrb/axes.rb', line 53 add_attributes :type, :scale, :orient, :format, :ticks, :values, :subdivide, :tick_padding, :tick_size, :tick_size_major, :tick_size_minor, :tick_size_end, :offset, :layer, :properties, :title, :title_offset, :grid |
#properties(element = nil, &block) ⇒ Hash
Returns optional mark property definitions for custom styling.
53 54 55 56 |
# File 'lib/plotrb/axes.rb', line 53 add_attributes :type, :scale, :orient, :format, :ticks, :values, :subdivide, :tick_padding, :tick_size, :tick_size_major, :tick_size_minor, :tick_size_end, :offset, :layer, :properties, :title, :title_offset, :grid |
#scale ⇒ String
Returns the name of the scale backing the axis.
53 54 55 56 |
# File 'lib/plotrb/axes.rb', line 53 add_attributes :type, :scale, :orient, :format, :ticks, :values, :subdivide, :tick_padding, :tick_size, :tick_size_major, :tick_size_minor, :tick_size_end, :offset, :layer, :properties, :title, :title_offset, :grid |
#subdivide ⇒ Integer
Returns the number of minor ticks between major ticks.
53 54 55 56 |
# File 'lib/plotrb/axes.rb', line 53 add_attributes :type, :scale, :orient, :format, :ticks, :values, :subdivide, :tick_padding, :tick_size, :tick_size_major, :tick_size_minor, :tick_size_end, :offset, :layer, :properties, :title, :title_offset, :grid |
#tick_padding ⇒ Integer
Returns the padding between ticks and text labels.
53 54 55 56 |
# File 'lib/plotrb/axes.rb', line 53 add_attributes :type, :scale, :orient, :format, :ticks, :values, :subdivide, :tick_padding, :tick_size, :tick_size_major, :tick_size_minor, :tick_size_end, :offset, :layer, :properties, :title, :title_offset, :grid |
#tick_size ⇒ Integer
Returns the size of major, minor, and end ticks.
53 54 55 56 |
# File 'lib/plotrb/axes.rb', line 53 add_attributes :type, :scale, :orient, :format, :ticks, :values, :subdivide, :tick_padding, :tick_size, :tick_size_major, :tick_size_minor, :tick_size_end, :offset, :layer, :properties, :title, :title_offset, :grid |
#tick_size_end ⇒ Integer
Returns the size of end ticks.
53 54 55 56 |
# File 'lib/plotrb/axes.rb', line 53 add_attributes :type, :scale, :orient, :format, :ticks, :values, :subdivide, :tick_padding, :tick_size, :tick_size_major, :tick_size_minor, :tick_size_end, :offset, :layer, :properties, :title, :title_offset, :grid |
#tick_size_major ⇒ Integer
Returns the size of major ticks.
53 54 55 56 |
# File 'lib/plotrb/axes.rb', line 53 add_attributes :type, :scale, :orient, :format, :ticks, :values, :subdivide, :tick_padding, :tick_size, :tick_size_major, :tick_size_minor, :tick_size_end, :offset, :layer, :properties, :title, :title_offset, :grid |
#tick_size_minor ⇒ Integer
Returns the size of minor ticks.
53 54 55 56 |
# File 'lib/plotrb/axes.rb', line 53 add_attributes :type, :scale, :orient, :format, :ticks, :values, :subdivide, :tick_padding, :tick_size, :tick_size_major, :tick_size_minor, :tick_size_end, :offset, :layer, :properties, :title, :title_offset, :grid |
#ticks ⇒ Integer
Returns a desired number of ticks.
53 54 55 56 |
# File 'lib/plotrb/axes.rb', line 53 add_attributes :type, :scale, :orient, :format, :ticks, :values, :subdivide, :tick_padding, :tick_size, :tick_size_major, :tick_size_minor, :tick_size_end, :offset, :layer, :properties, :title, :title_offset, :grid |
#title ⇒ String
Returns the title for the axis.
53 54 55 56 |
# File 'lib/plotrb/axes.rb', line 53 add_attributes :type, :scale, :orient, :format, :ticks, :values, :subdivide, :tick_padding, :tick_size, :tick_size_major, :tick_size_minor, :tick_size_end, :offset, :layer, :properties, :title, :title_offset, :grid |
#tittle_offset ⇒ Integer
Returns the offset from the axis at which to place the title.
53 54 55 56 |
# File 'lib/plotrb/axes.rb', line 53 add_attributes :type, :scale, :orient, :format, :ticks, :values, :subdivide, :tick_padding, :tick_size, :tick_size_major, :tick_size_minor, :tick_size_end, :offset, :layer, :properties, :title, :title_offset, :grid |
#type ⇒ Symbol
Returns type of the axis, either :x or :y.
53 54 55 56 |
# File 'lib/plotrb/axes.rb', line 53 add_attributes :type, :scale, :orient, :format, :ticks, :values, :subdivide, :tick_padding, :tick_size, :tick_size_major, :tick_size_minor, :tick_size_end, :offset, :layer, :properties, :title, :title_offset, :grid |
#values ⇒ Array
Returns explicitly set the visible axis tick values.
53 54 55 56 |
# File 'lib/plotrb/axes.rb', line 53 add_attributes :type, :scale, :orient, :format, :ticks, :values, :subdivide, :tick_padding, :tick_size, :tick_size_major, :tick_size_minor, :tick_size_end, :offset, :layer, :properties, :title, :title_offset, :grid |
Instance Method Details
#above(&block) ⇒ Object
88 89 90 91 92 |
# File 'lib/plotrb/axes.rb', line 88 def above(&block) @layer = :front self.instance_eval(&block) if block_given? self end |
#above? ⇒ Boolean
94 95 96 |
# File 'lib/plotrb/axes.rb', line 94 def above? @layer == :front end |
#below(&block) ⇒ Object
98 99 100 101 102 |
# File 'lib/plotrb/axes.rb', line 98 def below(&block) @layer = :back self.instance_eval(&block) if block_given? self end |
#below? ⇒ Boolean
104 105 106 |
# File 'lib/plotrb/axes.rb', line 104 def below? @layer == :back end |
#no_grid(&block) ⇒ Object
108 109 110 111 112 |
# File 'lib/plotrb/axes.rb', line 108 def no_grid(&block) @grid = false self.instance_eval(&block) if block self end |