From a1ae0905a39a53a0705acdac0558aa45dc898123 Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Wed, 9 Oct 2024 16:51:55 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20add=20extra=20padding=20after=20?= =?UTF-8?q?last=20visible=20node?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/tree/phyloTree/helpers.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/components/tree/phyloTree/helpers.js b/src/components/tree/phyloTree/helpers.js index 5d41bde04..ca38a1775 100644 --- a/src/components/tree/phyloTree/helpers.js +++ b/src/components/tree/phyloTree/helpers.js @@ -115,12 +115,27 @@ function getDisplayOrderCallback(nodes, focus) { */ let displayOrder = 0; + /** + * Keep track of whether the previous node was selected + */ + let previousWasVisible; + if (focus) { - const nSelected = nodes.filter((d) => !d.hasChildren && d.visibility === NODE_VISIBLE).length; - const yPerSelected = (0.8 * nodes.length) / nSelected; - const yPerUnselected = (0.2 * nodes.length) / (nodes.length - nSelected); + const numVisible = nodes.filter((d) => !d.hasChildren && d.visibility === NODE_VISIBLE).length; + const yPerFocused = (0.8 * nodes.length) / numVisible; + const yPerUnfocused = (0.2 * nodes.length) / (nodes.length - numVisible); + return (node) => { - displayOrder += node.visibility === NODE_VISIBLE ? yPerSelected : yPerUnselected; + // Focus if the current node is visible or if the previous node was visible (for symmetric padding) + if (node.visibility === NODE_VISIBLE || previousWasVisible) { + displayOrder += yPerFocused; + } else { + displayOrder += yPerUnfocused; + } + + // Update for the next node + previousWasVisible = node.visibility === NODE_VISIBLE; + return displayOrder; }; } else {