UNPKG

908 BJavaScriptView Raw
1
2import { category } from './fsw-structure';
3import { parse } from './fsw-parse';
4
5/**
6 * Array of colors associated with the seven symbol categories.
7 * @alias fsw.colors
8 * @type {array}
9 */
10const colors = ['#0000CC', '#CC0000', '#FF0099', '#006600', '#000000', '#884411', '#FF9900'];
11
12/**
13 * Function that returns the standardized color for a symbol.
14 * @function fsw.colorize
15 * @param {string} key - an FSW symbol key
16 * @returns {string} name of standardized color for symbol
17 * @example
18 * fsw.colorize('S10000')
19 *
20 * return '#0000CC'
21 */
22const colorize = (key) => {
23 const parsed = parse.symbol(key);
24 let color = '#000000';
25 if (parsed.symbol) {
26 const dec = parseInt(parsed.symbol.slice(1, 4), 16);
27 const index = category.findIndex((val) => val > dec);
28 color = colors[(index < 0 ? 6 : index - 1)];
29 }
30 return color;
31}
32
33export { colors, colorize }