mxGraphModel

Cells are the elements of the graph model.  They represent the state of the groups, vertices and edges in a graph.

Fires a graphModelChanged event after each group of changes.

Summary
mxGraphModelCells are the elements of the graph model.
Variables
rootHolds the root cell, which in turn contains the cells that represent the layers of the diagram as child cells.
cellsMaps from Ids to cells.
maintainEdgeParentSpecifies if edges should automatically be moved into the nearest common ancestor of their terminals.
createIdsSpecifies if the model should automatically create Ids for new cells.
nextIdSpecifies the next Id to be created.
updateLevelCounter for the depth of nested transactions.
Functions
mxGraphModelConstructs a new graph model using the specified root cell.
clearSets a new root using createRoot.
createRootCreates a new root cell with a default layer (child 0).
getCellsReturns the internal lookup table that is used to map from Ids to cells.
setRoot
getRootReturns the root of the model.
setRootSets the root of the model using <mxRootChange> and adds the change to the current transaction.
cloneCellReturns a deep clone of the given mxCell (including the children) which is created using cloneCells.
cloneCellsReturns an array of clones for the given array of mxCells.
cloneCellImplInner helper method for cloning cells recursively.
cellClonedHook for cloning the cell.
restoreCloneInner helper method for restoring the connections in a network of cloned cells.
isAncestorReturns true if the given parent is an ancestor of the given child.
containsReturns true if the model contains the given mxCell.
getParentReturns the parent of the given cell.
addAdds the specified child to the parent at the given index using <mxChildChange> and adds the change to the current transaction.
cellAddedInner callback to update cells when a cell has been added.
createIdHook method to create an Id for the specified cell.
updateEdgeParentsUpdates the parent for all edges that are connected to cell or one of its descendants using updateEdgeParent.
updateEdgeParentInner callback to update the parent of the specified mxCell to the nearest-common-ancestor of its two terminals.
getOriginReturns the absolute, cummulated origin for the children inside the given parent as an mxPoint.
getNearestCommonAncestorReturns the nearest common ancestor for the specified cells.
removeRemoves the specified cell from the model using <mxChildChange> and adds the change to the current transaction.
cellRemovedInner callback to update cells when a cell has been removed.
getChildCountReturns the number of children in the given cell.
getChildAtReturns the child of the given mxCell at the given index.
getTerminalReturns the source or target mxCell of the given edge depending on the value of the boolean parameter.
setTerminalSets the source or target terminal of the given mxCell using <mxTerminalChange> and adds the change to the current transaction.
setTerminalsSets the source and target mxCell of the given mxCell in a single transaction using setTerminal for each end of the edge.
getEdgeCountReturns the number of distinct edges connected to the given cell.
getEdgeAtReturns the edge of cell at the given index.
getEdgesReturns all distinct edges connected to this cell as an array of mxCells.
isVertexReturns true if the given cell is a vertex.
isEdgeReturns true if the given cell is an edge.
isConnectableReturns true if the given mxCell is connectable.
getValueReturns the user object of the given mxCell using mxCell.getValue.
setValueSets the user object of then given mxCell using <mxValueChange> and adds the change to the current transaction.
getGeometryReturns the mxGeometry of the given mxCell.
setGeometrySets the mxGeometry of the given mxCell.
getStyleReturns the style of the given mxCell.
setStyleSets the style of the given mxCell using <mxStyleChange> and adds the change to the current transaction.
isCollapsedReturns true if the given mxCell is collapsed.
setCollapsedSets the collapsed state of the given mxCell using <mxCollapseChange> and adds the change to the current transaction.
isVisibleReturns true if the given mxCell is visible.
setVisibleSets the visible state of the given mxCell using <mxVisibleChange> and adds the change to the current transaction.
mergeChildrenMerges the children of the given cell into the given target cell inside this model.
mergeChildrenImplClones 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.
beginUpdateIncrements the updateLevel by one.
endUpdateDecrements the updateLevel by one and fires a notification event if the updateLevel reaches 0.
getDirectedEdgeCountReturns the number of incoming or outgoing edges, ignoring the given edge.

Variables

root

var $root

Holds the root cell, which in turn contains the cells that represent the layers of the diagram as child cells.  That is, the actual elements of the diagram are supposed to live in the third generation of cells and below.

cells

var $cells

Maps from Ids to cells.

maintainEdgeParent

var $maintainEdgeParent

