Skip to content

Fix data-panel misassignment#424

Merged
teunbrand merged 4 commits into
posit-dev:mainfrom
teunbrand:fix_facet_sort_order
May 4, 2026
Merged

Fix data-panel misassignment#424
teunbrand merged 4 commits into
posit-dev:mainfrom
teunbrand:fix_facet_sort_order

Conversation

@teunbrand
Copy link
Copy Markdown
Collaborator

@teunbrand teunbrand commented May 4, 2026

This PR aims to fix #409.

Briefly the "facet": {"column/row": {"sort": [...]}} sorting array is buggy upstream in VL. We circumvent the upstream problem by converting our facet columns to integer indices by matching these to the facet order. This causes the panels to sort themselves naturally in VL.

There is a small effort at code duplication as well.

teunbrand and others added 4 commits May 4, 2026 10:45
Vega-Lite has a bug where explicit sort arrays on facet field definitions
cause data-panel misalignment (vega/vega-lite#8675). Work around this by
converting discrete facet column values to integer sort indices in the
unified dataset and reconstructing display labels via header.labelExpr.

- Split apply_facet_ordering into resolve_facet_ordering (pure: scale →
  index map) and apply_facet_ordering (rewrites data column to integers)
- Add build_indexed_facet_label_expr to map integers back to labels,
  composing with user RENAMING when present
- Extract apply_binned_facet_reverse for the binned sort: "descending"
  case (unaffected by the bug since it uses a string, not an array)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extract the per-field facet pipeline (build def, resolve ordering, rewrite
data, label renaming, binned reverse) into apply_facet_aesthetic. Hoist the
shared "move layer/width/height into inner spec" block after the match.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@teunbrand teunbrand changed the title Fix data-panel assignment in mapping Fix data-panel misassignment May 4, 2026
@teunbrand teunbrand marked this pull request as ready for review May 4, 2026 12:31
@teunbrand teunbrand requested a review from thomasp85 May 4, 2026 12:31
Copy link
Copy Markdown
Collaborator

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

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

LGTM

@teunbrand teunbrand merged commit 44eb17d into posit-dev:main May 4, 2026
2 checks passed
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.

Facet data-to-panel mapping is incorrect

2 participants