Skip to content

Commit

Permalink
Merge pull request #592 from nextstrain/legend
Browse files Browse the repository at this point in the history
Removing legend duplicates, Add some month labels
  • Loading branch information
jameshadfield authored Jul 9, 2018
2 parents 493f958 + b21121d commit d8242fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/components/tree/legend/legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,11 @@ class Legend extends React.Component {
if (this.props.colorBy === "clade_membership") {
return label; /* unchanged */
} else if (this.props.colorBy === "num_date") {
const vals = this.props.colorScale.legendValues;
if (vals[vals.length - 1] - vals[0] > 10) {
const legendValues = this.props.colorScale.legendValues;
if (
(legendValues[legendValues.length-1] - legendValues[0] > 10) && /* range spans more than 10 years */
(legendValues[legendValues.length-1] - parseInt(label, 10) >= 10) /* current label (value) is more than 10 years from the most recent */
) {
return parseInt(label, 10);
}
const [yyyy, mm, dd] = numericToCalendar(label).split('-'); // eslint-disable-line
Expand Down
3 changes: 2 additions & 1 deletion src/util/colorScale.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ export const calcColorScale = (colorBy, controls, tree, treeToo, metadata) => {
const spaceBetween = parseInt(vals.length / (n - 1), 10);
for (let i = 0; i < (n-1); i++) domain.push(vals[spaceBetween*i]);
domain.push(vals[vals.length-1]);
range = colors[n+1];
domain = [...new Set(domain)]; /* filter to unique values only */
range = colors[domain.length]; /* use the right number of colours */
break;
default:
range = colors[9];
Expand Down

0 comments on commit d8242fc

Please sign in to comment.