class Plotrb::Mark
Marks are the basic visual building block of a visualization. See {github.com/trifacta/vega/wiki/Marks}
Constants
- MARK_PROPERTIES
@!attributes type
@return [Symbol] the mark type
@!attributes name
@return [String] the name of the mark
@!attributes description
@return [String] optional description of the mark
@!attributes from
@return [Hash] the data this mark set should visualize
@!attributes properties
@return [MarkProperty] the property set definitions
@!attributes key
@return [String] the data field to use an unique key for data binding
@!attributes delay
@return [ValueRef] the transition delay for mark updates
@!attributes ease
@return [String] the transition easing function for mark updates
- TYPES
all available types of marks defined by Vega
Public Class Methods
new(type, &block)
click to toggle source
# File lib/plotrb/marks.rb, line 41 def initialize(type, &block) @type = type @properties = {} define_single_val_attributes(:name, :description, :key, :delay, :ease, :group) define_multi_val_attributes(:from) if @type == :group add_attributes(:scales, :axes, :marks) define_multi_val_attributes(:scales, :axes, :marks) end ::Plotrb::Kernel.marks << self self.instance_eval(&block) if block_given? self end
Public Instance Methods
enter(&block)
click to toggle source
# File lib/plotrb/marks.rb, line 64 def enter(&block) process_from data = @from[:data] if @from @properties.merge!( { enter: ::Plotrb::Mark::MarkProperty. new(@type, data, &block) } ) self end
exit(&block)
click to toggle source
# File lib/plotrb/marks.rb, line 74 def exit(&block) process_from data = @from[:data] if @from @properties.merge!( { exit: ::Plotrb::Mark::MarkProperty. new(@type, data, &block) } ) self end
hover(&block)
click to toggle source
# File lib/plotrb/marks.rb, line 94 def hover(&block) process_from data = @from[:data] if @from @properties.merge!( { hover: ::Plotrb::Mark::MarkProperty. new(@type, data, &block) } ) self end
properties()
click to toggle source
# File lib/plotrb/marks.rb, line 60 def properties @properties end
type()
click to toggle source
# File lib/plotrb/marks.rb, line 56 def type @type end
update(&block)
click to toggle source
# File lib/plotrb/marks.rb, line 84 def update(&block) process_from data = @from[:data] if @from @properties.merge!( { update: ::Plotrb::Mark::MarkProperty. new(@type, data, &block) } ) self end
Private Instance Methods
attribute_post_processing()
click to toggle source
# File lib/plotrb/marks.rb, line 106 def attribute_post_processing process_name process_from process_group end
process_from()
click to toggle source
# File lib/plotrb/marks.rb, line 119 def process_from return unless @from && !@from_processed from = {} @from.each do |f| case f when String if ::Plotrb::Kernel.find_data(f) from[:data] = f else raise ArgumentError, 'Invalid data for Mark from' end when ::Plotrb::Data from[:data] = f.name when ::Plotrb::Transform from[:transform] ||= [] from[:transform] << f else raise ArgumentError, 'Invalid Mark from' end end @from = from @from_processed = true end
process_group()
click to toggle source
# File lib/plotrb/marks.rb, line 143 def process_group return unless @scales unless @scales.all? { |s| s.is_a?(::Plotrb::Scale) } raise ArgumentError, 'Invalid scales for group mark' end return unless @axes unless @axes.all? { |s| s.is_a?(::Plotrb::Axis) } raise ArgumentError, 'Invalid axes for group mark' end return unless @marks unless @marks.all? { |s| s.is_a?(::Plotrb::Mark) } raise ArgumentError, 'Invalid marks for group mark' end end
process_name()
click to toggle source
# File lib/plotrb/marks.rb, line 112 def process_name return unless @name if ::Plotrb::Kernel.duplicate_mark?(@name) raise ArgumentError, 'Duplicate Mark name' end end