Skip to content

fix: missing-check bugs across layout, model, parsers and metrics (follow-up to #551) - #553

Merged
stevenweaver merged 28 commits into
masterfrom
fix/missing-checks
Nov 17, 2026
Merged

stevenweaver merged 28 commits into
masterfrom
fix/missing-checks

Conversation

@stevenweaver

@stevenweaver stevenweaver commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Fixes the bugs of the kind reported in #551 across the whole library: fields read before they are set, one field holding two types, a guard present in one layout or code path but missing in a sibling, arithmetic on undefined values that silently produces NaN, and caches that outlive their inputs.

An audit after #552 found 74 such defects (each confirmed by reproducing it through the public API); this PR addresses 73 of them, each with a regression test, and the bullets below are the inventory. Tests go from 476 to 796. No public API is removed or renamed.

Rendering

Layout (src/render/draw.js)

  • scaling: false placed internal nodes to the right of their own tips (max_depth was 1 during layout).
  • A clade collapsed around a hidden leaf drew an outline with spikes off the plot.
  • Trees with an undefined or non-finite branch length now fall back to an unscaled layout instead of NaN positions (undef_BL was a dead local).
  • Zero-length trees render without NaN; a single-node tree no longer throws (see Not fixed for its radial layout).
  • rescale_nodeSpan is the minimum positive span over all tips, so a custom node-span no longer gives order-dependent spacing.
  • update() refreshes links after a topology change; the brush uses the current links.
  • Collapsed clade outlines are mirrored in right-to-left layouts.
  • Malformed selection-sets / initial-sets options no longer throw; initial-sets is applied once per tree, so a reroot no longer re-adds nodes.
  • style_edges(null) clears the styler.
  • font_size() and scale_bar_font_size() were shadowed by numeric fields and could never be called. New fontSize([n]) and scaleBarFontSize([n]) methods; the fields are unchanged.

Unrooted layout (src/render/unrooted.js, src/render/clades.js)

  • Hidden and collapsed clades were still laid out, so hiding a subtree shrank the visible tree to a blob and collapsed clades drew at the origin. Hidden clades now take no angle or extent; a collapsed clade counts as one leaf and gets a wedge outline.
  • Zero-length (and negative) branches were drawn with length 1 in raw units, about 1000× too long.
  • Collapsing a leaf no longer throws in the transitions branch.

Interaction (src/render/menus.js, selection-sets.js, edges.js, nodes.js)

  • With binary-selectable and a multi-entry attribute-list, selecting for one attribute wiped the others.
  • The node menu threw when container was an Element or d3 selection.
  • restricted-selectable broke method chaining; Hide was a dead menu item when selectable: false.
  • Selection sets survive a reroot (members were rebuilt without the nodes' _selectionSet flags).
  • Newick annotations named children, data, collapsed, etc. overwrote node fields.
  • internal-names callbacks received node.data from one call site and the hierarchy node from the others; unnamed internal nodes made render() throw.

Tree model (src/main.js, branches.js, rooting.js, nodes.js, traversal.js, export.js)

  • branch_length and branch_length_accessor could diverge; setBranchLength now sets both, and every reader (metrics, clustering, getTipLengths, hasBranchLengths) uses the accessor.
  • normalizeBranchLengths never mapped the shortest branch to 0 (write-back only when > 0), divided by zero for equal lengths, and rejected numeric attributes.
  • reroot(root) threw and left tree.nodes undefined; rerooting with a lengthless child produced NaN.
  • mrca() cached across calls and included the node itself, so a second call returned the wrong node.
  • deleteANode on a child of a binary root threw and left the tree half-modified; graftANode built plain objects without .data. Both now rebuild depth and height.
  • neighborJoining() returned nodes without depth, height or links, so the tree could not be rendered (every branch NaN) or rerooted. It now returns a proper phylotree; it also joined a node with itself on all-zero distances.
  • The constructor throws a clear Error when a parser fails (including for an empty string or a {json: null, error} result), instead of an obscure TypeError from [].links(). An object is treated as a parser result when it has a json field and no children array of its own; anything with children is hierarchical JSON.
  • leftChildRightSibling tolerates unary nodes; getDistanceMatrix handles empty input and unequal sequence lengths.

Parsers and export (src/formats/*, src/extract-dates.js)

  • getNewick() after hiding nodes emitted (,B) and ,, phantom tips; a taxon named root was dropped; an unnamed internal node threw.
  • Newick: the root label and length after the final ) are kept; an unlabeled internal node no longer gets bootstrap_values = '' (which read as support 0); type: 'nhx' enables bracket delimiters; NHX keys that collide with node fields are stored as nhx_<key>.
  • NeXML was unusable (.map on single elements, wrong return shape, hard-coded nex: prefix). It parses now; tip names come from OTU labels.
  • PhyloXML: if (DOMParser) threw a ReferenceError in Node; unnamed clades broke getNewick; @branch_length attributes were ignored and every branch got an invented 0.01.
  • NEXUS: multi-line TREE statements and TRANSLATE blocks are handled (split outside quotes and [comments], so a quoted label may contain ; or ,); lowercase keywords work; a missing TREES block returns an error instead of throwing.
  • extractDates() with the default getter returned no dates (it checked 'name' in node instead of node.data.name).

Metrics and clustering (src/metrics/*, src/clustering/*)

  • computeMidpoint never reset max_path between calls; rootToTip/fitRootToTip gave NaN or threw on fewer than two dated tips or a single-node tree; fitRootToTip fitted the current root from a field only the other-root pass sets, so its baseline fit was always NaN and the current root could never be chosen; candidates were also compared against 0 rather than the current root's fit; centerOfTree divided 0/0 on zero-length branches; sackin used stale depth after a reroot; pairwiseDistances crashed on a single-node tree.
  • clusterPicker and phylopart treated an unlabeled internal node as support 0 instead of missing; clusterPicker validates its thresholds (the README example passed an options object it never accepted).
  • phylopart added the last child's branch to every root-to-leaf path, and its histogram bin index was not clamped.

Behavior changes to note in the release

  • phylopart on test/data/EU3031.txt finds 300 clusters; it found 297 because of the root-path bug. The test is updated.
  • PhyloXML no longer invents a 0.01 branch length; lengthless trees fall back to length 1 like Newick.
  • getNewick() preserves root labels and a taxon named root.
  • The constructor throws on unparseable input rather than producing a broken tree.
  • clusterPicker throws on a non-numeric bootstrap_threshold or a negative or non-numeric diameter_threshold. Numeric strings are still accepted.
  • normalizeBranchLengths() and scaleBranchLengths() with a custom accessor write the results into data.attribute and restore the default accessor, since a custom accessor cannot be written through.
  • initial-sets is applied once per tree; a second render() of the same tree with different initial-sets does not re-apply them.
  • fitRootToTip returns { root, fit: null } when no root has a finite fit: fewer than two dated tips, all dates identical, or zero/infinite distances everywhere. A current root without a fit no longer stops the search for a better one. Undated tips (decimal_date_value undefined, null or '') count as missing; numeric strings are accepted.
  • getBranchLengths(), getTipLengths(), hasBranchLengths() and every metric read through branch_length_accessor. Assigning the branch_length field directly no longer affects them; use setBranchLength(). On a tree with no branch lengths, getBranchLengths() reports the constructor's fallback of 1 per branch instead of undefined.
  • mrca() returns undefined when a requested name is absent (it returned the root), matches leaf names only, and no longer caches on node.data.mrca.
  • loadAnnotations(tree, label, …) stores under label (it always stored under "test"); parseAnnotations() returns an empty {dimensions, format, matrix} structure instead of '' when there is no DATA block.
  • clusterPicker accepts Infinity as an unbounded diameter; NaN or a negative diameter throws.

Not fixed

  • A one-node tree in the radial layout still gets translate(NaN,NaN); the linear layout is fixed.
  • Collapsing the root in the unrooted layout now draws nothing (master drew one misplaced outline). Collapsing any other clade works.
  • getNewick() cannot distinguish a real taxon label root on the root node from the parser's implicit root name; the root's label is dropped in that one case, as on master.
  • Pre-existing and unchanged: computeMidpoint throws on a one-node tree; deleteANode on the only child of a unary node throws; deleting a node drops the connecting branch length rather than adding it to the sibling.
  • Rerooting on a node that is a selection-set member drops that one node from the set (the reroot rebuilds the node). Minor; follow-up.

Checks

  • yarn build, 796/796 tests, yarn lint (0 errors; 12 warnings, down from 14), yarn typecheck.
  • An independent Codex session then verified the branch against a master build: it confirmed 15 sampled fixes (reproduced on master, gone on the branch, regression test fails with the fix reverted) and found four regressions in the merged result, all fixed with tests (two further Codex passes on the fixes found adjacent edge cases, also fixed): the constructor dropped trees passed as {json} without an error field, the NEXUS splitter broke quoted labels containing ;, fitRootToTip returned a non-null fit for undated tips, and clusterPicker rejected Infinity.
  • A final review of the combined diff checked the cross-package interactions (neighbor joining into every layout, hide and collapse in every layout, reroot, setBranchLength, update()) and that the public API is unchanged apart from the behavior changes listed above.
  • Each regression test was confirmed to fail on the unfixed code, either by reverting the fix or by the verifier's reproduction.

…tDates

Locations fixed:
- src/metrics/compute-midpoint.js: reset max_path per call; use branch_length_accessor
- src/metrics/center-of-tree.js: avoid 0/0 breakpoint on zero-length branches
- src/metrics/pairwise-distances.js: finite-number check; root with no children
- src/metrics/root-to-tip.js: use accessor; <2 points early return; best_node starts at root; r2t || {}
- src/metrics/sackins.js: compute depth by walking parents
- src/extract-dates.js: use node.data.name, drop /g regex
…ix phylopart root paths

Locations fixed:
- src/clustering/cluster-picker.js:38 use branch_length_accessor
- src/clustering/cluster-picker.js:64 treat '' / NaN bootstrap as missing
- src/clustering/cluster-picker.js:68 validate numeric thresholds; fix README example
- src/clustering/phylopart.js:113 include root path segments (EU3031 297 -> 300)
- src/clustering/phylopart.js:149 clamp histogram bin index
- src/clustering/phylopart.js:183 treat '' / NaN bootstrap as missing
Locations fixed: src/formats/nexml.js:38,44; src/formats/phyloxml.js:44,47,57,68; src/formats/nexus.js:7,28
…join, distance matrix

Locations fixed:
- src/nodes.js:24 graftANode builds d3 hierarchy nodes and updates
- src/nodes.js:50 addChild sets parent; NJ returns new phylotree(newick)
- src/nodes.js:99 deleteANode root case lifts sibling children, then updates
- src/export.js:12 getTipLengths uses the branch length accessor
- src/traversal.js:80 leftChildRightSibling guards unary nodes
- src/neighbor-join.js:120,38 jj starts at ii+1
- src/neighbor-join.js:62 getDistanceMatrix uses min length, guards empty input
…ets, annotations, internal-names

- menus.js modifySelection: attribute-list clear uses === true; restricted-selectable returns this and uses Array.isArray; notshown/tag bypass selectable and restricted-selectable
- menus.js nodeDropdownMenu: resolve container with d3.select(container).node()
- selection-sets.js initializeSelectionSets: rebuild members from node._selectionSet, persist active set and initial-sets-applied marker on phylotree
- edges.js initializeEdgeLabels: skip reserved annotation names
- nodes.js defNodeLabel: pass hierarchy node to showInternalName, never return undefined
…oot and branch-length scaling

Locations fixed:
- src/main.js: setBranchLength sync in constructor, parse errors thrown, JSON input, phyloxml detection, mrca, update(), name normalisation
- src/rooting.js: reroot(root) no-op, NaN branch lengths after reroot
- src/branches.js: defBranchLengthAccessor numeric/zero, setBranchLength sync, normalize equal/zero lengths, normalize/scale with custom accessor
Locations fixed:
- src/formats/registry.js: nhx defaults to [ ] delimiters
- src/formats/newick.js: reserved NHX keys namespaced (nhx_<key>), annotation initialised;
  getNewick skips hidden children without stray commas; coerces names and only
  skips 'root' for the actual root; non-string input rejected; root label/length
  kept; bootstrap_values left undefined for unlabeled internal nodes
- src/formats/beast.js: default options, no caller mutation, null json passthrough
- unrooted.js: bbox/scale skip notshown and hidden nodes
- unrooted.js: zero and negative branch lengths clamp to 0 (no || 1)
- unrooted.js: countLeaves gives 0 for notshown and 1 for collapsed; collapsed clades are not recursed into
- unrooted.js: collapsed clades get a screen-space [d.x, d.y] outline wedge
- clades.js: only draw collapsed outlines that are non-empty arrays (leaf collapse no longer throws)
… tips, and setup guards

Locations fixed in src/render/draw.js:
- placenodes: compute max_depth before the first tree_layout (scaling:false)
- placenodes/tree_layout: undef_BL is now an instance field so the unscaled
  fallback fires for undefined/non-finite branch lengths
- _handle_single_node_layout: collapsed outline skips hidden/coordinate-less tips
- process_internal_node: require a displayed child before placing the node
- constructor: rescale_nodeSpan over all descendants (no root.children access;
  fixes single-node tree); guard selection-sets / initial-sets / initial-selection
- placenodes/do_lr/radial/scale bar: guard zero extents against NaN
- update(): refresh this.links; brush handler uses this.links
- RTL: mirror collapsed outline points like d.y
- replace shadowed font_size()/scale_bar_font_size() with fontSize() and
  scaleBarFontSize(); declare in types and usage.ts
- style_edges(null) no longer throws
- getBranchLengths() returns undefined for the root, as on master; the
  Newick parser now keeps a root length, and normalize/scale skip the root.
- render-layout test looks up the root by its preserved label.
- tree-model tests skip the root entry when checking normalized lengths.
- getBranchLengths() returns the accessor value for every node again;
  normalize/scale include the root only when it has an explicit length.
- clusterPicker coerces numeric-string thresholds and throws only when the
  result is not a finite number.
- The constructor honours a {json, error} parser result, rejects
  non-object input with a clear error and recognises <phylogeny> as XML.
- The Newick parser rejects empty and whitespace-only strings; the
  neighbor-join seed that needed them is gone.
- Drop the redundant refreshHierarchy in nodes.js (update() does it).
- Lint: unused catch bindings and an unused eslint-disable directive.
@github-actions

Copy link
Copy Markdown
Contributor

API Documentation Preview

The API documentation has been updated in this PR. Here is a preview:

## Modules

<dl>
<dt><a href="#module_render/event-emitter">render/event-emitter</a></dt>
<dd><p>Event emitter mixin for phylotree TreeRender
Provides on/off/emit pattern for tree events</p>
</dd>
<dt><a href="#module_render/selection-sets">render/selection-sets</a></dt>
<dd><p>Multi-set selection management for phylotree</p>
</dd>
</dl>

## Classes

<dl>
<dt><a href="#Phylotree">Phylotree</a></dt>
<dd><p>An instance of a phylotree. Sets event listeners, parses tags, and creates links
that represent branches.</p>
</dd>
</dl>

## Functions

<dl>
<dt><a href="#getBranchLengths">getBranchLengths()</a> ⇒ <code>Array</code></dt>
<dd><p>Returns branch lengths</p>
</dd>
<dt><a href="#setBranchLength">setBranchLength(attr)</a> ⇒ <code>Object</code></dt>
<dd><p>Get or set branch length accessor.</p>
</dd>
<dt><a href="#normalize">normalize()</a> ⇒ <code><a href="#Phylotree">Phylotree</a></code></dt>
<dd><p>Normalizes branch lengths to range [0,1]</p>
</dd>
<dt><a href="#scale">scale(scale_by)</a> ⇒ <code><a href="#Phylotree">Phylotree</a></code></dt>
<dd><p>Scales branch lengths using a custom transformation function</p>
</dd>
<dt><a href="#branchName">branchName(attr)</a> ⇒</dt>
<dd><p>Get or set branch name accessor.</p>
</dd>
<dt><a href="#clusterPicker">clusterPicker(tree, bootstrap_thresold, diameter_threshold, root_node, missing_bootstrap_value)</a> ⇒</dt>
<dd><p>Implements a linear time / space version of the Cluster picker algorithm</p>
</dd>
<dt><a href="#newickParser">newickParser(nwk_str)</a> ⇒ <code>Object</code></dt>
<dd><p>Parses a Newick string into an equivalent JSON representation that is
suitable for consumption by <code>hierarchy</code>.</p>
<p>Optionally accepts bootstrap values. Currently supports Newick strings with or without branch lengths,
as well as tagged trees such as
 <code>(a,(b{TAG},(c{TAG},d{ANOTHERTAG})))</code></p>
</dd>
<dt><a href="#getNewick">getNewick(annotator, node)</a> ⇒ <code>String</code></dt>
<dd><p>Return Newick string representat

... (truncated)

Full documentation will be available at: https://veg.github.io/phylotree.js/API.md when merged.

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Preview removed because the pull request was closed.

- Constructor unwraps a {json} parser result whether or not it carries an
  error field, so trees passed in that wrapper are no longer replaced by a
  one-node tree.
- NEXUS statements and TRANSLATE entries are split outside quotes and
  [comments], so quoted labels containing ';' or ',' parse again.
- fitRootToTip treats undefined dates as missing and returns fit: null
  when the dates cannot support a fit (fewer than two, or no spread).
- The default branch-length accessor reports 0 for the actual root, not
  for any node that happens to be named "root".
- clusterPicker accepts Infinity as an unbounded diameter again.
- Selection sets skip malformed definitions; initial-sets are not consumed
  by a render that has no set definitions yet.
- NeXML picks the unreferenced node as root when none is flagged;
  PhyloXML keeps a lone self-closing <clade/> child.
- Declarations: update() returns the tree, createNode returns a node,
  fitRootToTip's fit may be null.
@github-actions

Copy link
Copy Markdown
Contributor

API Documentation Preview

The API documentation has been updated in this PR. Here is a preview:

## Modules

<dl>
<dt><a href="#module_render/event-emitter">render/event-emitter</a></dt>
<dd><p>Event emitter mixin for phylotree TreeRender
Provides on/off/emit pattern for tree events</p>
</dd>
<dt><a href="#module_render/selection-sets">render/selection-sets</a></dt>
<dd><p>Multi-set selection management for phylotree</p>
</dd>
</dl>

## Classes

<dl>
<dt><a href="#Phylotree">Phylotree</a></dt>
<dd><p>An instance of a phylotree. Sets event listeners, parses tags, and creates links
that represent branches.</p>
</dd>
</dl>

## Functions

<dl>
<dt><a href="#getBranchLengths">getBranchLengths()</a> ⇒ <code>Array</code></dt>
<dd><p>Returns branch lengths</p>
</dd>
<dt><a href="#setBranchLength">setBranchLength(attr)</a> ⇒ <code>Object</code></dt>
<dd><p>Get or set branch length accessor.</p>
</dd>
<dt><a href="#normalize">normalize()</a> ⇒ <code><a href="#Phylotree">Phylotree</a></code></dt>
<dd><p>Normalizes branch lengths to range [0,1]</p>
</dd>
<dt><a href="#scale">scale(scale_by)</a> ⇒ <code><a href="#Phylotree">Phylotree</a></code></dt>
<dd><p>Scales branch lengths using a custom transformation function</p>
</dd>
<dt><a href="#branchName">branchName(attr)</a> ⇒</dt>
<dd><p>Get or set branch name accessor.</p>
</dd>
<dt><a href="#clusterPicker">clusterPicker(tree, bootstrap_thresold, diameter_threshold, root_node, missing_bootstrap_value)</a> ⇒</dt>
<dd><p>Implements a linear time / space version of the Cluster picker algorithm</p>
</dd>
<dt><a href="#newickParser">newickParser(nwk_str)</a> ⇒ <code>Object</code></dt>
<dd><p>Parses a Newick string into an equivalent JSON representation that is
suitable for consumption by <code>hierarchy</code>.</p>
<p>Optionally accepts bootstrap values. Currently supports Newick strings with or without branch lengths,
as well as tagged trees such as
 <code>(a,(b{TAG},(c{TAG},d{ANOTHERTAG})))</code></p>
</dd>
<dt><a href="#getNewick">getNewick(annotator, node)</a> ⇒ <code>String</code></dt>
<dd><p>Return Newick string representat

... (truncated)

Full documentation will be available at: https://veg.github.io/phylotree.js/API.md when merged.

- A hierarchy object that happens to carry a json field is no longer
  mistaken for a parser result; only {json[, error]} without name or
  children is unwrapped.
- fitRootToTip coerces numeric-string dates, returns fit: null when the
  distances leave no finite line, and fits the current root from
  data.rootToTip. It read data.rtta, which only the other-root pass sets,
  so the baseline fit was always NaN and the current root could never win.
- NEXUS: the TREES block ends at the END statement found by quote-aware
  splitting, so END; inside a quoted label is fine; doubled quotes inside
  a single-quoted label unescape.
- initial-sets are consumed only once a requested set is actually defined.
@github-actions

Copy link
Copy Markdown
Contributor

API Documentation Preview

The API documentation has been updated in this PR. Here is a preview:

## Modules

<dl>
<dt><a href="#module_render/event-emitter">render/event-emitter</a></dt>
<dd><p>Event emitter mixin for phylotree TreeRender
Provides on/off/emit pattern for tree events</p>
</dd>
<dt><a href="#module_render/selection-sets">render/selection-sets</a></dt>
<dd><p>Multi-set selection management for phylotree</p>
</dd>
</dl>

## Classes

<dl>
<dt><a href="#Phylotree">Phylotree</a></dt>
<dd><p>An instance of a phylotree. Sets event listeners, parses tags, and creates links
that represent branches.</p>
</dd>
</dl>

## Functions

<dl>
<dt><a href="#getBranchLengths">getBranchLengths()</a> ⇒ <code>Array</code></dt>
<dd><p>Returns branch lengths</p>
</dd>
<dt><a href="#setBranchLength">setBranchLength(attr)</a> ⇒ <code>Object</code></dt>
<dd><p>Get or set branch length accessor.</p>
</dd>
<dt><a href="#normalize">normalize()</a> ⇒ <code><a href="#Phylotree">Phylotree</a></code></dt>
<dd><p>Normalizes branch lengths to range [0,1]</p>
</dd>
<dt><a href="#scale">scale(scale_by)</a> ⇒ <code><a href="#Phylotree">Phylotree</a></code></dt>
<dd><p>Scales branch lengths using a custom transformation function</p>
</dd>
<dt><a href="#branchName">branchName(attr)</a> ⇒</dt>
<dd><p>Get or set branch name accessor.</p>
</dd>
<dt><a href="#clusterPicker">clusterPicker(tree, bootstrap_thresold, diameter_threshold, root_node, missing_bootstrap_value)</a> ⇒</dt>
<dd><p>Implements a linear time / space version of the Cluster picker algorithm</p>
</dd>
<dt><a href="#newickParser">newickParser(nwk_str)</a> ⇒ <code>Object</code></dt>
<dd><p>Parses a Newick string into an equivalent JSON representation that is
suitable for consumption by <code>hierarchy</code>.</p>
<p>Optionally accepts bootstrap values. Currently supports Newick strings with or without branch lengths,
as well as tagged trees such as
 <code>(a,(b{TAG},(c{TAG},d{ANOTHERTAG})))</code></p>
</dd>
<dt><a href="#getNewick">getNewick(annotator, node)</a> ⇒ <code>String</code></dt>
<dd><p>Return Newick string representat

... (truncated)

Full documentation will be available at: https://veg.github.io/phylotree.js/API.md when merged.

- A parser result that also carries a name is still unwrapped when it has
  an error field.
- NEXUS unquoting strips one layer of quotes, so a single-quoted label may
  contain literal double quotes.
- fitRootToTip: identical distances give fit: null (r2 was 0/0); blank
  strings and booleans are not dates; a candidate root has to beat the
  current root's r2 instead of 0, so a perfect current root is kept.
@github-actions

Copy link
Copy Markdown
Contributor

API Documentation Preview

The API documentation has been updated in this PR. Here is a preview:

## Modules

<dl>
<dt><a href="#module_render/event-emitter">render/event-emitter</a></dt>
<dd><p>Event emitter mixin for phylotree TreeRender
Provides on/off/emit pattern for tree events</p>
</dd>
<dt><a href="#module_render/selection-sets">render/selection-sets</a></dt>
<dd><p>Multi-set selection management for phylotree</p>
</dd>
</dl>

## Classes

<dl>
<dt><a href="#Phylotree">Phylotree</a></dt>
<dd><p>An instance of a phylotree. Sets event listeners, parses tags, and creates links
that represent branches.</p>
</dd>
</dl>

## Functions

<dl>
<dt><a href="#getBranchLengths">getBranchLengths()</a> ⇒ <code>Array</code></dt>
<dd><p>Returns branch lengths</p>
</dd>
<dt><a href="#setBranchLength">setBranchLength(attr)</a> ⇒ <code>Object</code></dt>
<dd><p>Get or set branch length accessor.</p>
</dd>
<dt><a href="#normalize">normalize()</a> ⇒ <code><a href="#Phylotree">Phylotree</a></code></dt>
<dd><p>Normalizes branch lengths to range [0,1]</p>
</dd>
<dt><a href="#scale">scale(scale_by)</a> ⇒ <code><a href="#Phylotree">Phylotree</a></code></dt>
<dd><p>Scales branch lengths using a custom transformation function</p>
</dd>
<dt><a href="#branchName">branchName(attr)</a> ⇒</dt>
<dd><p>Get or set branch name accessor.</p>
</dd>
<dt><a href="#clusterPicker">clusterPicker(tree, bootstrap_thresold, diameter_threshold, root_node, missing_bootstrap_value)</a> ⇒</dt>
<dd><p>Implements a linear time / space version of the Cluster picker algorithm</p>
</dd>
<dt><a href="#newickParser">newickParser(nwk_str)</a> ⇒ <code>Object</code></dt>
<dd><p>Parses a Newick string into an equivalent JSON representation that is
suitable for consumption by <code>hierarchy</code>.</p>
<p>Optionally accepts bootstrap values. Currently supports Newick strings with or without branch lengths,
as well as tagged trees such as
 <code>(a,(b{TAG},(c{TAG},d{ANOTHERTAG})))</code></p>
</dd>
<dt><a href="#getNewick">getNewick(annotator, node)</a> ⇒ <code>String</code></dt>
<dd><p>Return Newick string representat

... (truncated)

Full documentation will be available at: https://veg.github.io/phylotree.js/API.md when merged.

- An object with a children array is hierarchical JSON even if it also
  carries json and error fields; only objects without children are
  unwrapped as parser results.
- fitRootToTip keeps searching alternative roots when the current root has
  no usable fit, instead of returning early with fit: null.
@github-actions

Copy link
Copy Markdown
Contributor

API Documentation Preview

The API documentation has been updated in this PR. Here is a preview:

## Modules

<dl>
<dt><a href="#module_render/event-emitter">render/event-emitter</a></dt>
<dd><p>Event emitter mixin for phylotree TreeRender
Provides on/off/emit pattern for tree events</p>
</dd>
<dt><a href="#module_render/selection-sets">render/selection-sets</a></dt>
<dd><p>Multi-set selection management for phylotree</p>
</dd>
</dl>

## Classes

<dl>
<dt><a href="#Phylotree">Phylotree</a></dt>
<dd><p>An instance of a phylotree. Sets event listeners, parses tags, and creates links
that represent branches.</p>
</dd>
</dl>

## Functions

<dl>
<dt><a href="#getBranchLengths">getBranchLengths()</a> ⇒ <code>Array</code></dt>
<dd><p>Returns branch lengths</p>
</dd>
<dt><a href="#setBranchLength">setBranchLength(attr)</a> ⇒ <code>Object</code></dt>
<dd><p>Get or set branch length accessor.</p>
</dd>
<dt><a href="#normalize">normalize()</a> ⇒ <code><a href="#Phylotree">Phylotree</a></code></dt>
<dd><p>Normalizes branch lengths to range [0,1]</p>
</dd>
<dt><a href="#scale">scale(scale_by)</a> ⇒ <code><a href="#Phylotree">Phylotree</a></code></dt>
<dd><p>Scales branch lengths using a custom transformation function</p>
</dd>
<dt><a href="#branchName">branchName(attr)</a> ⇒</dt>
<dd><p>Get or set branch name accessor.</p>
</dd>
<dt><a href="#clusterPicker">clusterPicker(tree, bootstrap_thresold, diameter_threshold, root_node, missing_bootstrap_value)</a> ⇒</dt>
<dd><p>Implements a linear time / space version of the Cluster picker algorithm</p>
</dd>
<dt><a href="#newickParser">newickParser(nwk_str)</a> ⇒ <code>Object</code></dt>
<dd><p>Parses a Newick string into an equivalent JSON representation that is
suitable for consumption by <code>hierarchy</code>.</p>
<p>Optionally accepts bootstrap values. Currently supports Newick strings with or without branch lengths,
as well as tagged trees such as
 <code>(a,(b{TAG},(c{TAG},d{ANOTHERTAG})))</code></p>
</dd>
<dt><a href="#getNewick">getNewick(annotator, node)</a> ⇒ <code>String</code></dt>
<dd><p>Return Newick string representat

... (truncated)

Full documentation will be available at: https://veg.github.io/phylotree.js/API.md when merged.

@stevenweaver
stevenweaver merged commit ab2b817 into master Nov 17, 2026
7 checks passed
stevenweaver added a commit that referenced this pull request Nov 17, 2026
The API Documentation workflow pushed a regenerated API.md to master after
every merge. The branch ruleset added for Dependabot auto-merge now rejects
that push (GH013), so the run after #553 failed and API.md went stale.

API.md is now committed with the JSDoc change that affects it, and the
workflow runs `yarn docs:validate` on pushes and pull requests. The PR
preview comment compares against the base branch instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant