Skip to content

Commit

Permalink
Merge pull request #1842 from nextstrain/remove-lbi-color-scale
Browse files Browse the repository at this point in the history
Remove custom LBI color scale
  • Loading branch information
huddlej committed Aug 29, 2024
2 parents 35a0fa1 + e579c1e commit e6d9b40
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changelog

* Remove hardcoded color scale for LBI ([#1842](https://github.com/nextstrain/auspice/pull/1842))
* Any `node_attr` in the tree can be used as a tip label, as well as the special-cases of strain-name and "none".
Previously we only allowed valid colorings.
([#1668](https://github.com/nextstrain/auspice/pull/1668))
Expand Down
28 changes: 9 additions & 19 deletions src/util/colorScale.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,7 @@ function createOrdinalScale(colorBy, t1nodes, t2nodes) {

function createContinuousScale(colorBy, providedScale, t1nodes, t2nodes) {

let minMax;
if (colorBy==="lbi") {
minMax = [0, 0.7]; /* TODO: this is for historical reasons, and we should switch to a provided scale */
} else {
minMax = getMinMaxFromTree(t1nodes, t2nodes, colorBy);
}
const minMax = getMinMaxFromTree(t1nodes, t2nodes, colorBy);

/* user-defined anchor points across the scale */
const anchorPoints = _validateAnchorPoints(providedScale, (val) => typeof val==="number");
Expand All @@ -244,19 +239,14 @@ function createContinuousScale(colorBy, providedScale, t1nodes, t2nodes) {
}
const scale = scaleLinear().domain(domain).range(range);

let legendValues;
if (colorBy==="lbi") {
/* TODO: this is for historical reasons, and we should switch to a provided scale */
legendValues = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7];
} else {
const spread = minMax[1] - minMax[0];
const dp = spread > 5 ? 2 : 3;
/* if legend values are identical (for the specified number of decimal places) then we
should filter them out */
legendValues = genericDomain
.map((d) => parseFloat((minMax[0] + d*spread).toFixed(dp)))
.filter((el, idx, values) => values.indexOf(el)===idx);
}
const spread = minMax[1] - minMax[0];
const dp = spread > 5 ? 2 : 3;
/* if legend values are identical (for the specified number of decimal places) then we
should filter them out */
const legendValues = genericDomain
.map((d) => parseFloat((minMax[0] + d*spread).toFixed(dp)))
.filter((el, idx, values) => values.indexOf(el)===idx);

// Hack to avoid a bug: https://github.com/nextstrain/auspice/issues/540
if (Object.is(legendValues[0], -0)) legendValues[0] = 0;

Expand Down

0 comments on commit e6d9b40

Please sign in to comment.