Search API
  • Preparing search index...
  • The search index is not available

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.More... The value may also be a function taking two arguments, where the first argument will be a node data object. If the second argument is not supplied, the function should return the string or number key for the parent node data object of which the given data object is a child; if the second argument is supplied, the function should modify the node data object so that it has that new key (which may be undefined to refer to no node) as the parent key for that node.. The default value is the name 'parent', meaning that it expects the data to have a property named 'parent' if the node wants to refer to the parent node by its key. The value must not be null nor an empty string.

If you want to set this property you must do so before using the model, and especially before you assign Diagram.model. Note that functions cannot be serialized into JSON-formatted text, so if you are using toJson and Model.fromJson, and if you want this property to be a function, you will need to assign this property to your desired function immediately after creating the model, including when it is created by Model.fromJson.

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.More... The value may also be a function taking two arguments, where the first argument will be a node data object. If the second argument is not supplied, the function should return the category name for any parent link; if the second argument is supplied, the function should modify the node data object so that its parent link has that new category name. The default value is the name 'parentLinkCategory'. 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.

If you want to set this property you must do so before using the model, and especially before you assign Diagram.model. Note that functions cannot be serialized into JSON-formatted text, so if you are using toJson and Model.fromJson, and if you want this property to be a function, you will need to assign this property to your desired function immediately after creating the model, including when it is created by Model.fromJson.

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. Note that the new template must be an instance of the same class as the original link. Thus one cannot change the category of a link from an instance of Link to an instance of a subclass of Link, nor vice-versa.

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, commit, commitTransaction, containsNodeData, copy, findNodeDataForKey, getCategoryForNodeData, getKeyForNodeData, insertArrayItem, makeNodeDataKeyUnique, raiseChangedEvent, raiseDataChanged, removeArrayItem, removeChangedListener, removeNodeData, removeNodeDataCollection, rollbackTransaction, set, setCategoryForNodeData, setKeyForNodeData, startTransaction, toIncrementalJson, toJson, updateTargetBindings