Skip to content

Commit

Permalink
Fix #973 (legend ordering)
Browse files Browse the repository at this point in the history
  • Loading branch information
douglowder committed Mar 24, 2020
1 parent cd37494 commit 436e0df
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/util/colorScale.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getExtraVals } from "./colorHelpers";
import { isColorByGenotype, decodeColorByGenotype } from "./getGenotype";
import { setGenotype, orderOfGenotypeAppearance } from "./setGenotype";
import { getTraitFromNode } from "./treeMiscHelpers";
import { sortedDomain } from "./sortedDomain";

const unknownColor = "#AAAAAA";

Expand Down Expand Up @@ -39,13 +40,7 @@ const getDiscreteValuesFromTree = (nodes, nodesToo, attr) => {
stateCount.set(state, currentCount+1);
}
}
const domain = Array.from(stateCount.keys()).filter((x) => isValueValid(x));
/* sorting technique depends on the colorBy */
if (attr === "clade_membership") {
domain.sort();
} else {
domain.sort((a, b) => stateCount[a] > stateCount[b] ? 1 : -1);
}
const domain = sortedDomain(Array.from(stateCount.keys()).filter((x) => isValueValid(x)), attr, stateCount);
return domain;
};

Expand Down
15 changes: 15 additions & 0 deletions src/util/sortedDomain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const sortedDomain = (domain, attr, stateCount) => {
/* sorting technique depends on the colorBy */
const sorted = Array.from(domain);
if (attr === "clade_membership") {
sorted.sort();
} else {
sorted.sort(
(a, b) =>
stateCount.get(a) === stateCount.get(b)
? a < b ? -1 : 1
: stateCount.get(a) > stateCount.get(b) ? -1 : 1
);
}
return sorted;
};

0 comments on commit 436e0df

Please sign in to comment.