Color Collisions on Cartodiagram Plugin
- Dominant language
- Python
- Stars
- 74.8k
- Forks
- 18.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 664
Description
### Bug description
The charts rendered through the cartodiagram plugin might run into color collisions for cases when the sets of labels differ. This might lead to confusion and misinterpretation of the data, since two distinct labels might share the same color and/or a label might be assigned different colors, within a single cartodiagram.
Given following dataset:
| geom | value | category |
| --- | --- | --- |
|{ "coordinates": [ 10.021094598147045, 51.12881242291189 ], "type": "Point" } | 1 | far |
|{ "coordinates": [ 10.021094598147045, 51.12881242291189 ], "type": "Point" } | 1 | faz |
|{ "coordinates": [ 9.573277401918602, 50.77733656456951 ], "type": "Point" } | 1 | bar |
|{ "coordinates": [ 9.573277401918602, 50.77733656456951 ], "type": "Point" } | 1 | baz |
The first two items and the last two items share the same location, respectively, but have different categories on each location.
If we create a pie chart based on this dataset (using `category` as dimension) and then reference this pie chart in the cartodiagram plugin, following two charts will be created on a map:

As you can see, the same colors will be applied for both charts, even though the labels differ completely (`far` and `faz` for the first chart, `bar` and `baz` for the second chart).
I would expect that each label has a distinct color throughout the charts contained in the cartodiagram, and that a single color is not used by two different labels.
### Screenshots/recordings
_No response_
### Superset version
5.0.0
### Python version
3.9
### Node version
16
### Browser
Not applicable
### Additional context
In our superset fork, I already created a fix on dashboard level (see https://github.com/terrestris/superset/pull/23). Here, I can manually register all labels in the `LabelsColorMapSingleton` before creating the single charts. The result looks as follows:

However, the provided approach only works in the context of dashboards - it does not work in the explore view, and thus it does not work when embedding a single chart directly. There, the `LabelsColorMapSingleton` is not being used but instead a label map for each distinct chart will be created.
In order to solve this problem, we probably have to adjust the approach on how colors will be assigned during chart rendering.
@villebro Before doing any changes here, it would be great to get some feedback regarding a feasible approach for that, as otherwise I might oversee some cases.
### 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.
- [ ] 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
No source file or test is named. Start by tracing cartodiagram rendering and the per-chart label color maps, including LabelsColorMapSingleton usage in dashboard and Explore paths. Done means one label receives one color across all charts in a cartodiagram, different labels do not collide, and the behavior is covered for both dashboard and embedded chart rendering.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100