Class: Plotly::Offline::HTML

Inherits:
Object
  • Object
show all
Defined in:
lib/plotly/offline/html.rb

Constant Summary collapse

DEFAULT_CONFIG =
{ linkText: 'Export to plot.ly', showLink: true }.freeze
PLOTLY_JS_CDN_URL =
'https://cdn.plot.ly/plotly-latest.min'.freeze
LOCAL_PLOTLY_JS =
File.read(File.expand_path('../plotly.min.js', __FILE__))

Instance Method Summary collapse

Constructor Details

#initialize(id, data, layout: {}, config: DEFAULT_CONFIG, embedded: false) ⇒ HTML

Returns a new instance of HTML.

Options Hash (layout:):

  • (Hash)

Options Hash (config:):

  • (Hash)

Options Hash (embedded:):

  • (Boolean)


16
17
18
19
20
21
22
# File 'lib/plotly/offline/html.rb', line 16

def initialize(id, data, layout: {}, config: DEFAULT_CONFIG, embedded: false)
  @id       = id
  @data     = data
  @layout   = layout
  @config   = config
  @embedded = embedded
end

Instance Method Details

#renderString



25
26
27
28
29
30
# File 'lib/plotly/offline/html.rb', line 25

def render
  template_name = @embedded ? :body : :plot
  template = template_for(template_name)
  erb = ERB.new(template)
  erb.result(binding)
end

#to_irubyArray

This method is used to embed plots into IRuby notebooks.



34
35
36
# File 'lib/plotly/offline/html.rb', line 34

def to_iruby
  ['text/html', render]
end