Module: IRuby

Defined in:
lib/iruby-plotly.rb

Defined Under Namespace

Modules: Display

Constant Summary collapse

DEFAULT_PLOT_HEIGHT =
800

Class Method Summary collapse

Class Method Details

.plot(data, options = {}) ⇒ Object



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: options.merge({height: DEFAULT_PLOT_HEIGHT})}, mime: "application/vnd.plotly.v1+json")
end

.plotly(data, layout = {}) ⇒ Object



28
29
30
# File 'lib/iruby-plotly.rb', line 28

def self.plotly(data, layout = {})
  IRuby.convert({data: data, layout: layout}, mime: "application/vnd.plotly.v1+json")
end