Repository navigation
v2.7.0 - right-click node menu, collapsed-clade fixes, 70+ robustness fixes, Node 22.12
LatestWhat's Changed
Requirements
- Node 22.12 or newer is required (
engines.node >= 22.12; it was>= 20). Node 20 is end-of-life, andcommander@15needs 22.12. Browser use is unaffected. (#544)
New
- Right-click node menu. The new
menu-triggerrender 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) contextMenuevent. Listed in the docs for years but never emitted; it now fires with(node, event)just before a node's menu opens. Callevent.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, andaddCustomMenuis exported from the package (import { addCustomMenu } from "phylotree"), with a README section, API docs and TypeScript types. (#545)fontSize([n])andscaleBarFontSize([n])on the renderer. The oldfont_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
TREEstatements,TRANSLATEblocks and lowercase keywords parse; PhyloXML readsbranch_lengthattributes. (#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: falsedrew 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-leftlayouts. - Trees with an undefined branch length fell apart into
NaNpositions; they now fall back to an unscaled layout. Zero-length and single-node trees render. update()refreshes the branch list afterreroot,deleteANodeorgraftANode, so deleted branches are no longer drawn.- With
binary-selectableand a multi-entryattribute-list, selecting for one attribute wiped the others. The node menu threw whencontainerwas an Element or d3 selection.restricted-selectablebroke method chaining; Hide was a dead menu item whenselectable: false. - Selection sets survive a reroot;
initial-setsis applied once per tree instead of re-adding nodes on every re-render. - Newick annotations named
children,data,collapsedand the like overwrote node fields. internal-namescallbacks received the hierarchy node from some call sites andnode.datafrom others; unnamed internal nodes maderender()throw.
Tree model (#553)
neighborJoining()returned nodes without depth, height or links, so its tree could not be rendered (every branchNaN) 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 lefttree.nodesundefined; rerooting with a lengthless child producedNaN.mrca()cached across calls and included the node itself, so a second call returned the wrong node.deleteANodeon a child of a binary root threw and left the tree half-modified;graftANodebuilt plain objects without.data. Both now rebuild depth and height.- The constructor throws a clear
Errorwhen a parser fails, instead of an obscureTypeError. A{json, error}parser result is accepted directly.
Parsers and export (#553)
getNewick()after hiding nodes emitted(,B)and,,phantom tips; a taxon namedrootwas 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 inclusterPickerandphylopart.type: 'nhx'enables bracket delimiters. - PhyloXML:
if (DOMParser)threw in Node; unnamed clades brokegetNewick; every branch got an invented0.01length. - 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)
fitRootToTipnever computed a valid fit for the current root and compared candidates against 0, so it could pick a worse root; it gaveNaNor threw on fewer than two dated tips.computeMidpointnever reset its state between calls;centerOfTreedivided 0/0 on zero-length branches;sackinused stale depths after a reroot;pairwiseDistancescrashed on a single-node tree.phylopartadded the last child's branch to every root-to-leaf path, and its histogram bin index was not clamped.clusterPickerandphyloparttreated an unlabeled internal node as support 0 instead of missing.
Behaviour changes to be aware of
phyloparton the bundled EU3031 example finds 300 clusters; it found 297 because of the root-path bug.- PhyloXML no longer invents a
0.01branch length; lengthless trees fall back to length 1 like Newick. getNewick()preserves root labels and a taxon namedroot.- The constructor throws on unparseable input (including an empty string) rather than producing a broken tree.
getBranchLengths(),getTipLengths(),hasBranchLengths()and every metric read throughbranch_length_accessor. Assigning thebranch_lengthfield directly no longer affects them; usesetBranchLength().normalizeBranchLengths()andscaleBranchLengths()with a custom accessor write the results intodata.attributeand restore the default accessor.fitRootToTipreturns{ root, fit: null }when no root has a finite fit; undated tips count as missing, numeric-string dates are accepted.mrca()returnsundefinedwhen a requested name is absent (it returned the root).clusterPickerthrows on a non-numericbootstrap_thresholdor a negative or non-numericdiameter_threshold;Infinityis accepted as an unbounded diameter.loadAnnotations(tree, label, …)stores underlabel(it always stored under"test").- The UMD bundle no longer
require()s lodash or expects an undefined_$1global;underscore(_) is still the only external.
Dependencies and packaging
- All dependencies and workflow actions are on their latest majors:
commander15,eslint10,jsdom30,typescript7. (#544) - Ten dependencies removed:
lodash,winston,csv-stringifyandpretty-datafrom the runtime set, andprettier,@rollup/plugin-commonjs,rollup-plugin-copy,concurrently,http-serverandsource-map-supportfrom dev.jquerywas already unused and is gone. The runtime dependencies are nowd3,@types/d3,underscore,commander,fast-xml-parserandmoment. (#544, #549) yarn.lockis 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
NaNtransform (the linear layout is fixed). - Collapsing the root node in the unrooted layout draws nothing.
getNewick()cannot tell a real taxon labelrooton 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