Diagram Connections
The connections in the Kendo UI for Angular Diagram represent relationships between two Shapes (graph nodes). This article describes all Diagram connection customization options and configuration features.
Basics
A connection is a link that shows a relationship between two Diagram Shapes. A connection can also span across points with specific coordinates, with no associated Shapes.
The fundamental settings of the Kendo UI for Angular Diagram connections include:
- The
fromandtoproperties must match the associated Shapeids. You can also define a connection that does not link Shapes by using specific coordinates. UsefromConnectorandtoConnectorto specify which connector point on each shape the connection attaches to. - The connection type determines the connection route and route angles.
- The connection cap
Typedetermines whether the connections appear directed or undirected. - The
Selectableparameter ofConnectionDefaultssets if connections can be selected, which determines the ability to drag or remove them. Textdefines the connection label. Use the Connectioncontentproperty to set the label text and its styling.
Basic connection parameters are defined in the ConnectionOptions interface:
public connections: ConnectionOptions[] = [
{
from: 'start',
to: 'process',
content: {
text: 'Next'
}
}
];
For connections without Shapes, you can define specific coordinates:
public connections: ConnectionOptions[] = [
{
from: { x: 50, y: 100 },
to: { x: 150, y: 200 }
}
];
Use the fromConnector and toConnector properties to control which connector point on a shape the connection attaches to. By default, shapes expose four connectors: top, right, bottom, and left.
public connections: ConnectionOptions[] = [
{
from: 'shapeA',
to: 'shapeB',
fromConnector: 'right',
toConnector: 'left',
},
];
The following example demonstrates basic connection usage, including shape-based connections, coordinate-based connections, and connector targeting with fromConnector and toConnector.
Connection Types
The Diagram supports different connection types that determine the route and angles of the connection line. The default connection type is cascading, which displays connections as rectangular routes with one or more right angles. The polyline connection type displays connections as polylines that connect the related Shapes and all intermediate points. If connection points are not defined, then the connection displays as a straight line.
The following example demonstrates the available connection types.
Type Configuration
You can set a default connection type for all connections using the connectionDefaults property:
public connectionDefaults: ConnectionOptions[] = {
type: 'polyline'
};
Individual connections can override the default setting by specifying their own type:
public connections: ConnectionOptions[] = [
{
from: 'shape1',
to: 'shape2',
type: 'cascading'
}
];
Connection Points
Polyline connections can pass through multiple points at specific coordinates, regardless of whether the connections link Shapes or not.
public connections: ConnectionOptions[] = [
{
type: 'polyline',
from: { x: 20, y: 20 },
to: { x: 200, y: 200 },
points: [
{ x: 150, y: 50 },
{ x: 50, y: 100 },
{ x: 150, y: 150 },
{ x: 100, y: 170 }
]
}
];
The following example demonstrates how to define connection points.
Connection Styling
You can customize the visual appearance of connections through various styling options including caps, colors, fonts, and borders.
Connection Caps
The link between two Diagram Shapes is always defined through the from and to properties. From this point of view, a Diagram connection is always directed. However, you can configure the connections to appear bi-directional or non-directional.
The following example demonstrates the difference between caps and selection handles.
The available cap types include:
ArrowEnd—The cap arrow points away from the connection, towards the Shape.FilledCircle(default)None
You can configure cap types using connectionDefaults to apply settings to all connections:
public connectionDefaults = {
startCap: {
type: 'ArrowEnd'
},
endCap: {
type: 'ArrowEnd'
}
};
For individual connections, specify the cap types directly on the connection:
public connections: ConnectionOptions[] = [
{
from: 'shape1',
to: 'shape2',
startCap: {
type: 'FilledCircle'
},
endCap: {
type: 'FilledCircle'
}
}
];
Note the difference between caps and selection handles:
- The caps are visible when a connection is not selected.
- The selection handles are visible when a connection is selected (clicked).
Styling Options
The following connection styling options are available:
- Text color and font properties for connection content
- Background color (fill) for the connection caps
- Background color (fill) for the default and hover states of the selection handles
- Border (stroke) color, type, and width for the caps and selection handles
The following example demonstrates how to style connections.
Connection Content and Labels
You can add text labels to connections to provide additional information about the relationship they represent. Use the content property to configure the label appearance and position.
The following example demonstrates various label configuration options, including text content, styling, and positioning on both horizontal and vertical connections.
The ConnectionContent interface provides options for configuring:
- Text content and styling (color, font family, size, weight, and style).
- Label positioning relative to the connection line.
- Offset distance between the label and connection path.
- Custom templates for dynamic content rendering.
public connections: ConnectionOptions[] = [
{
from: 'shape1',
to: 'shape2',
content: {
text: 'Reports to',
color: '#666',
fontFamily: 'Arial',
fontSize: 12,
position: {
vertical: 'top',
horizontal: 'right'
}
}
}
];
The position property controls where the label appears:
inline—Positions the label directly on the connection line.vertical—Controls the vertical position relative to horizontal connections (top(default) orbottom).horizontal—Controls the horizontal position relative to vertical connections (right(default) orleft).
Editable Connections
The Diagram connections are editable by default. Users can drag a connection by its start and end cap to link different shapes, or remove selected connections. You can control the editability of connections globally or on an individual basis.
The following example demonstrate editable and non-editable connections.
You can control these operations using connectionDefaults to set the behavior for all connections:
public connectionDefaults = {
editable: {
drag: true,
remove: true
}
};
Individual connections can have different editable settings:
public connections: ConnectionOptions[] = [
{
from: 'shape1',
to: 'shape2',
editable: {
drag: false,
remove: false
}
}
];
Connection dragging and removing requires the connection to be selectable, which is enabled by default.
Defining Shape Connector Points
By default, each shape exposes four connectors named top, right, bottom, and left. Custom connectors are useful when you need to separate multiple connections leaving the same edge, enforce directional flow in layered diagrams, or anchor connections to specific visual regions of a shape. You can replace the defaults by setting the connectors property on individual shapes or on shapeDefaults to apply them to all shapes. Defining custom connectors replaces the defaults, so include every connector your connections need in the array.
The following example demonstrates custom connectors on Diagram shapes. The UI Layer shape uses offset RightTop and RightBottom connectors at 30% and 70% down the right edge to prevent overlapping connections. The remaining shapes use Rect convenience methods to place connectors at standard edge centers.
Each connector requires:
- A unique
nameused to reference the connector inConnectionOptions. - A
positionfunction that receives the parentShapeand returns aPointdefining the connector's location on the diagram canvas.
Use the shape.bounds() method inside the function to calculate positions relative to the shape's current geometry. The method returns a Rect object with the following API:
xandy—The top-left corner coordinates.widthandheight—The shape dimensions.top(),right(),bottom(),left()—Convenience methods that return aPointat each edge center.center()—Returns aPointat the shape center.
import { Point, Shape } from '@progress/kendo-angular-diagrams';
const connectors = [
{
name: 'Right',
// Use the convenience method to get the right-center point directly.
position: (shape: Shape) => shape.bounds().right(),
},
{
name: 'RightTop',
// Place the connector at 30% down the right edge so two connections
// leaving the same side do not overlap.
position: (shape: Shape) => {
const b = shape.bounds();
return new Point(b.x + b.width, b.y + b.height * 0.3);
},
},
{
name: 'RightBottom',
position: (shape: Shape) => {
const b = shape.bounds();
return new Point(b.x + b.width, b.y + b.height * 0.7);
},
},
];
To route connections to and from custom connectors, reference them by name using the fromConnector and toConnector properties of ConnectionOptions:
public connections: ConnectionOptions[] = [
{
from: 'ui',
to: 'logic',
fromConnector: 'RightTop',
toConnector: 'Left',
},
{
from: 'ui',
to: 'data',
fromConnector: 'RightBottom',
toConnector: 'Left',
},
];