feat(dashboard): make color indices referable #23657
Merged
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.
SUMMARY
Currently it's only possible to assign series colors on dashboards based on the color names (e.g. "red") or hex codes (e.g. "#FF0000"). This tends to be impractical, as it's often only necessary to ensure that the colors stay constant across charts. In addition, assigning fixed hex colors will fail to change if color schemes are updated.
This PR adds the option to assign colors based on the color scheme index. This ensures that the color will be fixed, but also makes it adapt to whichever color scheme is chosen. This is done by letting the
CategoricalColorScale
objects swap out the index based color reference of theparentForcedColors
that's passed to it in the constructor (theparentForcedColors
object is mutated by charts as series are populated, hence it's ok to make changes to the object here, too).SCREENSHOT
Here we're using the "D3 category 10" scheme, and assign index 2 (=the third value) for "boy" and the fixed color "red" for "girl":
After we do that, the charts update accordingly:
If we then change the scale to the "ECharts 5.0" scheme, the dashboard updates accordingly (notice "boy" turns yellow, which is the third color in that scheme, while "girl" stays unchanged):
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION