Class: Plot::Mark
- Inherits:
-
Object
- Object
- Plot::Mark
- Defined in:
- lib/plot/mark.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #add_option(k, v) ⇒ Object
-
#initialize(type, **options) ⇒ Mark
constructor
A new instance of Mark.
- #render(data) ⇒ Object
Constructor Details
#initialize(type, **options) ⇒ Mark
Returns a new instance of Mark.
68 69 70 71 |
# File 'lib/plot/mark.rb', line 68 def initialize(type, **) @type = type = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
66 67 68 |
# File 'lib/plot/mark.rb', line 66 def end |
#type ⇒ Object
Returns the value of attribute type.
66 67 68 |
# File 'lib/plot/mark.rb', line 66 def type @type end |
Instance Method Details
#add_option(k, v) ⇒ Object
73 74 75 |
# File 'lib/plot/mark.rb', line 73 def add_option(k, v) [k.to_s] = v end |
#render(data) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/plot/mark.rb', line 78 def render(data) .values do |o| if o.try(:value).try(:lambda?) output = [] data.each? do |obj| output.push(o.call(obj)) end o.value = output end if o.try(:transform).try(:lambda?) o.value = o.transform.call(data).to_a o.transform = nil end end data.each do |d| d.each do |k,v| if v.class == Date then d[k] = { date: true, string: v.to_s } end end end "Plot['#{@type}'](JSON.parse(`#{JSON.generate(data)}`).map((obj) => { Object.keys(obj).forEach((k) => { if (obj[k].date) { obj[k] = new Date(Date.parse(obj[k].string)) } } ); return obj; }), JSON.parse('#{JSON.generate(@options)}'))" end |