Skip to content

Fix #333: allow showSelected.legend=FALSE to keep explicit showSelected without legend auto-injection - #336

Open
ANAMASGARD wants to merge 8 commits into
masterfrom
issue-333-opt-out-showSelected-legend
Open

Fix #333: allow showSelected.legend=FALSE to keep explicit showSelected without legend auto-injection#336
ANAMASGARD wants to merge 8 commits into
masterfrom
issue-333-opt-out-showSelected-legend

Conversation

@ANAMASGARD

Copy link
Copy Markdown
Contributor

Summary

Fixes #333

PR #292 added showSelected = character() so a layer can opt out of all auto legend showSelected behavior while keeping the legend visible. Issue #333 asks for a narrower case: keep an explicit showSelected (e.g. filter by year) but do not auto-add showSelected for colour/fill legend variables on the same layer (e.g. region from colour = region).

What was wrong?

On master, if you write geom_point(..., colour = region, showSelected = "year"), animint2 adds both year and region to the layer’s showSelected aesthetics. There was no way to suppress only the legend-driven part while keeping your own showSelected.

What this PR does

Commit 1 (this push): failing test only — per CONTRIBUTING

  • Adds tests/testthat/test-renderer2-issue333-opt-out-ss-with-other-showSelected.R
  • Uses proposed API: geom(..., showSelected = "year", showSelected.legend = FALSE)
  • Asserts (once the API works):
    • Viz compiles
    • Layer showSelected is only "year" (not "region")
    • Colour legend for region is still present
    • year selector stays single for animation / tallrect
  • Expected CI on commit 1: red — error at animint2dir() because error_for_showSelected_variants() does not whitelist showSelected.legend yet

Commit 2 (next): implementation

  • Whitelist showSelected.legend in error_for_showSelected_variants() (R/z_animintHelpers.R)
  • In addShowSelectedForLegend(), when isFALSE(extra_params$showSelected.legend), skip appending legend variables to showSelected (still honor user-specified showSelected)
  • Strip showSelected.legend in getLayerParams() so it never appears in TSV/JSON export
  • Expected CI after commit 2: green — same test file passes

Expected result

Users can write:

geom_point(aes(..., colour = region), showSelected = "year", showSelected.legend = FALSE)

Adds a WorldBank viz that keeps showSelected="year" but opts out of
auto-adding region from the colour legend via showSelected.legend=FALSE.
Fails on master because error_for_showSelected_variants() rejects the
new parameter.
#333
…lected only

Whitelist showSelected.legend in error_for_showSelected_variants(), skip
legend variable auto-injection in addShowSelectedForLegend() when FALSE, and
strip the param in getLayerParams() so it never reaches exported data.
#333
@ANAMASGARD

Copy link
Copy Markdown
Contributor Author

Sir @tdhock, I’ve implemented the fix for issue :

  • Added showSelected.legend = FALSE to opt out of legend-driven showSelected auto-injection.
  • Kept explicit showSelected = "year" working as intended.
  • Preserved the existing showSelected = character() opt-out behavior from PR Fix #140: Add ability to disable automatic showSelected on legends #292.
  • Whitelisted showSelected.legend in parameter validation.
  • Removed showSelected.legend before export so it stays compiler-only.
  • Added a regression test for the new behavior.
Screenshot From 2026-06-07 22-17-32

@codecov

codecov Bot commented Jun 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.03%. Comparing base (426295c) to head (670abc6).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #336   +/-   ##
=======================================
  Coverage   73.03%   73.03%           
=======================================
  Files         164      164           
  Lines        8840     8840           
=======================================
  Hits         6456     6456           
  Misses       2384     2384           
Flag Coverage Δ
javascript 81.25% <ø> (ø)
r 69.14% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ANAMASGARD
ANAMASGARD requested a review from tdhock June 7, 2026 17:17
@tdhock

tdhock commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

it seems reasonable to create a new argument, showSelected.legend, for this.
in that case, I would expect showSelected=character() no longer has special meaning, is that right?

@ANAMASGARD

Copy link
Copy Markdown
Contributor Author

Yes, that is my understanding as well. I’ll consolidate on showSelected.legend=FALSE as the explicit opt-out, remove the special handling for showSelected=character(), migrate the recent tests to the new API, and note the API cleanup in NEWS.

…Selected.legend

Remove dual opt-out paths in addShowSelectedForLegend(). Migrate PR #292
tests to showSelected.legend=FALSE. Add regression test proving character()
no longer has special meaning. Note breaking API cleanup in NEWS.
#333
Comment thread R/z_animintHelpers.R Outdated
Comment thread tests/testthat/test-renderer2-legend-without-showSelected.R Outdated
ANAMASGARD and others added 2 commits June 29, 2026 20:32
Strip showSelected.legend before error_for_showSelected_variants() instead
of special-casing it in the grep. Rename plot1 to legendInjectionPlot in
the character() regression test.
Comment thread R/z_animintHelpers.R
## If showSelected is character(0), user wants to opt out of auto-showSelected
user_disabled_showSelected <- is.character(L$extra_params$showSelected) &&
length(L$extra_params$showSelected) == 0
legend_auto_ss_disabled <- isFALSE(L$extra_params$showSelected.legend)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ANAMASGARD , Can you create a test case that showSelected.legend=TRUE?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Faye-yufan thanks for review

I have added test for showSelected.legend = TRUE in test-renderer2-legend-without-showSelected.R. It checks that legend-driven showSelected still works like the default.

Also fixed a small bug: extra_params$showSelected was accidentally picking up showSelected.legend when TRUE was passed. Using extra_params[["showSelected"]] fixed it.

Add regression test requested in PR review. Fix partial matching bug where
extra_params$showSelected read showSelected.legend when appending legend vars.
@tdhock

tdhock commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

R tests fail?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

opt out of auto but specify other showSelected

3 participants