Class: Branch

A branch of the tree.

Constructor

new Branch()

Source:

Members

branchLength :number

The length of the branch.
Source:

centerx :number

The center of the end of the node on the x axis.
Source:

centery :number

The center of the end of the node on the y axis.
Source:

children :Array.<Branch>

The branches that stem from this branch.
Source:

collapsed :boolean

True if the node has been collapsed.
Source:

colour :string

Custom colour for branch, initialised as null to use tree-level default.
Source:

data :object

Holds custom data for this node.
Source:

highlighted :boolean

This node's highlight status.
Source:

hovered :boolean

Whether the user is hovering over the node.
Source:

id :string

This node's unique ID.
Source:

label :string

The text label for this node.
Source:

leaf :boolean

If true, this node has no children.
Default Value:
  • true
Source:

maxChildAngle :number

The angle that the last child of this brach 'splays' at, used for circular trees.
Source:

minChildAngle :number

The angle that the last child of this brach 'splays' at, used for circular trees.
Source:

nodeShape :string

What kind of teminal should be drawn on this node.
Default Value:
  • circle
Source:

parent :Branch

The parent branch of this branch.
Source:

radius :number

The relative size of the terminal of this node.
Default Value:
  • 1
Source:

selected :boolean

True if this branch is currently selected.
Source:

startx :number

The x position of the start of the branch.
Source:

starty :number

The y position of the start of the branch.
Source:

totalBranchLength :number

The length from the root of the tree to the tip of this branch.
Source:

tree :Tree

The tree object that this branch is part of.
Source:

pruned :boolean

If true, this branch is not rendered.
Source:

labelStyle :object

Allows label to be individually styled.
Properties:
Name Type Description
colour string
textSize number
font string
format string e.g. bold, italic
Source:

internalLabelStyle :object

Allows label to be individually styled.
Properties:
Name Type Description
colour string
textSize number
font string
format string e.g. bold, italic
Source:

interactive :boolean

If false, branch does not respond to mouse events.
Default Value:
  • true
Source:

leafStyle :object

Defines leaf style for this branch.
Properties:
Name Type
lineWidth number
strokeStyle string
fillStyle string
Source:
Example
branch.leafStyle = {
  lineWidth: 2,
  strokeStyle: '#ff0000',
  fillStyle: 'blue'
};

minx :number

Minimum x coordintate.
Source:

miny :number

Minimum y coordintate.
Source:

maxx :number

Maximum x coordintate.
Source:

maxy :number

Maximum y coordintate.
Source:

isHighlighted :boolean

True if the branch is highlighted or hovered.
Source:

canvas :CanvasRenderingContext2D

The canvas drawing context of the parent tree.
Source:

(static) lastId :number

Static counter for generated ids.
Source:

angle :number

The branch's angle clockwise from horizontal in radians (used paricularly for circular and radial trees).
Source:

Methods

generateId() → {string}

For branches without a label.
Returns:
new ID
Type
string
Source:

clicked(x, y) → {Branch}

Determines if this branch has been clicked.
Parameters:
Name Type
x number
y number
Returns:
Type
Branch
Source:

drawLabel()

Source:

setNodeDimensions(centerX, centerY, radius)

Sets the minimum and maximum coordinates of the branch.
Parameters:
Name Type
centerX number
centerY number
radius number
Source:

drawCollapsed(centerX, centerY)

Draws the "collapsed tip".
Parameters:
Name Type
centerX number
centerY number
Source:

drawLabelConnector()

For aligned labels.
Source:

drawLeaf()

Source:

drawHighlight(centerX, centerY)

Parameters:
Name Type
centerX number
centerY number
Source:

drawBranchLabels()

Source:

drawNode()

Draws the line of the branch.
Source:

getChildProperties(property) → {Array.<string>}

Get property values of leaves under this branch.
Parameters:
Name Type Description
property string property name
Returns:
Type
Array.<string>
Source:

getChildCount() → {number}

Returns:
Type
number
Source:

getChildYTotal() → {number}

Returns:
Type
number
Source:

cascadeFlag(property, value, predicateopt)

Set a boolean property of this branch and its descendants.
Parameters:
Name Type Attributes
property string
value boolean
predicate function <optional>
Source:

reset()

Resets the coordinates and angle of this branch and its descendants.
Source:

redrawTreeFromBranch()

Set this branch to be the root.
Source:

extractChildren()

Store this branch's children.
Source:

hasCollapsedAncestor() → {boolean}

Walks up the tree looking for a collapsed branch.
Returns:
Type
boolean
Source:

collapse()

Source:

expand()

Source:

toggleCollapsed()

Source:

setTotalLength()

Sums the length of all branches from this one back to the root.
Source:

addChild(node)

Add a child branch to this branch.
Parameters:
Name Type Description
node Branch the node to add as a child
Source:

getChildColours() → {Array.<string>}

Return the node colour of all the nodes that are children of this one.
Returns:
Type
Array.<string>
Source:

getColour() → {string}

Get the colour(s) of the branch itself.
Returns:
Type
string
Source:

getNwk() → {string}

Create a newick representation of this branch.
Returns:
Type
string
Source:

getTextColour() → {string}

Returns:
Type
string
Source:

getLabel() → {string}

Ensures the return value is always a string.
Returns:
Type
string
Source:

getTextSize() → {number}

Returns:
Type
number
Source:

getFontString() → {string}

Returns:
Type
string
Source:

getLabelSize() → {number}

Returns:
length of label in pixels
Type
number
Source:

getRadius() → {number}

Returns:
Type
number
Source:

getDiameter() → {number}

Returns:
Type
number
Source:

hasLabelConnector() → {boolean}

Returns:
Type
boolean
Source:

getLabelStartX() → {number}

Calculates label start position offset + aesthetic padding
Returns:
x coordinate
Type
number
Source:

getHighlightLineWidth() → {number}

Returns:
Type
number
Source:

getHighlightRadius() → {number}

Returns:
Type
number
Source:

getHighlightSize() → {number}

Combination of radius and line width
Returns:
Type
number
Source:

rotate()

Reverses the order of the children. Runs the prerenderer again.
Source:

getChildNo() → {number}

Returns:
index of this branch in its parent's array.
Type
number
Source:

setDisplay(options)

Parameters:
Name Type Description
options Object
Properties
Name Type Description
colour string
shape string
size number
leafStyle Object See Branch#leafStyle
labelStyle Object See Branch#labelStyle
Source:

getTotalLength() → {number}

Returns:
the node radius plus label length if labels are shown
Type
number
Source:

getBounds() → {Object}

Returns:
bounds
Type
Object
Properties:
Name Type
minx number
miny number
maxx number
maxy number
Source:

getLeafStyle() → {Object}

Merges global and local styles together.
Returns:
Type
Object
Source:
See: