[6.0.0rc3] Same color being picked twice in a chart when dashboard doesn't have a map_label_colors
- Dominant language
- Python
- Stars
- 74.8k
- Forks
- 18.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 664
Description
### Bug description
Bug is that in a dashboard with more than 1 chart, the same color can be picked twice for a given chart. To reproduce, the dashboard needs to have an empty map_label_colors or an incomplete map_label_colors.
To reproduce:
1. Import the given superset dashboard [twice-same-color-bug.zip](https://github.com/user-attachments/files/23904698/twice-same-color-bug.zip)
2. Make sure the imported dashboard doesn't have a map_label_colors by calling the api `/api/v1/dashboard/{pk}` and check the field `json_metadata`
3. Go to the dashboard "Twice same color bug"
4. The 2nd charts "Call of duty Sales" is displaying the light blue color 2 times for "PC" and "Playstation" KO
5. If the bug doesn't appear refresh the page several times
To note:
- This happen regardless of the type of charts used
- This doesn't happen when you edit the dashboard first because the field map_label_colors is being filled while editing.
- When filling the map_label_colors by editing the dashboard, if the same color is picked twice, then the map_label_color will also be filled with twice the same color.
- Relying on fixing this bug by having a map_label_colors with all the possible values is not an optimal solution because it can be tricky to have the full list of labels for all charts and this break the theme system where the first colors are more likely to be used in the dashboard.
- To remove the map_label_colors you can call the api `/api/v1/dashboard/{pk}/colors` with the payload `{"map_label_colors": {}}`
- I reproduced it in superset 6.0.0rc3 and superset 5.0.0
### Screenshots/recordings
We are using the superset theme which contains the following colors:
1. light blue
2. dark blue
3. green
For every chart the color picking logic is the same, the 1st label have the 1st color, 2nd label 2nd colors... If a label already have a picked color for the current dashboard then this color will be used.
In this example with have 2 charts. So 1st chart have labels: "Playstation", "Xbox" and 2nd chart have "PC", "Playstation", "Xbox"
On the first load:
- The 1st chart got loaded first so light blue is assigned to "Playstation" and dark blue to "Xbox"
- Then the 2nd chart is loaded, so light blue is assigned to "PC" and then the others labels already have a color in this dashboard so light blue goes to "Playstation" and dark blue to "Xbox"
- KO
On the 2nd load:
- The 2nd chart got loaded first so light blue is assigned to "PC" and dark blue to "Playstation" and green to "Xbox"
- Then 1st chart is loaded, all labels have assigned colors. So the colors are reused and dark blue goes to "Playstation" and green to "Xbox"
- OK
On the 3rd load:
- We are in the same case as the 1st load
Full video of the bug:
https://github.com/user-attachments/assets/a0c637e9-d633-4c43-9302-baf724832d99
Observed behaviour (1st load):
Expected behaviour (2nd load):
### Superset version
master / latest-dev
### Python version
3.9
### Node version
16
### Browser
Chrome
### Additional context
The STR are using the superset theme with the example datasource.
Before exporting the dashboard, the map_label_colors of the dashboard was emptied by calling the api.
### Checklist
- [x] I have searched Superset docs and Slack and didn't find a solution to my problem.
- [x] I have searched the GitHub issue tracker and didn't find a similar bug report.
- [x] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
Contributor guide
Research direction
Start by reproducing the issue with twice-same-color-bug.zip, then inspect the dashboard JSON metadata through GET /api/v1/dashboard/{pk} and clear map_label_colors with /api/v1/dashboard/{pk}/colors. Trace the chart color-assignment entry point while loading the two charts in different orders. Done means each distinct label receives a distinct available color without requiring map_label_colors to be prefilled, and the behavior is consistent across reloads.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, react
- Domain
- data-visualization, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100