-
Notifications
You must be signed in to change notification settings - Fork 634
Updates to better support dendrograms #818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
a6663c4
208eed4
9489610
4dcdebb
10936b4
f7cce29
7862f00
3e63f3c
16d097b
dac04d2
180fcfd
183b39f
88110c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,7 @@ layers2traces <- function(data, prestats_data, layout, p) { | |
d <- datz[[i]] | ||
# variables that produce multiple traces and deserve their own legend entries | ||
split_legend <- paste0(names(discreteScales), "_plotlyDomain") | ||
show_legend <- paste0(names(Filter(function(x) x$guide != "none", discreteScales)), "_plotlyDomain") | ||
# add variable that produce multiple traces, but do _not_ deserve entries | ||
split_by <- c(split_legend, "PANEL", "frame", split_on(d)) | ||
# ensure the factor level orders (which determines traces order) | ||
|
@@ -120,7 +121,7 @@ layers2traces <- function(data, prestats_data, layout, p) { | |
trs <- Map(function(x, y) { x$set <- attr(y, "set"); x}, trs, dl) | ||
# if we need a legend, set name/legendgroup/showlegend | ||
# note: this allows us to control multiple traces from one legend entry | ||
if (any(split_legend %in% names(d))) { | ||
if (any(show_legend %in% names(d))) { | ||
nms <- strsplit(names(trs), separator, fixed = TRUE) | ||
nms <- vapply(nms, function(x) { | ||
y <- unique(x[seq_along(split_legend)]) | ||
|
@@ -254,11 +255,26 @@ to_basic.GeomSegment <- function(data, prestats_data, layout, params, p, ...) { | |
to_basic.GeomRect <- function(data, prestats_data, layout, params, p, ...) { | ||
data$group <- seq_len(nrow(data)) | ||
others <- data[!names(data) %in% c("xmin", "ymin", "xmax", "ymax", "y", "x")] | ||
if (inherits(p$coordinates, "CoordFlip")) { | ||
x_min <- layout$y_min | ||
x_max <- layout$y_max | ||
y_min <- layout$x_min | ||
y_max <- layout$x_max | ||
} else { | ||
x_min <- layout$x_min | ||
x_max <- layout$x_max | ||
y_min <- layout$y_min | ||
y_max <- layout$y_max | ||
} | ||
dat <- with(data, { | ||
rbind(cbind(x = xmin, y = ymin, others), | ||
cbind(x = xmin, y = ymax, others), | ||
cbind(x = xmax, y = ymax, others), | ||
cbind(x = xmax, y = ymin, others)) | ||
rbind(cbind(x = ifelse(xmin == -Inf, x_min, xmin), | ||
y = ifelse(ymin == -Inf, y_min, ymin), others), | ||
cbind(x = ifelse(xmin == -Inf, x_min, xmin), | ||
y = ifelse(ymax == Inf, y_max, ymax), others), | ||
cbind(x = ifelse(xmax == Inf, x_max, xmax), | ||
y = ifelse(ymax == Inf, y_max, ymax), others), | ||
cbind(x = ifelse(xmax == Inf, x_max, xmax), | ||
y = ifelse(ymin == -Inf, y_min, ymin), others)) | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps it's better (more efficient) to use |
||
prefix_class(dat, c("GeomPolygon", "GeomRect")) | ||
} | ||
|
@@ -603,10 +619,15 @@ geom2trace.GeomBoxplot <- function(data, params, p) { | |
|
||
#' @export | ||
geom2trace.GeomText <- function(data, params, p) { | ||
text <- as.character(data[["label"]]) | ||
i_ind <- grepl("italic", data[["fontface"]]) | ||
text[i_ind] <- paste0("<i>", text[i_ind], "</i>") | ||
b_ind <- grepl("bold", data[["fontface"]]) | ||
text[b_ind] <- paste0("<b>", text[b_ind], "</b>") | ||
compact(list( | ||
x = data[["x"]], | ||
y = data[["y"]], | ||
text = data[["label"]], | ||
text = text, | ||
key = data[["key"]], | ||
frame = data[["frame"]], | ||
ids = data[["ids"]], | ||
|
@@ -618,6 +639,14 @@ geom2trace.GeomText <- function(data, params, p) { | |
aes2plotly(data, params, "alpha") | ||
) | ||
), | ||
textposition = paste0( | ||
ifelse(data[["vjust"]] < 0.5, "top ", | ||
ifelse(data[["vjust"]] > 0.5, "bottom ", "") | ||
), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the trailing whitespace be removed here (e.g., There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, nevermind. I see why it's done this why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should default to |
||
ifelse(data[["hjust"]] < 0.5, "right", | ||
ifelse(data[["vjust"]] > 0.5, "left", "center") | ||
) | ||
), | ||
type = "scatter", | ||
mode = "text", | ||
hoveron = hover_on(data) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,3 +139,36 @@ test_that('Specifying alpha in hex color code works', { | |
expect_match(info$data[[1]]$fillcolor, "rgba\\(0,0,0,0\\.0[6]+") | ||
}) | ||
|
||
p1 = ggplot(data.frame(x = 1, y = 1)) + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be great to have another test that specifying |
||
geom_point(aes(x = x, y = y)) + | ||
geom_rect(xmin = 0.9, xmax = 1.1, ymin = -Inf, ymax = Inf) | ||
p2 = ggplot(data.frame(x = 1, y = 1)) + | ||
geom_point(aes(x = x, y = y)) + | ||
geom_rect(ymin = 0.9, ymax = 1.1, xmin = -Inf, xmax = Inf) + | ||
coord_flip() | ||
info1 <- save_outputs(p1, "rect-vert-inf") | ||
info2 <- save_outputs(p2, "rect-vert-flip-inf") | ||
|
||
test_that("rect vertical inf is translated correctly", { | ||
expect_identical(info1$data[[2]]$x, c(0.9, 0.9, 1.1, 1.1, 0.9)) | ||
expect_identical(info1$data[[2]]$y, c(0.5, 1.5, 1.5, 0.5, 0.5)) | ||
expect_identical(info2$data[[2]]$x, c(0.9, 1.1, 1.1, 0.9, 0.9)) | ||
expect_identical(info2$data[[2]]$y, c(0.5, 0.5, 1.5, 1.5, 0.5)) | ||
}) | ||
|
||
p3 = ggplot(data.frame(x = 1, y = 1)) + | ||
geom_point(aes(x = x, y = y)) + | ||
geom_rect(ymin = 0.9, ymax = 1.1, xmin = -Inf, xmax = Inf) | ||
p4 = ggplot(data.frame(x = 1, y = 1)) + | ||
geom_point(aes(x = x, y = y)) + | ||
geom_rect(xmin = 0.9, xmax = 1.1, ymin = -Inf, ymax = Inf) + | ||
coord_flip() | ||
info3 <- save_outputs(p3, "rect-hor-inf") | ||
info4 <- save_outputs(p4, "rect-hor-flip-inf") | ||
|
||
test_that("rect horizontal inf is translated correctly", { | ||
expect_identical(info4$data[[2]]$y, c(0.9, 0.9, 1.1, 1.1, 0.9)) | ||
expect_identical(info4$data[[2]]$x, c(0.5, 1.5, 1.5, 0.5, 0.5)) | ||
expect_identical(info3$data[[2]]$y, c(0.9, 1.1, 1.1, 0.9, 0.9)) | ||
expect_identical(info3$data[[2]]$x, c(0.5, 0.5, 1.5, 1.5, 0.5)) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a lot of redundant code...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I've simplified things a bit.