Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TreeModel

Hierarchy

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.

since

1.1

Index

Constructors

constructor

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

    Parameters

    • Optional nodedataarray: ObjectData[]

      an optional Array containing JavaScript objects to be represented by Nodes.

    Returns TreeModel

Properties

nodeParentKeyProperty : string | ((a: ObjectData, b?: Key) => Key)

  • 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. 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.

    see

    getParentKeyForNodeData, setParentKeyForNodeData

parentLinkCategoryProperty : string | ((a: ObjectData, b?: string) => string)

  • Gets or sets the name of the data property that returns a string describing that node data's parent link's category. 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.

    see

    getParentLinkCategoryForNodeData, setParentLinkCategoryForNodeData

Methods

Override Virtual copyNodeData

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

    see

    Model.copyNodeData

    Parameters

    • nodedata: ObjectData

      a JavaScript object represented by a node, group, or non-link.

    Returns ObjectData

getParentKeyForNodeData

getParentLinkCategoryForNodeData

  • getParentLinkCategoryForNodeData(childdata: ObjectData): string

Override Virtual setDataProperty

  • setDataProperty(data: ObjectData, propname: string, val: any): void
  • 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.

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

    see

    Model.setDataProperty

    Parameters

    • data: ObjectData

      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.

    • propname: string

      a string that is not null or the empty string.

    • val: any

      the new value for the property.

    Returns void

setParentKeyForNodeData

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

    see

    nodeParentKeyProperty, getParentKeyForNodeData

    Parameters

    • nodedata: ObjectData

      a JavaScript object represented by a node.

    • key: Key

      This may be undefined if there should be no parent node data.

    Returns void

setParentLinkCategoryForNodeData

  • setParentLinkCategoryForNodeData(childdata: ObjectData, cat: string): void
  • 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.

    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.

    see

    parentLinkCategoryProperty, getParentLinkCategoryForNodeData

    Parameters

    • childdata: ObjectData

      a JavaScript object represented by a node data.

    • cat: string

      Must not be null.

    Returns void