-
Notifications
You must be signed in to change notification settings - Fork 44
Fix #333: allow showSelected.legend=FALSE to keep explicit showSelected without legend auto-injection #336
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
Open
ANAMASGARD
wants to merge
5
commits into
master
Choose a base branch
from
issue-333-opt-out-showSelected-legend
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3c9e341
test(issue-333): failing test for showSelected.legend=FALSE
ANAMASGARD bb0b218
fix(issue-333): support showSelected.legend=FALSE for explicit showSe…
ANAMASGARD c0e707f
refactor(issue-333): retire showSelected=character() in favor of show…
ANAMASGARD 4545718
Merge branch 'master' into issue-333-opt-out-showSelected-legend
ANAMASGARD bbb4225
Merge branch 'master' into issue-333-opt-out-showSelected-legend
ANAMASGARD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
tests/testthat/test-renderer2-issue333-opt-out-ss-with-other-showSelected.R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| acontext("opt out of showSelected legend but keep showSelected variable") | ||
| ## Issue #333 https://github.com/animint/animint2/issues/333 | ||
| ## Issue #333: keep showSelected="year" for filtering, but do not auto-add region from | ||
| ## colour=region when the legend is shown. API: showSelected.legend=FALSE. | ||
| data(WorldBank, package = "animint2") | ||
| issue333_viz <- function() { | ||
| list( | ||
| scatter = ggplot() + | ||
| geom_point( | ||
| aes(fertility.rate, life.expectancy, colour = region, key = year), | ||
| showSelected = "year", | ||
| showSelected.legend = FALSE, | ||
| data = WorldBank | ||
| ), | ||
| ts = ggplot() + make_tallrect(WorldBank, "year"), | ||
| time = list(variable = "year", ms = 3000), | ||
| duration = list(year = 3000), | ||
| selector.types = list(year = "single"), | ||
| title = "issue333 opt out legend keep showSelected" | ||
| ) | ||
| } | ||
| showSelected_variables <- function(info, plot.name = "scatter") { | ||
| geom.names <- names(info$geoms) | ||
| pat <- sprintf("_point_%s$", plot.name) | ||
| point.geom.name <- geom.names[grepl(pat, geom.names)] | ||
| stopifnot(length(point.geom.name) == 1) | ||
| aes.map <- info$geoms[[point.geom.name[[1]]]]$aes | ||
| ss.names <- grep("^showSelected", names(aes.map), value = TRUE) | ||
| as.character(unlist(aes.map[ss.names])) | ||
| } | ||
| info <- animint2dir(issue333_viz(), open.browser = FALSE) | ||
| test_that("issue333 viz compiles with showSelected.legend=FALSE", { | ||
| expect_identical(info$time$variable, "year") | ||
| }) | ||
| test_that("explicit showSelected=year without legend-injected region", { | ||
| expect_identical(showSelected_variables(info), "year") | ||
| }) | ||
| test_that("colour legend for region is still compiled", { | ||
| legend.info <- info$plots$scatter$legend$region | ||
| expect_false(is.null(legend.info)) | ||
| expect_gt(length(legend.info$entries), 0L) | ||
| expect_identical(legend.info$selector, "region") | ||
| }) | ||
| test_that("year selector remains for animation and tallrect", { | ||
| expect_identical(info$selectors[["year"]]$type, "single") | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,12 +29,10 @@ test_that("default: legend with color aesthetic creates selector for interactivi | |
| expect_identical(legend_info$selector, "comparison") | ||
| expect_identical("comparison" %in% names(info$selectors), TRUE) | ||
| }) | ||
| test_that("showSelected=character() keeps legend selector but opts layer out", { | ||
| ## Proposed API: empty character vector disables auto showSelected injection | ||
| ## for this layer, but keeps legend interactivity intact. | ||
| test_that("showSelected.legend=FALSE keeps legend selector but opts layer out", { | ||
| viz_no_ss <- list( | ||
| plot1 = ggplot(test_data, aes(x, y, color = comparison)) + | ||
| geom_point(showSelected = character()) + | ||
| geom_point(showSelected.legend = FALSE) + | ||
| facet_wrap(~facet_var) | ||
| ) | ||
| info <- animint2dir(viz_no_ss, open.browser = FALSE) | ||
|
|
@@ -50,3 +48,16 @@ test_that("showSelected=character() keeps legend selector but opts layer out", { | |
| show_aes_names <- names(info$geoms[[point_geom_name]]$aes) | ||
| expect_identical(any(grepl("^showSelected", show_aes_names)), FALSE) | ||
| }) | ||
| test_that("showSelected=character() no longer opts layer out of legend injection", { | ||
| viz_char_ss <- list( | ||
| plot1 = ggplot(test_data, aes(x, y, color = comparison)) + | ||
|
Collaborator
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. use informative name instead of number (plot1) |
||
| geom_point(showSelected = character()) + | ||
| facet_wrap(~facet_var) | ||
| ) | ||
| info <- animint2dir(viz_char_ss, open.browser = FALSE) | ||
| geom_names <- names(info$geoms) | ||
| point_geom_name <- geom_names[grepl("_point_plot1$", geom_names)] | ||
| expect_identical(length(point_geom_name), 1L) | ||
| show_aes_names <- names(info$geoms[[point_geom_name]]$aes) | ||
| expect_identical(any(grepl("^showSelected", show_aes_names)), TRUE) | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don’t think this is necessary. Can you please revert?