Fix categorical color mapping in overlays for different factor subsets #6698
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.
Problem
When overlaying Points elements with categorical color mappings, elements with different categorical subsets would incorrectly share color mapper factors, resulting in broken legends and inconsistent color assignments.
This issue manifested in two main scenarios:
Example
Root Cause
The issue was in the
_apply_transforms
method where categorical color mappings (color=hv.dim('category')
) were computed. The code was using shared factors from the overlay's combined ranges instead of computing factors from each element's individual data:This caused all elements in an overlay to share the same categorical factors (typically from the first element), breaking color mapping consistency.
Solution
Modified the factor computation logic to always use each element's individual data for categorical color mappings:
This ensures each element maintains its own categorical color mapping integrity while preserving existing functionality for non-overlay scenarios.
Changes
_apply_transforms
method (lines 1888-1897) - Primary fix forcolor=hv.dim()
mappings_get_color_data
method (lines 2908-2913) - Secondary fix forcolor_index
based mappingsTesting
All scenarios from the original issue now work correctly:
Fixes #6691
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.