Skip to content

Commit

Permalink
Merge pull request #1657 from nextstrain/continous-scale-fixes-2
Browse files Browse the repository at this point in the history
Continous scale fixes 2
  • Loading branch information
jameshadfield authored Jun 6, 2023
2 parents 4b06389 + 17d8ef0 commit 8c53f60
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/util/colorScale.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const calcColorScale = (colorBy, controls, tree, treeToo, metadata) => {
colorBy,
version: controls.colorScale === undefined ? 1 : controls.colorScale.version + 1,
legendValues: ["unknown"],
legendBounds: createLegendBounds(["unknown"]),
legendBounds: {unknown: [-Infinity, Infinity]},
genotype: null,
scaleType: null,
domain: [],
Expand Down Expand Up @@ -393,15 +393,19 @@ function booleanColorScale(val) {
return "#CBB742";
}

/**
* @param {Array<Number>} legendValues
* @returns {Record<Number, [Number, Number]>}
*/
function createLegendBounds(legendValues) {
const valBetween = (x0, x1) => x0 + 0.5*(x1-x0);
const len = legendValues.length;
const legendBounds = {};
legendBounds[legendValues[0]] = [0, valBetween(legendValues[0], legendValues[1])];
legendBounds[legendValues[0]] = [-Infinity, valBetween(legendValues[0], legendValues[1])];
for (let i = 1; i < len - 1; i++) {
legendBounds[legendValues[i]] = [valBetween(legendValues[i-1], legendValues[i]), valBetween(legendValues[i], legendValues[i+1])];
}
legendBounds[legendValues[len-1]] = [valBetween(legendValues[len-2], legendValues[len-1]), 10000];
legendBounds[legendValues[len-1]] = [valBetween(legendValues[len-2], legendValues[len-1]), Infinity];
return legendBounds;
}

Expand Down

0 comments on commit 8c53f60

Please sign in to comment.