Skip to content

v2.7.0 - right-click node menu, collapsed-clade fixes, 70+ robustness fixes, Node 22.12

Latest

Choose a tag to compare

@stevenweaver stevenweaver released this 17 Nov 23:37
· 1 commit to master since this release

What's Changed

Requirements

  • Node 22.12 or newer is required (engines.node >= 22.12; it was >= 20). Node 20 is end-of-life, and commander@15 needs 22.12. Browser use is unaffected. (#544)

New

  • Right-click node menu. The new menu-trigger render option takes "click" (default, unchanged), "contextmenu" or "both". With right-click enabled the browser's own context menu is suppressed on nodes. (#545, closes #520 and #523)
  • contextMenu event. Listed in the docs for years but never emitted; it now fires with (node, event) just before a node's menu opens. Call event.preventDefault() in a listener to show your own menu instead of the built-in one. (#545)
  • openNodeMenu(node, event) opens a node's menu from code, and addCustomMenu is exported from the package (import { addCustomMenu } from "phylotree"), with a README section, API docs and TypeScript types. (#545)
  • fontSize([n]) and scaleBarFontSize([n]) on the renderer. The old font_size() / scale_bar_font_size() methods were shadowed by numeric fields and could never be called. (#553)
  • NeXML input works. It threw on every document before. NEXUS files with multi-line TREE statements, TRANSLATE blocks and lowercase keywords parse; PhyloXML reads branch_length attributes. (#553)

Bug fixes

Collapsed clades (#552, fixes #551; reported and fixed by @YehyaBELHAMRA)

  • In the radial layout, a collapsed clade's outline was all NaN, so its tips vanished and nothing was drawn.
  • A clade collapsed inside an already collapsed clade left a stray second shape.
  • On trees over 300 nodes (no transitions), a collapsed clade's shape never moved when the layout changed around it.
  • toggleCollapse() on a node inside a collapsed clade threw.

Rendering (#553)

  • scaling: false drew internal nodes to the right of their own tips.
  • The unrooted layout ignored Hide and Collapse: hidden nodes still took part in the layout, so hiding a subtree shrank the visible tree, and collapsed clades drew at the origin. Zero-length branches were drawn with length 1.
  • A clade collapsed around a hidden leaf drew an outline with spikes off the plot; collapsed outlines were not mirrored in right-to-left layouts.
  • Trees with an undefined branch length fell apart into NaN positions; they now fall back to an unscaled layout. Zero-length and single-node trees render.
  • update() refreshes the branch list after reroot, deleteANode or graftANode, so deleted branches are no longer drawn.
  • 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; initial-sets is applied once per tree instead of re-adding nodes on every re-render.
  • Newick annotations named children, data, collapsed and the like overwrote node fields.
  • internal-names callbacks received the hierarchy node from some call sites and node.data from others; unnamed internal nodes made render() throw.

Tree model (#553)

  • neighborJoining() returned nodes without depth, height or links, so its tree could not be rendered (every branch NaN) or rerooted. It also joined a node with itself on all-zero distances, and reused an internal node label once there were more than ten. (#549, #553)
  • normalizeBranchLengths() never mapped the shortest branch to 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.
  • The constructor throws a clear Error when a parser fails, instead of an obscure TypeError. A {json, error} parser result is accepted directly.

Parsers and export (#553)

  • getNewick() after hiding nodes emitted (,B) and ,, phantom tips; a taxon named root was dropped; an unnamed internal node threw. The root label and length after the final ) are kept.
  • Newick: an unlabeled internal node got bootstrap_values = '', which read as support 0 in clusterPicker and phylopart. type: 'nhx' enables bracket delimiters.
  • PhyloXML: if (DOMParser) threw in Node; unnamed clades broke getNewick; every branch got an invented 0.01 length.
  • NEXUS: quoted labels may contain ; or ,; a missing TREES block returns an error instead of throwing.
  • extractDates() with the default getter returned no dates.

Metrics and clustering (#553)

  • fitRootToTip never computed a valid fit for the current root and compared candidates against 0, so it could pick a worse root; it gave NaN or threw on fewer than two dated tips.
  • computeMidpoint never reset its state between calls; centerOfTree divided 0/0 on zero-length branches; sackin used stale depths after a reroot; pairwiseDistances crashed on a single-node tree.
  • phylopart added the last child's branch to every root-to-leaf path, and its histogram bin index was not clamped. clusterPicker and phylopart treated an unlabeled internal node as support 0 instead of missing.

Behaviour changes to be aware of

  • phylopart on the bundled EU3031 example finds 300 clusters; it found 297 because of the root-path bug.
  • 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 (including an empty string) rather than producing a broken tree.
  • getBranchLengths(), getTipLengths(), hasBranchLengths() and every metric read through branch_length_accessor. Assigning the branch_length field directly no longer affects them; use setBranchLength(). normalizeBranchLengths() and scaleBranchLengths() with a custom accessor write the results into data.attribute and restore the default accessor.
  • fitRootToTip returns { root, fit: null } when no root has a finite fit; undated tips count as missing, numeric-string dates are accepted.
  • mrca() returns undefined when a requested name is absent (it returned the root).
  • clusterPicker throws on a non-numeric bootstrap_threshold or a negative or non-numeric diameter_threshold; Infinity is accepted as an unbounded diameter.
  • loadAnnotations(tree, label, …) stores under label (it always stored under "test").
  • The UMD bundle no longer require()s lodash or expects an undefined _$1 global; underscore (_) is still the only external.

Dependencies and packaging

  • All dependencies and workflow actions are on their latest majors: commander 15, eslint 10, jsdom 30, typescript 7. (#544)
  • Ten dependencies removed: lodash, winston, csv-stringify and pretty-data from the runtime set, and prettier, @rollup/plugin-commonjs, rollup-plugin-copy, concurrently, http-server and source-map-support from dev. jquery was already unused and is gone. The runtime dependencies are now d3, @types/d3, underscore, commander, fast-xml-parser and moment. (#544, #549)
  • yarn.lock is no longer committed, so CI installs the same fresh versions npm users get. (#550)
  • Dependabot security and minor/patch updates auto-merge once CI passes; routine checks are monthly. (#548)
  • Dependency bumps: rollup 4.65.0, @rollup/plugin-terser 1.0.2 (#546), serialize-javascript (#547).

Known issues

  • A one-node tree in the radial layout still gets a NaN transform (the linear layout is fixed).
  • Collapsing the root node in the unrooted layout draws nothing.
  • getNewick() cannot tell a real taxon label root on the root node from the parser's implicit root name, so that one label is dropped, as before.

Thanks to @YehyaBELHAMRA for the detailed report and fix behind #551/#552, and to @gaurav for the addCustomMenu documentation in #521.

Full Changelog: v2.6.1...v2.7.0