mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-08 16:08:11 +08:00
sort object keys to our specification before generating user colormap (#1792)
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user