mxMultiplicity

Defines invalid connections along with the error messages that they produce.  To add or remove rules on a graph, you must add/remove instances of this class to mxGraph.multiplicities.

Example

graph.multiplicities.push(new mxMultiplicity(
  true, 'rectangle', null, null, 0, 2, ['circle'],
  'Only 2 targets allowed',
  'Only circle targets allowed'));

Defines a rule where each rectangle must be connected to no more than 2 circles and no other types of targets are allowed.

Summary
mxMultiplicityDefines invalid connections along with the error messages that they produce.
Functions
mxMultiplicityInstantiate class mxMultiplicity in order to describe allowed connections in a graph.
Variables
typeDefines the type of the source or target terminal.
attrOptional string that specifies the attributename to be passed to mxUtils.isNode to check if the rule applies to a cell.
valueOptional string that specifies the value of the attribute to be passed to mxUtils.isNode to check if the rule applies to a cell.
sourceBoolean that specifies if the rule is applied to the source or target terminal of an edge.
minDefines the minimum number of connections for which this rule applies.
maxDefines the maximum number of connections for which this rule applies.
validNeighborsHolds an array of strings that specify the type of neighbor for which this rule applies.
validNeighborsAllowedBoolean indicating if the list of validNeighbors are those that are allowed for this rule or those that are not allowed for this rule.
countErrorHolds the localized error message to be displayed if the number of connections for which the rule applies is smaller than min or greater than max.
typeErrorHolds the localized error message to be displayed if the type of the neighbor for a connection does not match the rule.
Functions
checkChecks the multiplicity for the given arguments and returns the error for the given connection or null if the multiplicity does not apply.
checkNeighborsChecks if there are any valid neighbours in validNeighbors.
checkTerminalChecks the given terminal cell and returns true if this rule applies.
checkTypeChecks the type of the given value.

Functions

mxMultiplicity

function mxMultiplicity(source,
type,
attr,
value,
min,
max,
validNeighbors,
countError,
typeError,
validNeighborsAllowed)

Instantiate class mxMultiplicity in order to describe allowed connections in a graph.  Not all constraints can be enforced while editing, some must be checked at validation time.  The countError and typeError are treated as resource keys in mxResources.

Parameters

sourceBoolean indicating if this rule applies to the source or target terminal.
typeType of the source or target terminal that this rule applies to.  See type for more information.
attrOptional attribute name to match the source or target terminal.
valueOptional attribute value to match the source or target terminal.
minMinimum number of edges for this rule.  Default is 1.
maxMaximum number of edges for this rule. n means infinite.  Default is n.
validNeighborsArray of types of the opposite terminal for which this rule applies.
countErrorError to be displayed for invalid number of edges.
typeErrorError to be displayed for invalid opposite terminals.
validNeighborsAllowedOptional boolean indicating if the array of opposite types should be valid or invalid.

Variables

type

mxMultiplicity.prototype.type

Defines the type of the source or target terminal.  The type is a string passed to mxUtils.isNode together with the source or target vertex value as the first argument.

attr

mxMultiplicity.prototype.attr

Optional string that specifies the attributename to be passed to mxUtils.isNode to check if the rule applies to a cell.

value

mxMultiplicity.prototype.value

Optional string that specifies the value of the attribute to be passed to mxUtils.isNode to check if the rule applies to a cell.

source

mxMultiplicity.prototype.source

Boolean that specifies if the rule is applied to the source or target terminal of an edge.

min

mxMultiplicity.prototype.min

Defines the minimum number of connections for which this rule applies.  Default is 0.

max

mxMultiplicity.prototype.max

Defines the maximum number of connections for which this rule applies.  A value of ‘n’ means unlimited times.  Default is ‘n’.

validNeighbors

mxMultiplicity.prototype.validNeighbors

Holds an array of strings that specify the type of neighbor for which this rule applies.  The strings are used in <mxCell.is> on the opposite terminal to check if the rule applies to the connection.

validNeighborsAllowed

