- Create connector port
- Port alignment
- Port displacement
- Connector port connection
- See also
Contact Support
Create connector port
The creation of connector ports is similar to the creation of node ports. To create connector ports, you need to define a port collection and assign it to the connector’s ports property.
The following code example shows how to create connector port.
var connectors = [
{
id: 'connector1',
sourcePoint: { x: 100, y: 100 },
targetPoint: { x: 300, y: 100 },
ports: [
{
offset: 0.5,
visibility: ej.diagrams.PortVisibility.Visible,
},
],
},
{
id: 'connector2',
sourcePoint: { x: 100, y: 200 },
targetPoint: { x: 300, y: 220 },
type: 'Orthogonal',
ports: [
{
offset: 0.5,
visibility: ej.diagrams.PortVisibility.Visible,
},
],
},
];
// initialize Diagram component
var diagram = new ej.diagrams.Diagram(
{
width: '100%',
height: '600px',
connectors: connectors,
},
'#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/28.2.3/ej2-base/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/28.2.3/ej2-buttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/28.2.3/ej2-popups/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/28.2.3/ej2-splitbuttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/28.2.3/ej2-diagrams/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/28.2.3/ej2-navigations/styles/fabric.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/28.2.3/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>
Port alignment
The port can be aligned before, after, or at the center of the connector by utilizing the alignment
property. By default, the port alignment is set to center.
The following code example shows how to set alignment to the connector port.
var connectors = [
{
id: 'connector1',
sourcePoint: { x: 100, y: 200 },
targetPoint: { x: 300, y: 220 },
type: 'Orthogonal',
ports: [
{
offset: 0.5,
visibility: ej.diagrams.PortVisibility.Visible,
alignment: 'Before',
},
],
},
{
id: 'connector2',
sourcePoint: { x: 320, y: 200 },
targetPoint: { x: 500, y: 220 },
type: 'Orthogonal',
ports: [
{
offset: 0.5,
visibility: ej.diagrams.PortVisibility.Visible,
alignment: 'Center',
},
],
},
{
id: 'connector3',
sourcePoint: { x: 520, y: 200 },
targetPoint: { x: 700, y: 220 },
type: 'Orthogonal',
ports: [
{
offset: 0.5,
visibility: ej.diagrams.PortVisibility.Visible,
alignment: 'After',
},
],
},
];
// initialize Diagram component
var diagram = new ej.diagrams.Diagram(
{
width: '100%',
height: '600px',
connectors: connectors,
},
'#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/28.2.3/ej2-base/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/28.2.3/ej2-buttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/28.2.3/ej2-popups/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/28.2.3/ej2-splitbuttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/28.2.3/ej2-diagrams/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/28.2.3/ej2-navigations/styles/fabric.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/28.2.3/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>
Port displacement
The connector port displacement allows users to adjust the position of ports relative to the connector. By setting displacement offsets, ports can be moved to precise locations along the connector.
The following code example shows how to set displacement to the connector port.
var connectors = [
{
id: 'connector1',
sourcePoint: { x: 100, y: 200 },
targetPoint: { x: 100, y: 320 },
type: 'Orthogonal',
ports: [
{
offset: 0.5,
visibility: ej.diagrams.PortVisibility.Visible,
//Displacement
displacement: { x: 50, y: 0 },
alignment: 'Before',
},
],
},
{
id: 'connector2',
sourcePoint: { x: 300, y: 200 },
targetPoint: { x: 500, y: 220 },
type: 'Orthogonal',
ports: [
{
offset: 0.5,
visibility: ej.diagrams.PortVisibility.Visible,
//Displacement
displacement: { x: 0, y: 50 },
alignment: 'Before',
},
],
},
];
// initialize Diagram component
var diagram = new ej.diagrams.Diagram(
{
width: '100%',
height: '600px',
connectors: connectors,
},
'#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/28.2.3/ej2-base/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/28.2.3/ej2-buttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/28.2.3/ej2-popups/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/28.2.3/ej2-splitbuttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/28.2.3/ej2-diagrams/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/28.2.3/ej2-navigations/styles/fabric.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/28.2.3/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>
NOTE
The displacement will work only if we set alignment as after or before.
Connector port connection
To establish a connection between connectors, connector ports are utilized. For this connection, the sourcePortID
or targetPortID
should be set to the ID of the respective port on the connector.
The following code example explains how to connect connector to the connector port.
var nodes = [
{
// Position of the node
id: 'node1',
offsetX: 250,
offsetY: 250,
// Size of the node
width: 100,
height: 100,
style: { fill: '#6BA5D7', strokeColor: 'white' },
ports: [
{
id: 'nodePort',
offset: { x: 1, y: 0.5 },
visibility: ej.diagrams.PortVisibility.Visible,
},
],
},
];
var connectors = [
{
id: 'connector1',
sourcePoint: { x: 100, y: 100 },
targetPoint: { x: 300, y: 120 },
type: 'Orthogonal',
ports: [
{
id: 'connectorPort',
offset: 0.5,
visibility: ej.diagrams.PortVisibility.Visible,
},
],
},
{
id: 'connector2',
sourceID: 'node1',
//connector id
targetID: 'connector1',
sourcePortID: 'nodePort',
//Connector port id
targetPortID: 'connectorPort',
type: 'Orthogonal',
ports: [
{
offset: 0.5,
visibility: ej.diagrams.PortVisibility.Visible,
},
],
},
];
// initialize Diagram component
var diagram = new ej.diagrams.Diagram(
{
width: '100%',
height: '600px',
nodes: nodes,
connectors: connectors,
},
'#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/28.2.3/ej2-base/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/28.2.3/ej2-buttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/28.2.3/ej2-popups/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/28.2.3/ej2-splitbuttons/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/28.2.3/ej2-diagrams/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/28.2.3/ej2-navigations/styles/fabric.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/28.2.3/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>