Specifies if edges should automatically be moved into the nearest common ancestor of their terminals.  Default is true.

createIds

var $createIds

Specifies if the model should automatically create Ids for new cells.  Default is true.

nextId

var $nextId

Specifies the next Id to be created.  Default is 0.

updateLevel

var $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.

Functions

mxGraphModel

function mxGraphModel($root =  null)

Constructs a new graph model using the specified root cell.

clear

function clear()

Sets a new root using createRoot.

createRoot

function createRoot()

Creates a new root cell with a default layer (child 0).

getCells

function getCells()

Returns the internal lookup table that is used to map from Ids to cells.

setRoot

getRoot

function getRoot()

Returns the root of the model.

setRoot

function setRoot($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.

Parameters

rootmxCell that specifies the new root.

cloneCell

function cloneCell($cell)

Returns a deep clone of the given mxCell (including the children) which is created using cloneCells.

Parameters

cellmxCell to be cloned.

cloneCells

function cloneCells($cells,  
$includeChildren = true)

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.

Parameters

cellsArray of mxCell to be cloned.
includeChildrenBoolean indicating if the cells should be cloned with all descendants.

cloneCellImpl

function cloneCellImpl($cell,
$mapping,
$includeChildren)

Inner helper method for cloning cells recursively.

cellCloned

function cellCloned($cell)

Hook for cloning the cell.  This returns cell->copy() or any possible exceptions.

restoreClone

function restoreClone($clne,
$cell,
$mapping)

Inner helper method for restoring the connections in a network of cloned cells.

isAncestor

function isAncestor($parent,
$child)

Returns true if the given parent is an ancestor of the given child.

Parameters

parentmxCell that specifies the parent.
childmxCell that specifies the child.

contains

function contains($cell)

Returns true if the model contains the given mxCell.

Parameters

cellmxCell that specifies the cell.

getParent

function getParent($cell)

Returns the parent of the given cell.

Parameters

cellmxCell whose parent should be returned.

add

function add($parent,  
$child,  
$index =  null)

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.

Parameters

parentmxCell that specifies the parent to contain the child.
childmxCell that specifies the child to be inserted.
indexOptional integer that specifies the index of the child.

cellAdded

function cellAdded($cell)

Inner callback to update cells when a cell has been added.  This implementation resolves collisions by creating new Ids.

Parameters

cellmxCell that specifies the cell that has been added.

createId

function createId($cell)

Hook method to create an Id for the specified cell.  This implementation increments nextId.

Parameters

cellmxCell to create the Id for.

updateEdgeParents

function updateEdgeParents($cell,  
$root =  null)

Updates the parent for all edges that are connected to cell or one of its descendants using updateEdgeParent.

updateEdgeParent

function updateEdgeParent($edge,
$root)

Inner callback to update the parent of the specified mxCell to the nearest-common-ancestor of its two terminals.

Parameters

edgemxCell that specifies the edge.
rootmxCell that represents the current root of the model.

getOrigin

function getOrigin($cell)

Returns the absolute, cummulated origin for the children inside the given parent as an mxPoint.

getNearestCommonAncestor

function getNearestCommonAncestor($cell1,
$cell2)

Returns the nearest common ancestor for the specified cells.

Parameters

cell1mxCell that specifies the first cell in the tree.
cell2mxCell that specifies the second cell in the tree.

remove

function remove($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.

Parameters

cellmxCell that should be removed.

cellRemoved

function cellRemoved($cell)

Inner callback to update cells when a cell has been removed.

Parameters

cellmxCell that specifies the cell that has been removed.

getChildCount

function getChildCount($cell)

Returns the number of children in the given cell.

Parameters

cellmxCell whose number of children should be returned.

getChildAt

function getChildAt($cell,
$index)

Returns the child of the given mxCell at the given index.

Parameters

cellmxCell that represents the parent.
indexInteger that specifies the index of the child to be returned.

getTerminal

function getTerminal($edge,
$cource)

Returns the source or target mxCell of the given edge depending on the value of the boolean parameter.

Parameters

edgemxCell that specifies the edge.
courceBoolean indicating which end of the edge should be returned.

setTerminal

function setTerminal($edge,
$terminal,
$source)

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.

Parameters

edgemxCell that specifies the edge.
terminalmxCell that specifies the new terminal.
isSourceBoolean indicating if the terminal is the new source or target terminal of the edge.

setTerminals

function setTerminals($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.

Parameters

edgemxCell that specifies the edge.
sourcemxCell that specifies the new source terminal.
targetmxCell that specifies the new target terminal.

getEdgeCount

function getEdgeCount($cell)

Returns the number of distinct edges connected to the given cell.

Parameters

cellmxCell that represents the vertex.

getEdgeAt

function getEdgeAt($cell,
$index)

Returns the edge of cell at the given index.

Parameters

cellmxCell that specifies the vertex.
indexInteger that specifies the index of the edge to return.

getEdges

function getEdges($cell)

Returns all distinct edges connected to this cell as an array of mxCells.  The return value should be only be read.

Parameters

cellmxCell that specifies the cell.

isVertex

function isVertex($cell)

Returns true if the given cell is a vertex.

Parameters

cellmxCell that represents the possible vertex.

isEdge

function isEdge($cell)

Returns true if the given cell is an edge.

Parameters

cellmxCell that represents the possible edge.

isConnectable

function isConnectable($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.

Parameters

cellmxCell whose connectable state should be returned.

getValue

function getValue($cell)

Returns the user object of the given mxCell using mxCell.getValue.

Parameters

cellmxCell whose user object should be returned.

setValue

function setValue($cell,
$value)

Sets the user object of then given mxCell using <mxValueChange> and adds the change to the current transaction.

Parameters

cellmxCell whose user object should be changed.
valueObject that defines the new user object.

getGeometry

function getGeometry($cell)

Returns the mxGeometry of the given mxCell.

Parameters

cellmxCell whose geometry should be returned.

setGeometry

function setGeometry($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.

Parameters

cellmxCell whose geometry should be changed.
geometrymxGeometry that defines the new geometry.

getStyle

function getStyle($cell)

Returns the style of the given mxCell.

Parameters

cellmxCell whose style should be returned.

setStyle

function setStyle($cell,
$style)

Sets the style of the given mxCell using <mxStyleChange> and adds the change to the current transaction.

Parameters

cellmxCell whose style should be changed.
styleString of the form stylename[;key=value] to specify the new cell style.

isCollapsed

function isCollapsed($cell)

Returns true if the given mxCell is collapsed.

Parameters

cellmxCell whose collapsed state should be returned.

setCollapsed

function setCollapsed($cell,
$isCollapsed)

Sets the collapsed state of the given mxCell using <mxCollapseChange> and adds the change to the current transaction.

Parameters

cellmxCell whose collapsed state should be changed.
collapsedBoolean that specifies the new collpased state.

isVisible

function isVisible($cell)

Returns true if the given mxCell is visible.

Parameters

cellmxCell whose visible state should be returned.

setVisible

function setVisible($cell,
$visible)

Sets the visible state of the given mxCell using <mxVisibleChange> and adds the change to the current transaction.

Parameters

cellmxCell whose visible state should be changed.
visibleBoolean that specifies the new visible state.

mergeChildren

function mergeChildren($from,  
$to,  
$cloneAllEdges =  true)

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.

mergeChildrenImpl

function mergeChildrenImpl($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.

beginUpdate

function beginUpdate()

Increments the updateLevel by one.  The event notification is queued until updateLevel reaches 0 by use of endUpdate.

endUpdate

function endUpdate()

Decrements the updateLevel by one and fires a notification event if the updateLevel reaches 0.  This function indirectly fires a notification.

getDirectedEdgeCount

function getDirectedEdgeCount($cell,  
$outgoing,  
$ignoredEdge =  null)

Returns the number of incoming or outgoing edges, ignoring the given edge.

Parameters

cellmxCell whose edge count should be returned.
outgoingBoolean that specifies if the number of outgoing or incoming edges should be returned.
ignoredEdgemxCell that represents an edge to be ignored.
var $root
Holds the root cell, which in turn contains the cells that represent the layers of the diagram as child cells.
var $cells
Maps from Ids to cells.
var $maintainEdgeParent
Specifies if edges should automatically be moved into the nearest common ancestor of their terminals.
var $createIds
Specifies if the model should automatically create Ids for new cells.
var $nextId
Specifies the next Id to be created.
var $updateLevel
Counter for the depth of nested transactions.
function mxGraphModel($root =  null)
Constructs a new graph model using the specified root cell.
function clear()
Sets a new root using createRoot.
function createRoot()
Creates a new root cell with a default layer (child 0).
function getCells()
Returns the internal lookup table that is used to map from Ids to cells.
function getRoot()
Returns the root of the model.
function setRoot($root)
Sets the root of the model using mxRootChange and adds the change to the current transaction.
function cloneCell($cell)
Returns a deep clone of the given mxCell (including the children) which is created using cloneCells.
Cells are the elements of the graph model.
function cloneCells($cells,  
$includeChildren = true)
Returns an array of clones for the given array of mxCells.
function cloneCellImpl($cell,
$mapping,
$includeChildren)
Inner helper method for cloning cells recursively.
function cellCloned($cell)
Hook for cloning the cell.
function restoreClone($clne,
$cell,
$mapping)
Inner helper method for restoring the connections in a network of cloned cells.
function isAncestor($parent,
$child)
Returns true if the given parent is an ancestor of the given child.
function contains($cell)
Returns true if the model contains the given mxCell.
function getParent($cell)
Returns the parent of the given cell.
function add($parent,  
$child,  
$index =  null)
Adds the specified child to the parent at the given index using mxChildChange and adds the change to the current transaction.
function cellAdded($cell)
Inner callback to update cells when a cell has been added.
function createId($cell)
Hook method to create an Id for the specified cell.
function updateEdgeParents($cell,  
$root =  null)
Updates the parent for all edges that are connected to cell or one of its descendants using updateEdgeParent.
function updateEdgeParent($edge,
$root)
Inner callback to update the parent of the specified mxCell to the nearest-common-ancestor of its two terminals.
function getOrigin($cell)
Returns the absolute, cummulated origin for the children inside the given parent as an mxPoint.
Implements a 2-dimensional point with double precision coordinates.
function getNearestCommonAncestor($cell1,
$cell2)
Returns the nearest common ancestor for the specified cells.
function remove($cell)
Removes the specified cell from the model using mxChildChange and adds the change to the current transaction.
function cellRemoved($cell)
Inner callback to update cells when a cell has been removed.
function getChildCount($cell)
Returns the number of children in the given cell.
function getChildAt($cell,
$index)
Returns the child of the given mxCell at the given index.
function getTerminal($edge,
$cource)
Returns the source or target mxCell of the given edge depending on the value of the boolean parameter.
function setTerminal($edge,
$terminal,
$source)
Sets the source or target terminal of the given mxCell using mxTerminalChange and adds the change to the current transaction.
function setTerminals($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.
function getEdgeCount($cell)
Returns the number of distinct edges connected to the given cell.
function getEdgeAt($cell,
$index)
Returns the edge of cell at the given index.
function getEdges($cell)
Returns all distinct edges connected to this cell as an array of mxCells.
function isVertex($cell)
Returns true if the given cell is a vertex.
function isEdge($cell)
Returns true if the given cell is an edge.
function isConnectable($cell)
Returns true if the given mxCell is connectable.
function getValue($cell)
Returns the user object of the given mxCell using mxCell.getValue.
function getValue()
Returns the user object of the cell.
function setValue($cell,
$value)
Sets the user object of then given mxCell using mxValueChange and adds the change to the current transaction.
function getGeometry($cell)
Returns the mxGeometry of the given mxCell.
Represents the geometry of a cell.
function setGeometry($cell,
$geometry)
Sets the mxGeometry of the given mxCell.
function getStyle($cell)
Returns the style of the given mxCell.
function setStyle($cell,
$style)
Sets the style of the given mxCell using mxStyleChange and adds the change to the current transaction.
function isCollapsed($cell)
Returns true if the given mxCell is collapsed.
function setCollapsed($cell,
$isCollapsed)
Sets the collapsed state of the given mxCell using mxCollapseChange and adds the change to the current transaction.
function isVisible($cell)
Returns true if the given mxCell is visible.
function setVisible($cell,
$visible)
Sets the visible state of the given mxCell using mxVisibleChange and adds the change to the current transaction.
function mergeChildren($from,  
$to,  
$cloneAllEdges =  true)
Merges the children of the given cell into the given target cell inside this model.
function mergeChildrenImpl($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.
function beginUpdate()
Increments the updateLevel by one.
function endUpdate()
Decrements the updateLevel by one and fires a notification event if the updateLevel reaches 0.
function getDirectedEdgeCount($cell,  
$outgoing,  
$ignoredEdge =  null)
Returns the number of incoming or outgoing edges, ignoring the given edge.
function isConnectable()
Returns true if the cell is connectable.
Close