Skip to content

Commit c7098c7

Browse files
committed
start thinking about shapes/annotations
1 parent 888999e commit c7098c7

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

R/subplots.R

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ subplot <- function(..., nrows = 1, which_layout = "merge", margin = 0.02) {
2424
# build each plot
2525
plots <- lapply(list(...), plotly_build)
2626
# rename axes, respecting the fact that each plot could be a subplot itself
27-
layouts <- lapply(plots, "[[", "layout")
2827
traces <- lapply(plots, "[[", "data")
28+
layouts <- lapply(plots, "[[", "layout")
29+
30+
annotations <- compact(lapply(layouts, "[[", "annotations"))
31+
shapes <- compact(lapply(layouts, "[[", "shapes"))
2932
xAxes <- lapply(layouts, function(x) {
3033
x[grepl("^xaxis", names(x))] %||%
3134
list(xaxis = list(domain = c(0, 1), anchor = "y"))
@@ -55,6 +58,8 @@ subplot <- function(..., nrows = 1, which_layout = "merge", margin = 0.02) {
5558
for (i in seq_along(plots)) {
5659
xMap <- xAxisMap[[i]]
5760
yMap <- yAxisMap[[i]]
61+
xDom <- as.numeric(domainInfo[i, c("xstart", "xend")])
62+
yDom <- as.numeric(domainInfo[i, c("yend", "ystart")])
5863
for (j in seq_along(xAxes[[i]])) {
5964
# before bumping axis anchor, bump trace info, where appropriate
6065
traces[[i]] <- lapply(traces[[i]], function(tr) {
@@ -64,10 +69,9 @@ subplot <- function(..., nrows = 1, which_layout = "merge", margin = 0.02) {
6469
# bump anchors
6570
map <- yMap[yMap %in% sub("y", "yaxis", xAxes[[i]][[j]]$anchor)]
6671
xAxes[[i]][[j]]$anchor <- sub("axis", "", names(map))
72+
browser()
6773
xAxes[[i]][[j]]$domain <- sort(scales::rescale(
68-
xAxes[[i]][[j]]$domain,
69-
as.numeric(domainInfo[i, c("xstart", "xend")]),
70-
from = c(0, 1)
74+
xAxes[[i]][[j]]$domain, xDom, from = c(0, 1)
7175
))
7276
}
7377
for (j in seq_along(yAxes[[i]])) {
@@ -78,9 +82,7 @@ subplot <- function(..., nrows = 1, which_layout = "merge", margin = 0.02) {
7882
map <- xMap[xMap %in% sub("x", "xaxis", yAxes[[i]][[j]]$anchor)]
7983
yAxes[[i]][[j]]$anchor <- sub("axis", "", names(map))
8084
yAxes[[i]][[j]]$domain <- sort(scales::rescale(
81-
yAxes[[i]][[j]]$domain,
82-
as.numeric(domainInfo[i, c("yend", "ystart")]),
83-
from = c(0, 1)
85+
yAxes[[i]][[j]]$domain, yDom, from = c(0, 1)
8486
))
8587
}
8688
xAxes[[i]] <- setNames(xAxes[[i]], names(xMap))

0 commit comments

Comments
 (0)