# Methods

#

# addLayer

Adds a new layer to the tree rendering engine.

tree.addLayer(layerId, visiblePredicate, renderer);

Parameters:

  • layerId - (String, required) A unique string to identify the layer.
  • visiblePredicate - (Function, required) A function called on each render cycle to decide whether to show or hide the layer.
  • renderer - (Function, required) A function called on each render cycle if visiblePredicate returns true.

Returns:

  • an Object containing the newly created layer.

Example:

See init function in PhylocanvasGL class (opens new window).


# collapseNode

Collapses an internal subtree, or uncollapses the subtree if the node is already collapsed.

tree.collapseNode(nodeOrId);

Parameters:

  • nodeOrId - (TreeNode | String, required) A tree node to collapse or uncollapse. Can be either a Node object or the node id.

Internally, collapseNode method adds the node id to collapsedIds array (or removes the id if it is already in the array).

Example:

tree.props.collapsedIds; // returns []
tree.collapseNode("1");
tree.props.collapsedIds; // returns [ "1" ]

# destroy

Frees resources associated with the tree instance immediately and removes the tree canvas.

tree.destroy();

# exportJSON

Exports the tree as a JavaScript Object Notation (JSON) string.

tree.exportJSON();

Returns:

A String containing the JavaScript Object Notation (JSON).


# exportNewick

Exports the tree in Newick (opens new window) format.

tree.exportNewick();

Returns:

A String containing the Newick in plain text format.


# exportPNG

Exports the tree in Portable Network Graphics (opens new window) (PNG) format.

tree.exportPNG();

Returns:

A DOMString (opens new window) containing the PNG image as data URI.


# exportSVG

Exports the tree in Scalable Vector Graphics (opens new window) (SVG) format.

tree.exportSVG();

Returns:


# findNodeById

Finds and returns a TreeNode object representing the node whose id property matches the specified string.

tree.findNodeById(nodeId);

Parameters:

  • nodeId - (String, required) The id of the node to find.

Returns:

A TreeNode if the nodeId is found, otherwise undefined is returned.

Example:

tree.getNodeById("0");

# fitInPanel

Resets tree centre, zoom, branchZoom, and stepZoom to default values.

tree.fitInPanel();

# getBranchScale

tree.getBranchScale();

# getBranchZoom

tree.getBranchZoom();

# getBranchZoomingAxis

tree.getBranchZoomingAxis();

# getCanvasCentrePoint

tree.getCanvasCentrePoint();

# getCanvasSize

tree.getCanvasSize();

# getDrawingArea

tree.getDrawingArea();

# getFontFamily

tree.getFontFamily();

# getFontSize

tree.getFontSize();

# getLeafIds

tree.getLeafIds();

# getLeafLabels

tree.getLeafLabels();

# getLineColour

tree.getLineColour();

# getLineWidth

tree.getLineWidth();

# getMainAxis

tree.getMainAxis();

# getMaxZoom

tree.getMaxZoom();

# getMinZoom

tree.getMinZoom();

# getNodeSize

tree.getNodeSize();

# getGraphWithStyles

tree.getGraphWithStyles();

# getPadding

tree.getPadding();

# getScale

tree.getScale();

# getStepScale

tree.getStepScale();

# getStepZoom

tree.getStepZoom();

# getStepZoomingAxis

tree.getStepZoomingAxis();

# getTreeType

tree.getTreeType();

# getWorldBounds

tree.getWorldBounds();

# getZoom

tree.getZoom();

# handleClick

tree.handleClick();

# handleHover

tree.handleHover();

# highlightNode

tree.highlightNode();

# importJSON

Imports a tree from a JavaScript Object Notation (JSON) string.

tree.importJSON(text);

Parameters:

  • text - (String, required) A valid JSON string.

Example:

tree.importJSON(`{ "source": "..." }`);

# render

tree.render();

# rerootNode

tree.rerootNode();

# resetCollapsedNodes

tree.resetCollapsedNodes();

# resetRotatedNodes

tree.resetRotatedNodes();

# resize

tree.resize();

# resume

tree.resume();

# rotateNode

tree.rotateNode();

# selectLeafNodes

tree.selectLeafNodes();

# selectNode

tree.selectNode();

# setBranchZoom

tree.setBranchZoom();

# setFontSize

tree.setFontSize();

# setNodeSize

tree.setNodeSize();

# setProps

tree.setProps();

Updates tree Properties by performsing a shallow merge.

tree.setProps(updater);

Parameters:

  • updater - (Object, required) An object containing properties to be updated.

Example:

tree.setProps({
  nodeSize: 16,
  zoom: 0,  
});

# setRoot

tree.setRoot(subreeNode);

Sets the root node of the tree.

Parameters:

  • subreeNodeOrId - (TreeNode | String, required) A subtree node to set as new root. Can be either a non-leaf Node object or the non-leaf node id.

Example:

tree.setRoot("1");

# unprojectPoint

Converts the coordinates of a point from the canvas space to the tree space.

tree.unprojectPoint(canvasPoint);

Parameters:

  • canvasPoint - (GeometricPoint`, required) A point in the canvas space.

Internally, collapseNode method adds the node id to collapsedIds array (or removes the id if it is already in the array).

Example:

tree.props.collapsedIds; // returns []
tree.collapseNode("1");
tree.props.collapsedIds; // returns [ "1" ]

Last Updated: 1/27/2022, 11:59:08 AM