class Plotly::Offline::HTML

Constants

DEFAULT_CONFIG
LOCAL_PLOTLY_JS
PLOTLY_JS_CDN_URL

Public Class Methods

new(id, data, layout: {}, config: DEFAULT_CONFIG, embedded: false) click to toggle source

@param id [String] @param data [Array] @option layout [Hash] @option config [Hash] @option embedded [Boolean]

# 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

Public Instance Methods

render() click to toggle source

@return [String] HTML document

# 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_iruby() click to toggle source

This method is used to embed plots into IRuby notebooks. @return [Array]

# File lib/plotly/offline/html.rb, line 34
def to_iruby
  ['text/html', render]
end

Private Instance Methods

template_for(name) click to toggle source
# File lib/plotly/offline/html.rb, line 40
def template_for(name)
  template_path = File.expand_path("../templates/#{name}.erb", __FILE__)
  File.read(template_path)
end