SciNim / nim-plotly

plotly wrapper for nim-lang
https://scinim.github.io/nim-plotly/
MIT License
173 stars 15 forks source link

feature: resizing plot #38

Open timotheecour opened 5 years ago

timotheecour commented 5 years ago

/cc @Vindaar

image

Vindaar commented 5 years ago

The plot size isn't hardcoded. You can either change it by creating the plot manually, e.g.

  # assuming x, y contains some data
  let d = Trace[float64](mode: PlotMode.LinesMarkers, `type`: PlotType.Scatter,
                         xs: x, ys: y)
  let layout = Layout(width: 1200, height: 400,
                      autosize: false)
  Plot[float64](layout: layout, traces: @[d]).show()

and change the layout to whatever you like. Or if you're using the procs from plotly_sugar, you may modify the code as such:

plotScatter(x, y)
  .width(1200)
  .height(400)
  .show()

If you specifically refer to modifying the plot when it's being shown in the browser, hmm. I don't think making the div in which the plot is shown resizable will actually change the plot size.

timotheecour commented 5 years ago

If you specifically refer to modifying the plot when it's being shown in the browser, hmm.

ya that's exactly what i meant

I don't think making the div in which the plot is shown resizable will actually change the plot size

so there's a few options here, some simple, some less, but still useful and better that status quo, eg:

then after resizing window:

image

since SVG is used, this should all be possible with javascript (and no need for server communication), correct?

brentp commented 5 years ago

maybe I misunderstand, but we can use e.g.:

window.onresize = function() {
  Plotly.Plots.resize('plot-div');
 };

as here

timotheecour commented 5 years ago

yes, perfect! this shd be the new default IMO

timotheecour commented 5 years ago

@brentp somehow ur suggestion https://github.com/brentp/nim-plotly/issues/38#issuecomment-457788772 didn't work ; but let's followup here https://github.com/brentp/nim-plotly/pull/39