From 0446278c1661758d18d61aaef0a55f970e9dd613 Mon Sep 17 00:00:00 2001 From: james hadfield Date: Wed, 26 Feb 2020 13:05:28 +1300 Subject: [PATCH] [tree] Don't allow tiny x-axis domains 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. The threshold for tiny is set here arbitrarily at 1E-8, however this will become problematic if we get eukaryotic genomes in nextstrain. --- src/components/tree/phyloTree/layouts.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/tree/phyloTree/layouts.js b/src/components/tree/phyloTree/layouts.js index bf1a74e6d..144da4754 100644 --- a/src/components/tree/phyloTree/layouts.js +++ b/src/components/tree/phyloTree/layouts.js @@ -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;