Skip to content

Commit

Permalink
Use DOM el attributes to find specified height/width, closes #1553
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert committed Jul 13, 2019
1 parent 2a439bc commit e5ad4a3
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions inst/htmlwidgets/plotly.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ HTMLWidgets.widget({
},

resize: function(el, width, height, instance) {
if (instance.autosize) {
var width = instance.width || width;
var height = instance.height || height;
if (el.layout.autosize || true) {
// User specified height/width overrides htmlwidgets height/width
var width = el.layout.width || width;
var height = el.layout.height || height;
Plotly.relayout(el.id, {width: width, height: height});
}
},
Expand Down Expand Up @@ -153,17 +154,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 e5ad4a3

Please sign in to comment.