Skip to content

Better resizing logic #1575

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

Merged
merged 2 commits into from
Oct 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions inst/htmlwidgets/plotly.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ HTMLWidgets.widget({

renderValue: function(el, x, instance) {

// Plotly.relayout() mutates the plot input object, so make sure to
// keep a reference to the user-supplied width/height *before*
// we call Plotly.plot();
var lay = x.layout || {};
instance.width = lay.width;
instance.height = lay.height;
instance.autosize = lay.autosize || true;

/*
/ 'inform the world' about highlighting options this is so other
/ crosstalk libraries have a chance to respond to special settings
Expand Down Expand Up @@ -153,17 +161,9 @@ HTMLWidgets.widget({

var plot = Plotly.plot(graphDiv, x);
instance.plotly = true;
instance.autosize = x.layout.autosize || true;
instance.width = x.layout.width;
instance.height = x.layout.height;

} else {

// new x data could contain a new height/width...
// attach to instance so that resize logic knows about the new size
instance.width = x.layout.width || instance.width;
instance.height = x.layout.height || instance.height;

// this is essentially equivalent to Plotly.newPlot(), but avoids creating
// a new webgl context
// https://github.com/plotly/plotly.js/blob/2b24f9def901831e61282076cf3f835598d56f0e/src/plot_api/plot_api.js#L531-L532
Expand Down