Plotly.js: newPlot doesn't respect layout.height unless layout.autosize is explicitly true

Created on 15 May 2016  路  5Comments  路  Source: plotly/plotly.js

I know this should really be done with relayout, but nevertheless, I found the behavior surprising.

http://codepen.io/cpsievert/pen/yOrQya

bug

All 5 comments

I would definitively call this a bug. Thanks for bringing this up.

The root of the problem is in this block where layouts with incomplete size specifications (denoted by autosize: 'initial' internally) go through the plotAutoSize routine which overrides the user layout spec by the computed size of the graph div.

I believe the aforementioned block should instead be:

computedStyle = window.getComputedStyle(gd);
newHeight = fullLayout.height || parseFloat(computedStyle.height);
newWidth = fullLayout.width || parseFloat(computedStyle.width);

@etpinard While looking into #106 and #272 I came across this TODO and I'm looking into removing 'initial' from autosize. Since it touches the same code, I could address this issue in the same PR.

I've also found that autosize: true isn't honoured in the following cases:

  • when Plotly.plot(Tabs.fresh(), [{ x:[1,2,3], y:[3,2,1]}], {autosize: true}) is run, the graph is given the default dimensions 700x450 regardless of the dimensions of the container. Only after Plotly.relayout(gd, {autosize: true}) is run, the graph takes the dimensions of the container;
  • Plotly.relayout(gd, {}) has no effect.

In the PR I'm preparing, I'm planning to ensure that:

  • Plotly.plot(Tabs.fresh(), [{ x:[1,2,3], y:[3,2,1]}], {autosize: true}) creates a graph with the dimensions of the container;
  • and that Plotly.relayout(gd, {}) triggers plotAutoSize if autosize is set.

It looks like the issue I originally reported still persists?

It looks like the issue I originally reported still persists?

Correct. Will be done in https://github.com/plotly/plotly.js/pull/635

Was this page helpful?
0 / 5 - 0 ratings