Class GraphLinksModel

GraphLinksModels support links between nodes and grouping nodes and links into subgraphs. GraphLinksModels hold node data and link data in separate arrays. Node data is normally represented in a Diagram by instances of Node, but they could be represented by simple Parts or by Groups. Link data should be represented by instances of Link.

Hierarchy

Index

Constructor methods

Properties

Methods

Constructor methods

constructor(nodedataarray?: Array<Object>, linkdataarray?: Array<Object>): GraphLinksModel

This constructs an empty GraphLinksModel unless one provides arguments as the initial data array values for the Model#nodeDataArray and GraphLinksModel#linkDataArray properties.

Parameters

  • nodedataarray?: Array<Object> optional

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

  • linkdataarray?: Array<Object> optional

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

Returns

GraphLinksModel

Properties

public archetypeNodeData: Object

Gets or sets a data object that will be copied and added to the model as a new node data each time there is a link reference (either the "to" or the "from" of a link data) to a node key that does not yet exist in the model.

public copyLinkDataFunction: (obj: Object, model: go.GraphLinksModel) => Object

Gets or sets a function that makes a copy of a link data object.

public copyNodeDataFunction: (obj: Object, model: go.Model) => Object

Gets or sets a function that makes a copy of a node data object.

public dataFormat: string

Gets or sets the name of the format of the diagram data.

public isReadOnly: boolean

Gets or sets whether this model may be modified, such as adding nodes.

public linkCategoryProperty: any

Gets or sets the name of the data property that returns a string describing that data's category, or a function that takes a link data object and returns that category string; the default value is the name 'category'.

public linkDataArray: Array<Object>

Gets or sets the array of link data objects that correspond to Links in the Diagram.

public linkFromKeyProperty: any

Gets or sets the name of the data property that returns the key of the node data that the link data is coming from, or a function that takes a link data object and returns that key; the default value is the name 'from'. The name must not be null. If the value is an empty string,

getFromKeyForLinkData will return undefined for all link data objects.

public linkFromPortIdProperty: any

Gets or sets the name of the data property that returns the optional parameter naming a "port" element on the node that the link data is connected from, or a function that takes a link data object and returns that string.

public linkLabelKeysProperty: any

Gets or sets the name of the data property that returns an array of keys of node data that are labels on that link data, or a function that takes a link data object and returns such an array; the default value is the empty string: ''.

public linkToKeyProperty: any

Gets or sets the name of the data property that returns the key of the node data that the link data is going to, or a function that takes a link data object and returns that key; the default value is the name 'to'.

public linkToPortIdProperty: any

Gets or sets the name of the data property that returns the optional parameter naming a "port" element on the node that the link data is connected to, or a function that takes a link data object and returns that string.

public makeUniqueKeyFunction: (model: go.Model, obj: Object) => any

Gets or sets a function that returns a unique id number or string for a node data object.

public name: string

Gets or sets the name of this model.

public nodeCategoryProperty: any

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

public nodeDataArray: Array<Object>

Gets or sets the array of node data objects that correspond to Nodes, Groups, or non-Link Parts in the Diagram.

public nodeGroupKeyProperty: any

Gets or sets the name of the property on node data that specifies the string or number key of the group data that "owns" that node data, or a function that takes a node data object and returns that group key.

public nodeIsGroupProperty: any

Gets or sets the name of the boolean property on node data that indicates whether the data should be represented as a group of nodes and links or as a simple node, or a function that takes a node data object and returns true or false; the default value is the name 'isGroup'.

public nodeIsLinkLabelProperty: any

Gets or sets the name of the boolean property on node data that indicates whether the data should be represented as a node acting as a label on a link instead of being a regular node, or a function that takes a node data object and returns true or false; the default value is the empty string: ''.

public nodeKeyProperty: any

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

public skipsUndoManager: boolean

Gets or sets whether ChangedEvents are not recorded by the UndoManager.

public undoManager: UndoManager

Gets or sets the UndoManager for this Model.

Methods

public addArrayItem(arr: Array<any>, val: any): any

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.

Parameters

  • arr: Array<any>

    an Array that is the value of some Panel's Panel#itemArray.

  • val: any

    the new value to be pushed onto the array.

Returns

any

