Class: Plotrb::Mark

Inherits:
Object show all
Includes:
Base
Defined in:
lib/plotrb/marks.rb

Overview

Marks are the basic visual building block of a visualization. See https://github.com/trifacta/vega/wiki/Marks

Defined Under Namespace

Classes: MarkProperty

Constant Summary collapse

TYPES =

all available types of marks defined by Vega

%i(rect symbol path arc area line image text group)
MARK_PROPERTIES =
[:type, :name, :description, :from, :properties, :key,
:delay, :ease, :group]

Instance Method Summary collapse

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) ⇒ Mark

Returns a new instance of Mark.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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

Instance Method Details

#enter(&block) ⇒ Object



64
65
66
67
68
69
70
71
72
# 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) ⇒ Object



74
75
76
77
78
79
80
81
82
# 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) ⇒ Object



94
95
96
97
98
99
100
101
102
# 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

#propertiesObject



60
61
62
# File 'lib/plotrb/marks.rb', line 60

def properties
  @properties
end

#typeObject



56
57
58
# File 'lib/plotrb/marks.rb', line 56

def type
  @type
end

#update(&block) ⇒ Object



84
85
86
87
88
89
90
91
92
# 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