Constraints in EJ2 JavaScript Diagram control
5 Jul 202424 minutes to read
Constraints are used to enable or disable certain behaviors of the diagram, nodes, and connectors. Constraints are provided as flagged enumerations, so that multiple behaviors can be enabled or disabled using the Bitwise operators (&, | , ~, «, etc.). |
To know more about Bitwise operators, refer to Bitwise Operations
.
Diagram constraints
Diagram constraints
allows you to enable or disable the following behaviors:
The following table displays the list of all diagram constraints.
Constraints | Description |
---|---|
None | Disable all diagram functionalities. |
Bridging | Enables or disables Bridging support for connector in diagram. |
Undo/redo | Enables or disables the Undo/Redo support for the diagram. |
UserInteraction | Enables or disables user interaction support for the diagram. |
ApiUpdate | Enables or disables Api update support for the diagram. |
PageEditable | Enables or disables Page Editable support for the diagram. |
Zoom | Enables or disables Zoom support for the diagram. |
PanX | Enables or disables Panning X coordinate support for the diagram. |
PanY | Enables or disables Panning Y coordinate support for the diagram. |
Pan | Enables or disables panning both X and Y coordinates support for the diagram. |
ZoomTextEdit | Enables or disables zooming the text box while editing the text. |
Tooltip | Enables or disables the tooltip for the diagram. |
Virtualization | Enables or disables Virtualization support for the diagram. |
LineRouting | Enables or disables the line routing. |
Default | Enables or disables all constraints in diagram. |
The following example illustrates how to disable page editing using the diagram constraints.
var diagram = new ej.diagrams.Diagram({
width: '100%', height: 600,
constraints: ej.diagrams.DiagramConstraints.Default & ~ej.diagrams.DiagramConstraints.PageEditable
});
The following example shows how to enable Bridging constraint to the default constraints of diagram.
var diagram = new ej.diagrams.Diagram({
width: '100%', height: 600,
constraints: ej.diagrams.DiagramConstraints.Default | ej.diagrams.DiagramConstraints.Bridging
});
Multiple behaviors can be added or removed from the default constraints using the Bitwise Operations in the diagram.
var diagram = new ej.diagrams.Diagram({
width: '100%', height: 600,
constraints: ej.diagrams.DiagramConstraints.Default & ~(ej.diagrams.DiagramConstraints.PageEditable|ej.diagrams.DiagramConstraints.Zoom);
});
For more information about diagram constraints, refer to DiagramConstraints
.
NOTE
By default, the following constraints are enabled in the diagram,
* Zoom
* ApiUpdate
* PanX
* PanY
* Pan
* Undo/Redo
* PageEditable
* Default
Node constraints
Node constraints allows to enable or disable the following behaviors of node. They are as follows:
Constraints | Description |
---|---|
None | Disable all node Constraints |
Select | Enables or disables the node to be selected. |
Drag | Enables or disables the node to be dragged. |
Rotate | Enables or disables the node to be rotated. |
Shadow | Enables or disables the node to display shadow. |
PointerEvents | Enables or disables the node to provide pointer option. |
Delete | Enables or disables node to be deleted. |
InConnect | Enables or disables node to provide in connect option. |
OutConnect | Enables or disables node to provide out connect option. |
AllowDrop | Enables node to provide allow to drop option. |
Individual | Enables node to provide individual resize option |
ResizeNorthEast | Enable or disable to resize NorthEast side of the node. |
ResizeEast | Enable or disable to resize East side of the node. |
ResizeSouthEast | Enable or disable to resize SouthEast side of the node. |
ResizeSouth | Enable or disable to resize South side of the node. |
ResizeSouthWest | Enable or disable to resize SouthWest side of the node. |
ResizeWest | Enable or disable to resize West side of the node. |
ResizeNorthWest | Enable or disable to resize NorthWest side of the node. |
ResizeNorth | Enable or disable to resize North side of the node. |
AspectRatio | Enables the Aspect ratio of the node. |
ReadOnly | Enables the ReadOnly support for annotation in the node. |
HideThumbs | Enable to hide all resize thumbs for the node. |
Tooltip | Enables or disables tooltip for the Nodes. |
InheritTooltip | Enables or disables inherit tooltip option from the parent object. |
Resize | Enables or Disables the expansion or compression of a node. |
Inherit | Enables the node to inherit the interaction option from the parent object. |
Expandable | Enables node to provide Expandable option |
AllowMovingOutsideLane | Enables or disables child in parent for the swimLane node |
Default | Enables all default constraints for the node. |
The following example illustrates how to disable rotation using the node constraints.
var nodes = [{ id: 'node', offsetX: 100, offsetY: 100, constraints: ej.diagrams.NodeConstraints.Default & ~ej.diagrams.NodeConstraints.Rotate }];
var diagram = new ej.diagrams.Diagram({
width: '100%, height: 600, nodes: nodes,
},'#element');
The following example shows how to add Shadow constraint to the default constraints of node.
var node = { id: 'node', offsetX: 100, offsetY: 100, constraints: ej.diagrams.NodeConstraints.Default | ej.diagrams.NodeConstraints.Shadow };
The following code example shows how the tooltip can be enabled for the node.
//Enabled the tooltip constraints for the node.
var node = { id: 'node', offsetX: 100, offsetY: 100, tooltip:{content:'Node'}, constraints: ej.diagrams.NodeConstraints.Default | ej.diagrams.NodeConstraints.Tooltip };
Multiple behaviors can be added or removed from the default constraints using the Bitwise Operations
.
The following code example shows how to remove rotate and resize constraints from node.
//Removing multiple constraints from default.
var node = { id: 'node', offsetX: 100, offsetY: 100,constraints: ej.diagrams.NodeConstraints.Default &~ (ej.diagrams.NodeConstraints.Rotate | ej.diagrams.NodeConstraints.Resize) };
Refer sample below
ej.diagrams.Diagram.Inject(
ej.diagrams.UndoRedo,
ej.diagrams.DiagramContextMenu
);
var diagram;
var nodes = [
{
id: 'Node1',
offsetX: 100,
offsetY: 100,
annotations: [{ content: 'Select disabled' }],
constraints:
ej.diagrams.NodeConstraints.Default & ~ej.diagrams.NodeConstraints.Select,
},
{
id: 'Node2',
offsetX: 250,
offsetY: 100,
annotations: [{ content: 'Rotate disabled' }],
constraints:
ej.diagrams.NodeConstraints.Default & ~ej.diagrams.NodeConstraints.Rotate,
},
{
id: 'Node3',
offsetX: 400,
offsetY: 100,
annotations: [{ content: 'Resize disabled' }],
constraints:
ej.diagrams.NodeConstraints.Default & ~ej.diagrams.NodeConstraints.Resize,
},
{
id: 'Node4',
offsetX: 550,
offsetY: 100,
annotations: [{ content: 'Drag disabled' }],
constraints:
ej.diagrams.NodeConstraints.Default & ~ej.diagrams.NodeConstraints.Drag,
},
{
id: 'Node5',
offsetX: 700,
offsetY: 100,
annotations: [{ content: 'Tooltip enabled' }],
constraints:
ej.diagrams.NodeConstraints.Default | ej.diagrams.NodeConstraints.Tooltip,
tooltip: { content: 'Node Tooltip', relativeMode: 'Object' },
},
];
//Initialize the diagram
diagram = new ej.diagrams.Diagram({
width: '100%',
height: '645px',
nodes: nodes,
//Sets the default values of a nodes
getNodeDefaults: function (obj) {
obj.width = 100;
obj.height = 100;
obj.shape = { shape: 'Ellipse' };
return obj;
},
});
diagram.appendTo('#element');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Diagram</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-base/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-buttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-popups/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-splitbuttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-diagrams/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-navigations/styles/fabric.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/27.2.2/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
For more information about node constraints, refer to NodeConstraints
.
NOTE
By default, the following constraints are enabled for the node,
* Select
* Drag
* Resize
* Rotate
* InConnect
* OutConnect
* PointerEvents
* ResizeNorthEast
* ResizeEast
* ResizeSouthEast
* ResizeSouth
* ResizeSouthWest
* ResizeWest
* ResizeNorthWest
* ResizeNorth
* Inherit
* Expandable
* Individual
* InheritTooltip
* Default
Connector constraints
Connector constraints allows you to enable or disable certain behaviors of connectors.
Constraints | Description |
---|---|
None | Disable all connector Constraints. |
Select | Enables or disables connector to be selected. |
Delete | Enables or disables connector to be deleted. |
Drag | Enables or disables connector to be dragged. |
DragSourceEnd | Enables connectors source end to be selected. |
DragTargetEnd | Enables connectors target end to be selected. |
DragSegmentThumb | Enables control point and end point of every segment in a connector for editing. |
Interaction | Enables or disables Interaction for the connector. |
AllowDrop | Enables allow drop support to the connector. |
Bridging | Enables bridging to the connector. |
InheritBridging | Enables to inherit bridging option from the parent object. |
BridgeObstacle | Enables or Disables Bridge Obstacles with overlapping of connectors. |
PointerEvents | Enables to set the pointer events. |
ConnectToNearByNode | Enables to connect to the nearest node. |
ConnectToNearByPort | Enables to connect to the nearest port. |
Tooltip | Enables or disables tooltip for the connectors. |
LineRouting | Enables or disables routing to the connector. |
InheritLineRouting | Enables or disables routing to the connector. |
InheritTooltip | Enables or disables inherit tooltip option from the parent object |
ConnectToNearByElement | Enables to connect to the nearest elements. |
InheritSegmentThumbShape | Enables or disables to inherit the value of segmentThumbShape. |
ReadOnly | Enables or disables readonly for the connector. |
Default | Enables all constraints for the connector. |
The following code shows how to disable select constraint from the default constraints of connector.
var connectors = [{
id: 'connector1',
type: 'Straight',
sourcePoint: { x: 100, y: 100 },
targetPoint: { x: 200, y: 200 },
constraints: ej.diagrams.ConnectorConstraints.Default & ~ej.diagrams.ConnectorConstraints.Select
}];
var diagram = new ej.diagrams.Diagram({
width: '100%', height: 600, connectors: connectors,
},'#element');
The following example shows how to add Bridging constraint to the default constraints of connector.
var connector = {
id: 'connector1',
type: 'Straight',
sourcePoint: { x: 100, y: 100 },
targetPoint: { x: 200, y: 200 },
constraints: ej.diagrams.ConnectorConstraints.Default | ej.diagrams.ConnectorConstraints.Bridging
};
NOTE
To visualize connector bridging, we need to inject ConnectorBridgin module.
The following code example shows how the tooltip can be enabled for the connector.
var connector = {
id: 'connector1',
type: 'Straight',
sourcePoint: { x: 100, y: 100 },
targetPoint: { x: 200, y: 200 },
tooltip:{content:'Connector'},
constraints: ej.diagrams.ConnectorConstraints.Default | ej.diagrams.ConnectorConstraints.Tooltip
};
The connector constraints are provided as flagged enumerations, so that multiple behaviors can be added or removed from the default constraints using the Bitwise Operations.
//Removing multiple constraints from default.
var connector = {
id: 'connector1',
type: 'Straight',
sourcePoint: { x: 100, y: 100 },
targetPoint: { x: 200, y: 200 },
tooltip:{content:'Connector'},
constraints: ej.diagrams.ConnectorConstraints.Default &~ (ej.diagrams.ConnectorConstraints.DragSourceEnd|ej.diagrams.ConnectorConstraints.DragTargetEnd)
};
Refer sample below
ej.diagrams.Diagram.Inject(ej.diagrams.UndoRedo);
var diagram;
var connectors = [
{
id: 'connector1',
sourcePoint: { x: 100, y: 100 },
targetPoint: { x: 200, y: 200 },
type: 'Orthogonal',
constraints:
ej.diagrams.ConnectorConstraints.Default &
~ej.diagrams.ConnectorConstraints.Select,
annotations: [{ content: 'Select disabled', alignment: 'After' }],
},
{
id: 'connector2',
sourcePoint: { x: 250, y: 100 },
targetPoint: { x: 350, y: 200 },
type: 'Orthogonal',
constraints:
ej.diagrams.ConnectorConstraints.Default &
~ej.diagrams.ConnectorConstraints.Drag,
annotations: [{ content: 'Drag disabled', alignment: 'After' }],
},
{
id: 'connector3',
sourcePoint: { x: 400, y: 100 },
targetPoint: { x: 500, y: 200 },
type: 'Orthogonal',
constraints:
ej.diagrams.ConnectorConstraints.Default &
~ej.diagrams.ConnectorConstraints.DragSourceEnd,
annotations: [{ content: 'Source end disabled', alignment: 'After' }],
},
{
id: 'connector4',
sourcePoint: { x: 550, y: 100 },
targetPoint: { x: 650, y: 200 },
type: 'Orthogonal',
constraints:
ej.diagrams.ConnectorConstraints.Default &
~ej.diagrams.ConnectorConstraints.DragTargetEnd,
annotations: [{ content: 'Target end disabled', alignment: 'After' }],
},
{
id: 'connector5',
sourcePoint: { x: 700, y: 100 },
targetPoint: { x: 800, y: 200 },
type: 'Orthogonal',
constraints:
ej.diagrams.ConnectorConstraints.Default &
~ej.diagrams.ConnectorConstraints.Delete,
annotations: [{ content: 'Delete disabled', alignment: 'After' }],
},
];
//Initialize the diagram
diagram = new ej.diagrams.Diagram({
width: '100%',
height: '645px',
connectors: connectors,
});
diagram.appendTo('#element');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Diagram</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-base/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-buttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-popups/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-splitbuttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-diagrams/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-navigations/styles/fabric.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/27.2.2/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
For more information about connector constraints, refer to ConnectorConstraints
.
NOTE
By default, the following constraints are enabled for the connector,
* Select
* Delete
* Drag
* Interaction
* ConnectToNearByNode
* ConnectToNearByPort
* ConnectToNearByElement
* BridgeObstacle
* InheritBridging
* PointerEvents
* InheritLineRouting
* InheritTooltip
* InheritSegmentThumbShape
* Default
Port constraints
The constraints property of the Port allows you to enable or disable the following behaviors of port.
Constraints | Description |
---|---|
None | Disable all port Constraints. |
Draw | Enables to create the connection when mouse hover on the port. |
Drag | Enables or disables port dragging |
InConnect | Enables or disables to connect only the target end of connector. |
OutConnect | Enables or disables to connect only the source end of connector. |
ToolTip | Enables or disables the Tooltip for the ports. |
InheritTooltip | Enables or disables the Tooltip for the ports. |
Default | Enables all constraints for the port. |
The following code illustrates how to disable creating connections with a port.
var nodes = [
{
id: 'node',
offsetX: 100,
offsetY: 100,
ports: [
{
constraints: ej.diagrams.PortConstraints.None
}
]
}
];
var diagram = new ej.diagrams.Diagram({
width: '100%', height: 600, nodes: nodes,
});
The following code example shows how to modify the port constraints to accept target connection alone.
ports: [
{ //Enable to create target connection alone.
constraints: ej.diagrams.PortConstraints.InConnect
}
]
The port constraints are provided as flagged enumerations, so that multiple behaviors can be added or removed from the default constraints using the Bitwise Operations.
ports: [
{ //Enable to draw connector from port also accepts both in and out connections.
constraints: ej.diagrams.PortConstraints.Default | ej.diagrams.PortConstraints.Draw;
}
]
Refer sample below
var diagram;
var nodes = [
{
id: 'Node1',
offsetX: 200,
offsetY: 200,
annotations: [
{ content: 'tooltip enabled', offset: { x: 0.5, y: 0.1 } },
{ content: 'draw enabled', offset: { x: 0.2, y: 0.5 } },
{ content: 'drg enabled', offset: { x: 0.8, y: 0.5 } },
{ content: 'InConnect disabled', offset: { x: 0.2, y: 0.9 } },
{ content: 'OutConnect disabled', offset: { x: 0.8, y: 0.9 } },
],
ports: [
{
id: 'left',
offset: { x: 0, y: 0.5 },
visibility: ej.diagrams.PortVisibility.Visible,
constraints:
ej.diagrams.PortConstraints.Default |
ej.diagrams.PortConstraints.Draw,
},
{
id: 'right',
offset: { x: 1, y: 0.5 },
visibility: ej.diagrams.PortVisibility.Visible,
constraints:
ej.diagrams.PortConstraints.Default |
ej.diagrams.PortConstraints.Drag,
},
{
id: 'top',
offset: { x: 0.5, y: 0 },
visibility: ej.diagrams.PortVisibility.Visible,
constraints:
ej.diagrams.PortConstraints.Default |
ej.diagrams.PortConstraints.ToolTip,
tooltip: { content: 'Port tooltip' },
},
{
id: 'bottomLeft',
offset: { x: 0.2, y: 1 },
visibility: ej.diagrams.PortVisibility.Visible,
constraints:
ej.diagrams.PortConstraints.Default &
~ej.diagrams.PortConstraints.InConnect,
},
{
id: 'bottomRight',
offset: { x: 0.8, y: 1 },
visibility: ej.diagrams.PortVisibility.Visible,
constraints:
ej.diagrams.PortConstraints.Default &
~ej.diagrams.PortConstraints.OutConnect,
},
],
},
];
//Initialize the diagram
diagram = new ej.diagrams.Diagram({
width: '100%',
height: '645px',
nodes: nodes,
//Sets the default values of a nodes
getNodeDefaults: function (obj) {
obj.width = 300;
obj.height = 200;
return obj;
},
});
diagram.appendTo('#element');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Diagram</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-base/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-buttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-popups/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-splitbuttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-diagrams/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-navigations/styles/fabric.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/27.2.2/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
For more information about port constraints, refer to PortConstraints
.
NOTE
By default, the following constraints are enabled for the port,
* InConnect
* OutConnect
Annotation constraints
The constraints property of the Annotations allows you to enable or disable certain behaviors of annotation.
Constraints | Description |
---|---|
ReadOnly | Enables or disables the ReadOnly Constraints, |
InheritReadOnly | Enables or disables to inherit the ReadOnly option from the parent object. |
Select | Enables or Disable select support for the annotation |
Drag | Enables or Disable drag support for the annotation |
Resize | Enables or Disable resize support for the annotation |
Rotate | Enables or Disable rotate support for the annotation |
Interaction | Enables interaction of annotation |
None | Disables all constraints for the annotation. |
The read-only mode for the annotation is enabled by settings ReadOnly constraints to the annotation.
The following code illustrates how to enable read-only mode for the annotations.
var nodes = [
{
id: 'node',
offsetX: 100,
offsetY: 100,
annotations: [
{
id: 'anotation_1',
content: 'annotation',
constraints: ej.diagrams.AnnotationConstraints.ReadOnly,
}
]
}
];
var diagram = new ej.diagrams.Diagram({
width: '100%', height: 600, nodes: nodes,
});
Interactions such as select, drag, resize, and rotate can be enabled for the annotation as shown below.
annotations: [
{
id: 'anotation_1',
content: 'annotation',
constraints: ej.diagrams.AnnotationConstraints.Select | ej.diagrams.AnnotationConstraints.Drag | ej.diagrams.AnnotationConstraints.Resize |
ej.diagrams.AnnotationConstraints.Rotate,
}
]
Refer sample below
var diagram;
var nodes = [
{
id: 'Node1',
offsetX: 200,
offsetY: 200,
annotations: [
{
content: 'Interaction enabled',
offset: { x: 0.5, y: 0.1 },
constraints: ej.diagrams.AnnotationConstraints.Interaction,
},
{
content: 'ReadOnly enabled',
offset: { x: 0.2, y: 0.5 },
constraints: ej.diagrams.AnnotationConstraints.ReadOnly,
},
{
content: 'Select and drag enabled',
offset: { x: 0.8, y: 0.5 },
constraints:
ej.diagrams.AnnotationConstraints.Select |
ej.diagrams.AnnotationConstraints.Drag,
},
{
content: 'Select and rotate enabled',
offset: { x: 0.5, y: 0.9 },
constraints:
ej.diagrams.AnnotationConstraints.Select |
ej.diagrams.AnnotationConstraints.Rotate,
},
],
},
];
//Initialize the diagram
diagram = new ej.diagrams.Diagram({
width: '100%',
height: '645px',
nodes: nodes,
//Sets the default values of a nodes
getNodeDefaults: function (obj) {
obj.width = 300;
obj.height = 200;
return obj;
},
});
diagram.appendTo('#element');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Diagram</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-base/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-buttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-popups/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-splitbuttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-diagrams/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-navigations/styles/fabric.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/27.2.2/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
For more details about annotation constraints, refer to AnnotationConstraints
.
Selector constraints
Selector visually represents the selected elements with certain editable thumbs. The visibility of the thumbs can be controlled with selector constraints. The part of selector is categorized as follows:
Constraints | Description |
---|---|
None | Hides all the selector elements. |
ConnectorSourceThumb | Shows or hides the source thumb of the connector. |
ConnectorTargetThumb | Shows or hides the target thumb of the connector. |
ResizeSouthEast | Shows or hides the bottom right resize handle of the selector. |
ResizeSouthWest | Shows or hides the bottom left resize handle of the selector. |
ResizeNorthEast | Shows or hides the top right resize handle of the selector. |
ResizeNorthWest | Shows or hides the top left resize handle of the selector. |
ResizeEast | Shows or hides the middle right resize handle of the selector. |
ResizeWest | Shows or hides the middle left resize handle of the selector. |
ResizeSouth | Shows or hides the bottom center resize handle of the selector. |
ResizeNorth | Shows or hides the top center resize handle of the selector. |
Rotate | Shows or hides the rotate handle of the selector. |
UserHandle | Shows or hides the user handles of the selector. |
ToolTip | Shows or hides the default tooltip for the drag, resize, and rotate operation of nodes and connectors. |
ResizeAll | Shows or hides all resize handles of the selector. |
All | Shows all handles of the selector. |
The following code illustrates how to hide rotator.
var diagram = new ej.diagrams.Diagram({
width: '100%', height: 600,
selectedItems: { constraints: ej.diagrams.SelectorConstraints.All & ~ej.diagrams.SelectorConstraints.Rotate}
});
The following code demonstrates how to hide the default tooltip during the drag, resize, and rotate operations on nodes:
var diagram = new ej.diagrams.Diagram({
width: '100%', height: 600,
selectedItems: { constraints: ej.diagrams.SelectorConstraints.All & ~ej.diagrams.SelectorConstraints.ToolTip}
});
The following code example shows how to disable the userhandle functionality for the selected item.
var diagram = new ej.diagrams.Diagram({
width: '100%', height: 600,
selectedItems: { constraints: ej.diagrams.SelectorConstraints.All & ~ej.diagrams.SelectorConstraints.UserHandle}
});
Refer sample below
var diagram;
var nodes = [
{
id: 'Node1',
offsetX: 200,
offsetY: 200,
annotations: [
{ content: 'Resize handle disabled in selector constraints' },
],
},
];
//Initialize the diagram
diagram = new ej.diagrams.Diagram({
width: '100%',
height: '645px',
nodes: nodes,
//Sets the default values of a nodes
getNodeDefaults: function (obj) {
obj.width = 100;
obj.height = 100;
return obj;
},
selectedItems: {
constraints:
ej.diagrams.SelectorConstraints.All &
~ej.diagrams.SelectorConstraints.ResizeAll,
},
});
diagram.appendTo('#element');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Diagram</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-base/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-buttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-popups/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-splitbuttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-diagrams/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-navigations/styles/fabric.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/27.2.2/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
For more information about selector constraints, refer to SelectorConstraints
.
NOTE
By default, the following constraints are enabled for the selected items,
* Rotate
* UserHandel
* ResizeAll
* All
* ToolTip
Snap constraints
Snap constraints control the visibility of gridlines and enable/disable snapping.
The following list of snapping constraints are used to enable or disable certain features of snapping.
Constraints | Description |
---|---|
None | Disable snapping for the nodes/connectors in diagram. |
ShowHorizontalLines | Displays only the horizontal gridlines in diagram. |
ShowVerticalLines | Displays only the Vertical gridlines in diagram. |
ShowLines | Display both Horizontal and Vertical gridlines. |
SnapToHorizontalLines | Enables the object to snap only with horizontal gridlines. |
SnapToVerticalLines | Enables the object to snap only with Vertical gridlines. |
SnapToLines | Enables the object to snap with both horizontal and Vertical gridlines. |
SnapToObject | Enables the object to snap with the other objects in the diagram. |
All | Shows gridlines and enables snapping. |
The following code illustrates how to show only horizontal gridlines.
var diagram = new ej.diagrams.Diagram({
width: '100%', height: 600,
snapSettings: {
constraints: ej.diagrams.SnapConstraints.ShowHorizontalLines
}
});
The snap constraints are provided as flagged enumerations, so that multiple behaviors can be added or removed from the default constraints using the Bitwise Operations.
snapSettings: {
constraints: ej.diagrams.SnapConstraints.ShowHorizontalLines | ej.diagrams.SnapConstraints.ShowVerticalLines
};
Refer sample below
var diagram;
var nodes = [
{
id: 'Node1',
offsetX: 200,
offsetY: 200,
annotations: [{ content: 'Node 1' }],
},
{
id: 'Node2',
offsetX: 400,
offsetY: 200,
annotations: [{ content: 'Node 2' }],
},
];
//Initialize the diagram
diagram = new ej.diagrams.Diagram({
width: '100%',
height: '645px',
nodes: nodes,
//Sets the default values of a nodes
getNodeDefaults: function (obj) {
obj.width = 100;
obj.height = 100;
return obj;
},
//Snap to object and horizontal gridlines disabled
snapSettings: {
constraints:
ej.diagrams.SnapConstraints.All &
~(
ej.diagrams.SnapConstraints.ShowHorizontalLines |
ej.diagrams.SnapConstraints.SnapToObject
),
},
});
diagram.appendTo('#element');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Diagram</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-base/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-buttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-popups/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-splitbuttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-diagrams/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-navigations/styles/fabric.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/27.2.2/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
For more information about snap constraints, refer to SnapConstraints
.
NOTE
By default, the following constraints are enabled for the snap functionality in the diagram,
* ShowLines
* ShowVerticalLines
* ShowHorizontalLines
* SnapToLines
* SnapToHorizontalLines
* SnapToVerticalLines
* SnapToObject
* All
Boundary constraints
Boundary constraints defines a boundary for the diagram inside which the interaction should be done.
The following list of constraints are used to enable or disable certain features of boundary interactions of the diagram.
Constraints | Description |
---|---|
Infinity | Allow the interactions to take place at the infinite height and width. |
Diagram | Allow the interactions to take place around the diagram height and width. |
Page | Allow the interactions to take place around the page height and width. |
The following code illustrates how to limit the interaction done inside a diagram within a page.
var diagram = new ej.diagrams.Diagram({
width: '100%', height: 600,
pageSettings: {
boundaryConstraints: 'Page'
}
});
Refer sample below
var diagram;
var nodes = [
{
id: 'Node1',
offsetX: 200,
offsetY: 200,
width:100,
height:100,
annotations: [{ content: 'Node interactions restricted within page' }],
},
];
//Initialize the diagram
diagram = new ej.diagrams.Diagram({
width: '100%',
height: '645px',
nodes: nodes,
pageSettings: {
// Boundary set as page
boundaryConstraints: 'Page',
width: 500,
height: 500,
showPageBreaks: true,
background: { color: 'grey' },
},
});
diagram.appendTo('#element');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Diagram</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-base/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-buttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-popups/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-splitbuttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-diagrams/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-navigations/styles/fabric.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/27.2.2/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
For more information about selector constraints, refer to BoundaryConstraints
.
Inherit behaviors
Some of the behaviors can be defined through both the specific object (node/connector) and diagram. When the behaviors are contradictorily defined through both, the actual behavior is set through inherit options.
The following code example illustrates how to inherit the line bridging behavior from the diagram model.
ej.diagrams.Diagram.Inject(ej.diagrams.ConnectorBridging);
var connectors = [
{
id: 'connector1',
type: 'Straight',
sourcePoint: { x: 100, y: 100 },
targetPoint: { x: 200, y: 200 },
constraints:
ej.diagrams.ConnectorConstraints.Default |
ej.diagrams.ConnectorConstraints.InheritBridging,
},
{
id: 'connector2',
type: 'Straight',
sourcePoint: { x: 100, y: 200 },
targetPoint: { x: 200, y: 100 },
constraints:
ej.diagrams.ConnectorConstraints.Default |
ej.diagrams.ConnectorConstraints.InheritBridging,
},
];
var diagram = new ej.diagrams.Diagram({
width: '100%',
height: 600,
connectors: connectors,
constraints:
ej.diagrams.DiagramConstraints.Default |
ej.diagrams.DiagramConstraints.Bridging,
});
diagram.appendTo('#element');
Bitwise operations
Bitwise operations are used to manipulate the flagged enumerations enum
.In this section, Bitwise operations are shown by using the node constraints. The same is applicable when working connector constraints, or port constraints.
Add operation
You can add or enable multiple values at a time by using Bitwise ‘ | ’ (OR) operator. |
The following code demonstrates how to add tooltip constraints to the default node constraints, thereby enabling tooltip functionality for the node:
node.constraints = ej.diagrams.NodeConstraints.Default | ej.diagrams.NodeConstraints.Tooltip;
In the previous example, you can perform basic interactions with the node while also enabling tooltip functionality.
Remove Operation
You can remove or disable values by using Bitwise ‘&~’ (XOR) operator.
node.constraints = ej.diagrams.NodeConstraints.Default & ~(ej.diagrams.NodeConstraints.Rotate);
In the previous example, rotation is disabled from the default node constraints.
Check operation
You can check any value by using Bitwise ‘&’ (AND) operator.
if ((node.constraints & (ej.diagrams.NodeConstraints.Rotate)) == (ej.diagrams.NodeConstraints.Rotate));
In the previous example, check whether the rotate constraints are enabled in a node. When node constraints have rotate constraints, the expression returns a rotate constraint.