Skip to content

Commit e07f80c

Browse files
committed
make a deep copy of x.layout.width/x.layout.height for use in the resize method, closes #1553
1 parent 2a439bc commit e07f80c

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

inst/htmlwidgets/plotly.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ HTMLWidgets.widget({
1717

1818
renderValue: function(el, x, instance) {
1919

20+
// Make a deep copy of user data that we need for the resize method
21+
// (Plotly.relayout() mutates the plot input object -- https://codepen.io/cpsievert/pen/WNeOrjj)
22+
instance.width = JSON.parse(JSON.stringify(x.layout.width || null));
23+
instance.height = JSON.parse(JSON.stringify(x.layout.height || null));
24+
instance.autosize = JSON.parse(JSON.stringify(x.layout.autosize || true));
25+
2026
/*
2127
/ 'inform the world' about highlighting options this is so other
2228
/ crosstalk libraries have a chance to respond to special settings
@@ -153,17 +159,9 @@ HTMLWidgets.widget({
153159

154160
var plot = Plotly.plot(graphDiv, x);
155161
instance.plotly = true;
156-
instance.autosize = x.layout.autosize || true;
157-
instance.width = x.layout.width;
158-
instance.height = x.layout.height;
159162

160163
} else {
161164

162-
// new x data could contain a new height/width...
163-
// attach to instance so that resize logic knows about the new size
164-
instance.width = x.layout.width || instance.width;
165-
instance.height = x.layout.height || instance.height;
166-
167165
// this is essentially equivalent to Plotly.newPlot(), but avoids creating
168166
// a new webgl context
169167
// https://github.com/plotly/plotly.js/blob/2b24f9def901831e61282076cf3f835598d56f0e/src/plot_api/plot_api.js#L531-L532

0 commit comments

Comments
 (0)