Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: resizing plot #38

Open
timotheecour opened this issue Jan 25, 2019 · 5 comments
Open

feature: resizing plot #38

timotheecour opened this issue Jan 25, 2019 · 5 comments

Comments

@timotheecour
Copy link
Contributor

timotheecour commented Jan 25, 2019

/cc @Vindaar

  • looking at generated html file looks like size is hardcoded to 800x600; i think a reasonable and useful feature is ability to drag the bottom right corner of the view to make the plot bigger (ie more pixels on screen)
  • and making it easy to do so by adding a border ; right now it's invisible

image

@Vindaar
Copy link
Member

Vindaar commented Jan 26, 2019

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
Copy link
Contributor Author

timotheecour commented Jan 26, 2019

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:

  • easiest: just zooming to fit the dragged div size (so everything will look proportionally bigger, including fonts); it's SVG IIUC so there shd be no pixelation artifacts
  • middle: expland canvas but keep font size and scatter plot size (same behavior as say, matlab or matplotlib when u resize a window:
    image

then after resizing window:

image

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

  • (harder, probably overkill for this particular feature but most flexible for further extensions) using a callback to a proc redraw(state: State) which communicates with the server to redraw eg when dragging happens (instead of file:///private/tmp/x.html it would be localhost:someport)
    maybe out of scope for nim-plotly, although that functionality would be generally useful and can be made transparently for users, for all uses of nim-plotly

@brentp
Copy link
Collaborator

brentp commented Jan 26, 2019

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

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

as here

@timotheecour
Copy link
Contributor Author

yes, perfect! this shd be the new default IMO

@timotheecour
Copy link
Contributor Author

@brentp somehow ur suggestion #38 (comment) didn't work ; but let's followup here #39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants