Skip to content

Commit

Permalink
make a deep copy of x.layout.width/x.layout.height for use in the res…
Browse files Browse the repository at this point in the history
…ize method, closes #1553
  • Loading branch information
cpsievert committed Aug 28, 2019
1 parent 2a439bc commit e07f80c
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions inst/htmlwidgets/plotly.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ HTMLWidgets.widget({

renderValue: function(el, x, instance) {

// Make a deep copy of user data that we need for the resize method
// (Plotly.relayout() mutates the plot input object -- https://codepen.io/cpsievert/pen/WNeOrjj)
instance.width = JSON.parse(JSON.stringify(x.layout.width || null));
instance.height = JSON.parse(JSON.stringify(x.layout.height || null));
instance.autosize = JSON.parse(JSON.stringify(x.layout.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 +159,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

0 comments on commit e07f80c

Please sign in to comment.