Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9a9876f

Browse filesBrowse files
authored
Merge pull request #1572 from ropensci/ggplot2-dev
Account for new changes in ggplot2's internal API, fixes #1561
2 parents ecf3b39 + 9aaffa2 commit 9a9876f
Copy full SHA for 9a9876f

File tree

Expand file treeCollapse file tree

6 files changed

+25
-21
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+25
-21
lines changed

‎R/ggplotly.R

Copy file name to clipboardExpand all lines: R/ggplotly.R
+16-17Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,10 @@ gg2list <- function(p, width = NULL, height = NULL,
506506
layout$layout$xanchor <- paste0("y", sub("^1$", "", layout$layout$xanchor))
507507
layout$layout$yanchor <- paste0("x", sub("^1$", "", layout$layout$yanchor))
508508
# for some layers2traces computations, we need the range of each panel
509-
layout$layout$x_min <- sapply(layout$panel_params, function(z) min(z$x.range %||% z$x_range))
510-
layout$layout$x_max <- sapply(layout$panel_params, function(z) max(z$x.range %||% z$x_range))
511-
layout$layout$y_min <- sapply(layout$panel_params, function(z) min(z$y.range %||% z$y_range))
512-
layout$layout$y_max <- sapply(layout$panel_params, function(z) max(z$y.range %||% z$y_range))
509+
layout$layout$x_min <- sapply(layout$panel_params, function(z) { min(z[["x"]]$dimension %()% z$x.range %||% z$x_range) })
510+
layout$layout$x_max <- sapply(layout$panel_params, function(z) { max(z[["x"]]$dimension %()% z$x.range %||% z$x_range) })
511+
layout$layout$y_min <- sapply(layout$panel_params, function(z) { min(z[["y"]]$dimension %()% z$y.range %||% z$y_range) })
512+
layout$layout$y_max <- sapply(layout$panel_params, function(z) { max(z[["y"]]$dimension %()% z$y.range %||% z$y_range) })
513513

514514
# layers -> plotly.js traces
515515
plot$tooltip <- tooltip
@@ -566,7 +566,7 @@ gg2list <- function(p, width = NULL, height = NULL,
566566
)
567567
# allocate enough space for the _longest_ text label
568568
axisTextX <- theme[["axis.text.x"]] %||% theme[["axis.text"]]
569-
labz <- unlist(lapply(layout$panel_params, "[[", "x.labels"))
569+
labz <- unlist(lapply(layout$panel_params, function(pp) { pp[["x"]]$get_labels %()% pp$x.labels }))
570570
lab <- labz[which.max(nchar(labz))]
571571
panelMarginY <- panelMarginY + axisTicksX +
572572
bbox(lab, axisTextX$angle, unitConvert(axisTextX, "npc", "height"))[["height"]]
@@ -578,7 +578,7 @@ gg2list <- function(p, width = NULL, height = NULL,
578578
)
579579
# allocate enough space for the _longest_ text label
580580
axisTextY <- theme[["axis.text.y"]] %||% theme[["axis.text"]]
581-
labz <- unlist(lapply(layout$panel_params, "[[", "y.labels"))
581+
labz <- unlist(lapply(layout$panel_params, function(pp) { pp[["y"]]$get_labels %()% pp$y.labels }))
582582
lab <- labz[which.max(nchar(labz))]
583583
panelMarginX <- panelMarginX + axisTicksY +
584584
bbox(lab, axisTextY$angle, unitConvert(axisTextY, "npc", "width"))[["width"]]
@@ -615,7 +615,10 @@ gg2list <- function(p, width = NULL, height = NULL,
615615
idx <- rng$graticule$type == direction & !is.na(rng$graticule$degree_label)
616616
tickData <- rng$graticule[idx, ]
617617
# TODO: how to convert a language object to unicode character string?
618-
rng[[paste0(xy, ".labels")]] <- as.character(tickData[["degree_label"]])
618+
rng[[paste0(xy, ".labels")]] <- sub(
619+
"\\*\\s+degree[ ]?[\\*]?", "&#176;",
620+
gsub("\"", "", tickData[["degree_label"]])
621+
)
619622
rng[[paste0(xy, ".major")]] <- tickData[[paste0(xy, "_start")]]
620623

621624
# If it doesn't already exist (for this panel),
@@ -650,14 +653,7 @@ gg2list <- function(p, width = NULL, height = NULL,
650653
tickExists <- with(rng$graticule, sapply(degree_label, is.language))
651654
if (sum(tickExists) == 0) {
652655
theme$axis.ticks.length <- 0
653-
} else{
654-
# convert the special *degree expression in plotmath to HTML entity
655-
# TODO: can this be done more generally for all ?
656-
rng[[paste0(xy, ".labels")]] <- sub(
657-
"\\*\\s+degree[ ]?[\\*]?", "&#176;", rng[[paste0(xy, ".labels")]]
658-
)
659656
}
660-
661657
}
662658

663659
# stuff like layout$panel_params is already flipped, but scales aren't
@@ -687,16 +683,19 @@ gg2list <- function(p, width = NULL, height = NULL,
687683
isDiscrete <- identical(sc$scale_name, "position_d")
688684
isDiscreteType <- isDynamic && isDiscrete
689685

686+
ticktext <- rng[[xy]]$get_labels %()% rng[[paste0(xy, ".labels")]]
687+
tickvals <- rng[[xy]]$break_positions %()% rng[[paste0(xy, ".major")]]
688+
690689
axisObj <- list(
691690
# TODO: log type?
692691
type = if (isDateType) "date" else if (isDiscreteType) "category" else "linear",
693692
autorange = isDynamic,
694693
range = rng[[paste0(xy, ".range")]] %||% rng[[paste0(xy, "_range")]],
695694
tickmode = if (isDynamic) "auto" else "array",
696-
ticktext = rng[[paste0(xy, ".labels")]],
697-
tickvals = rng[[paste0(xy, ".major")]],
695+
ticktext = ticktext,
696+
tickvals = tickvals,
698697
categoryorder = "array",
699-
categoryarray = rng[[paste0(xy, ".labels")]],
698+
categoryarray = ticktext,
700699
nticks = nrow(rng),
701700
ticks = if (is_blank(axisTicks)) "" else "outside",
702701
tickcolor = toRGB(axisTicks$colour),

‎R/utils.R

Copy file name to clipboardExpand all lines: R/utils.R
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ is.discrete <- function(x) {
3636
if (length(x) > 0 || is_blank(x)) x else y
3737
}
3838

39+
"%()%" <- function(x, y) {
40+
if (is.function(x)) return(x())
41+
y
42+
}
43+
3944
# kind of like %||%, but only respects user-defined defaults
4045
# (instead of defaults provided in the build step)
4146
"%|D|%" <- function(x, y) {

‎tests/figs/geom-sf/sf-aspect.svg

Copy file name to clipboardExpand all lines: tests/figs/geom-sf/sf-aspect.svg
+1-1Lines changed: 1 addition & 1 deletion
Loading

‎tests/figs/geom-sf/sf-fill-text.svg

Copy file name to clipboardExpand all lines: tests/figs/geom-sf/sf-fill-text.svg
+1-1Lines changed: 1 addition & 1 deletion
Loading

‎tests/figs/geom-sf/sf-points.svg

Copy file name to clipboardExpand all lines: tests/figs/geom-sf/sf-points.svg
+1-1Lines changed: 1 addition & 1 deletion
Loading

‎tests/figs/geom-sf/sf.svg

Copy file name to clipboardExpand all lines: tests/figs/geom-sf/sf.svg
+1-1Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.