Class: Plotrb::Visualization

Inherits:
Object
  • Object
show all
Includes:
Base, Kernel
Defined in:
lib/plotrb/visualization.rb

Overview

The container for all visual elements. See https://github.com/trifacta/vega/wiki/Visualization

Instance Method Summary collapse

Methods included from Kernel

axes, data, duplicate_data?, duplicate_mark?, duplicate_scale?, find_data, find_mark, find_scale, #legend, legends, marks, #method_missing, #pdata, scales, transforms, #visualization

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

Returns a new instance of Visualization.


33
34
35
36
37
# File 'lib/plotrb/visualization.rb', line 33

def initialize(&block)
  define_single_val_attributes(:name, :width, :height, :viewport, :padding)
  define_multi_val_attributes(:data, :scales, :marks, :axes, :legends)
  self.instance_eval(&block) if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Plotrb::Kernel

Instance Method Details

#generate_spec(format = nil) ⇒ Object


39
40
41
42
43
44
45
# File 'lib/plotrb/visualization.rb', line 39

def generate_spec(format=nil)
  if format == :pretty
    JSON.pretty_generate(self.collect_attributes)
  else
    JSON.generate(self.collect_attributes)
  end
end