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

For custom attributes we recommend using an XML node as the value of a cell. The following code can be used to create a cell with an XML node as the value:

var doc = mxUtils.createXmlDocument();
var node = doc.createElement('MyNode')
node.setAttribute('label', 'MyLabel');
node.setAttribute('attribute1', 'value1');
graph.insertVertex(graph.getDefaultParent(), null, node, 40, 40, 80, 30);

For the label to work, graph.convertValueToString and graph.cellLabelChanged should be overridden as follows:

graph.convertValueToString(cell)
{
if (mxUtils.isNode(cell.value))
{
return cell.getAttribute('label', '')
}
};

var cellLabelChanged = graph.cellLabelChanged;
graph.cellLabelChanged(cell, newValue, autoSize)
{
if (mxUtils.isNode(cell.value))
{
// Clones the value for correct undo/redo
var elt = cell.value.cloneNode(true);
elt.setAttribute('label', newValue);
newValue = elt;
}

cellLabelChanged.apply(this, arguments);
};

Cell

Hierarchy (view full)

Implements

Constructors

Properties

children: Cell[] = []

Holds the child cells.

collapsed: boolean = false

Specifies whether the cell is collapsed. Default is false.

connectable: boolean = true

Specifies whether the cell is connectable. Default is true.

edge: boolean = false

Specifies whether the cell is an edge. Default is false.

edges: Cell[] = []

Holds the edges.

geometry: null | Geometry = null

Holds the Geometry. Default is null.

id: null | string = null

Holds the Id. Default is null.

invalidating: boolean = false
mxTransient: string[] = ...

List of members that should not be cloned inside . This field is passed to Utils#clone and is not made persistent in . This is not a convention for all classes, it is only used in this class to mark transient fields since transient modifiers are not supported by the language.

onInit: null | (() => void) = null
overlays: CellOverlay[] = []
parent: null | Cell = null

Reference to the parent cell.

source: null | Cell = null

Reference to the source terminal.

style: CellStyle = {}

Holds the style as a string of the form [(stylename|key=value);]. Default is null.

target: null | Cell = null

Reference to the target terminal.

value: any = null

Holds the user object. Default is null.

vertex: boolean = false

Specifies whether the cell is a vertex. Default is false.

visible: boolean = true

Specifies whether the cell is visible. Default is true.

Methods

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

    Example: The following example extracts all vertices from a given model:

    var filter(cell)
    {
    return model.isVertex(cell);
    }
    var vertices = model.filterDescendants(filter);

    Parameters

    • filter: null | FilterFunction

      JavaScript function that takes an Cell as an argument and returns a boolean.

    Returns Cell[]

  • Returns the specified attribute from the user object if it is an XML node.

    Parameters

    • name: string

      Name of the attribute whose value should be returned.

    • OptionaldefaultValue: any

      Optional default value to use if the attribute has no value.

    Returns any

  • Returns the children of the given cell that are vertices and/or edges depending on the arguments.

    Parameters

    • vertices: boolean = false

      Boolean indicating if child vertices should be returned. Default is false.

    • edges: boolean = false

      Boolean indicating if child edges should be returned. Default is false.

    Returns Cell[]

  • Returns all descendants of the given cell and the cell itself in an array.

    Returns Cell[]

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

    Parameters

    • outgoing: boolean

      Boolean that specifies if the number of outgoing or incoming edges should be returned.

    • ignoredEdge: null | Cell = null

      that represents an edge to be ignored.

    Returns number

  • Returns the number of edges in the edge array.

    Returns number

  • Returns the index of the specified edge in .

    Parameters

    Returns number

  • Returns all distinct edges connected to this cell as a new array of Cell. 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.

    Parameters

    • incoming: boolean = true

      Optional boolean that specifies if incoming edges should be returned. Default is true.

    • outgoing: boolean = true

      Optional boolean that specifies if outgoing edges should be returned. Default is true.

    • includeLoops: boolean = true

      Optional boolean that specifies if loops should be returned. Default is true.

    Returns Cell[]

  • Returns the Id of the cell as a string.

    Returns null | string

  • Returns the index of the specified child in the child array.

    Parameters

    • child: null | Cell

      Child whose index should be returned.

    Returns number

  • Returns the nearest common ancestor for the specified cells to this.

    Parameters

    • cell2: Cell

      that specifies the second cell in the tree.

    Returns null | Cell

  • Returns the source or target terminal.

    Parameters

    • source: boolean = false

      Boolean that specifies if the source terminal should be returned.

    Returns null | Cell

  • Returns the user object of the cell. The user object is stored in .

    Returns any

  • Returns true if the user object is an XML node that contains the given attribute.

    Parameters

    • name: string

      Name nameName of the attribute.

    Returns boolean

  • Inserts the specified child into the child array at the specified index and updates the parent reference of the child. If not childIndex is specified then the child is appended to the child array. Returns the inserted child.

    Parameters

    • child: Cell
    • Optionalindex: number

    Returns null | Cell

  • Inserts the specified edge into the edge array and returns the edge. Will update the respective terminal reference of the edge.

    Parameters

    • edge: Cell

      to be inserted into the edge array.

    • isOutgoing: boolean = false

      Boolean that specifies if the edge is outgoing.

    Returns Cell

  • Returns true if the given parent is an ancestor of the given child. Note returns true if child == parent.

    Parameters

    • child: null | Cell

      that specifies the child.

    Returns boolean

  • Returns true if the cell is collapsed.

    Returns boolean

  • Returns true if the cell is connectable.

    Returns boolean

  • Returns true if the cell is visibile.

    Returns boolean

  • Removes the child at the specified index from the child array and returns the child that was removed. Will remove the parent reference of the child.

    Parameters

    • index: number

    Returns null | Cell

  • Removes the specified edge from the edge array and returns the edge. Will remove the respective terminal reference from the edge.

    Parameters

    • edge: null | Cell
    • isOutgoing: boolean = false

      Boolean that specifies if the edge is outgoing.

    Returns null | Cell

  • Removes the edge from its source or target terminal.

    Parameters

    • isSource: boolean

      Boolean that specifies if the edge should be removed from its source or target terminal.

    Returns void

  • Sets the specified attribute on the user object if it is an XML node.

    Parameters

    • name: string

      Name of the attribute whose value should be set.

    • value: any

      New value of the attribute.

    Returns void

  • Sets the collapsed state.

    Parameters

    • collapsed: boolean

      Boolean that specifies the new collapsed state.

    Returns void

  • Sets the connectable state.

    Parameters

    • connectable: boolean

      Boolean that specifies the new connectable state.

    Returns void

  • Specifies if the cell is an edge. This should only be assigned at construction of the cell and not be changed during its lifecycle.

    Parameters

    • edge: boolean

      Boolean that specifies if the cell is an edge.

    Returns void

  • Sets the Id of the cell to the given string.

    Parameters

    • id: string

    Returns void

  • Sets the source or target terminal and returns the new terminal.

    Parameters

    • terminal: null | Cell

      Cell that represents the new source or target terminal.

    • isSource: boolean

      boolean that specifies if the source or target terminal should be set.

    Returns null | Cell

  • Sets the user object of the cell. The user object is stored in .

    Parameters

    • value: any

    Returns void

  • Specifies if the cell is a vertex. This should only be assigned at construction of the cell and not be changed during its lifecycle.

    Parameters

    • vertex: boolean

      Boolean that specifies if the cell is a vertex.

    Returns void

  • Specifies if the cell is visible.

    Parameters

    • visible: boolean

      Boolean that specifies the new visible state.

    Returns void

  • Changes the user object after an in-place edit and returns the previous value. This implementation replaces the user object with the given value and returns the old user object.

    Parameters

    • newValue: any

    Returns any