class Plotrb::Mark::MarkProperty::ValueRef
A value reference specifies the value for a given mark property
Constants
- VALUE_REF_PROPERTIES
@!attributes value
@return A constant value
@!attributes field
@return [String] A field from which to pull a data value
@!attributes scale
@return [String] the name of a scale transform to apply
@!attributes mult
@return [Numeric] a multiplier for the value
@!attributes offset
@return [Numeric] an additive offset to bias the final value
@!attributes band
@return [Boolean] whether to use range band of the scale as the retrieved value
Attributes
data[R]
Public Class Methods
new(data, value=nil, &block)
click to toggle source
# File lib/plotrb/marks.rb, line 375 def initialize(data, value=nil, &block) @data = data define_single_val_attributes(:value, :mult, :offset, :group, :field, :scale) define_boolean_attribute(:band) self.singleton_class.class_eval { alias_method :from, :field alias_method :use_band, :band alias_method :use_band?, :band? alias_method :times, :mult } if value @value = value end self.instance_eval(&block) if block self end
Private Instance Methods
attribute_post_processing()
click to toggle source
# File lib/plotrb/marks.rb, line 395 def attribute_post_processing process_scale process_field end
get_full_field_ref(field)
click to toggle source
# File lib/plotrb/marks.rb, line 437 def get_full_field_ref(field) data = if @data.is_a?(::Plotrb::Data) @data else ::Plotrb::Kernel.find_data(@data) end extra_fields = (data.extra_fields if data) || [] if field.to_s.start_with?('data.') field elsif extra_fields.include?(field.to_s.split('.')[0].to_sym) classify(field, :json) else "data.#{field}" end end
process_field()
click to toggle source
# File lib/plotrb/marks.rb, line 400 def process_field return unless @field case @field when String, Symbol @field = get_full_field_ref(@field) when Hash if @field[:group] @field[:group] = get_full_field_ref(@field[:group]) else raise ArgumentError, 'Missing field group' end else raise ArgumentError, 'Invalid value field' end end
process_scale()
click to toggle source
# File lib/plotrb/marks.rb, line 416 def process_scale return unless @scale case @scale when String unless ::Plotrb::Kernel.find_scale(@scale) raise ArgumentError, 'Invalid value scale' end when ::Plotrb::Scale @scale = @scale.name when Hash if @scale[:field] @scale[:field] = get_full_field_ref(@scale[:field]) end if @scale[:group] @scale[:group] = get_full_field_ref(@scale[:group]) end else raise ArgumentError, 'Invalid value scale' end end