mirror of
https://github.com/apache/superset.git
synced 2026-05-09 09:55:19 +00:00
Allow users to specify label->color mapping (#3879)
Users can define `label_colors` in a dashboard's JSON metadata that
enforces a label to color mapping.
This also makes the function that maps labels to colors case insensitive.
(cherry picked from commit a82bb588f4)
This commit is contained in:
@@ -103,17 +103,36 @@ export const spectrums = {
|
||||
],
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a color from a scheme specific palette (scheme)
|
||||
* The function cycles through the palette while memoizing labels
|
||||
* association to colors. If the function is called twice with the
|
||||
* same string, it will return the same color.
|
||||
*
|
||||
* @param {string} s - The label for which we want to get a color
|
||||
* @param {string} scheme - The palette name, or "scheme"
|
||||
* @param {string} forcedColor - A color that the caller wants to
|
||||
forcibly associate to a label.
|
||||
*/
|
||||
export const getColorFromScheme = (function () {
|
||||
// Color factory
|
||||
const seen = {};
|
||||
return function (s, scheme) {
|
||||
const forcedColors = {};
|
||||
return function (s, scheme, forcedColor) {
|
||||
if (!s) {
|
||||
return;
|
||||
}
|
||||
const selectedScheme = scheme ? ALL_COLOR_SCHEMES[scheme] : ALL_COLOR_SCHEMES.bnbColors;
|
||||
let stringifyS = String(s);
|
||||
let stringifyS = String(s).toLowerCase();
|
||||
// next line is for superset series that should have the same color
|
||||
stringifyS = stringifyS.replace('---', '');
|
||||
|
||||
if (forcedColor && !forcedColors[stringifyS]) {
|
||||
forcedColors[stringifyS] = forcedColor;
|
||||
}
|
||||
if (forcedColors[stringifyS]) {
|
||||
return forcedColors[stringifyS];
|
||||
}
|
||||
|
||||
if (seen[selectedScheme] === undefined) {
|
||||
seen[selectedScheme] = {};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user