Table of Contents
- _destroyed
- _pendingFrames
- constructor
- setData
- setTree
- _nodeGlyphSelector
- _rulerOffset
- draw
- setLayout
- setColorOptions
- setMode
- setType
- setRotation
- setHStretch
- setVStretch
- setAnimation
- setBranchNodes
- eachBranchNode
- setBranchLabels
- eachBranchLabel
- setBranchDistances
- eachBranchDistance
- setLeafNodes
- eachLeafNode
- setEquidistantLeaves
- setLeafLabels
- eachLeafLabel
- setRuler
- setTooltipFormatter
- collapseNode
- isNodeCollapsed
- getDescendantGUIDs
- _getFilteredHierarchy
- _getVisibleHierarchy
- addAnnotation
- getAnnotation
- removeAnnotation
- addTemporalAnnotation
- getTemporalAnnotation
- removeTemporalAnnotation
- setShowTemporalAnnotations
- getNodeGUIDs
- search
- on
- off
- trigger
- destroy
- _transition
- redraw
- setInteractive
- setBranchNodeSize
- setBranchLabelSize
- setBranchDistanceSize
- setLeafNodeSize
- setLeafLabelSize
- setTooltips
- setShowTemporal
- setBackground
- recenter
- findNodeColor
- interpolateColor
- findBranchColor
- getAllLeaves
- setNodeLabelPosition
- updateRuler
- arcFlagIndices
- interpolatePath
- samplePath
- circularPoint
- uprightRotation
- smoothLinkLabel
- smoothRadialLinkLabel
- chordLinkLabel
- elbowLinkLabel
- isLeftHalf
_destroyed
True once destroy() has been called; queued redraws are skipped.
_pendingFrames
Pending requestAnimationFrame ids for queued redraws.
constructor
This class function creates a TidyTree object.
Parameters
-
data**(stringpatristic.Branch)** A valid newick string or patristic.Branch object optionsTidyTreeOptions? A Javascript object containing options to set up the treeeventsTidyTreeEvents? Event handlers
setData
Update the TidyTree’s underlying data structure There are two contexts in which you should call this: 1. You wish to replace the tree with a completely different tree, given by a different newick string 2. Your underlying tree data has changed (e.g. the tree has been re-rooted)
Parameters
datapatristic.Branch A patristic.Branch object
Returns TidyTree the TidyTree object
setTree
Update the TidyTree’s underlying data structure There are two contexts in which you should call this: 1. You wish to replace the tree with a completely different tree, given by a different newick string 2. Your underlying tree data has changed (e.g. the tree has been re-rooted)
Parameters
newickstring A valid newick string
Returns TidyTree the TidyTree object
_nodeGlyphSelector
Returns the CSS selector for the node glyph element based on the current nodeShape.
Returns string The selector string (“circle”, “rect”, or “polygon”).
_rulerOffset
Private method to calculate how much vertical space to leave for the ruler
Returns number
draw
Draws a Phylogenetic on the element referred to by selector
Parameters
-
selector**(stringd3.Selection<any, any, any, any>)** A CSS selector
Returns TidyTree the TidyTree object
setLayout
Set the TidyTree’s layout
Parameters
newLayoutLayout The new layout
Returns TidyTree The TidyTree Object
setColorOptions
Set the TidyTree’s colorOptions
Parameters
newColorOptionsColorOptions The new colorOptions
Returns TidyTree The TidyTree Object
setMode
Set the TidyTree’s mode
Parameters
newModeMode The new mode
Returns TidyTree the TidyTree object
setType
Set the TidyTree’s type
Parameters
newTypeTreeType The new type
Returns TidyTree the TidyTree object
setRotation
Set the TidyTree’s rotation
Parameters
degreesnumber The new number of degrees by which to rotate the tree
Returns TidyTree the TidyTree object
setHStretch
Set the TidyTree’s Horizontal Stretch
Parameters
proportionnumber The new proportion by which to stretch the tree
Returns TidyTree the TidyTree object
setVStretch
Set the TidyTree’s Vertical Stretch
Parameters
proportionnumber The new proportion by which to stretch the tree
Returns TidyTree the TidyTree object
setAnimation
Set the TidyTree’s animation time. Note that this does not trigger a redraw.
Parameters
timenumber The desired duration of an animation, in ms. Set to 0 to turn animations off completely.
Returns TidyTree The TidyTree object
setBranchNodes
Shows or hides the Branch Nodes
Parameters
showboolean Should Branch nodes be shown?
Returns TidyTree the TidyTree object
eachBranchNode
Restyles Leaf Nodes
Parameters
stylerfunction (node: Element, datum: any): void A function that restyles each node.stylerreceives a reference to the DOM node to be styled, and an associated data object.
Returns TidyTree the TidyTree Object
setBranchLabels
Set the TidyTree’s branchLabels
Parameters
showboolean Should the TidyTree show branchLabels?
Returns TidyTree the TidyTree Object
eachBranchLabel
Restyles Branch Label
Parameters
stylerfunction (node: Element, datum: any): void A function that restyles each node.stylerreceives a reference to the DOM node to be styled, and an associated data object.
Returns TidyTree the TidyTree Object
setBranchDistances
Shows or hides the TidyTree’s branch labels
Parameters
showboolean Should the TidyTree show branch distances?
Returns TidyTree The TidyTree Object
eachBranchDistance
Restyles Branch Distances
Parameters
stylerfunction (node: Element, datum: any): void A function that restyles each node.stylerreceives a reference to the DOM node to be styled, and an associated data object.
Returns TidyTree the TidyTree Object
setLeafNodes
Shows or Hides the Leaf Nodes
Parameters
showboolean Should leaf nodes be visible?
Returns TidyTree The TidyTree Object
eachLeafNode
Restyles Leaf Nodes
Parameters
stylerfunction (node: Element, datum: any): void A function that restyles each node.stylerreceives a reference to the DOM node to be styled, and an associated data object.
Returns TidyTree the TidyTree Object
setEquidistantLeaves
Set the TidyTree’s leaves to be equidistant
Parameters
isEquidistantboolean
Returns TidyTree
setLeafLabels
Shows or Hides the TidyTree’s Leaf Labels
Parameters
showboolean Should the TidyTree show leafLabels?
Returns TidyTree the TidyTree Object
eachLeafLabel
Restyles Leaf Labels
Parameters
stylerfunction (node: Element, datum: any): void A function that restyles each node.stylerreceives a reference to the DOM node to be styled, and an associated data object.
Returns TidyTree the TidyTree Object
setRuler
Shows or hides the TidyTree’s branch labels
Parameters
showboolean Should the TidyTree show branchLabels?
Returns TidyTree The TidyTree Object
setTooltipFormatter
Set a custom formatter function for tooltip content.
The formatter receives the node data object and should return a string
to display in the tooltip. If not set, the node id is used by default.
The result is passed to showtooltip handlers as the third element of
their argument. It may contain text from the Newick input, so handlers
should render it as plain text (e.g. selection.text() or
textContent), not as HTML.
Parameters
formatterfunction (data: any): string A function that takes node data and returns a string.
Returns TidyTree The TidyTree object.
collapseNode
Collapse or expand a subtree rooted at the given node GUID. If the node is already collapsed, it will be expanded; otherwise it will be collapsed.
Parameters
nodeGuidstring The GUID of the node whose subtree to collapse/expand.
Returns TidyTree The TidyTree object.
isNodeCollapsed
Check whether a node is currently collapsed.
Parameters
nodeGuidstring The GUID of the node to check.
Returns boolean True if the node is collapsed, false otherwise.
getDescendantGUIDs
Returns an array of all descendant GUIDs (including the node itself) for a given node GUID.
Parameters
nodeGuidstring The GUID of the root node.
Returns Array<string> Array of descendant GUIDs.
_getFilteredHierarchy
Returns a filtered copy of the hierarchy that excludes collapsed subtrees. Nodes that are collapsed (and all their descendants) are removed from the returned hierarchy so they are not rendered.
Returns d3.HierarchyNode<NodeDatum> A filtered d3 hierarchy object.
_getVisibleHierarchy
Returns a filtered hierarchy containing only nodes within the visible viewport. Used for virtualization of large trees (1000+ nodes).
Parameters
hierarchyd3.HierarchyNode<NodeDatum> The full filtered hierarchy
Returns d3.HierarchyNode<NodeDatum> A d3 hierarchy with only visible nodes
addAnnotation
Add or update an annotation (metadata) for a specific node.
Parameters
nodeGuidstring The GUID of the node to annotate.dataany The annotation data to store.
Returns TidyTree The TidyTree object.
getAnnotation
Retrieve the annotation data for a specific node.
Parameters
nodeGuidstring The GUID of the node.
| Returns **(any | undefined)** The annotation data, or undefined if none exists. |
removeAnnotation
Remove the annotation for a specific node.
Parameters
nodeGuidstring The GUID of the node.
Returns TidyTree The TidyTree object.
addTemporalAnnotation
Add or update a temporal annotation for a specific node. Temporal annotations render as colored bars overlaid on branches to represent time intervals (e.g., divergence dates, sampling dates).
Parameters
guidstring The GUID of the node to annotate.startnumber Start time value.endnumber End time value.labelstring? Optional label to display.colorstring? Optional color for the temporal bar.
Returns TidyTree The TidyTree object.
getTemporalAnnotation
Retrieve the temporal annotation for a specific node.
Parameters
guidstring The GUID of the node.
| Returns **(TemporalAnnotation | undefined)** The temporal annotation data, or undefined if none exists. |
removeTemporalAnnotation
Remove the temporal annotation for a specific node.
Parameters
guidstring The GUID of the node.
Returns TidyTree The TidyTree object.
setShowTemporalAnnotations
Set whether temporal annotations are visible.
Parameters
showboolean Whether to show temporal annotations.
Returns TidyTree The TidyTree object.
getNodeGUIDs
Retrieves the GUIDs of the nodes in the TidyTree instance.
Parameters
leavesOnlyboolean Whether to retrieve GUIDs only for leaf nodes.predicatefunction (node: Element): boolean? A function that returns true if the node should be included
Returns Array<{_guid: string, id: string}> An array of GUIDs of the nodes.
search
Searches the tree, returns Search Results
Parameters
testfunction (d: any): boolean A function which takes a Branch and returns a Truthy or Falsy value.
| Returns **(d3.Selection<any, any, any, any> | undefined)** The array of results |
on
Attaches a new event listener Please note that this is not yet functioning.
Parameters
eventsstring A space-delimited list of event namescallbackfunction (…args: Array<any>): void The function to run when one of theeventsoccurs.
Returns TidyTree The TidyTree on which this method was called.
off
Removes all event listeners from the given events
Parameters
eventsstring A space-delimited list of event names
Returns TidyTree The TidyTree on which this method was called.
trigger
Forces the tree to respond as though an event has occurred
Parameters
eventsstring space-delimited list of names of events to trigger.args…Array<any> Any arguments which should be passed to the event handler(s).
Returns Array<any> The output of the callback run on event
destroy
Destroys the TidyTree
Returns void undefined
_transition
Wraps a d3 selection transition with requestAnimationFrame for smoother rendering. If animation is 0, applies attributes immediately without animation.
Parameters
selectiond3.Selection<any, any, any, any> The d3 selection to transition.-
attrs**Record<string, (stringnumber)>?** Object of attribute/style key-value pairs to apply. applyFnfunction (transition: d3.Transition<any, any, any, any>): void? Optional function to apply custom transition logic.
| Returns **(d3.Selection<any, any, any, any> | d3.Transition<any, any, any, any>)** The transition or selection. |
redraw
Redraws the links and relocates the nodes accordingly
Returns TidyTree The TidyTree Object
setInteractive
Set the TidyTree’s interactivity
Parameters
boolboolean Whether the tree should be interactive
Returns TidyTree The TidyTree object
setBranchNodeSize
Set the branch node size.
Parameters
sizenumber The size of branch nodes.
Returns TidyTree The TidyTree object.
setBranchLabelSize
Set the branch label size.
Parameters
sizenumber The font size for branch labels.
Returns TidyTree The TidyTree object.
setBranchDistanceSize
Set the branch distance size.
Parameters
sizenumber The font size for branch distance labels.
Returns TidyTree The TidyTree object.
setLeafNodeSize
Set the leaf node size.
Parameters
sizenumber The size of leaf nodes.
Returns TidyTree The TidyTree object.
setLeafLabelSize
Set the leaf label size.
Parameters
sizenumber The font size for leaf labels.
Returns TidyTree The TidyTree object.
setTooltips
Set whether tooltips are enabled.
Parameters
enabledboolean Whether tooltips should be shown.
Returns TidyTree The TidyTree object.
setShowTemporal
Set whether temporal annotations are visible.
Parameters
showboolean Whether to show temporal annotations.
Returns TidyTree The TidyTree object.
setBackground
Set the background color of the tree container.
Parameters
colorstring A CSS color string.
Returns TidyTree The TidyTree object.
recenter
Recenters the tree in the center of the view
Returns TidyTree The TidyTree object
findNodeColor
Finds the color of a given node based on the color options provided.
Parameters
nodeany The node for which to find the color.colorOptionsColorOptions The color options object containing the color mode, leavesOnly, predicate, default color, and highlight color.
Returns string The color of the node.
interpolateColor
Interpolate between two hex colors by a factor t (0 to 1).
Parameters
colorAstring Starting hex color.colorBstring Ending hex color.tnumber Interpolation factor between 0 to 1.
Returns string The interpolated hex color.
findBranchColor
Find the color of a given link based on the provided color options.
Parameters
linkany The link for which to find the color.colorOptionsColorOptions The options for different link colors.
Returns string The color of the link.
getAllLeaves
Returns an array of all the child leaf nodes of the given node in a tree.
Parameters
nodeany A node of the tree.includeSelfboolean Whether to include the given node itself as a leaf node. Defaults to false. (optional, defaultfalse)
Returns Array<any> An array of leaf nodes.
setNodeLabelPosition
Sets the position and rotation of node labels based on layout.
Parameters
-
selection**(d3.Selection<any, any, any, any>d3.Transition<any, any, any, any>)** The text selection to position. layoutstring The current layout (“vertical”, “horizontal”, “circular”).
Returns void
updateRuler
Updates the ruler display based on the current zoom transform.
Parameters
thisTidyTreetransformd3.ZoomTransform The current zoom transform.
Returns void
arcFlagIndices
Returns the indices (among all numbers in the path) of arc flags, i.e. the
large-arc-flag and sweep-flag arguments of each A/a command. These must
be 0 or 1, so they cannot be linearly interpolated.
Parameters
pathstring
interpolatePath
Interpolates between two SVG path strings with the same command structure,
keeping arc flags valid (0 or 1). d3’s default string interpolation tweens
every number, including arc flags, producing invalid path data such as
A45,45 0 0 0.5 … mid-transition.
If the paths have different structures (e.g. switching between straight,
square and smooth branches), both are resampled into polylines with the
same number of points and those are tweened instead. Where the DOM can’t
measure paths (no getPointAtLength), the interpolator jumps to the target.
Parameters
Returns function (t: number): string
samplePath
Samples SAMPLES + 1 evenly spaced points along a path, or returns null if
the environment can’t measure SVG paths.
Parameters
dstring
| Returns **(Array<[number, number]> | null)** |
circularPoint
Converts a polar position (angle, radius) to SVG [x, y].
Parameters
uprightRotation
Rotation (degrees) that keeps text along direction (dx, dy) upright.
Parameters
Returns number
smoothLinkLabel
Branch label for a smooth link in a horizontal or vertical layout (d3.linkHorizontal / d3.linkVertical), given its ends in screen coordinates. These curves are symmetric, so their midpoint is the chord’s midpoint, but their tangent there has twice the chord’s slope across the depth axis.
Parameters
x0numbery0numberx1numbery1numberhorizontalboolean true for d3.linkHorizontal (depth runs along x).
Returns string
smoothRadialLinkLabel
Branch label for a smooth radial link (d3.linkRadial, a cubic Bézier with control points at the mid radius): placed at the curve’s midpoint and aligned with its tangent there.
Parameters
Returns string
chordLinkLabel
Branch label for a straight link drawn as a chord from source to target.
Parameters
Returns string
elbowLinkLabel
Branch label for an elbow link (an arc at the source radius, then a radial line out to the target): placed at the middle of the radial line.
Parameters
Returns string
isLeftHalf
Whether a node label at this angle is on the left half of the circle, where it is flipped (anchored at its end) so it reads outward and stays upright. The 6 o’clock position (angle π) counts as the left half: its rotation is -90°, so only an end anchor points the text away from the center.
Parameters
anglenumber
Returns boolean