mxMultiplicity.prototype.validNeighborsAllowed

Boolean indicating if the list of validNeighbors are those that are allowed for this rule or those that are not allowed for this rule.

countError

mxMultiplicity.prototype.countError

Holds the localized error message to be displayed if the number of connections for which the rule applies is smaller than min or greater than max.

typeError

mxMultiplicity.prototype.typeError

Holds the localized error message to be displayed if the type of the neighbor for a connection does not match the rule.

Functions

check

mxMultiplicity.prototype.check = function(graph,
edge,
source,
target,
sourceOut,
targetIn)

Checks the multiplicity for the given arguments and returns the error for the given connection or null if the multiplicity does not apply.

Parameters

graphReference to the enclosing mxGraph instance.
edgemxCell that represents the edge to validate.
sourcemxCell that represents the source terminal.
targetmxCell that represents the target terminal.
sourceOutNumber of outgoing edges from the source terminal.
targetInNumber of incoming edges for the target terminal.

checkNeighbors

mxMultiplicity.prototype.checkNeighbors = function(graph,
edge,
source,
target)

Checks if there are any valid neighbours in validNeighbors.  This is only called if validNeighbors is a non-empty array.

checkTerminal

mxMultiplicity.prototype.checkTerminal = function(graph,
terminal,
edge)

Checks the given terminal cell and returns true if this rule applies.  The given cell is the source or target of the given edge, depending on source.  This implementation uses checkType on the terminal’s value.

checkType

mxMultiplicity.prototype.checkType = function(graph,
value,
type,
attr,
attrValue)

Checks the type of the given value.

function mxMultiplicity(source,
type,
attr,
value,
min,
max,
validNeighbors,
countError,
typeError,
validNeighborsAllowed)
Instantiate class mxMultiplicity in order to describe allowed connections in a graph.
mxMultiplicity.prototype.type
Defines the type of the source or target terminal.
mxMultiplicity.prototype.attr
Optional string that specifies the attributename to be passed to mxUtils.isNode to check if the rule applies to a cell.
isNode: function(value,
nodeName,
attributeName,
attributeValue)
Returns true if the given value is an XML node with the node name and if the optional attribute has the specified value.
mxMultiplicity.prototype.value
Optional string that specifies the value of the attribute to be passed to mxUtils.isNode to check if the rule applies to a cell.
mxMultiplicity.prototype.source
Boolean that specifies if the rule is applied to the source or target terminal of an edge.
mxMultiplicity.prototype.min
Defines the minimum number of connections for which this rule applies.
mxMultiplicity.prototype.max
Defines the maximum number of connections for which this rule applies.
mxMultiplicity.prototype.validNeighbors
Holds an array of strings that specify the type of neighbor for which this rule applies.
mxMultiplicity.prototype.validNeighborsAllowed
Boolean indicating if the list of validNeighbors are those that are allowed for this rule or those that are not allowed for this rule.
mxMultiplicity.prototype.countError
Holds the localized error message to be displayed if the number of connections for which the rule applies is smaller than min or greater than max.
mxMultiplicity.prototype.typeError
Holds the localized error message to be displayed if the type of the neighbor for a connection does not match the rule.
mxMultiplicity.prototype.check = function(graph,
edge,
source,
target,
sourceOut,
targetIn)
Checks the multiplicity for the given arguments and returns the error for the given connection or null if the multiplicity does not apply.
mxMultiplicity.prototype.checkNeighbors = function(graph,
edge,
source,
target)
Checks if there are any valid neighbours in validNeighbors.
mxMultiplicity.prototype.checkTerminal = function(graph,
terminal,
edge)
Checks the given terminal cell and returns true if this rule applies.
mxMultiplicity.prototype.checkType = function(graph,
value,
type,
attr,
attrValue)
Checks the type of the given value.
mxGraph.prototype.multiplicities
An array of mxMultiplicities describing the allowed connections in a graph.
Implements internationalization.
Extends mxEventSource to implement a graph component for the browser.
Cells are the elements of the graph model.
Close