Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions R/dittoViz_ScatterPlot_module_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ dittoViz_scatterPlotServer <- function(id, data, hide.inputs = NULL, hide.tabs =
updateSelectInput(session, "color.adj.fxn", selected = .get_default(defaults, "color.adj.fxn", ""))

# Points
updateSelectInput(session, "size.by", selected = .get_default(defaults, "size.by", ""))
updateNumericInput(session, "size", value = .get_default(defaults, "size", 1, is.numeric))
updateNumericInput(session, "opacity", value = .get_default(defaults, "opacity", 1, is.numeric))
updateCheckboxInput(session, "show.others",
Expand Down Expand Up @@ -323,12 +324,6 @@ dittoViz_scatterPlotServer <- function(id, data, hide.inputs = NULL, hide.tabs =
updateTextInput(session, "legend.color.title",
value = .get_default(defaults, "legend.color.title", "make")
)
updateNumericInput(session, "legend.color.size",
value = .get_default(defaults, "legend.color.size", 5, is.numeric)
)
updateNumericInput(session, "legend.shape.size",
value = .get_default(defaults, "legend.shape.size", 5, is.numeric)
)
updateTextInput(session, "legend.color.breaks",
value = .get_default(defaults, "legend.color.breaks", "")
)
Expand All @@ -350,6 +345,12 @@ dittoViz_scatterPlotServer <- function(id, data, hide.inputs = NULL, hide.tabs =
updateCheckboxInput(session, "webgl", value = .get_default(defaults, "webgl", TRUE, is.logical))
.reset_plotly_inputs(session, defaults)
.reset_legend_inputs(session, defaults)
updateNumericInput(session, "size.legend.x",
value = .get_default(defaults, "size.legend.x", 1.04, is.numeric)
)
updateNumericInput(session, "size.legend.y",
value = .get_default(defaults, "size.legend.y", 0.35, is.numeric)
)
updateCheckboxInput(session, "do.ellipse",
value = .get_default(defaults, "do.ellipse", FALSE, is.logical)
)
Expand Down Expand Up @@ -390,6 +391,7 @@ dittoViz_scatterPlotServer <- function(id, data, hide.inputs = NULL, hide.tabs =
"add.trajectory.by.groups" = .na_to_null(isolate_fn(input$add.trajectory.by.groups)),
"color.by" = .na_to_null(isolate_fn(input$color.by)),
"shape.by" = .na_to_null(isolate_fn(input$shape.by)),
"size.by" = .na_to_null(isolate_fn(input$size.by)),
"split.by" = .na_to_null(isolate_fn(input$split.by)),
"annotate.by" = .na_to_null(isolate_fn(input$annotate.by)),
"x.adjustment" = .na_to_null(isolate_fn(input$x.adjustment)),
Expand Down Expand Up @@ -429,7 +431,8 @@ dittoViz_scatterPlotServer <- function(id, data, hide.inputs = NULL, hide.tabs =
isolate_fn(input$y.by),
paste0(isolate_fn(input$y.by), ".y.adj"),
null.na.inputs$shape.by,
null.na.inputs$split.by
null.na.inputs$split.by,
null.na.inputs$size.by
))
} else {
hover.data <- unique(c(null.na.inputs$hover.data, null.na.inputs$annotate.by))
Expand All @@ -453,7 +456,11 @@ dittoViz_scatterPlotServer <- function(id, data, hide.inputs = NULL, hide.tabs =
color.by = null.na.inputs$color.by,
shape.by = null.na.inputs$shape.by,
split.by = null.na.inputs$split.by,
size = isolate_fn(input$size),
size = if (!is.null(null.na.inputs$size.by)) {
null.na.inputs$size.by
} else {
isolate_fn(input$size)
},
show.others = isolate_fn(input$show.others),
x.adjustment = null.na.inputs$x.adjustment,
y.adjustment = null.na.inputs$y.adjustment,
Expand Down Expand Up @@ -490,11 +497,9 @@ dittoViz_scatterPlotServer <- function(id, data, hide.inputs = NULL, hide.tabs =
do.ellipse = isolate_fn(input$do.ellipse),
legend.show = isolate_fn(input$legend.show),
legend.color.title = isolate_fn(input$legend.color.title),
legend.color.size = isolate_fn(input$legend.color.size),
legend.color.breaks = waiver.inputs$legend.color.breaks,
legend.color.breaks.labels = waiver(),
legend.shape.title = null.na.inputs$shape.by,
legend.shape.size = isolate_fn(input$legend.shape.size),
data.out = TRUE
)

Expand Down Expand Up @@ -824,6 +829,21 @@ dittoViz_scatterPlotServer <- function(id, data, hide.inputs = NULL, hide.tabs =
)
}

# Custom size legend:
# plotly drops the size legend when point size encodes a numeric
# column (see plotly.R#705), so draw a manual circle legend that
# mirrors the plotted marker sizes when `size.by` is set.
fig <- .custom_legend(
fig,
data = data(),
size_by = null.na.inputs$size.by,
gap = 0.04,
title.size = isolate_fn(input$legend.title.size),
text.size = isolate_fn(input$legend.text.size),
start_y = isolate_fn(input$size.legend.y),
start_x = isolate_fn(input$size.legend.x)
)

# Apply uniform legend title/label font sizes
fig <- .apply_legend_styling(
fig,
Expand Down
53 changes: 37 additions & 16 deletions R/dittoViz_ScatterPlot_module_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#' \item \code{sub} - Plot subtitle (not supported in plotly)
#' \item \code{theme} - ggplot2 theme (not applicable to plotly)
#' \item \code{legend.title} - Legend title (managed by plotly interactively)
#' \item \code{legend.color.size} - Legend color size (not supported in plotly)
#' \item \code{legend.shape.size} - Legend shape size (not supported in plotly)
#' \item \code{add.xline} - Use \code{vline.intercepts} instead for vertical lines with full styling options
#' \item \code{add.yline} - Use \code{hline.intercepts} instead for horizontal lines with full styling options
#' \item \code{xline.linetype} - Use \code{vline.linetypes} instead
Expand Down Expand Up @@ -54,6 +56,8 @@
#' \item \code{y.adj.fxn} - Y adjustment function (UI: "Y Adjustment Function", default: "")
#' \item \code{color.adj.fxn} - Color adjustment function (UI: "Color Adjustment Function", default: "")
#' \item \code{size} - Point size (UI: "Point Size", default: 1)
#' \item \code{size.by} - Numeric column mapped to point size (UI: "Size By", default: ""); when set,
#' a custom circle size legend is drawn since plotly cannot render a native size legend
#' \item \code{opacity} - Point opacity (UI: "Point Opacity", default: 1)
#' \item \code{show.others} - Show others (UI: "Show Others", default: TRUE)
#' \item \code{split.show.all.others} - Show split others (UI: "Show Split Others", default: TRUE)
Expand Down Expand Up @@ -83,11 +87,11 @@
#' \item \code{annotation.arrowcolor} - Arrow color (UI: "Arrow Color", default: "black")
#' \item \code{annotation.arrowhead} - Arrowhead style (UI: "Arrowhead Style", default: 2)
#' \item \code{annotation.arrowwidth} - Arrow linewidth (UI: "Arrow Linewidth", default: 1.5)
#' \item \code{legend.show} - Show legend (UI: "Show Legend", default: TRUE)
#' \item \code{legend.color.title} - Legend title (UI: "Legend Title", default: "make")
#' \item \code{legend.color.size} - Legend color size (UI: "Legend Color Size", default: 5)
#' \item \code{legend.shape.size} - Legend shape size (UI: "Legend Shape Size", default: 5)
#' \item \code{legend.color.breaks} - Legend tick breaks (UI: "Legend Tick Breaks", default: "")
#' \item \code{size.legend.x} - Custom size-legend x position (UI: "Size Legend X Position",
#' default: 1.02); nudges the manual size legend (drawn when \code{size.by} is set) along the x-axis.
#' \item \code{size.legend.y} - Custom size-legend y position (UI: "Size Legend Y Position",
#' default: 0.95); nudges the manual size legend (drawn when \code{size.by} is set) along the y-axis.
#' \item \code{min.value} - Minimum value (UI: "Min Value", default: NA)
#' \item \code{max.value} - Maximum value (UI: "Max Value", default: NA)
#' \item \code{trajectory.group.by} - Trajectory group by (UI: "Trajectory Group By", default: "")
Expand Down Expand Up @@ -172,6 +176,8 @@
dittoViz_scatterPlotInputsUI <- function(id, data, defaults = NULL, title = NULL, columns = 2) {
ns <- NS(id)

if (is.null(defaults)) defaults <- list()

# Get variables of data.
choices <- c("", names(data))

Expand All @@ -196,7 +202,6 @@ dittoViz_scatterPlotInputsUI <- function(id, data, defaults = NULL, title = NULL
"do.ellipse", "do.contour",
"hover.data", "hover.round.digits",
"legend.show", c("legend.color.title", "legend.shape.title"),
c("legend.color.size", "legend.shape.size"),
"legend.color.breaks",
c("min.value", "max.value"),
"trajectory.group.by", "add.trajectory.by.groups",
Expand Down Expand Up @@ -233,6 +238,13 @@ dittoViz_scatterPlotInputsUI <- function(id, data, defaults = NULL, title = NULL
function(x) x %in% choices
), selectize = FALSE
), documentParameters$color.by, placement = "top", options = list(container = "body")),
tipify(selectInput(ns("size.by"), "Size By",
choices = num.choices,
selected = .get_default(
defaults, "size.by", "",
function(x) x == "" || x %in% num.choices
), selectize = FALSE
), documentParameters$size, placement = "top", options = list(container = "body")),
tipify(selectInput(ns("shape.by"), "Shape By",
choices = cat.choices,
selected = .get_default(
Expand Down Expand Up @@ -496,22 +508,31 @@ dittoViz_scatterPlotInputsUI <- function(id, data, defaults = NULL, title = NULL
value = .get_default(defaults, "legend.color.title", "make")
), documentParameters$legend.color.title, placement = "top", options = list(container = "body")),
.uniform_legend_inputs_ui(ns, defaults),
tipify(numericInput(ns("legend.color.size"), "Legend Color Size",
min = 1,
value = .get_default(defaults, "legend.color.size", 5, is.numeric)
), documentParameters$legend.color.size, placement = "top", options = list(container = "body")),
tipify(numericInput(ns("legend.shape.size"), "Legend Shape Size",
min = 1,
value = .get_default(defaults, "legend.shape.size", 5, is.numeric)
), documentParameters$legend.shape.size, placement = "top", options = list(container = "body")),
tipify(textInput(ns("legend.color.breaks"), "Legend Tick Breaks",
tipify(textInput(ns("legend.color.breaks"), "Color Tick Breaks",
placeholder = "e.g. -3, 0, 3",
value = .get_default(defaults, "legend.color.breaks", "", is.character)
), documentParameters$legend.color.breaks, placement = "top", options = list(container = "body")),
tipify(numericInput(ns("min.value"), "Min Value",
tipify(numericInput(ns("size.legend.x"), "Size Legend X Position",
value = .get_default(defaults, "size.legend.x", 1.03, is.numeric),
step = 0.02
), paste(
"Horizontal position (paper coordinates) of the custom size",
"legend drawn when 'Size By' is set. Values just above 1 sit to",
"the right of the plot; lower it to pull the legend inward on",
"narrow plots or raise it to push it further out."
), placement = "top", options = list(container = "body")),
tipify(numericInput(ns("size.legend.y"), "Size Legend Y Position",
value = .get_default(defaults, "size.legend.y", 0.35, is.numeric),
step = 0.05
), paste(
"Vertical position (paper coordinates) of the custom size",
"legend drawn when 'Size By' is set. Lower it to offset the",
"size legend from an overlapping color or shape legend."
), placement = "top", options = list(container = "body")),
tipify(numericInput(ns("min.value"), "Color Min",
value = .get_default(defaults, "min.value", NA, is.numeric)
), documentParameters$min.value, placement = "top", options = list(container = "body")),
tipify(numericInput(ns("max.value"), "Max Value",
tipify(numericInput(ns("max.value"), "Color Max",
value = .get_default(defaults, "max.value", NA, is.numeric)
), documentParameters$max.value, placement = "top", options = list(container = "body"))
),
Expand Down
Loading
Loading