2019-05-07 17:42:34 +02:00
|
|
|
/*
|
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
|
* or more contributor license agreements. Licensed under the Elastic License;
|
|
|
|
* you may not use this file except in compliance with the Elastic License.
|
|
|
|
*/
|
|
|
|
|
2019-11-18 15:36:07 +01:00
|
|
|
import euiVars from '@elastic/eui/dist/eui_theme_dark.json';
|
2019-05-07 17:42:34 +02:00
|
|
|
|
2020-06-19 08:39:50 +02:00
|
|
|
import { stringHash } from './string_utils';
|
|
|
|
|
2019-05-07 17:42:34 +02:00
|
|
|
const COLORS = [
|
|
|
|
euiVars.euiColorVis0,
|
|
|
|
euiVars.euiColorVis1,
|
|
|
|
euiVars.euiColorVis2,
|
|
|
|
euiVars.euiColorVis3,
|
|
|
|
// euiVars.euiColorVis4, // light pink, too hard to read with white text
|
|
|
|
euiVars.euiColorVis5,
|
|
|
|
euiVars.euiColorVis6,
|
|
|
|
euiVars.euiColorVis7,
|
|
|
|
euiVars.euiColorVis8,
|
|
|
|
euiVars.euiColorVis9,
|
|
|
|
euiVars.euiColorDarkShade,
|
2019-11-18 15:36:07 +01:00
|
|
|
euiVars.euiColorPrimary,
|
2019-05-07 17:42:34 +02:00
|
|
|
];
|
|
|
|
|
2019-11-18 15:36:07 +01:00
|
|
|
const colorMap: Record<string, string> = {};
|
2019-05-07 17:42:34 +02:00
|
|
|
|
2019-11-18 15:36:07 +01:00
|
|
|
export function tabColor(name: string): string {
|
2019-05-07 17:42:34 +02:00
|
|
|
if (colorMap[name] === undefined) {
|
|
|
|
const n = stringHash(name);
|
2019-11-18 15:36:07 +01:00
|
|
|
const color = COLORS[n % COLORS.length];
|
2019-05-07 17:42:34 +02:00
|
|
|
colorMap[name] = color;
|
|
|
|
return color;
|
|
|
|
} else {
|
|
|
|
return colorMap[name];
|
|
|
|
}
|
|
|
|
}
|