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
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 |