12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/iruby-plotly.rb', line 12
def self.plot(data, options = {})
if data.respond_to?(:keys)
options = options.merge(data)
if data.include?(:xy) then
data = data.clone
data[:x] = data[:xy].map(&:first)
data[:y] = data[:xy].map(&:last)
data.delete(:xy)
end
data = [data]
elsif not data.first.respond_to?(:keys)
data = [{y:data, x:(1..data.size).to_a}.merge(options)]
end
IRuby.convert({data: data, layout: {height: DEFAULT_PLOT_HEIGHT}.merge(options)}, mime: "application/vnd.plotly.v1+json")
end
|