Module: Plotly::Exportable

Included in:
Plot
Defined in:
lib/plotly/exportable.rb

Instance Method Summary collapse

Instance Method Details

#download_image(format: :png, path: 'plot.png', client: ::Plotly.client, width: nil, height: nil, scale: nil) ⇒ Object

Parameters:

  • format (Hash) (defaults to: :png)

    a customizable set of options

  • path (Hash) (defaults to: 'plot.png')

    a customizable set of options

  • width (Hash) (defaults to: nil)

    a customizable set of options

  • height (Hash) (defaults to: nil)

    a customizable set of options

  • scale (Hash) (defaults to: nil)

    a customizable set of options

  • client (Hash) (defaults to: ::Plotly.client)

    a customizable set of options

Options Hash (format:):

  • (String)

Options Hash (path:):

  • (String)

Options Hash (client:):

Options Hash (width:):

  • (FIxnum)

Options Hash (height:):

  • (FIxnum)

Options Hash (scale:):

  • (FIxnum)


9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/plotly/exportable.rb', line 9

def download_image(format: :png, path: 'plot.png', client: ::Plotly.client,
                   width: nil, height: nil, scale: nil)
  payload = {
    figure: { data: @data.map(&:to_h), layout: @layout.to_h },
    format: format
  }
  payload[:height] = height unless height.nil?
  payload[:width]  = width  unless width.nil?
  payload[:scale]  = scale  unless scale.nil?

  res = client.conn.post('images', payload.to_json)
  IO.binwrite(path, res.body)
end