Skip to content

[Lens] Fix coloring/palette assignment on partition charts#215426

Merged
nickofthyme merged 7 commits intoelastic:mainfrom
nickofthyme:fix-cm-partition-layers
Mar 27, 2025
Merged

[Lens] Fix coloring/palette assignment on partition charts#215426
nickofthyme merged 7 commits intoelastic:mainfrom
nickofthyme:fix-cm-partition-layers

Conversation

@nickofthyme
Copy link
Contributor

@nickofthyme nickofthyme commented Mar 20, 2025

Summary

Fixes an issue where reordering the groups within a layer would incorrectly assign the color mapping to a group other than the first.

Zight.Recording.2025-03-20.at.05.44.41.PM.mp4

Fixes #203178

release_note: Fixes issue with color mapping when reordering groups in partition charts.

Details

The issue here was due to the order of the columns. The colorMapping prop is applied at the layer so we need to find the first non-collapsed group to take "ownership" of the color mapping config. Previously we used layer.primaryGroups as the order but this could be incorrect when reordering groups.

We can correct this by relying on the column order from the datasource using the getSortedAccessorsForGroup utility.

This issue applied to both the group display properties that control the appearance of the group in the editor, and the Color mapping row within the editor.

Checklist

  • Unit or functional tests were updated or added to match the most common scenarios
  • This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The release_note:breaking label should be applied in these situations.
  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines
The primary assignment was applied to the order of `layer.primaryGroups` which may be different than `datasource` column order.
The groups all share the same `colorMapping` it just needs to know which is the first non-collapsed group. In this case, the it was using the wrong order of columns.
@nickofthyme nickofthyme added release_note:fix Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t// Feature:Lens backport:prev-major labels Mar 20, 2025
@nickofthyme nickofthyme requested a review from a team as a code owner March 20, 2025 22:49
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-visualizations (Team:Visualizations)

@markov00
Copy link
Contributor

@dej611 @nickofthyme I've checked the code and the fix works correctly. But I have a doubt: we are keeping the column order in two places: one at the datasourceState level in the columnOrder and another within the primaryGroups and secondaryGroups.
The usage of these primary and secondary groups are the following (from what I've understood):

  • keep track of the order of the column ids associated to the layer and to each group.
  • the secondary group is only used in the mosaic chart where we visually split in vertical/horizontal splits the data.
  • the order we aggregate the data is important because represent how each partition layer is defined: we have 0 or more partition layers (called groups) and the final aggregation is the metric.
  • in a pie/treemap the order is always defined by the aggregation order, so the data is driven by that columnOrder in the datasource and not by the primaryGroups sorting order (with the last column referring always to the metric)
  • in the mosaic the first partition layer/group is always the vertical axis, the second always the horizontal, and the last is the metric.

With that I'm wondering why we need to have these properties primaryGroups and secondaryGroups instead of just relying to the datasource columnOrder, that is actually what Nick have done by using the getSortedAccessorsForGroup

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
lens 1.4MB 1.4MB -24.0B
@nickofthyme nickofthyme added backport:version Backport to applied version labels v8.19.0 and removed backport:prev-major labels Mar 27, 2025
@nickofthyme nickofthyme merged commit 2cbfe86 into elastic:main Mar 27, 2025
14 checks passed
@nickofthyme nickofthyme deleted the fix-cm-partition-layers branch March 27, 2025 19:29
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/14115122282

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Mar 27, 2025
…15426)

Fixes an issue where reordering the groups within a layer would incorrectly assign the color mapping to a group other than the first.

(cherry picked from commit 2cbfe86)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Mar 27, 2025
…5426) (#216225)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Lens] Fix coloring/palette assignment on partition charts
(#215426)](#215426)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Nick
Partridge","email":"nicholas.partridge@elastic.co"},"sourceCommit":{"committedDate":"2025-03-27T19:29:01Z","message":"[Lens]
Fix coloring/palette assignment on partition charts (#215426)\n\nFixes
an issue where reordering the groups within a layer would incorrectly
assign the color mapping to a group other than the
first.","sha":"2cbfe8641cc3b6a3929c46e7737938c3cb665c8a","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Visualizations","Feature:Lens","backport:version","v9.1.0","v8.19.0"],"title":"[Lens]
Fix coloring/palette assignment on partition
charts","number":215426,"url":"https://github.com/elastic/kibana/pull/215426","mergeCommit":{"message":"[Lens]
Fix coloring/palette assignment on partition charts (#215426)\n\nFixes
an issue where reordering the groups within a layer would incorrectly
assign the color mapping to a group other than the
first.","sha":"2cbfe8641cc3b6a3929c46e7737938c3cb665c8a"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/215426","number":215426,"mergeCommit":{"message":"[Lens]
Fix coloring/palette assignment on partition charts (#215426)\n\nFixes
an issue where reordering the groups within a layer would incorrectly
assign the color mapping to a group other than the
first.","sha":"2cbfe8641cc3b6a3929c46e7737938c3cb665c8a"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

---------

Co-authored-by: Nick Partridge <nicholas.partridge@elastic.co>
cqliu1 pushed a commit to cqliu1/kibana that referenced this pull request Mar 31, 2025
…15426)

Fixes an issue where reordering the groups within a layer would incorrectly assign the color mapping to a group other than the first.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels Feature:Lens release_note:fix Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t// v8.19.0 v9.1.0

4 participants