forked from Lattice-Automation/seqviz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
colors.ts
85 lines (66 loc) · 1.8 KB
/
colors.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { pSBC } from "./pSBC";
/**
* a color pallete of colors (for LinearSeq right now)\
* generated using:
* https://material.io/color/#!/?view.left=0&view.right=0&primary.color=FFCC80
*/
export const COLORS = [
"#9DEAED", // cyan
"#8FDE8C", // green
"#CFF283", // light green
"#8CDEBD", // teal
"#F0A3CE", // pink
"#F7C672", // orange
"#F07F7F", // red
"#FAA887", // red-orange
"#F099F7", // magenta
"#C59CFF", // purple
"#6B81FF", // blue
"#85A6FF", // light blue
];
export const COLOR_BORDER_MAP = {
// purple
"#6B81FF": "#2E3B85",
// blue
"#85A6FF": "#4C66AD",
// light green
"#8CDEBD": "#4CA17F",
// cyan
"#8FDE8C": "#5CA35A",
"#9DEAED": "#5EB5B8",
// magenta
"#C59CFF": "#8A60C4",
// green
"#CFF283": "#8DB041",
// orange
"#F07F7F": "#AD4040",
// red-orange
"#F099F7": "#AB63B0",
// teal
"#F0A3CE": "#BD6295",
// pink
"#F7C672": "#BD872B",
// red
"#FAA887": "#B36446", // light blue
};
// color generator function
export const chooseRandomColor = (colors?: string[]) => {
const choices = colors || COLORS;
const randIndex = Math.floor(Math.random() * choices.length);
return choices[randIndex];
};
/** get an "indexed" color from the colors array */
export const colorByIndex = (i: number, colors?: string[]) => (colors || COLORS)[i % (colors || COLORS).length];
/** get an "indexed" color from the colors array */
export const borderColorByIndex = (i: number) => COLOR_BORDER_MAP[COLORS[i % COLORS.length]];
/** cache for input color to those 50% darker */
const darkerColorCache = {};
/** darken a HEX color by 50% */
export const darkerColor = (c: string): string => {
if (darkerColorCache[c]) {
return darkerColorCache[c];
}
const darkerColor = pSBC(-0.5, c);
darkerColorCache[c] = darkerColor;
return darkerColor || c;
};