Extends mxEventSource to implement a graph model. The graph model acts as a wrapper around the cells which are in charge of storing the actual graph datastructure. The model acts as a transactional wrapper with event notification for all changes, whereas the cells contain the atomic operations for updating the actual datastructure.
The cell hierarchy in the model must have a top-level root cell which contains the layers (typically one default layer), which in turn contain the top-level cells of the layers. This means each cell is contained in a layer. If no layers are required, then all new cells should be added to the default layer.
Layers are useful for hiding and showing groups of cells, or for placing groups of cells on top of other cells in the display. To identify a layer, the isLayer function is used. It returns true if the parent of the given cell is the root of the model.
See events section for more details. There is a new set of events for tracking transactional changes as they happen. The events are called startEdit for the initial beginUpdate, executed for each executed change and endEdit for the terminal endUpdate. The executed event contains a property called change which represents the change after execution.
var enc = new mxCodec(); var node = enc.encode(graph.getModel());
This will create an XML node that contains all the model information.
For the encoding of changes, a graph model listener is required that encodes each change from the given array of changes.
model.addListener(mxEvent.CHANGE, function(sender, evt) { var changes = evt.getProperty('edit').changes; var nodes = []; var codec = new mxCodec(); for (var i = 0; i < changes.length; i++) { nodes.push(codec.encode(changes[i])); } // do something with the nodes });
For the decoding and execution of changes, the codec needs a lookup function that allows it to resolve cell IDs as follows:
var codec = new mxCodec(); codec.lookup = function(id) { return model.getCell(id); }
For each encoded change (represented by a node), the following code can be used to carry out the decoding and create a change object.
var changes = []; var change = codec.decode(node); change.model = model; change.execute(); changes.push(change);
The changes can then be dispatched using the model as follows.
var edit = new mxUndoableEdit(model, false); edit.changes = changes; edit.notify = function() { edit.source.fireEvent(new mxEventObject(mxEvent.CHANGE, 'edit', edit, 'changes', edit.changes)); edit.source.fireEvent(new mxEventObject(mxEvent.NOTIFY, 'edit', edit, 'changes', edit.changes)); } model.fireEvent(new mxEventObject(mxEvent.UNDO, 'edit', edit)); model.fireEvent(new mxEventObject(mxEvent.CHANGE, 'edit', edit, 'changes', changes));
mxGraphModel | Extends mxEventSource to implement a graph model. |
Events | |
mxEvent. | Fires when an undoable edit is dispatched. |
mxEvent. | Same as mxEvent.CHANGE, this event can be used for classes that need to implement a sync mechanism between this model and, say, a remote model. |
mxEvent. | Fires between begin- and endUpdate and after an atomic change was executed in the model. |
mxEvent. | Fires between START_EDIT and END_EDIT after an atomic change was executed. |
mxEvent. | Fires after the updateLevel was incremented in beginUpdate. |
mxEvent. | Fires after the updateLevel was changed from 0 to 1. |
mxEvent. | Fires after the updateLevel was decreased in endUpdate but before any notification or change dispatching. |
mxEvent. | Fires after the updateLevel was changed from 1 to 0. |
mxEvent. | Fires before the change is dispatched after the update level has reached 0 in endUpdate. |
mxEvent.UNDO | Fires after the change was dispatched in endUpdate. |
Functions | |
mxGraphModel | Constructs a new graph model. |
Variables | |
root | Holds the root cell, which in turn contains the cells that represent the layers of the diagram as child cells. |
cells | Maps from Ids to cells. |
maintainEdgeParent | Specifies if edges should automatically be moved into the nearest common ancestor of their terminals. |
ignoreRelativeEdgeParent | Specifies if relative edge parents should be ignored for finding the nearest common ancestors of an edge’s terminals. |
createIds | Specifies if the model should automatically create Ids for new cells. |
prefix | Defines the prefix of new Ids. |
postfix | Defines the postfix of new Ids. |
nextId | Specifies the next Id to be created. |
currentEdit | Holds the changes for the current transaction. |
updateLevel | Counter for the depth of nested transactions. |
endingUpdate | True if the program flow is currently inside endUpdate. |
Functions | |
clear | Sets a new root using createRoot. |
isCreateIds | Returns createIds. |
setCreateIds | Sets createIds. |
createRoot | Creates a new root cell with a default layer (child 0). |
getCell | Returns the mxCell for the specified Id or null if no cell can be found for the given Id. |
filterCells | Returns the cells from the given array where the given filter function returns true. |
getDescendants | Returns all descendants of the given cell and the cell itself in an array. |
filterDescendants | Visits all cells recursively and applies the specified filter function to each cell. |
getRoot | Returns the root of the model or the topmost parent of the given cell. |
setRoot | Sets the root of the model using mxRootChange and adds the change to the current transaction. |
rootChanged | Inner callback to change the root of the model and update the internal datastructures, such as cells and nextId. |
isRoot | Returns true if the given cell is the root of the model and a non-null value. |
isLayer | Returns true if isRoot returns true for the parent of the given cell. |
isAncestor | Returns true if the given parent is an ancestor of the given child. |
contains | Returns true if the model contains the given mxCell. |
getParent | Returns the parent of the given cell. |
add | Adds the specified child to the parent at the given index using mxChildChange and adds the change to the current transaction. |
cellAdded | Inner callback to update cells when a cell has been added. |
createId | Hook method to create an Id for the specified cell. |
updateEdgeParents | Updates the parent for all edges that are connected to cell or one of its descendants using updateEdgeParent. |
updateEdgeParent | Inner callback to update the parent of the specified mxCell to the nearest-common-ancestor of its two terminals. |
getOrigin | Returns the absolute, accumulated origin for the children inside the given parent as an mxPoint. |
getNearestCommonAncestor | Returns the nearest common ancestor for the specified cells. |
remove | Removes the specified cell from the model using mxChildChange and adds the change to the current transaction. |
cellRemoved | Inner callback to update cells when a cell has been removed. |
parentForCellChanged | Inner callback to update the parent of a cell using mxCell.insert on the parent and return the previous parent. |
getChildCount | Returns the number of children in the given cell. |
getChildAt | Returns the child of the given mxCell at the given index. |
getChildren | Returns all children of the given mxCell as an array of mxCells. |
getChildVertices | Returns the child vertices of the given parent. |
getChildEdges | Returns the child edges of the given parent. |
getChildCells | Returns the children of the given cell that are vertices and/or edges depending on the arguments. |
getTerminal | Returns the source or target mxCell of the given edge depending on the value of the boolean parameter. |
setTerminal | Sets the source or target terminal of the given mxCell using mxTerminalChange and adds the change to the current transaction. |
setTerminals | Sets the source and target mxCell of the given mxCell in a single transaction using setTerminal for each end of the edge. |
terminalForCellChanged | Inner helper function to update the terminal of the edge using mxCell.insertEdge and return the previous terminal. |
getEdgeCount | Returns the number of distinct edges connected to the given cell. |
getEdgeAt | Returns the edge of cell at the given index. |
getDirectedEdgeCount | Returns the number of incoming or outgoing edges, ignoring the given edge. |
getConnections | Returns all edges of the given cell without loops. |
getIncomingEdges | Returns the incoming edges of the given cell without loops. |
getOutgoingEdges | Returns the outgoing edges of the given cell without loops. |
getEdges | Returns all distinct edges connected to this cell as a new array of mxCells. |
getEdgesBetween | Returns all edges between the given source and target pair. |
getOpposites | Returns all opposite vertices wrt terminal for the given edges, only returning sources and/or targets as specified. |
getTopmostCells | Returns the topmost cells of the hierarchy in an array that contains no descendants for each mxCell that it contains. |
isVertex | Returns true if the given cell is a vertex. |
isEdge | Returns true if the given cell is an edge. |
isConnectable | Returns true if the given mxCell is connectable. |
getValue | Returns the user object of the given mxCell using mxCell.getValue. |
setValue | Sets the user object of then given mxCell using mxValueChange and adds the change to the current transaction. |
valueForCellChanged | Inner callback to update the user object of the given mxCell using mxCell.valueChanged and return the previous value, that is, the return value of mxCell.valueChanged. |
getGeometry | Returns the mxGeometry of the given mxCell. |
setGeometry | Sets the mxGeometry of the given mxCell. |
geometryForCellChanged | Inner callback to update the mxGeometry of the given mxCell using mxCell.setGeometry and return the previous mxGeometry. |
getStyle | Returns the style of the given mxCell. |
setStyle | Sets the style of the given mxCell using mxStyleChange and adds the change to the current transaction. |
styleForCellChanged | Inner callback to update the style of the given mxCell using mxCell.setStyle and return the previous style. |
isCollapsed | Returns true if the given mxCell is collapsed. |
setCollapsed | Sets the collapsed state of the given mxCell using mxCollapseChange and adds the change to the current transaction. |
collapsedStateForCellChanged | Inner callback to update the collapsed state of the given mxCell using mxCell.setCollapsed and return the previous collapsed state. |
isVisible | Returns true if the given mxCell is visible. |
setVisible | Sets the visible state of the given mxCell using mxVisibleChange and adds the change to the current transaction. |
visibleStateForCellChanged | Inner callback to update the visible state of the given mxCell using mxCell.setCollapsed and return the previous visible state. |
execute | Executes the given edit and fires events if required. |
beginUpdate | Increments the updateLevel by one. |
endUpdate | Decrements the updateLevel by one and fires an <undo> event if the updateLevel reaches 0. |
createUndoableEdit | Creates a new mxUndoableEdit that implements the notify function to fire a <change> and <notify> event through the mxUndoableEdit’s source. |
mergeChildren | Merges the children of the given cell into the given target cell inside this model. |
mergeChildren | Clones the children of the source cell into the given target cell in this model and adds an entry to the mapping that maps from the source cell to the target cell with the same id or the clone of the source cell that was inserted into this model. |
getParents | Returns an array that represents the set (no duplicates) of all parents for the given array of cells. |
cloneCell | Returns a deep clone of the given mxCell (including the children) which is created using cloneCells. |
cloneCells | Returns an array of clones for the given array of mxCells. |
cloneCellImpl | Inner helper method for cloning cells recursively. |
cellCloned | Hook for cloning the cell. |
restoreClone | Inner helper method for restoring the connections in a network of cloned cells. |
mxRootChange | Action to change the root in a model. |
Functions | |
mxRootChange | Constructs a change of the root in the specified model. |
execute | Carries out a change of the root using mxGraphModel.rootChanged. |
mxChildChange | Action to add or remove a child in a model. |
Functions | |
mxChildChange | Constructs a change of a child in the specified model. |
execute | Changes the parent of <child> using mxGraphModel.parentForCellChanged and removes or restores the cell’s connections. |
disconnect | Disconnects the given cell recursively from its terminals and stores the previous terminal in the cell’s terminals. |
mxTerminalChange | Action to change a terminal in a model. |
Functions | |
mxTerminalChange | Constructs a change of a terminal in the specified model. |
execute | Changes the terminal of <cell> to <previous> using mxGraphModel.terminalForCellChanged. |
mxValueChange | Action to change a user object in a model. |
Functions | |
mxValueChange | Constructs a change of a user object in the specified model. |
execute | Changes the value of <cell> to <previous> using mxGraphModel.valueForCellChanged. |
mxStyleChange | Action to change a cell’s style in a model. |
Functions | |
mxStyleChange | Constructs a change of a style in the specified model. |
execute | Changes the style of <cell> to <previous> using mxGraphModel.styleForCellChanged. |
mxGeometryChange | Action to change a cell’s geometry in a model. |
Functions | |
mxGeometryChange | Constructs a change of a geometry in the specified model. |
execute | Changes the geometry of <cell> ro <previous> using mxGraphModel.geometryForCellChanged. |
mxCollapseChange | Action to change a cell’s collapsed state in a model. |
Functions | |
mxCollapseChange | Constructs a change of a collapsed state in the specified model. |
execute | Changes the collapsed state of <cell> to <previous> using mxGraphModel.collapsedStateForCellChanged. |
mxVisibleChange | Action to change a cell’s visible state in a model. |
Functions | |
mxVisibleChange | Constructs a change of a visible state in the specified model. |
execute | Changes the visible state of <cell> to <previous> using mxGraphModel.visibleStateForCellChanged. |
mxCellAttributeChange | Action to change the attribute of a cell’s user object. |
Functions | |
mxCellAttributeChange | Constructs a change of a attribute of the DOM node stored as the value of the given mxCell. |
execute | Changes the attribute of the cell’s user object by using mxCell.setAttribute. |
Fires when an undoable edit is dispatched. The <code>edit</code> property contains the mxUndoableEdit. The <code>changes</code> property contains the array of atomic changes inside the undoable edit. The changes property is <strong>deprecated</strong>, please use edit.changes instead.
graph.model.addListener(mxEvent.CHANGE, function(sender, evt) { var changes = evt.getProperty('edit').changes; for (var i = 0; i < changes.length; i++) { var change = changes[i]; if (change instanceof mxChildChange && change.change.previous == null) { graph.startEditingAtCell(change.child); break; } } });
Same as mxEvent.CHANGE, this event can be used for classes that need to implement a sync mechanism between this model and, say, a remote model. In such a setup, only local changes should trigger a notify event and all changes should trigger a change event.
Fires after the updateLevel was incremented in beginUpdate. This event contains no properties.
Fires after the updateLevel was changed from 0 to 1. This event contains no properties.
Fires after the updateLevel was decreased in endUpdate but before any notification or change dispatching. The <code>edit</code> property contains the currentEdit.
Fires after the updateLevel was changed from 1 to 0. This event contains no properties.
Fires before the change is dispatched after the update level has reached 0 in endUpdate. The <code>edit</code> property contains the <curreneEdit>.
Fires after the change was dispatched in endUpdate. The <code>edit</code> property contains the currentEdit.
mxGraphModel.prototype.currentEdit
Holds the changes for the current transaction. If the transaction is closed then a new object is created for this variable using createUndoableEdit.
mxGraphModel.prototype.updateLevel
Counter for the depth of nested transactions. Each call to beginUpdate will increment this number and each call to endUpdate will decrement it. When the counter reaches 0, the transaction is closed and the respective events are fired. Initial value is 0.
mxGraphModel.prototype.clear = function()
Sets a new root using createRoot.
mxGraphModel.prototype.isCreateIds = function()
Returns createIds.
mxGraphModel.prototype.setCreateIds = function( value )
Sets createIds.
mxGraphModel.prototype.getCell = function( id )
Returns the mxCell for the specified Id or null if no cell can be found for the given Id.
id | A string representing the Id of the cell. |
mxGraphModel.prototype.getDescendants = function( parent )
Returns all descendants of the given cell and the cell itself in an array.
parent | mxCell whose descendants should be returned. |
mxGraphModel.prototype.filterDescendants = function( filter, parent )
Visits all cells recursively and applies the specified filter function to each cell. If the function returns true then the cell is added to the resulting array. The parent and result paramters are optional. If parent is not specified then the recursion starts at root.
The following example extracts all vertices from a given model:
var filter = function(cell) { return model.isVertex(cell); } var vertices = model.filterDescendants(filter);
filter | JavaScript function that takes an mxCell as an argument and returns a boolean. |
parent | Optional mxCell that is used as the root of the recursion. |
mxGraphModel.prototype.getRoot = function( cell )
Returns the root of the model or the topmost parent of the given cell.
cell | Optional mxCell that specifies the child. |
mxGraphModel.prototype.setRoot = function( root )
Sets the root of the model using mxRootChange and adds the change to the current transaction. This resets all datastructures in the model and is the preferred way of clearing an existing model. Returns the new root.
var root = new mxCell(); root.insert(new mxCell()); model.setRoot(root);
root | mxCell that specifies the new root. |
mxGraphModel.prototype.isRoot = function( cell )
Returns true if the given cell is the root of the model and a non-null value.
cell | mxCell that represents the possible root. |
mxGraphModel.prototype.getParent = function( cell )
Returns the parent of the given cell.
cell | mxCell whose parent should be returned. |
mxGraphModel.prototype.add = function( parent, child, index )
Adds the specified child to the parent at the given index using mxChildChange and adds the change to the current transaction. If no index is specified then the child is appended to the parent’s array of children. Returns the inserted child.
parent | mxCell that specifies the parent to contain the child. |
child | mxCell that specifies the child to be inserted. |
index | Optional integer that specifies the index of the child. |
mxGraphModel.prototype.cellAdded = function( cell )
Inner callback to update cells when a cell has been added. This implementation resolves collisions by creating new Ids. To change the ID of a cell after it was inserted into the model, use the following code:
(code delete model.cells[cell.getId()]; cell.setId(newId); model.cells[cell.getId()] = cell; (end)
If the change of the ID should be part of the command history, then the cell should be removed from the model and a clone with the new ID should be reinserted into the model instead.
cell | mxCell that specifies the cell that has been added. |
mxGraphModel.prototype.createId = function( cell )
Hook method to create an Id for the specified cell. This implementation concatenates prefix, id and postfix to create the Id and increments nextId. The cell is ignored by this implementation, but can be used in overridden methods to prefix the Ids with eg. the cell type.
cell | mxCell to create the Id for. |
mxGraphModel.prototype.updateEdgeParents = function( cell, root )
Updates the parent for all edges that are connected to cell or one of its descendants using updateEdgeParent.
mxGraphModel.prototype.getOrigin = function( cell )
Returns the absolute, accumulated origin for the children inside the given parent as an mxPoint.
mxGraphModel.prototype.remove = function( cell )
Removes the specified cell from the model using mxChildChange and adds the change to the current transaction. This operation will remove the cell and all of its children from the model. Returns the removed cell.
cell | mxCell that should be removed. |
mxGraphModel.prototype.parentForCellChanged = function( cell, parent, index )
Inner callback to update the parent of a cell using mxCell.insert on the parent and return the previous parent.
cell | mxCell to update the parent for. |
parent | mxCell that specifies the new parent of the cell. |
index | Optional integer that defines the index of the child in the parent’s child array. |
mxGraphModel.prototype.getChildCount = function( cell )
Returns the number of children in the given cell.
cell | mxCell whose number of children should be returned. |
mxGraphModel.prototype.getChildVertices = function( parent )
Returns the child vertices of the given parent.
cell | mxCell whose child vertices should be returned. |
mxGraphModel.prototype.getChildEdges = function( parent )
Returns the child edges of the given parent.
cell | mxCell whose child edges should be returned. |
mxGraphModel.prototype.getChildCells = function( parent, vertices, edges )
Returns the children of the given cell that are vertices and/or edges depending on the arguments.
cell | mxCell the represents the parent. |
vertices | Boolean indicating if child vertices should be returned. Default is false. |
edges | Boolean indicating if child edges should be returned. Default is false. |
mxGraphModel.prototype.setTerminal = function( edge, terminal, isSource )
Sets the source or target terminal of the given mxCell using mxTerminalChange and adds the change to the current transaction. This implementation updates the parent of the edge using updateEdgeParent if required.
edge | mxCell that specifies the edge. |
terminal | mxCell that specifies the new terminal. |
isSource | Boolean indicating if the terminal is the new source or target terminal of the edge. |
mxGraphModel.prototype.setTerminals = function( edge, source, target )
Sets the source and target mxCell of the given mxCell in a single transaction using setTerminal for each end of the edge.
edge | mxCell that specifies the edge. |
source | mxCell that specifies the new source terminal. |
target | mxCell that specifies the new target terminal. |
mxGraphModel.prototype.terminalForCellChanged = function( edge, terminal, isSource )
Inner helper function to update the terminal of the edge using mxCell.insertEdge and return the previous terminal.
edge | mxCell that specifies the edge to be updated. |
terminal | mxCell that specifies the new terminal. |
isSource | Boolean indicating if the terminal is the new source or target terminal of the edge. |
mxGraphModel.prototype.getEdgeCount = function( cell )
Returns the number of distinct edges connected to the given cell.
cell | mxCell that represents the vertex. |
mxGraphModel.prototype.getEdgeAt = function( cell, index )
Returns the edge of cell at the given index.
cell | mxCell that specifies the vertex. |
index | Integer that specifies the index of the edge to return. |
mxGraphModel.prototype.getDirectedEdgeCount = function( cell, outgoing, ignoredEdge )
Returns the number of incoming or outgoing edges, ignoring the given edge.
cell | mxCell whose edge count should be returned. |
outgoing | Boolean that specifies if the number of outgoing or incoming edges should be returned. |
ignoredEdge | mxCell that represents an edge to be ignored. |
mxGraphModel.prototype.getConnections = function( cell )
Returns all edges of the given cell without loops.
cell | mxCell whose edges should be returned. |
mxGraphModel.prototype.getIncomingEdges = function( cell )
Returns the incoming edges of the given cell without loops.
cell | mxCell whose incoming edges should be returned. |
mxGraphModel.prototype.getOutgoingEdges = function( cell )
Returns the outgoing edges of the given cell without loops.
cell | mxCell whose outgoing edges should be returned. |
mxGraphModel.prototype.getEdges = function( cell, incoming, outgoing, includeLoops )
Returns all distinct edges connected to this cell as a new array of mxCells. If at least one of incoming or outgoing is true, then loops are ignored, otherwise if both are false, then all edges connected to the given cell are returned including loops.
cell | mxCell that specifies the cell. |
incoming | Optional boolean that specifies if incoming edges should be returned. Default is true. |
outgoing | Optional boolean that specifies if outgoing edges should be returned. Default is true. |
includeLoops | Optional boolean that specifies if loops should be returned. Default is true. |
mxGraphModel.prototype.getEdgesBetween = function( source, target, directed )
Returns all edges between the given source and target pair. If directed is true, then only edges from the source to the target are returned, otherwise, all edges between the two cells are returned.
source | mxCell that defines the source terminal of the edge to be returned. |
target | mxCell that defines the target terminal of the edge to be returned. |
directed | Optional boolean that specifies if the direction of the edge should be taken into account. Default is false. |
mxGraphModel.prototype.getOpposites = function( edges, terminal, sources, targets )
Returns all opposite vertices wrt terminal for the given edges, only returning sources and/or targets as specified. The result is returned as an array of mxCells.
edges | Array of mxCells that contain the edges to be examined. |
terminal | mxCell that specifies the known end of the edges. |
sources | Boolean that specifies if source terminals should be contained in the result. Default is true. |
targets | Boolean that specifies if target terminals should be contained in the result. Default is true. |
mxGraphModel.prototype.getTopmostCells = function( cells )
Returns the topmost cells of the hierarchy in an array that contains no descendants for each mxCell that it contains. Duplicates should be removed in the cells array to improve performance.
cells | Array of mxCells whose topmost ancestors should be returned. |
mxGraphModel.prototype.isVertex = function( cell )
Returns true if the given cell is a vertex.
cell | mxCell that represents the possible vertex. |
mxGraphModel.prototype.isEdge = function( cell )
Returns true if the given cell is an edge.
cell | mxCell that represents the possible edge. |
mxGraphModel.prototype.isConnectable = function( cell )
Returns true if the given mxCell is connectable. If <edgesConnectable> is false, then this function returns false for all edges else it returns the return value of mxCell.isConnectable.
cell | mxCell whose connectable state should be returned. |
mxGraphModel.prototype.getValue = function( cell )
Returns the user object of the given mxCell using mxCell.getValue.
cell | mxCell whose user object should be returned. |
mxGraphModel.prototype.setValue = function( cell, value )
Sets the user object of then given mxCell using mxValueChange and adds the change to the current transaction.
cell | mxCell whose user object should be changed. |
value | Object that defines the new user object. |
mxGraphModel.prototype.valueForCellChanged = function( cell, value )
Inner callback to update the user object of the given mxCell using mxCell.valueChanged and return the previous value, that is, the return value of mxCell.valueChanged.
To change a specific attribute in an XML node, the following code can be used.
graph.getModel().valueForCellChanged = function(cell, value) { var previous = cell.value.getAttribute('label'); cell.value.setAttribute('label', value); return previous; };
mxGraphModel.prototype.getGeometry = function( cell )
Returns the mxGeometry of the given mxCell.
cell | mxCell whose geometry should be returned. |
mxGraphModel.prototype.setGeometry = function( cell, geometry )
Sets the mxGeometry of the given mxCell. The actual update of the cell is carried out in geometryForCellChanged. The mxGeometryChange action is used to encapsulate the change.
cell | mxCell whose geometry should be changed. |
geometry | mxGeometry that defines the new geometry. |
mxGraphModel.prototype.geometryForCellChanged = function( cell, geometry )
Inner callback to update the mxGeometry of the given mxCell using mxCell.setGeometry and return the previous mxGeometry.
mxGraphModel.prototype.setStyle = function( cell, style )
Sets the style of the given mxCell using mxStyleChange and adds the change to the current transaction.
cell | mxCell whose style should be changed. |
style | String of the form [stylename;|key=value;] to specify the new cell style. |
mxGraphModel.prototype.styleForCellChanged = function( cell, style )
Inner callback to update the style of the given mxCell using mxCell.setStyle and return the previous style.
cell | mxCell that specifies the cell to be updated. |
style | String of the form [stylename;|key=value;] to specify the new cell style. |
mxGraphModel.prototype.setCollapsed = function( cell, collapsed )
Sets the collapsed state of the given mxCell using mxCollapseChange and adds the change to the current transaction.
cell | mxCell whose collapsed state should be changed. |
collapsed | Boolean that specifies the new collpased state. |
mxGraphModel.prototype.collapsedStateForCellChanged = function( cell, collapsed )
Inner callback to update the collapsed state of the given mxCell using mxCell.setCollapsed and return the previous collapsed state.
cell | mxCell that specifies the cell to be updated. |
collapsed | Boolean that specifies the new collpased state. |
mxGraphModel.prototype.setVisible = function( cell, visible )
Sets the visible state of the given mxCell using mxVisibleChange and adds the change to the current transaction.
cell | mxCell whose visible state should be changed. |
visible | Boolean that specifies the new visible state. |
mxGraphModel.prototype.visibleStateForCellChanged = function( cell, visible )
Inner callback to update the visible state of the given mxCell using mxCell.setCollapsed and return the previous visible state.
cell | mxCell that specifies the cell to be updated. |
visible | Boolean that specifies the new visible state. |
mxGraphModel.prototype.execute = function( change )
Executes the given edit and fires events if required. The edit object requires an execute function which is invoked. The edit is added to the currentEdit between beginUpdate and endUpdate calls, so that events will be fired if this execute is an individual transaction, that is, if no previous beginUpdate calls have been made without calling endUpdate. This implementation fires an execute event before executing the given change.
change | Object that described the change. |
mxGraphModel.prototype.beginUpdate = function()
Increments the updateLevel by one. The event notification is queued until updateLevel reaches 0 by use of endUpdate.
All changes on mxGraphModel are transactional, that is, they are executed in a single undoable change on the model (without transaction isolation). Therefore, if you want to combine any number of changes into a single undoable change, you should group any two or more API calls that modify the graph model between beginUpdate and endUpdate calls as shown here:
var model = graph.getModel(); var parent = graph.getDefaultParent(); var index = model.getChildCount(parent); model.beginUpdate(); try { model.add(parent, v1, index); model.add(parent, v2, index+1); } finally { model.endUpdate(); }
Of course there is a shortcut for appending a sequence of cells into the default parent:
graph.addCells([v1, v2]).
mxGraphModel.prototype.endUpdate = function()
Decrements the updateLevel by one and fires an <undo> event if the updateLevel reaches 0. This function indirectly fires a <change> event by invoking the notify function on the currentEdit und then creates a new currentEdit using createUndoableEdit.
The <undo> event is fired only once per edit, whereas the <change> event is fired whenever the notify function is invoked, that is, on undo and redo of the edit.
mxGraphModel.prototype.createUndoableEdit = function( significant )
Creates a new mxUndoableEdit that implements the notify function to fire a <change> and <notify> event through the mxUndoableEdit’s source.
significant | Optional boolean that specifies if the edit to be created is significant. Default is true. |
mxGraphModel.prototype.mergeChildren = function( from, to, cloneAllEdges )
Merges the children of the given cell into the given target cell inside this model. All cells are cloned unless there is a corresponding cell in the model with the same id, in which case the source cell is ignored and all edges are connected to the corresponding cell in this model. Edges are considered to have no identity and are always cloned unless the cloneAllEdges flag is set to false, in which case edges with the same id in the target model are reconnected to reflect the terminals of the source edges.
mxGraphModel.prototype.mergeChildrenImpl = function( from, to, cloneAllEdges, mapping )
Clones the children of the source cell into the given target cell in this model and adds an entry to the mapping that maps from the source cell to the target cell with the same id or the clone of the source cell that was inserted into this model.
mxGraphModel.prototype.cloneCell = function( cell, includeChildren )
Returns a deep clone of the given mxCell (including the children) which is created using cloneCells.
cell | mxCell to be cloned. |
includeChildren | Optional boolean indicating if the cells should be cloned with all descendants. Default is true. |
mxGraphModel.prototype.cloneCells = function( cells, includeChildren, mapping )
Returns an array of clones for the given array of mxCells. Depending on the value of includeChildren, a deep clone is created for each cell. Connections are restored based if the corresponding cell is contained in the passed in array.
cells | Array of mxCell to be cloned. |
includeChildren | Optional boolean indicating if the cells should be cloned with all descendants. Default is true. |
mapping | Optional mapping for existing clones. |
Action to change the root in a model.
Functions | |
mxRootChange | Constructs a change of the root in the specified model. |
execute | Carries out a change of the root using mxGraphModel.rootChanged. |
mxRootChange.prototype.execute = function()
Carries out a change of the root using mxGraphModel.rootChanged.
Action to add or remove a child in a model.
Functions | |
mxChildChange | Constructs a change of a child in the specified model. |
execute | Changes the parent of <child> using mxGraphModel.parentForCellChanged and removes or restores the cell’s connections. |
disconnect | Disconnects the given cell recursively from its terminals and stores the previous terminal in the cell’s terminals. |
mxChildChange.prototype.execute = function()
Changes the parent of <child> using mxGraphModel.parentForCellChanged and removes or restores the cell’s connections.
Action to change a terminal in a model.
Functions | |
mxTerminalChange | Constructs a change of a terminal in the specified model. |
execute | Changes the terminal of <cell> to <previous> using mxGraphModel.terminalForCellChanged. |
mxTerminalChange.prototype.execute = function()
Changes the terminal of <cell> to <previous> using mxGraphModel.terminalForCellChanged.
Action to change a user object in a model.
Functions | |
mxValueChange | Constructs a change of a user object in the specified model. |
execute | Changes the value of <cell> to <previous> using mxGraphModel.valueForCellChanged. |
mxValueChange.prototype.execute = function()
Changes the value of <cell> to <previous> using mxGraphModel.valueForCellChanged.
Action to change a cell’s style in a model.
Functions | |
mxStyleChange | Constructs a change of a style in the specified model. |
execute | Changes the style of <cell> to <previous> using mxGraphModel.styleForCellChanged. |
mxStyleChange.prototype.execute = function()
Changes the style of <cell> to <previous> using mxGraphModel.styleForCellChanged.
Action to change a cell’s geometry in a model.
Functions | |
mxGeometryChange | Constructs a change of a geometry in the specified model. |
execute | Changes the geometry of <cell> ro <previous> using mxGraphModel.geometryForCellChanged. |
mxGeometryChange.prototype.execute = function()
Changes the geometry of <cell> ro <previous> using mxGraphModel.geometryForCellChanged.
Action to change a cell’s collapsed state in a model.
Functions | |
mxCollapseChange | Constructs a change of a collapsed state in the specified model. |
execute | Changes the collapsed state of <cell> to <previous> using mxGraphModel.collapsedStateForCellChanged. |
mxCollapseChange.prototype.execute = function()
Changes the collapsed state of <cell> to <previous> using mxGraphModel.collapsedStateForCellChanged.
Action to change a cell’s visible state in a model.
Functions | |
mxVisibleChange | Constructs a change of a visible state in the specified model. |
execute | Changes the visible state of <cell> to <previous> using mxGraphModel.visibleStateForCellChanged. |
mxVisibleChange.prototype.execute = function()
Changes the visible state of <cell> to <previous> using mxGraphModel.visibleStateForCellChanged.
Action to change the attribute of a cell’s user object. There is no method on the graph model that uses this action. To use the action, you can use the code shown in the example below.
To change the attributeName in the cell’s user object to attributeValue, use the following code:
model.beginUpdate(); try { var edit = new mxCellAttributeChange( cell, attributeName, attributeValue); model.execute(edit); } finally { model.endUpdate(); }
Functions | |
mxCellAttributeChange | Constructs a change of a attribute of the DOM node stored as the value of the given mxCell. |
execute | Changes the attribute of the cell’s user object by using mxCell.setAttribute. |
function mxCellAttributeChange( cell, attribute, value )
Constructs a change of a attribute of the DOM node stored as the value of the given mxCell.
mxCellAttributeChange.prototype.execute = function()
Changes the attribute of the cell’s user object by using mxCell.setAttribute.
Counter for the depth of nested transactions.
mxGraphModel.prototype.updateLevel
Increments the updateLevel by one.
mxGraphModel.prototype.beginUpdate = function()
Decrements the updateLevel by one and fires an undo event if the updateLevel reaches 0.
mxGraphModel.prototype.endUpdate = function()
Constructs a new graph model.
function mxGraphModel( root )
Holds the root cell, which in turn contains the cells that represent the layers of the diagram as child cells.
mxGraphModel.prototype.root
Maps from Ids to cells.
mxGraphModel.prototype.cells
Specifies if edges should automatically be moved into the nearest common ancestor of their terminals.
mxGraphModel.prototype.maintainEdgeParent
Specifies if relative edge parents should be ignored for finding the nearest common ancestors of an edge’s terminals.
mxGraphModel.prototype.ignoreRelativeEdgeParent
Specifies if the model should automatically create Ids for new cells.
mxGraphModel.prototype.createIds
Defines the prefix of new Ids.
mxGraphModel.prototype.prefix
Defines the postfix of new Ids.
mxGraphModel.prototype.postfix
Specifies the next Id to be created.
mxGraphModel.prototype.nextId
Holds the changes for the current transaction.
mxGraphModel.prototype.currentEdit
True if the program flow is currently inside endUpdate.
mxGraphModel.prototype.endingUpdate
Sets a new root using createRoot.
mxGraphModel.prototype.clear = function()
Creates a new root cell with a default layer (child 0).
mxGraphModel.prototype.createRoot = function()
Returns createIds.
mxGraphModel.prototype.isCreateIds = function()
Sets createIds.
mxGraphModel.prototype.setCreateIds = function( value )
Returns the mxCell for the specified Id or null if no cell can be found for the given Id.
mxGraphModel.prototype.getCell = function( id )
Returns the cells from the given array where the given filter function returns true.
mxGraphModel.prototype.filterCells = function( cells, filter )
Returns all descendants of the given cell and the cell itself in an array.
mxGraphModel.prototype.getDescendants = function( parent )
Visits all cells recursively and applies the specified filter function to each cell.
mxGraphModel.prototype.filterDescendants = function( filter, parent )
Returns the root of the model or the topmost parent of the given cell.
mxGraphModel.prototype.getRoot = function( cell )
Sets the root of the model using mxRootChange and adds the change to the current transaction.
mxGraphModel.prototype.setRoot = function( root )
Inner callback to change the root of the model and update the internal datastructures, such as cells and nextId.
mxGraphModel.prototype.rootChanged = function( root )
Returns true if the given cell is the root of the model and a non-null value.
mxGraphModel.prototype.isRoot = function( cell )
Returns true if isRoot returns true for the parent of the given cell.
mxGraphModel.prototype.isLayer = function( cell )
Returns true if the given parent is an ancestor of the given child.
mxGraphModel.prototype.isAncestor = function( parent, child )
Returns true if the model contains the given mxCell.
mxGraphModel.prototype.contains = function( cell )
Returns the parent of the given cell.
mxGraphModel.prototype.getParent = function( cell )
Adds the specified child to the parent at the given index using mxChildChange and adds the change to the current transaction.
mxGraphModel.prototype.add = function( parent, child, index )
Inner callback to update cells when a cell has been added.
mxGraphModel.prototype.cellAdded = function( cell )
Hook method to create an Id for the specified cell.
mxGraphModel.prototype.createId = function( cell )
Updates the parent for all edges that are connected to cell or one of its descendants using updateEdgeParent.
mxGraphModel.prototype.updateEdgeParents = function( cell, root )
Inner callback to update the parent of the specified mxCell to the nearest-common-ancestor of its two terminals.
mxGraphModel.prototype.updateEdgeParent = function( edge, root )
Returns the absolute, accumulated origin for the children inside the given parent as an mxPoint.
mxGraphModel.prototype.getOrigin = function( cell )
Returns the nearest common ancestor for the specified cells.
mxGraphModel.prototype.getNearestCommonAncestor = function( cell1, cell2 )
Removes the specified cell from the model using mxChildChange and adds the change to the current transaction.
mxGraphModel.prototype.remove = function( cell )
Inner callback to update cells when a cell has been removed.
mxGraphModel.prototype.cellRemoved = function( cell )
Inner callback to update the parent of a cell using mxCell.insert on the parent and return the previous parent.
mxGraphModel.prototype.parentForCellChanged = function( cell, parent, index )
Inserts the specified child into the child array at the specified index and updates the parent reference of the child.
mxCell.prototype.insert = function( child, index )
Returns the number of children in the given cell.
mxGraphModel.prototype.getChildCount = function( cell )
Returns the child of the given mxCell at the given index.
mxGraphModel.prototype.getChildAt = function( cell, index )
Returns all children of the given mxCell as an array of mxCells.
mxGraphModel.prototype.getChildren = function( cell )
Returns the child vertices of the given parent.
mxGraphModel.prototype.getChildVertices = function( parent )
Returns the child edges of the given parent.
mxGraphModel.prototype.getChildEdges = function( parent )
Returns the children of the given cell that are vertices and/or edges depending on the arguments.
mxGraphModel.prototype.getChildCells = function( parent, vertices, edges )
Returns the source or target mxCell of the given edge depending on the value of the boolean parameter.
mxGraphModel.prototype.getTerminal = function( edge, isSource )
Sets the source or target terminal of the given mxCell using mxTerminalChange and adds the change to the current transaction.
mxGraphModel.prototype.setTerminal = function( edge, terminal, isSource )
Sets the source and target mxCell of the given mxCell in a single transaction using setTerminal for each end of the edge.
mxGraphModel.prototype.setTerminals = function( edge, source, target )
Inner helper function to update the terminal of the edge using mxCell.insertEdge and return the previous terminal.
mxGraphModel.prototype.terminalForCellChanged = function( edge, terminal, isSource )
Inserts the specified edge into the edge array and returns the edge.
mxCell.prototype.insertEdge = function( edge, isOutgoing )
Returns the number of distinct edges connected to the given cell.
mxGraphModel.prototype.getEdgeCount = function( cell )
Returns the edge of cell at the given index.
mxGraphModel.prototype.getEdgeAt = function( cell, index )
Returns the number of incoming or outgoing edges, ignoring the given edge.
mxGraphModel.prototype.getDirectedEdgeCount = function( cell, outgoing, ignoredEdge )
Returns all edges of the given cell without loops.
mxGraphModel.prototype.getConnections = function( cell )
Returns the incoming edges of the given cell without loops.
mxGraphModel.prototype.getIncomingEdges = function( cell )
Returns the outgoing edges of the given cell without loops.
mxGraphModel.prototype.getOutgoingEdges = function( cell )
Returns all distinct edges connected to this cell as a new array of mxCells.
mxGraphModel.prototype.getEdges = function( cell, incoming, outgoing, includeLoops )
Returns all edges between the given source and target pair.
mxGraphModel.prototype.getEdgesBetween = function( source, target, directed )
Returns all opposite vertices wrt terminal for the given edges, only returning sources and/or targets as specified.
mxGraphModel.prototype.getOpposites = function( edges, terminal, sources, targets )
Returns the topmost cells of the hierarchy in an array that contains no descendants for each mxCell that it contains.
mxGraphModel.prototype.getTopmostCells = function( cells )
Returns true if the given cell is a vertex.
mxGraphModel.prototype.isVertex = function( cell )
Returns true if the given cell is an edge.
mxGraphModel.prototype.isEdge = function( cell )
Returns true if the given mxCell is connectable.
mxGraphModel.prototype.isConnectable = function( cell )
Returns the user object of the given mxCell using mxCell.getValue.
mxGraphModel.prototype.getValue = function( cell )
Returns the user object of the cell.
mxCell.prototype.getValue = function()
Sets the user object of then given mxCell using mxValueChange and adds the change to the current transaction.
mxGraphModel.prototype.setValue = function( cell, value )
Inner callback to update the user object of the given mxCell using mxCell.valueChanged and return the previous value, that is, the return value of mxCell.valueChanged.
mxGraphModel.prototype.valueForCellChanged = function( cell, value )
Changes the user object after an in-place edit and returns the previous value.
mxCell.prototype.valueChanged = function( newValue )
Returns the mxGeometry of the given mxCell.
mxGraphModel.prototype.getGeometry = function( cell )
Sets the mxGeometry of the given mxCell.
mxGraphModel.prototype.setGeometry = function( cell, geometry )
Inner callback to update the mxGeometry of the given mxCell using mxCell.setGeometry and return the previous mxGeometry.
mxGraphModel.prototype.geometryForCellChanged = function( cell, geometry )
Sets the mxGeometry to be used as the geometry.
mxCell.prototype.setGeometry = function( geometry )
Returns the style of the given mxCell.
mxGraphModel.prototype.getStyle = function( cell )
Sets the style of the given mxCell using mxStyleChange and adds the change to the current transaction.
mxGraphModel.prototype.setStyle = function( cell, style )
Inner callback to update the style of the given mxCell using mxCell.setStyle and return the previous style.
mxGraphModel.prototype.styleForCellChanged = function( cell, style )
Sets the string to be used as the style.
mxCell.prototype.setStyle = function( style )
Returns true if the given mxCell is collapsed.
mxGraphModel.prototype.isCollapsed = function( cell )
Sets the collapsed state of the given mxCell using mxCollapseChange and adds the change to the current transaction.
mxGraphModel.prototype.setCollapsed = function( cell, collapsed )
Inner callback to update the collapsed state of the given mxCell using mxCell.setCollapsed and return the previous collapsed state.
mxGraphModel.prototype.collapsedStateForCellChanged = function( cell, collapsed )
Sets the collapsed state.
mxCell.prototype.setCollapsed = function( collapsed )
Returns true if the given mxCell is visible.
mxGraphModel.prototype.isVisible = function( cell )
Sets the visible state of the given mxCell using mxVisibleChange and adds the change to the current transaction.
mxGraphModel.prototype.setVisible = function( cell, visible )
Inner callback to update the visible state of the given mxCell using mxCell.setCollapsed and return the previous visible state.
mxGraphModel.prototype.visibleStateForCellChanged = function( cell, visible )
Executes the given edit and fires events if required.
mxGraphModel.prototype.execute = function( change )
Creates a new mxUndoableEdit that implements the notify function to fire a change and notify event through the mxUndoableEdit’s source.
mxGraphModel.prototype.createUndoableEdit = function( significant )
Merges the children of the given cell into the given target cell inside this model.
mxGraphModel.prototype.mergeChildren = function( from, to, cloneAllEdges )
Returns an array that represents the set (no duplicates) of all parents for the given array of cells.
mxGraphModel.prototype.getParents = function( cells )
Returns a deep clone of the given mxCell (including the children) which is created using cloneCells.
mxGraphModel.prototype.cloneCell = function( cell, includeChildren )
Returns an array of clones for the given array of mxCells.
mxGraphModel.prototype.cloneCells = function( cells, includeChildren, mapping )
Inner helper method for cloning cells recursively.
mxGraphModel.prototype.cloneCellImpl = function( cell, mapping, includeChildren )
Hook for cloning the cell.
mxGraphModel.prototype.cellCloned = function( cell )
Inner helper method for restoring the connections in a network of cloned cells.
mxGraphModel.prototype.restoreClone = function( clone, cell, mapping )
Constructs a change of the root in the specified model.
function mxRootChange( model, root )
Carries out a change of the root using mxGraphModel.rootChanged.
mxRootChange.prototype.execute = function()
Constructs a change of a child in the specified model.
function mxChildChange( model, parent, child, index )
Changes the parent of child using mxGraphModel.parentForCellChanged and removes or restores the cell’s connections.
mxChildChange.prototype.execute = function()
Constructs a change of a terminal in the specified model.
function mxTerminalChange( model, cell, terminal, source )
Changes the terminal of cell to previous using mxGraphModel.terminalForCellChanged.
mxTerminalChange.prototype.execute = function()
Constructs a change of a user object in the specified model.
function mxValueChange( model, cell, value )
Changes the value of cell to previous using mxGraphModel.valueForCellChanged.
mxValueChange.prototype.execute = function()
Constructs a change of a style in the specified model.
function mxStyleChange( model, cell, style )
Changes the style of cell to previous using mxGraphModel.styleForCellChanged.
mxStyleChange.prototype.execute = function()
Constructs a change of a geometry in the specified model.
function mxGeometryChange( model, cell, geometry )
Changes the geometry of cell ro previous using mxGraphModel.geometryForCellChanged.
mxGeometryChange.prototype.execute = function()
Constructs a change of a collapsed state in the specified model.
function mxCollapseChange( model, cell, collapsed )
Changes the collapsed state of cell to previous using mxGraphModel.collapsedStateForCellChanged.
mxCollapseChange.prototype.execute = function()
Constructs a change of a visible state in the specified model.
function mxVisibleChange( model, cell, visible )
Changes the visible state of cell to previous using mxGraphModel.visibleStateForCellChanged.
mxVisibleChange.prototype.execute = function()
Constructs a change of a attribute of the DOM node stored as the value of the given mxCell.
function mxCellAttributeChange( cell, attribute, value )
Changes the attribute of the cell’s user object by using mxCell.setAttribute.
mxCellAttributeChange.prototype.execute = function()
Sets the specified attribute on the user object if it is an XML node.
mxCell.prototype.setAttribute = function( name, value )
Returns true if the cell is connectable.
mxCell.prototype.isConnectable = function()