Skip to the content.

Table of Contents

_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

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

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

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

Returns TidyTree the TidyTree object

setLayout

Set the TidyTree’s layout

Parameters

Returns TidyTree The TidyTree Object

setColorOptions

Set the TidyTree’s colorOptions

Parameters

Returns TidyTree The TidyTree Object

setMode

Set the TidyTree’s mode

Parameters

Returns TidyTree the TidyTree object

setType

Set the TidyTree’s type

Parameters

Returns TidyTree the TidyTree object

setRotation

Set the TidyTree’s rotation

Parameters

Returns TidyTree the TidyTree object

setHStretch

Set the TidyTree’s Horizontal Stretch

Parameters

Returns TidyTree the TidyTree object

setVStretch

Set the TidyTree’s Vertical Stretch

Parameters

Returns TidyTree the TidyTree object

setAnimation

Set the TidyTree’s animation time. Note that this does not trigger a redraw.

Parameters

Returns TidyTree The TidyTree object

setBranchNodes

Shows or hides the Branch Nodes

Parameters

Returns TidyTree the TidyTree object

eachBranchNode

Restyles Leaf Nodes

Parameters

Returns TidyTree the TidyTree Object

setBranchLabels

Set the TidyTree’s branchLabels

Parameters

Returns TidyTree the TidyTree Object

eachBranchLabel

Restyles Branch Label

Parameters

Returns TidyTree the TidyTree Object

setBranchDistances

Shows or hides the TidyTree’s branch labels

Parameters

Returns TidyTree The TidyTree Object

eachBranchDistance

Restyles Branch Distances

Parameters

Returns TidyTree the TidyTree Object

setLeafNodes

Shows or Hides the Leaf Nodes

Parameters

Returns TidyTree The TidyTree Object

eachLeafNode

Restyles Leaf Nodes

Parameters

Returns TidyTree the TidyTree Object

setEquidistantLeaves

Set the TidyTree’s leaves to be equidistant

Parameters

Returns TidyTree

setLeafLabels

Shows or Hides the TidyTree’s Leaf Labels

Parameters

Returns TidyTree the TidyTree Object

eachLeafLabel

Restyles Leaf Labels

Parameters

Returns TidyTree the TidyTree Object

setRuler

Shows or hides the TidyTree’s branch labels

Parameters

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

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

Returns TidyTree The TidyTree object.

isNodeCollapsed

Check whether a node is currently collapsed.

Parameters

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

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

Returns d3.HierarchyNode<NodeDatum> A d3 hierarchy with only visible nodes

addAnnotation

Add or update an annotation (metadata) for a specific node.

Parameters

Returns TidyTree The TidyTree object.

getAnnotation

Retrieve the annotation data for a specific node.

Parameters

Returns **(any undefined)** The annotation data, or undefined if none exists.

removeAnnotation

Remove the annotation for a specific node.

Parameters

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

Returns TidyTree The TidyTree object.

getTemporalAnnotation

Retrieve the temporal annotation for a specific node.

Parameters

Returns **(TemporalAnnotation undefined)** The temporal annotation data, or undefined if none exists.

removeTemporalAnnotation

Remove the temporal annotation for a specific node.

Parameters

Returns TidyTree The TidyTree object.

setShowTemporalAnnotations

Set whether temporal annotations are visible.

Parameters

Returns TidyTree The TidyTree object.

getNodeGUIDs

Retrieves the GUIDs of the nodes in the TidyTree instance.

Parameters

Returns Array<{_guid: string, id: string}> An array of GUIDs of the nodes.

Searches the tree, returns Search Results

Parameters

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

Returns TidyTree The TidyTree on which this method was called.

off

Removes all event listeners from the given events

Parameters

Returns TidyTree The TidyTree on which this method was called.

trigger

Forces the tree to respond as though an event has occurred

Parameters

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

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

Returns TidyTree The TidyTree object

setBranchNodeSize

Set the branch node size.

Parameters

Returns TidyTree The TidyTree object.

setBranchLabelSize

Set the branch label size.

Parameters

Returns TidyTree The TidyTree object.

setBranchDistanceSize

Set the branch distance size.

Parameters

Returns TidyTree The TidyTree object.

setLeafNodeSize

Set the leaf node size.

Parameters

Returns TidyTree The TidyTree object.

setLeafLabelSize

Set the leaf label size.

Parameters

Returns TidyTree The TidyTree object.

setTooltips

Set whether tooltips are enabled.

Parameters

Returns TidyTree The TidyTree object.

setShowTemporal

Set whether temporal annotations are visible.

Parameters

Returns TidyTree The TidyTree object.

setBackground

Set the background color of the tree container.

Parameters

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

Returns string The color of the node.

interpolateColor

Interpolate between two hex colors by a factor t (0 to 1).

Parameters

Returns string The interpolated hex color.

findBranchColor

Find the color of a given link based on the provided color options.

Parameters

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

Returns Array<any> An array of leaf nodes.

setNodeLabelPosition

Sets the position and rotation of node labels based on layout.

Parameters

Returns void

updateRuler

Updates the ruler display based on the current zoom transform.

Parameters

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

Returns Set<number>

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

Returns **(Array<[number, number]> null)**

circularPoint

Converts a polar position (angle, radius) to SVG [x, y].

Parameters

Returns [number, number]

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

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

Returns boolean