Skip to content

Commit

Permalink
Remove custom LBI color scale
Browse files Browse the repository at this point in the history
Closes #805
  • Loading branch information
huddlej committed Aug 29, 2024
1 parent 35a0fa1 commit da17bd5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 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
27 changes: 9 additions & 18 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);
}
let minMax = getMinMaxFromTree(t1nodes, t2nodes, colorBy);

Check failure on line 226 in src/util/colorScale.js

View workflow job for this annotation

GitHub Actions / lint (16)

'minMax' is never reassigned. Use 'const' instead

Check failure on line 226 in src/util/colorScale.js

View workflow job for this annotation

GitHub Actions / lint (18)

'minMax' is never reassigned. Use 'const' instead

Check failure on line 226 in src/util/colorScale.js

View workflow job for this annotation

GitHub Actions / lint (20)

'minMax' is never reassigned. Use 'const' instead

Check failure on line 226 in src/util/colorScale.js

View workflow job for this annotation

GitHub Actions / lint (22)

'minMax' is never reassigned. Use 'const' instead

/* user-defined anchor points across the scale */
const anchorPoints = _validateAnchorPoints(providedScale, (val) => typeof val==="number");
Expand All @@ -245,18 +240,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 */
legendValues = genericDomain

Check failure on line 247 in src/util/colorScale.js

View workflow job for this annotation

GitHub Actions / lint (16)

'legendValues' is never reassigned. Use 'const' instead

Check failure on line 247 in src/util/colorScale.js

View workflow job for this annotation

GitHub Actions / lint (18)

'legendValues' is never reassigned. Use 'const' instead

Check failure on line 247 in src/util/colorScale.js

View workflow job for this annotation

GitHub Actions / lint (20)

'legendValues' is never reassigned. Use 'const' instead

Check failure on line 247 in src/util/colorScale.js

View workflow job for this annotation

GitHub Actions / lint (22)

'legendValues' is never reassigned. Use 'const' instead
.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 da17bd5

Please sign in to comment.