Class Model

Hierarchy

Index

Constructor methods

Properties

Methods

Constructor methods

constructor(nodedataarray?: Array<Object>): Model

You probably don't want to call this constructor, because this class does not support links (relationships between nodes) or groups (nodes and links and subgraphs as nodes): instead, create instances of a subclass such as GraphLinksModel or TreeModel.

Parameters

  • nodedataarray?: Array<Object> optional

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

Returns

Model

Properties

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 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 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 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 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 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 static fromJson(s: any, model?: Model): Model

This static method parses a string in JSON format and constructs, initializes, and returns a model.

Parameters

  • s: any

    a String in JSON format containing all of the persistent properties of the model, or an Object already read from JSON text.

  • model?: Model optional

    an optional model to be modified; if not supplied, it constructs and returns a new model whose name is specified by the "class" property.

Returns

Model

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