Skip to content

Commit 1e493bd

Browse files
committed
merge conflicts
2 parents 46588d6 + 3bf9f04 commit 1e493bd

File tree

5 files changed

+41
-5
lines changed

5 files changed

+41
-5
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: plotly
22
Title: Create Interactive Web Graphics via 'plotly.js'
3-
Version: 4.5.5
3+
Version: 4.5.5.9000
44
Authors@R: c(person("Carson", "Sievert", role = c("aut", "cre"),
55
email = "[email protected]"),
66
person("Chris", "Parmer", role = c("aut", "cph"),

NEWS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# 4.5.5.9000
2+
3+
## BUG FIXES
4+
5+
* When `height`/`width` are specified in `ggplotly()`, relative sizes are now translated correctly. Fixes #489 and #510.
6+
* More careful handling of font when expanding annotation arrays. Fixes #738.
7+
* Ignore data arrays of non-tidy traces. Fixes #737.
8+
19
# 4.5.5 -- 28 September 2016
210

311
## NEW FEATURES

R/ggplotly.R

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all",
115115
# https://github.com/hadley/ggplot2/blob/0cd0ba/R/plot-build.r#L18-L92
116116
# ------------------------------------------------------------------------
117117

118+
# open a new graphics device, so we can convert relative sizes correctly
119+
# if height/width is not specified, estimate it from the current device
120+
deviceWidth <- width %||% unitConvert(grid::unit(1, "npc"), "pixels", "width")
121+
deviceHeight <- height %||% unitConvert(grid::unit(1, "npc"), "pixels", "height")
122+
tmpPlotFile <- tempfile(fileext = ".png")
123+
grDevices::png(tmpPlotFile, width = deviceWidth, height = deviceHeight)
124+
125+
118126
plot <- ggfun("plot_clone")(p)
119127
if (length(plot$layers) == 0) {
120128
plot <- plot + geom_blank()
@@ -480,14 +488,15 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all",
480488
# npc is on a 0-1 scale of the _entire_ device,
481489
# but these units _should_ be wrt to the plotting region
482490
# multiplying the offset by 2 seems to work, but this is a terrible hack
483-
offset <- 1.75 * offset
484491
x <- if (xy == "x") 0.5 else offset
485492
y <- if (xy == "x") offset else 0.5
486493
gglayout$annotations <- c(
487494
gglayout$annotations,
488495
make_label(
489496
faced(axisTitleText, axisTitle$face), x, y, el = axisTitle,
490-
xanchor = "center", yanchor = "middle", annotationType = "axis"
497+
xanchor = if (xy == "x") "center" else "right",
498+
yanchor = if (xy == "x") "top" else "center",
499+
annotationType = "axis"
491500
)
492501
)
493502
}
@@ -719,6 +728,11 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all",
719728
gglayout$width <- width
720729
gglayout$height <- height
721730

731+
# we're now done with converting units, turn off the device,
732+
# and remove the temporary file
733+
grDevices::dev.off()
734+
unlink(tmpPlotFile)
735+
722736
l <- list(
723737
data = setNames(traces, NULL),
724738
layout = compact(gglayout),

R/plotly_build.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,14 @@ plotly_build.plotly <- function(p) {
4343

4444
# if an annotation attribute is an array, expand into multiple annotations
4545
nAnnotations <- max(lengths(x$annotations) %||% 0)
46+
# font is the only list object, so store it, and attach after transposing
47+
font <- x$annotations[["font"]]
4648
x$annotations <- purrr::transpose(lapply(x$annotations, function(x) {
4749
as.list(rep(x, length.out = nAnnotations))
4850
}))
51+
for (i in seq_len(nAnnotations)) {
52+
x$annotations[[i]][["font"]] <- font
53+
}
4954

5055
x[lengths(x) > 0]
5156

@@ -141,8 +146,8 @@ plotly_build.plotly <- function(p) {
141146
isArray <- lapply(Attrs, function(x) {
142147
tryCatch(identical(x[["valType"]], "data_array"), error = function(e) FALSE)
143148
})
144-
# I don't think we ever want mesh3d's data attrs
145-
dataArrayAttrs <- if (identical(trace[["type"]], "mesh3d")) NULL else names(Attrs)[as.logical(isArray)]
149+
# "non-tidy" traces allow x/y of different lengths, so ignore those
150+
dataArrayAttrs <- if (is_tidy(trace)) names(Attrs)[as.logical(isArray)]
146151
allAttrs <- c(
147152
dataArrayAttrs, special_attrs(trace), npscales(),
148153
# for some reason, text isn't listed as a data array in some traces

R/utils.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ getLevels <- function(x) {
4747
if (is.factor(x)) levels(x) else sort(unique(x))
4848
}
4949

50+
# Don't attempt to do "tidy" data training on these trace types
51+
is_tidy <- function(trace) {
52+
type <- trace[["type"]] %||% "scatter"
53+
!type %in% c(
54+
"mesh3d", "heatmap", "histogram2d",
55+
"histogram2dcontour", "contour", "surface"
56+
)
57+
}
58+
5059
# is grouping relevant for this geometry? (e.g., grouping doesn't effect a scatterplot)
5160
has_group <- function(trace) {
5261
inherits(trace, paste0("plotly_", c("segment", "path", "line", "polygon"))) ||

0 commit comments

Comments
 (0)