Connector Annotations in Angular Diagram Component
29 Aug 202512 minutes to read
Connector annotations are text labels that can be positioned along connector paths to provide descriptive information or context. These annotations offer flexible positioning and styling options to enhance diagram readability and communication.
Annotations on connectors can be precisely positioned and customized using the following properties of the Annotation class:
- Offset - Controls position along the connector path (0 to 1)
- Alignment - Aligns annotation relative to connector segments
- Displacement - Moves annotation away from its calculated position
- SegmentAngle - Rotates annotation based on connector direction
- HorizontalAlignment - Controls horizontal positioning
- VerticalAlignment - Controls vertical positioning
- Margin - Adds spacing around the annotation
Annotation offset
The offset
property for pathAnnotation
accepts a number value ranging from 0 to 1, representing the position along the connector path from source to target point. An offset value of 0 positions the annotation at the source point, while 1 positions it at the target point. The default offset value is 0.5, which centers the annotation on the connector.
The following code example demonstrates how to configure the offset for connector annotations:
import { Component, ViewEncapsulation, ViewChild } from '@angular/core';
import { DiagramModule, DiagramComponent, PointModel } from '@syncfusion/ej2-angular-diagrams';
@Component({
imports: [
DiagramModule
],
providers: [ ],
standalone: true,
selector: "app-container",
template: `<ejs-diagram #diagram id="diagram" width="100%" height="580px" >
<e-connectors>
<e-connector id='connector' [sourcePoint]='sourcePoint1' [targetPoint]='targetPoint1'>
<e-connector-annotations>
<e-connector-annotation content='Annotation' offset='0.2'>
</e-connector-annotation>
</e-connector-annotations>
</e-connector>
</e-connectors>
</ejs-diagram>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
@ViewChild("diagram")
public diagram?: DiagramComponent;
public sourcePoint1?: PointModel;
public targetPoint1?: PointModel;
ngOnInit(): void {
this.sourcePoint1 = { x: 300, y: 100 };
this.targetPoint1 = { x: 400, y: 200 };
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
The following image illustrates annotation positioning at different offset values along the connector path:
Annotation alignment
Connector annotations can be aligned relative to their segment path using the alignment
property. This property offers three alignment options:
- Before - Positions the annotation before the calculated offset point
- Center - Centers the annotation at the offset point (default)
- After - Positions the annotation after the calculated offset point
The following code example demonstrates how to configure alignment for connector annotations:
import { Component, ViewEncapsulation, ViewChild } from '@angular/core';
import { DiagramModule, DiagramComponent, NodeModel, DecoratorModel } from '@syncfusion/ej2-angular-diagrams';
@Component({
imports: [
DiagramModule
],
providers: [ ],
standalone: true,
selector: "app-container",
template: `<ejs-diagram #diagram id="diagram" width="100%" height="580px" [getNodeDefaults] ='getNodeDefaults'>
<e-nodes>
<e-node id='node1' [offsetX]=150 [offsetY]=150>
<e-node-annotations>
<e-node-annotation id="label1" content="Task1">
</e-node-annotation>
</e-node-annotations>
</e-node>
<e-node id='node2' [offsetX]=350 [offsetY]=150>
<e-node-annotations>
<e-node-annotation id="label1" content="Task2">
</e-node-annotation>
</e-node-annotations>
</e-node>
</e-nodes>
<e-connectors>
<e-connector id='connector' type='Orthogonal' sourceID='node1' targetID='node2' [targetDecorator]='shape'>
<e-connector-annotations>
<e-connector-annotation content='0' [offset]=0 alignment='Before'>
</e-connector-annotation>
<e-connector-annotation content='1' [offset]=1 alignment='After'>
</e-connector-annotation>
</e-connector-annotations>
</e-connector>
</e-connectors>
</ejs-diagram>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
@ViewChild("diagram")
public diagram?: DiagramComponent;
public shape?: DecoratorModel;
public getNodeDefaults(node: NodeModel): NodeModel {
node.height = 100;
node.width = 100;
return node;
}
ngOnInit(): void {
this.shape = { shape: 'None' }
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Displacement of annotation
The displacement
property allows annotations to be moved away from their calculated position by a specified distance. This feature is particularly useful for avoiding overlaps with connector paths or improving visual clarity.
The following example shows how to apply displacement to connector annotations:
import { Component, ViewEncapsulation, ViewChild } from '@angular/core';
import { DiagramModule, DiagramComponent, ConnectorModel, PointModel } from '@syncfusion/ej2-angular-diagrams';
@Component({
imports: [
DiagramModule
],
providers: [ ],
standalone: true,
selector: "app-container",
template: `<ejs-diagram #diagram id="diagram" width="100%" height="580px">
<e-connectors>
<e-connector id='connector' type='Straight' [sourcePoint]='sourcePoint' [targetPoint]='targetPoint'>
<e-connector-annotations>
<e-connector-annotation content='annotation' alignment='After' [displacement]='displacement'>
</e-connector-annotation>
</e-connector-annotations>
</e-connector>
</e-connectors>
</ejs-diagram>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
@ViewChild("diagram")
public diagram?: DiagramComponent;
public sourcePoint?: PointModel;
public targetPoint?: PointModel;
public displacement?: PointModel;
ngOnInit(): void {
this.sourcePoint = { x: 100, y: 100 };
this.targetPoint = { x: 400, y: 100 };
this.displacement = { x: 50, y: 50 }
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
NOTE
Displacement functionality is only applicable when the alignment property is set to
Before
orAfter
. Center-aligned annotations do not support displacement.
Segment angle for annotation
The segmentAngle
property controls whether annotations rotate to match the connector segment direction. When set to true
, annotations automatically rotate based on the angle of the connector segment they are positioned on, creating a more integrated visual appearance. When set to false
(default), annotations maintain their original orientation regardless of connector direction.
The following code example demonstrates how to configure segment angle rotation:
import { Component, ViewEncapsulation, ViewChild } from '@angular/core';
import { DiagramModule, DiagramComponent, PointModel } from '@syncfusion/ej2-angular-diagrams';
@Component({
imports: [
DiagramModule
],
providers: [ ],
standalone: true,
selector: "app-container",
template: `<ejs-diagram #diagram id="diagram" width="100%" height="580px">
<e-connectors>
<e-connector id='connector' type='Straight' [sourcePoint]='sourcePoint' [targetPoint]='targetPoint'>
<e-connector-annotations>
<e-connector-annotation content='annotation' segmentAngle='true'>
</e-connector-annotation>
</e-connector-annotations>
</e-connector>
</e-connectors>
</ejs-diagram>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
@ViewChild("diagram")
public diagram?: DiagramComponent;
public sourcePoint?: PointModel;
public targetPoint?: PointModel;
ngOnInit(): void {
this.sourcePoint = { x: 100, y: 100 };
this.targetPoint = { x: 200, y: 200 };
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
The following table illustrates the visual difference between segment angle settings:
Segment angle | Output |
---|---|
True | ![]() |
False | ![]() |