Skip to content

Commit

Permalink
wip brushing
Browse files Browse the repository at this point in the history
  • Loading branch information
gogonzo committed Nov 20, 2024
1 parent 026d72b commit 1499971
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions R/plot_with_settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,6 @@ plot_with_settings_srv <- function(id,
}
})



plotly_brush <- reactive({
req(plot_suppress(plot_r()))
# layer_data(plot_r(), 3)
Expand All @@ -416,13 +414,33 @@ plot_with_settings_srv <- function(id,
if (is.null(bbox)) {
return(NULL)
}

# aes() can be specified in ggplot() call or in geoms (layers)
facets_mapping <- if (!is.null(plot_r()$facet)) {
facets_quo <- unlist(plot_r()$facet$params[c("facets", "rows", "cols")], recursive = FALSE, use.names = FALSE)
unique(unlist(lapply(facets_quo, rlang::as_label)))
# todo: missing levels where brushing occurred - we don't know which facet has been brushed
# although we know which datapoints x and y has been selected on the plot
# we can match them with original data outside of this module... see returned $x and $y
}

layers_mapping <- lapply(c(x = "x", y = "y"), function(axis) {
cols <- unique(
c(
rlang::as_label(plot_r()$mapping[[axis]]),
sapply(plot_r()$layers, function(layer) rlang::as_label(layer$mapping[[axis]]))
)
)
setdiff(cols, "NULL")
})

list(
mapping = list(
x = rlang::as_label(plot_r()$mapping$x),
y = rlang::as_label(plot_r()$mapping$y)
),
mapping = layers_mapping,
xmin = min(bbox$x), xmax = max(bbox$x),
ymin = min(bbox$y), ymax = max(bbox$y),
facet_mapping = facets_mapping,
x = bbox$x,
y = bbox$y,
direction = "xy"
)
})
Expand Down

0 comments on commit 1499971

Please sign in to comment.