Skip to content

Commit 35ab305

Browse files
committed
Revert "better autosizing rules" (why is x.layout.height/x.layout.width being populated?!?)
This reverts commit b1589d1.
1 parent 5fcdaa7 commit 35ab305

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

R/plotly.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ plot_ly <- function(data = data.frame(), ..., type = NULL,
139139
# we always deal with a _list_ of traces and _list_ of layouts
140140
# since they can each have different data
141141
layout = list(
142-
width = width,
143-
height = height,
144-
# sane margin defaults (mainly for RStudio)
145-
margin = list(b = 40, l = 60, t = 25, r = 10)
142+
width = width,
143+
height = height,
144+
# sane margin defaults (mainly for RStudio)
145+
margin = list(b = 40, l = 60, t = 25, r = 10)
146146
),
147147
source = source
148148
)
@@ -228,7 +228,7 @@ plot_geo <- function(data = data.frame(), ...) {
228228
#'
229229

230230
as_widget <- function(x, ...) {
231-
if (inherits(x, "htmlwidget")) x <- x[["x"]]
231+
if (inherits(x, "htmlwidget")) return(x)
232232
# add plotly class mainly for printing method
233233
# customize the JSON serializer (for htmlwidgets)
234234
attr(x, 'TOJSON_FUNC') <- to_JSON

R/plotly_build.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,7 @@ plotly_build.plotly <- function(p) {
333333
p <- verify_webgl(p)
334334
# make sure plots don't get sent out of the network (for enterprise)
335335
p$x$base_url <- get_domain()
336-
337-
as_widget(p)
336+
p
338337
}
339338

340339
# ----------------------------------------------------------------

inst/htmlwidgets/plotly.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ HTMLWidgets.widget({
1414
},
1515

1616
resize: function(el, width, height, instance) {
17-
var width = instance.width || width;
18-
var height = instance.height || height;
19-
Plotly.relayout(el.id, {width: width, height: height});
17+
if (instance.autosize) {
18+
Plotly.relayout(el.id, {width: width, height: height});
19+
}
2020
},
2121

2222
renderValue: function(el, x, instance) {
@@ -30,16 +30,14 @@ HTMLWidgets.widget({
3030
}
3131

3232
var graphDiv = document.getElementById(el.id);
33-
var layout = x.layout || {};
3433

3534
// if no plot exists yet, create one with a particular configuration
3635
if (!instance.plotly) {
37-
var plot = Plotly.plot(graphDiv, x.data, layout, x.config);
36+
var plot = Plotly.plot(graphDiv, x.data, x.layout, x.config);
3837
instance.plotly = true;
39-
instance.height = layout.height;
40-
instance.width = layout.width;
38+
instance.autosize = x.layout.autosize;
4139
} else {
42-
var plot = Plotly.newPlot(graphDiv, x.data, layout);
40+
var plot = Plotly.newPlot(graphDiv, x.data, x.layout);
4341
}
4442

4543
sendEventData = function(eventType) {

0 commit comments

Comments
 (0)