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.
58 59 60 61 |
# File 'lib/plot/mark.rb', line 58 def initialize(type, **) @type = type @options = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
56 57 58 |
# File 'lib/plot/mark.rb', line 56 def @options end |
#type ⇒ Object
Returns the value of attribute type.
56 57 58 |
# File 'lib/plot/mark.rb', line 56 def type @type end |
Instance Method Details
#add_option(k, v) ⇒ Object
63 64 65 |
# File 'lib/plot/mark.rb', line 63 def add_option(k, v) @options[k.to_s] = v end |
#render(data) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/plot/mark.rb', line 68 def render(data) @options.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 |