public addChangedListener(listener: (e: go.ChangedEvent) => void): any

Register an event handler that is called when there is a ChangedEvent. This registration does not raise a ChangedEvent.

Parameters

  • listener: (e: go.ChangedEvent) => void

    a function that takes a ChangedEvent as its argument.

Returns

any

public addLabelKeyForLinkData(linkdata: Object, key: any): any

Adds a node key value that identifies a node data acting as a new label node on the given link data. This method only works if #linkLabelKeysProperty has been set to something other than an empty string.

Parameters

  • linkdata: Object

    a JavaScript object representing a link.

  • key: any

    a number or string that is the key of the new label node.

Returns

any

public addLinkData(linkdata: Object): any

When you want to add a link to the diagram, call this method with a new data object. This will add that data to the #linkDataArray and notify all listeners that a new link data object has been inserted into the collection. Presumably the link data object will already have its "from" and "to" node key references set, but it is also possible to set them after the link data is in the model by calling #setFromKeyForLinkData and #setToKeyForLinkData. This operation does nothing if the link data is already part of this model's #linkDataArray.

Parameters

  • linkdata: Object

    a JavaScript object representing a link.

Returns

any

public addNodeData(nodedata: Object): 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.

Parameters

  • nodedata: Object

    a JavaScript object representing a node, group, or non-link.

Returns

any

public clear(): any

Clear out all references to any model data.

Returns

any

public commitTransaction(tname: string): boolean

Commit the changes of the current transaction. This just calls UndoManager#commitTransaction.

Parameters

  • tname: string

    a descriptive name for the transaction.

Returns

boolean

public containsLinkData(linkdata: Object): boolean

Decide if a given link data is in this model.

Parameters

  • linkdata: Object

    a JavaScript object representing a link.

Returns

boolean

public containsNodeData(nodedata: Object): boolean

Decide if a given node data is in this model.

Parameters

  • nodedata: Object

    a JavaScript object representing a node, group, or non-link.

Returns

boolean

public copyLinkData(linkdata: Object): Object

Gets or sets a function that makes a copy of a link data object. You may need to set this property in order to ensure that a copied Link is bound to data that does not share certain data structures between the original link data and the copied link data. The value may be null in order to cause #copyLinkData to make a shallow copy of a JavaScript Object. The default value is null.

Parameters

  • linkdata: Object

Returns

Object

public copyNodeData(nodedata: Object): Object

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.

Parameters

  • nodedata: Object

    a JavaScript object representing a node, group, or non-link.

Returns

Object

public findNodeDataForKey(key: any): Object

Given a number or string, find the node data in this model that uses the given value as its unique key.

Parameters

  • key: any

    a string or a number.

Returns

Object

public getCategoryForLinkData(linkdata: Object): string

Find the category of a given link data, a string naming the link template that the Diagram should use to represent the link data.

Parameters

  • linkdata: Object

    a JavaScript object representing a link.

Returns

string

public getCategoryForNodeData(nodedata: Object): string

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.

Parameters

  • nodedata: Object

    a JavaScript object representing a node, group, or non-link.

Returns

string

public getFromKeyForLinkData(linkdata: Object): any

From a link data retrieve a value uniquely identifying the node data from which this link is connected.

Parameters

  • linkdata: Object

    a JavaScript object representing a link.

Returns

any

public getFromPortIdForLinkData(linkdata: Object): string

From a link data retrieve a value identifying the port object of the node from which this link is connected.

Parameters

  • linkdata: Object

    a JavaScript object representing a link.

Returns

string

public getGroupKeyForNodeData(nodedata: Object): any

If there is a container group for the given node data, return the group's key.

Parameters

  • nodedata: Object

    a JavaScript object representing a node, group, or non-link.

Returns

any

public getKeyForNodeData(nodedata: Object): any

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.

Parameters

  • nodedata: Object

    a JavaScript object representing a node, group, or non-link.

Returns

any

public getLabelKeysForLinkData(linkdata: Object): Array<any>

Gets an Array of node key values that identify node data acting as labels on the given link data. This method only works if #linkLabelKeysProperty has been set to something other than an empty string.

Parameters

  • linkdata: Object

    a JavaScript object representing a link.

Returns

Array<any>

