Class: Plotrb::Legend
Overview
Legends visualize scales. Legends aid interpretation of scales with ranges such as colors, shapes and sizes. See https://github.com/trifacta/vega/wiki/Legends
Constant Summary collapse
- LEGEND_PROPERTIES =
@return [Symbol] the name of the scale that determines an item’s size
@!attribute values @return [Array] explicitly set the visible legend values
[:size, :shape, :fill, :stroke, :orient, :title, :format, :offset, :values, :properties]
Instance Attribute Summary collapse
-
#fill ⇒ Symbol
The name of the scale that determines an item’s fill color.
-
#format ⇒ String
An optional formatting pattern for legend labels.
-
#offset ⇒ Integer
The offset of the legend.
-
#orient ⇒ Symbol
The orientation of the legend.
-
#shape ⇒ Symbol
The name of the scale that determines an item’s shape.
- #size ⇒ Object
-
#stroke ⇒ Symbol
The name of the scale that determines an item’s stroke color.
-
#title ⇒ Symbol
The title for the legend.
Instance Method Summary collapse
-
#initialize(&block) ⇒ Legend
constructor
A new instance of Legend.
- #method_missing(method, *args, &block) ⇒ Object
- #properties(element = nil, &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(&block) ⇒ Legend
Returns a new instance of Legend.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/plotrb/legends.rb', line 35 def initialize(&block) define_single_val_attributes(:size, :shape, :fill, :stroke, :orient, :title, :format, :offset) define_multi_val_attributes(:values) self.singleton_class.class_eval { alias_method :name, :title alias_method :offset_by, :offset } self.instance_eval(&block) if block_given? ::Plotrb::Kernel.legends << self self end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/plotrb/legends.rb', line 57 def method_missing(method, *args, &block) case method.to_s when /^at_(left|right)$/ # set orient of the legend self.orient($1.to_sym, &block) when /^with_(\d+)_name/ # set the title of the legend self.title($1.to_s, &block) else super end end |
Instance Attribute Details
#fill ⇒ Symbol
Returns the name of the scale that determines an item’s fill color.
30 31 |
# File 'lib/plotrb/legends.rb', line 30 LEGEND_PROPERTIES = [:size, :shape, :fill, :stroke, :orient, :title, :format, :offset, :values, :properties] |
#format ⇒ String
Returns an optional formatting pattern for legend labels.
30 31 |
# File 'lib/plotrb/legends.rb', line 30 LEGEND_PROPERTIES = [:size, :shape, :fill, :stroke, :orient, :title, :format, :offset, :values, :properties] |
#offset ⇒ Integer
Returns the offset of the legend.
30 31 |
# File 'lib/plotrb/legends.rb', line 30 LEGEND_PROPERTIES = [:size, :shape, :fill, :stroke, :orient, :title, :format, :offset, :values, :properties] |
#orient ⇒ Symbol
Returns the orientation of the legend.
30 31 |
# File 'lib/plotrb/legends.rb', line 30 LEGEND_PROPERTIES = [:size, :shape, :fill, :stroke, :orient, :title, :format, :offset, :values, :properties] |
#shape ⇒ Symbol
Returns the name of the scale that determines an item’s shape.
30 31 |
# File 'lib/plotrb/legends.rb', line 30 LEGEND_PROPERTIES = [:size, :shape, :fill, :stroke, :orient, :title, :format, :offset, :values, :properties] |
#size ⇒ Object
|
# File 'lib/plotrb/legends.rb', line 10
|
#stroke ⇒ Symbol
Returns the name of the scale that determines an item’s stroke color.
30 31 |
# File 'lib/plotrb/legends.rb', line 30 LEGEND_PROPERTIES = [:size, :shape, :fill, :stroke, :orient, :title, :format, :offset, :values, :properties] |
#title ⇒ Symbol
Returns the title for the legend.
30 31 |
# File 'lib/plotrb/legends.rb', line 30 LEGEND_PROPERTIES = [:size, :shape, :fill, :stroke, :orient, :title, :format, :offset, :values, :properties] |
Instance Method Details
#properties(element = nil, &block) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/plotrb/legends.rb', line 48 def properties(element=nil, &block) @properties ||= {} return @properties unless element @properties.merge!( element.to_sym => ::Plotrb::Mark::MarkProperty.new(:text, &block) ) self end |