sort object keys to our specification before generating user colormap (#1792)

This commit is contained in:
Severiano Badajoz
2020-08-25 12:25:55 -07:00
committed by GitHub
parent eb05d1cb5c
commit 0a10b3ec2a
+12 -1
View File
@@ -94,7 +94,18 @@ export const createColorTable = memoize(_createColorTable);
export function loadUserColorConfig(userColors) { export function loadUserColorConfig(userColors) {
const convertedUserColors = {}; const convertedUserColors = {};
Object.keys(userColors).forEach((category) => { Object.keys(userColors).forEach((category) => {
const [colors, scaleMap] = Object.keys(userColors[category]).reduce( // We cannot iterate over keys without sorting
// because we handle categorical values in alphabetical order __ignoring case__
// while Object.keys() _usually_ is ordered alphabetically where all upper characters are less than lowercase (A, B, C, a, b, c)
const [colors, scaleMap] = Object.keys(userColors[category])
.sort((a, b) => {
a = a.toLowerCase();
b = b.toLowerCase();
if (a === b) return 0;
if (a > b) return 1;
return -1;
})
.reduce(
(acc, label, i) => { (acc, label, i) => {
const color = parseRGB(userColors[category][label]); const color = parseRGB(userColors[category][label]);
acc[0][label] = color; acc[0][label] = color;