public getToKeyForLinkData(linkdata: Object): any

From a link data retrieve a value uniquely identifying the node data to which this link is connected.

Parameters

  • linkdata: Object

    a JavaScript object representing a link.

Returns

any

public getToPortIdForLinkData(linkdata: Object): string

From a link data retrieve a value identifying the port object of the node to which this link is connected.

Parameters

  • linkdata: Object

    a JavaScript object representing a link.

Returns

string

public insertArrayItem(arr: Array<any>, idx: number, val: any): any

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.

Parameters

  • arr: Array<any>

    an Array that is the value of some Panel's Panel#itemArray.

  • idx: number

    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.

  • val: any

    the new value to be inserted into the array.

Returns

any

public isGroupForNodeData(nodedata: Object): boolean

See if the given node data should be represented as a group or as a simple node. This value must not change as long as the node data is part of the model. At the current time there is no setIsGroupForNodeData method.

Parameters

  • nodedata: Object

    a JavaScript object representing a node, group, or non-link.

Returns

boolean

public isLinkLabelForNodeData(nodedata: Object): boolean

See if the given node data should act as a label on a link, in order to support the appearance and behavior of having links connected to links. This value must not change as long as the node data is part of the model. At the current time there is no setIsLinkLabelForNodeData method.

Parameters

  • nodedata: Object

    a JavaScript object representing a node, group, or non-link.

Returns

boolean

public makeNodeDataKeyUnique(nodedata: Object): any

This method is called when a node data object is added to the model to make sure that

getKeyForNodeData returns a unique key value.

The key value should be unique within the set of data managed by this model:

nodeDataArray.

If the key is already in use, this will assign an unused number to the

nodeKeyProperty property on the data.

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.

Parameters

  • nodedata: Object

    a JavaScript object representing a node, group, or non-link.

Returns

any

public raiseChangedEvent(change: EnumValue, propertyname: any, obj: Object, oldval: any, newval: any, oldparam?: any, newparam?: any): any

Call this method to notify that the model or its objects have changed. This constructs a ChangedEvent and calls all Changed listeners.

Parameters

  • change: EnumValue

    specifies the general nature of the change; typically the value is ChangedEvent#Property.

  • propertyname: any

    names the property that was modified, or a function that takes an Object and returns the property value.

  • obj: Object

    the object that was modified, typically a GraphObject, Diagram, or a Model.

  • oldval: any

    the previous or older value.

  • newval: any

    the next or newer value.

  • oldparam?: any optional

    an optional value that helps describe the older value.

  • newparam?: any optional

    an optional value that helps describe the newer value.

Returns

any

public raiseDataChanged(data: Object, propertyname: any, oldval: any, newval: any, oldparam?: any, newparam?: any): 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.

Parameters

  • data: Object

    the data object whose property changed value.

  • propertyname: any

    the name of the property, or a function that takes an Object and returns the property value.

  • oldval: any

    the previous or old value for the property.

  • newval: any

    the next or new value for the property.

  • oldparam?: any optional

    an optional value additionally describing the old value.

  • newparam?: any optional

    an optional value additionally describing the new value.

Returns

any

public removeArrayItem(arr: Array<any>, idx?: number): 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.

Parameters

  • arr: Array<any>

    an Array that is the value of some Panel's Panel#itemArray.

  • idx?: number optional

    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.

Returns

any

public removeChangedListener(listener: (e: go.ChangedEvent) => void): any

Unregister an event handler listener. This deregistration does not raise a ChangedEvent.

Parameters

  • listener: (e: go.ChangedEvent) => void

    a function that takes a ChangedEvent as its argument.

Returns

any

public removeLabelKeyForLinkData(linkdata: Object, key: any): any

Removes a node key value that identifies a node data acting as a former label node on the given link data. Removing a reference to a node data from the collection of link label keys does not automatically remove any node data from the model. This method only works if #linkLabelKeysProperty has been set to something other than an empty string.

Parameters

  • linkdata: Object

    a JavaScript object representing a link.

  • key: any

    a number or string that is the key of the label node being removed from the link.

Returns

any

public removeLinkData(linkdata: Object): any

