Skip to content

Commit

Permalink
Merge pull request #909 from nextstrain/x-axis-bug
Browse files Browse the repository at this point in the history
[tree] Don't allow tiny x-axis domains
  • Loading branch information
jameshadfield authored Feb 26, 2020
2 parents b0ca00e + 4ed3d6d commit fe00bb3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions scripts/get-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ data_files=(
"flu_seasonal_yam_na_3y.json" "flu_seasonal_yam_na_3y_tip-frequencies.json" \
"flu_seasonal_yam_na_6y.json" "flu_seasonal_yam_na_6y_tip-frequencies.json" \
"flu_seasonal_yam_na_12y.json" "flu_seasonal_yam_na_12y_tip-frequencies.json" \
"tb_global_meta.json" "tb_global_tree.json" \
"enterovirus_d68_genome_meta.json" "enterovirus_d68_genome_tree.json" \
"enterovirus_d68_vp1_meta.json" "enterovirus_d68_vp1_tree.json" \
"ncov.json" "ncov_2020-01-25.json" "ncov_2020-01-23.json" \
Expand Down
10 changes: 9 additions & 1 deletion src/components/tree/phyloTree/layouts.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,20 @@ export const mapToScreen = function mapToScreen() {
maxY += delta;
}

/* Don't allow tiny x-axis domains -- e.g. if zoomed into a polytomy where the
divergence values are all tiny, then we don't want to display the tree topology */
const minimumXAxisSpan = 1E-8;
let spanX = maxX-minX;
if (spanX < minimumXAxisSpan) {
maxX = minimumXAxisSpan - minX;
spanX = minimumXAxisSpan;
}

/* set the domain of the x & y scales */
if (this.layout === "radial" || this.layout === "unrooted") {
// handle "radial and unrooted differently since they need to be square
// since branch length move in x and y direction
// TODO: should be tied to svg dimensions
const spanX = maxX-minX;
const spanY = maxY-minY;
const maxSpan = max([spanY, spanX]);
const ySlack = (spanX>spanY) ? (spanX-spanY)*0.5 : 0.0;
Expand Down

0 comments on commit fe00bb3

Please sign in to comment.