I know this should really be done with relayout, but nevertheless, I found the behavior surprising.
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:
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;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