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.
This constructs an empty TreeModel unless one provides arguments as the initial data array values for the Model#nodeDataArray property.
an optional Array containing JavaScript objects to be represented by Nodes.
Gets or sets a function that makes a copy of a node data object.
Gets or sets the name of the format of the diagram data.
Gets or sets whether this model may be modified, such as adding nodes.
Gets or sets a function that returns a unique id number or string for a node data object.
Gets or sets the name of this model.
Gets or sets the name of the node data property that returns a string describing that data's category, or a function that takes a node data object and returns the category name; the default value is the name 'category'.
Gets or sets the array of node data objects that correspond to Nodes, Groups, or non-Link Parts in the Diagram.
Gets or sets the name of the data property that returns a unique id number or string for each node data object, or a function taking a node data object and returning the key value; the default value is the name '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, or a function that takes a node data object and returns that parent key; the default value is the name 'parent'.
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'.
Gets or sets whether ChangedEvents are not recorded by the UndoManager.
Gets or sets the UndoManager for this Model.
Add an item at the end of a data array that may be data bound by a Panel as its Panel#itemArray, in a manner that can be undone/redone and that automatically updates any bindings. This also calls #raiseChangedEvent to notify all listeners about the ChangedEvent#Insert. If you want to add a new node or part to the diagram, call #addNodeData.
an Array that is the value of some Panel's Panel#itemArray.
the new value to be pushed onto the array.
any
Register an event handler that is called when there is a ChangedEvent. This registration does not raise a ChangedEvent.
a function that takes a ChangedEvent as its argument.
any
When you want to add a node or group to the diagram, call this method with a new data object. This will add that data to the #nodeDataArray and notify all listeners that a new node data object has been inserted into the collection. To remove a node from the diagram, you can remove its data object by calling #removeNodeData. To add or remove an object or value from an item array, call #insertArrayItem or #removeArrayItem.
a JavaScript object representing a node, group, or non-link.
any
Clear out all references to any model data.
any
Commit the changes of the current transaction. This just calls UndoManager#commitTransaction.
a descriptive name for the transaction.
boolean
Decide if a given node data is in this model.
a JavaScript object representing a node, group, or non-link.
boolean
Make a copy of a node data object. This uses the value of #copyNodeDataFunction to actually perform the copy, unless it is null, in which case this method just makes a shallow copy of the JavaScript Object. This does not modify the model -- the returned data object is not added to this model. This assumes that the data's constructor can be called with no arguments.
a JavaScript object representing a node, group, or non-link.
Object
Given a number or string, find the node data in this model that uses the given value as its unique key.
a string or a number.
Object
Find the category of a given node data, a string naming the node template or group template or part template that the Diagram should use to represent the node data.
a JavaScript object representing a node, group, or non-link.
string
Given a node data object return its unique key: a number or a string. It is possible to change the key for a node data object by calling #setKeyForNodeData.
a JavaScript object representing a node, group, or non-link.
any
If there is a parent node for the given node data, return the parent's key.
a JavaScript object representing a node.
any
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.
a JavaScript object representing a node data.
string
Add an item to a data array that may be data bound by a Panel as its Panel#itemArray, given a new data value and the index at which to insert the new value, in a manner that can be undone/redone and that automatically updates any bindings. This also calls #raiseChangedEvent to notify all listeners about the ChangedEvent#Insert. If you want to add a new node or part to the diagram, call #addNodeData.
an Array that is the value of some Panel's Panel#itemArray.
the zero-based array index where the new value will be inserted; use -1 to push the new value on the end of the array.
the new value to be inserted into the array.
any
This method is called when a node data object is added to the model to make sure that
The key value should be unique within the set of data managed by this model:
If the key is already in use, this will assign an unused number to the
If you want to customize the way in which node data gets a unique key, you can set the #makeUniqueKeyFunction functional property. If the node data object is already in the model and you want to change its key value, call #setKeyForNodeData and give it a new unique key value.
a JavaScript object representing a node, group, or non-link.
any
Call this method to notify that the model or its objects have changed. This constructs a ChangedEvent and calls all Changed listeners.
specifies the general nature of the change; typically the value is ChangedEvent#Property.
names the property that was modified, or a function that takes an Object and returns the property value.
the object that was modified, typically a GraphObject, Diagram, or a Model.
the previous or older value.
the next or newer value.
an optional value that helps describe the older value.
an optional value that helps describe the newer value.
any
Call this method to notify about a data property having changed value. This constructs a ChangedEvent and calls all Changed listeners. You should call this method only if the property value actually changed. This method is called by #setDataProperty.
the data object whose property changed value.
the name of the property, or a function that takes an Object and returns the property value.
the previous or old value for the property.
the next or new value for the property.
an optional value additionally describing the old value.
an optional value additionally describing the new value.
any
Remove an item from a data array that may be data bound by a Panel as its Panel#itemArray, given the index at which to remove a data value, in a manner that can be undone/redone and that automatically updates any bindings. This also calls #raiseChangedEvent to notify all listeners about the ChangedEvent#Remove. If you want to remove a node from the diagram, call #removeNodeData. Note that there is no version of this method that takes an item value instead of an index into the array. Because item arrays may hold any JavaScript value, including numbers and strings, there may be duplicate entries with that value in the array. To avoid ambiguity, removing an item from an array requires an index.
an Array that is the value of some Panel's Panel#itemArray.
the zero-based array index of the data item to be removed from the array; if not supplied it will remove the last item of the array.
any
Unregister an event handler listener. This deregistration does not raise a ChangedEvent.
a function that takes a ChangedEvent as its argument.
any
When you want to remove a node or group from the diagram, call this method with an existing data object. This will remove that data from the #nodeDataArray and notify all listeners that a node data object has been removed from the collection. Removing a node data from a model does not automatically remove any connected link data from the model. Removing a node data that represents a group does not automatically remove any member node data or link data from the model. To add a node to the diagram, you can add its data object by calling #addNodeData. To add or remove an object or value from an item array, call #insertArrayItem or #removeArrayItem.
a JavaScript object representing a node, group, or non-link.
any
Rollback the current transaction, undoing any recorded changes.
boolean
Change the category of a given node data, a string naming the node template or group template or part template that the Diagram should use to represent the node data. Changing the node template for a node data will cause the existing Node, Group, or Part to be replaced with a new Node, Group, or Part created by copying the new node template and applying any data-bindings.
a JavaScript object representing a node, group, or non-link.
Must not be null.
any
a JavaScript object representing a node, group, or non-link.
a string that is not null or the empty string.
the new value for the property.
any
Change the unique key of a given node data that is already in this model. The new key value must be unique -- i.e. not in use by another node data object. You can call #findNodeDataForKey to check if a proposed new key is already in use. This operation will check all data objects in the model and replace all references using the old key value with the new one. If this is called on a node data object that is not (yet) in this model, this unconditionally modifies the property to the new key value.
a JavaScript object representing a node, group, or non-link.
any
Change the parent node for the given node data, given a key for the new parent, or undefined if there should be no parent.
a JavaScript object representing a node.
This may be undefined if there should be no parent node data.
any
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.
a JavaScript object representing a node data.
Must not be null.
any
Begin a transaction, where the changes are held by a Transaction object in the UndoManager. This just calls UndoManager.startTransaction.
a descriptive name for the transaction.
boolean
Generate a string representation of the persistent data in this model, in JSON format. Object properties whose names start with "_" are not written out. Functions are not able to be written in JSON format, so any properties that have function values will not be saved in the JSON string. There must not be any circular references within the model data. Any sharing of object references will be lost in the written JSON.
The optional name of the model class to use in the output; for the standard models, this is their class name prefixed with "go.".
string
Find a Part corresponding to the given data and call its Panel#updateTargetBindings method, in each Diagram that uses this Model.
The data object in this model that was modified.
If not present or the empty string, update all bindings on the target Part or item Panel; otherwise update only those bindings using this source property name.
any