Class TreeModel

Extends Model. TreeModels support tree-structured graphs of nodes and links. Each node can have at most one "tree parent"; cycles are not permitted. The reference to the parent node's key is a property of the child node data.

TreeModels, unlike GraphLinksModels, do not support arbitrary link relationships between nodes, nor is there a separate link data object for each parent-child relationship. Furthermore there is no support for grouping or label nodes.

The nodeParentKeyProperty property names the property on the node data whose value is the key of the "tree parent" node. The default value for this property is "parent".

For example, one can define a graph consisting of one parent node with two child nodes:

 model.nodeDataArray = [
   { key: "Alpha" },
   { key: "Beta", parent: "Alpha" },
   { key: "Gamma", parent: "Alpha" }
 ];

If you need to show a more complicated graph structure than a tree, use a GraphLinksModel. If you want to have multiple links between the same pair of nodes, or if you want to associate more information with each link and cannot put the information on the child node, you will need to have a separate link data object for each link, and that would require the use of GraphLinksModel.

Constructor Summary Details

Name Description
TreeModel(nodedataarray)

This constructs an empty TreeModel unless one provides arguments as the initial data array values for the Model.nodeDataArray property.More...

Parameters:
{Array=} nodedataarray
an optional Array containing JavaScript objects to be represented by Nodes.

Properties Summary Details

Name, Value Type Description
nodeParentKeyProperty
{string|function(Object,(string|number)=):(string|number)}

Gets or sets the name of the property on node data that specifies the string or number key of the node data that acts as the "parent" for this "child" node data, or a function that takes a node data object and returns that parent key; the default value is the name 'parent'.More... The value must not be null nor an empty string.

parentLinkCategoryProperty
{string|function(Object,string=):string}

Gets or sets the name of the data property that returns a string describing that node data's parent link's category, or a function that takes a node data object and returns its parent link's category string; the default value is the name 'parentLinkCategory'.More... This is used by the diagram to distinguish between different kinds of links. The name must not be null. If the value is an empty string, getParentLinkCategoryForNodeData will return an empty string for all node data objects.

Properties borrowed from class Model:
copiesArrayObjects, copiesArrays, copyNodeDataFunction, dataFormat, isReadOnly, makeUniqueKeyFunction, modelData, name, nodeCategoryProperty, nodeDataArray, nodeKeyProperty, skipsUndoManager, undoManager

Method Summary Details

Name, Return Type Description
copyNodeData(nodedata)
{Object}

This override also makes sure any copied node data does not have a reference to a parent node.More...

Parameters:
{Object} nodedata
a JavaScript object represented by a node, group, or non-link.
Returns:
{Object}
getParentKeyForNodeData(nodedata)
{string|number|undefined}

If there is a parent node for the given node data, return the parent's key.More...

Parameters:
{Object} nodedata
a JavaScript object represented by a node.
Returns:
{string|number|undefined} This returns undefined if there is no parent node data object.
getParentLinkCategoryForNodeData(childdata)
{string}

Find the category for the parent link of a given child node data, a string naming the link template that the Diagram should use to represent the link.More...

Parameters:
{Object} childdata
a JavaScript object represented by a node data.
Returns:
{string}
setDataProperty(data, propname, val)

This override changes the value of some property of a node data or an item data, given a string naming the property and the new value, in a manner that can be undone/redone and that automatically updates any bindings.More...

This gets the old value of the property; if the value is the same as the new value, no side-effects occur.

Parameters:
{Object} data
a JavaScript object typically the value of a Panel.data and represented by a Node, Link, Group, simple Part, or item in a Panel.itemArray; or this model's modelData.
{string} propname
a string that is not null or the empty string.
{*} val
the new value for the property.
setParentKeyForNodeData(nodedata, key)

Change the parent node for the given node data, given a key for the new parent, or undefined if there should be no parent.More...

Parameters:
{Object} nodedata
a JavaScript object represented by a node.
{string|number|undefined} key
This may be undefined if there should be no parent node data.
setParentLinkCategoryForNodeData(childdata, cat)

Change the category for the parent link of a given child node data, a string naming the link template that the Diagram should use to represent the link.More...

Changing the link template will cause any existing Link to be removed from the Diagram and replaced with a new Link created by copying the new link template and applying any data-bindings.

Parameters:
{Object} childdata
a JavaScript object represented by a node data.
{string} cat
Must not be null.
Methods borrowed from class Model:
addArrayItem, addChangedListener, addNodeData, addNodeDataCollection, applyIncrementalJson, clear, cloneProtected, commitTransaction, containsNodeData, copy, findNodeDataForKey, getCategoryForNodeData, getKeyForNodeData, insertArrayItem, makeNodeDataKeyUnique, raiseChangedEvent, raiseDataChanged, removeArrayItem, removeChangedListener, removeNodeData, removeNodeDataCollection, rollbackTransaction, setCategoryForNodeData, setKeyForNodeData, startTransaction, toIncrementalJson, toJson, updateTargetBindings