Class: Plotrb::Scale
Overview
Scales are functions that transform a domain of data values to a range of
visual values.
Defined Under Namespace
Classes: DataRef
Constant Summary collapse
- TYPES =
%i(linear log pow sqrt quantile quantize threshold ordinal time utc)
- SCALE_PROPERTIES =
[:name, :type, :domain, :domain_min, :domain_max, :range, :range_min, :range_max, :reverse, :round]
- RANGE_LITERALS =
%i(width height shapes colors more_colors)
- TIME_SCALE_NICE =
%i(second minute hour day week month year)
Instance Method Summary collapse
-
#initialize(type = :linear, &block) ⇒ Scale
constructor
A new instance of Scale.
- #method_missing(method, *args, &block) ⇒ Object
- #type ⇒ 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 = :linear, &block) ⇒ Scale
Returns a new instance of Scale.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/plotrb/scales.rb', line 28 def initialize(type=:linear, &block) @type = type case @type when :ordinal set_ordinal_scale_attributes when :time, :utc set_time_scale_attributes else set_quantitative_scale_attributes end set_common_scale_attributes ::Plotrb::Kernel.scales << self self.instance_eval(&block) if block_given? self end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/plotrb/scales.rb', line 48 def method_missing(method, *args, &block) case method.to_s when /in_(\w+)s$/ # set @nice for time and utc type, eg. in_seconds if TIME_SCALE_NICE.include?($1.to_sym) self.nice($1.to_sym, &block) else super end when /to_(\w+)$/ # set range literals, eg. to_more_colors if RANGE_LITERALS.include?($1.to_sym) self.range($1.to_sym, &block) else super end else super end end |
Instance Method Details
#type ⇒ Object
44 45 46 |
# File 'lib/plotrb/scales.rb', line 44 def type @type end |