When you want to remove a link from the diagram, call this method with an existing link data object. This will remove that data from the #linkDataArray and notify all listeners that a link data object has been removed from the collection. Removing a link data from a model does not automatically remove any associated label node data from the model. This operation does nothing if the link data is not present in the #linkDataArray.

Parameters

  • linkdata: Object

    a JavaScript object representing a link.

Returns

any

public removeNodeData(nodedata: Object): 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.

Parameters

  • nodedata: Object

    a JavaScript object representing a node, group, or non-link.

Returns

any

public rollbackTransaction(): boolean

Rollback the current transaction, undoing any recorded changes.

Returns

boolean

public setCategoryForLinkData(linkdata: Object, cat: string): any

Change the category of a given link data, a string naming the link template that the Diagram should use to represent the link data. Changing the link template for a link data will cause the 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

  • linkdata: Object

    a JavaScript object representing a link.

  • cat: string

    Must not be null.

Returns

any

public setCategoryForNodeData(nodedata: Object, cat: string): any

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.

Parameters

  • nodedata: Object

    a JavaScript object representing a node, group, or non-link.

  • cat: string

    Must not be null.

Returns

any

public setDataProperty(data: Object, propname: string, val: any): any

ignore

Change the value of some property of a node data, a link 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 override handles link data as well as node data. This gets the old value of the property; if the value is the same as the new value, no side-effects occur.

Parameters

  • data: Object

    a JavaScript object representing a node, group, or non-link.

  • propname: string

    a string that is not null or the empty string.

  • val: any

    the new value for the property.

Returns

any

public setFromKeyForLinkData(linkdata: Object, key: any): any

Change the node key that the given link data references as the source of the link.

Parameters

  • linkdata: Object

    a JavaScript object representing a link.

  • key: any

    This may be undefined if the link should no longer come from any node.

Returns

any

public setFromPortIdForLinkData(linkdata: Object, portname: string): any

Change the information that the given link data uses to identify the particular "port" that the link is coming from.

Parameters

  • linkdata: Object

    a JavaScript object representing a link.

  • portname: string

    This may be the empty string if the link should no longer be associated with any particular "port".

Returns

any

public setGroupKeyForNodeData(nodedata: Object, key: any): any

Change the container group for the given node data, given a key for the new group.

Parameters

  • nodedata: Object

    a JavaScript object representing a node, group, or non-link.

  • key: any

    This may be undefined if there should be no containing group data.

Returns

any

public setKeyForNodeData(nodedata: Object, key: any): 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.

Parameters

  • nodedata: Object

    a JavaScript object representing a node, group, or non-link.

  • key: any

Returns

any

public setLabelKeysForLinkData(linkdata: Object, arr: Array<any>): any

Replaces an Array of node key values that identify node data acting as labels on the given link data. This method only works if #linkLabelKeysProperty has been set to something other than an empty string.

Parameters

  • linkdata: Object

    a JavaScript object representing a link.

  • arr: Array<any>

    an Array of node keys; an empty Array if the property was not present.

Returns

any

public setToKeyForLinkData(linkdata: Object, key: any): any

Change the node key that the given link data references as the destination of the link.

Parameters

  • linkdata: Object

    a JavaScript object representing a link.

  • key: any

    This may be undefined if the link should no longer go to any node.

Returns

any

public setToPortIdForLinkData(linkdata: Object, portname: string): any

Change the information that the given link data uses to identify the particular "port" that the link is going to.

Parameters

  • linkdata: Object

    a JavaScript object representing a link.

  • portname: string

    This may be the empty string if the link should no longer be associated with any particular "port".

Returns

any

public startTransaction(tname?: string): boolean

Begin a transaction, where the changes are held by a Transaction object in the UndoManager. This just calls UndoManager.startTransaction.

Parameters

  • tname?: string optional

    a descriptive name for the transaction.

Returns

boolean

public toJson(classname?: string): string

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.

Parameters

  • classname?: string optional

    The optional name of the model class to use in the output; for the standard models, this is their class name prefixed with "go.".

Returns

string

public updateTargetBindings(data: Object, srcpropname?: string): any

Find a Part corresponding to the given data and call its Panel#updateTargetBindings method, in each Diagram that uses this Model.

Parameters

  • data: Object

    The data object in this model that was modified.

  • srcpropname?: string optional

    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.

Returns

any