Class: Tree

Syntree.Tree

Analogous to a linked list class, Tree is actually just a wrapper around some nodes which are linked to one another internally. Tree only stores a reference to the root node, and access all descendants through that link.

Constructor

new Tree()

Source:

Members

build_treestring :string

At construction time, a treestring to build this tree out of.
Type:
  • string
Source:
See:

id :number

Unique identifier, only used for trees you're going to save.
Type:
  • number
Source:
See:

node_properties_to_save :object

The Node properties that should be included in this tree's treestring.
Type:
  • object
Source:
See:

root :Syntree.Node

The root node of this Tree.
Type:
Source:

rowHeight :number

How much vertical space to have between parent/child nodes.
Type:
  • number
Source:

Methods

_buildFromTreestring(treestring)

Instead of just passively wrapping around the given root Node and its descendants, create nodes and attach them based on data from a treestring.
Parameters:
Name Type Description
treestring string the treestring to use
Source:
See:

_getPath(which) → {object}

Get an SVG path that outlines this Tree.
Parameters:
Name Type Description
which string 'left' or 'right' for which side of this Tree to outline, defaults to both sides
Source:
Returns:
- the path string, along with the visual bounds of the Tree.
Type
object

delete()

Delete this Tree.
Source:

distribute(angleopt)

Distribute the Nodes in this Tree such that they are spread out nicely and don't collide.
Parameters:
Name Type Attributes Default Description
angle number <optional>
60 the angle to spread Nodes across
Source:

getBracketNotation(nodeopt) → {string}

Get this Tree as bracket notation.
Parameters:
Name Type Attributes Default Description
node Syntree.Node <optional>
this.root the Node to start from
Source:
Returns:
- bracket notation representing this Tree
Type
string

getDescendantsOf(nodeopt, attropt, inclusiveopt, flatopt) → {Array.<object>|Array.<Syntree.Node>}

Get all descendants of the specified Node.
Parameters:
Name Type Attributes Default Description
node Syntree.Node <optional>
this.root
attr string <optional>
'' the attr used to represent each Node
inclusive boolean <optional>
true include the starting Node in the results?
flat boolean <optional>
false squash everything down into a flat array of Nodes
Source:
Returns:
- either an array of Nodes, or an array of objects containing more arrays represnting the descendant structure
Type
Array.<object> | Array.<Syntree.Node>

getId()

Accessor function for Tree.id.
Source:
See:

getNodeOffset(fromNode, toNode) → {number}

Get a Node's offset from a given Node.
Parameters:
Name Type Description
fromNode Syntree.Node the Node to check from
toNode Syntree.Node the Node to check to
Source:
Returns:
- how many levels between fromNode and toNode
Type
number

getNodesByOffset(off, nodeopt)

Get all Nodes at a specified offset from a given Node.
Parameters:
Name Type Attributes Default Description
off number what offset to return Nodes from
node Syntree.Node <optional>
this.root the Node to search from
Source:

getRoot()

Accessor function for Tree.root
Source:
See:

getTreestring() → {string}

Get a treestring for this Tree. A treestring contains all information required to describe Tree at a data level.
Source:
See:
Returns:
- the treestring
Type
string

setId(id)

Setter function for Tree.id.
Parameters:
Name Type Description
id number new id
Source:
See: