Annotation Interactions
Diagram allows annotation to be interacted by selecting, dragging, rotating, and resizing. Annotation interaction is disabled, by default. You can enable annotation interaction with the constraints
property of annotation. You can also curtail the services of interaction by enabling either selecting, dragging, rotating, or resizing individually with the respective constraints property of annotation. The following code illustrates how to enable interactive mode.
import { Component, ViewEncapsulation, ViewChild } from '@angular/core';
import { DiagramModule, DiagramComponent, AnnotationConstraints } 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-nodes>
<e-node id='node1' [offsetX]=150 [offsetY]=150 [width]=100 [height]=100>
<e-node-annotations>
<e-node-annotation id="label1" content="Annotation Text" [constraints]="constraints">
</e-node-annotation>
</e-node-annotations>
</e-node>
</e-nodes>
</ejs-diagram>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
@ViewChild("diagram")
public diagram?: DiagramComponent;
public constraints?: AnnotationConstraints;
ngOnInit(): void {
this.constraints = AnnotationConstraints.Interaction
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Constraints
The constraints
property of annotation allows you to enable/disable certain annotation behaviors.
Annotation rotation
The rotationReference
property of an annotation allows you to control whether the text should rotate relative to its parent node or the Page. The following code examples illustrate how to configure rotationReference for an annotation.
import { Component, ViewEncapsulation, ViewChild } from '@angular/core';
import { DiagramModule, DiagramComponent } 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-nodes>
<e-node id='node1' [offsetX]=150 [offsetY]=150 [width]=100 [height]=100>
<e-node-annotations>
<e-node-annotation content="Annotation" rotationReference='Page'>
</e-node-annotation>
</e-node-annotations>
</e-node>
</e-nodes>
</ejs-diagram>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
@ViewChild("diagram")
public diagram?: DiagramComponent;
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Value | Description | Image |
---|---|---|
Page | When this option is set, the annotation remains fixed in its original orientation even if its parent node is rotated. | ![]() |
Parent | In this case, the annotation rotates along with its parent node. | ![]() |
Read-only annotations
Diagram allows to create read-only annotations. You have to set the read-only constraints to the annotation’s constraints
property. The following code illustrates how to enable read-only mode.
import { Component, ViewEncapsulation, ViewChild } from '@angular/core';
import { DiagramModule, DiagramComponent, AnnotationConstraints } 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-nodes>
<e-node id='node1' [offsetX]=150 [offsetY]=150 [width]=100 [height]=100>
<e-node-annotations>
<e-node-annotation id="label1" content="Annotation Text" [constraints]="constraints">
</e-node-annotation>
</e-node-annotations>
</e-node>
</e-nodes>
</ejs-diagram>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
@ViewChild("diagram")
public diagram?: DiagramComponent;
public constraints?: AnnotationConstraints;
ngOnInit(): void {
this.constraints = AnnotationConstraints.ReadOnly
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Edit
Diagram provides support to edit an annotation at runtime, either programmatically or interactively. By default, annotation is in view mode. But it can be brought to edit mode in two ways;
Programmatically
By using startTextEdit
method, edit the text through programmatically.
import { Component, ViewEncapsulation, ViewChild } from '@angular/core';
import { DiagramModule, DiagramComponent, Diagram } from '@syncfusion/ej2-angular-diagrams';
@Component({
imports: [
DiagramModule
],
providers: [ ],
standalone: true,
selector: "app-container",
template: `
<div class="button">
<button id="textEdit" (click)='onClick($event)'>Start Text Edit</button>
</div>
<ejs-diagram #diagram id="diagram" width="100%" height="580px">
<e-nodes>
<e-node id='node1' [offsetX]=150 [offsetY]=150 [width]=100 [height]=100>
<e-node-annotations>
<e-node-annotation id="label1" content="Annotation Text">
</e-node-annotation>
</e-node-annotations>
</e-node>
</e-nodes>
</ejs-diagram>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
@ViewChild("diagram")
public diagram?: DiagramComponent;
onClick = (args: MouseEvent) => {
//Pass the node which you want to edit
(this.diagram as Diagram).startTextEdit((this.diagram as Diagram).nodes[0]);
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Interactively
1. By double-clicking the annotation.
2. By selecting the item and pressing the F2 key.
Double-clicking any annotation will enables editing mode. When the focus of editor is lost, the annotation for the node is updated. When you double-click on the node/connector/diagram model, the doubleClick
event gets triggered.
Drag Limit
-
The diagram control now supports defining the
dragLimit
to the label while dragging from the connector and also update the position to the nearest segment offset. -
You can set the value to dragLimit
left
,right
,top
, andbottom
properties which allow the dragging of connector labels to a certain limit based on the user defined values. -
By default, drag limit will be disabled for the connector. It can be enabled by setting connector constraints as drag.
-
The following code illustrates how to set a dragLimit for connector annotations.
import { Component, ViewEncapsulation, ViewChild } from '@angular/core';
import { DiagramModule, DiagramComponent, AnnotationConstraints, MarginModel } 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='Orthogonal' [sourcePoint]='{ x: 300, y: 100 }' [targetPoint]='{ x: 400, y: 300 }'>
<e-connector-annotations>
<e-connector-annotation content='connector' [constraints]="constraints" [dragLimit]="dragLimit">
</e-connector-annotation>
</e-connector-annotations>
</e-connector>
</e-connectors>
</ejs-diagram>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
@ViewChild("diagram")
public diagram?: DiagramComponent;
public constraints?: AnnotationConstraints;
public dragLimit?: MarginModel;
ngOnInit(): void {
//Enables drag constraints for a connector.
this.constraints = AnnotationConstraints.Interaction | AnnotationConstraints.Drag;
//Set drag limit for a connector annotation.
this.dragLimit = {left:20,right:20,top:20,bottom:20};
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Multiple annotations
You can add any number of annotations to a node or connector. The following code illustrates how to add multiple annotations to a node and connector.
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-nodes>
<e-node id='node1' [offsetX]=150 [offsetY]=150 [width]=100 [height]=100>
<e-node-annotations>
<e-node-annotation id="label1" content="Left" [offset]="offset1">
</e-node-annotation>
<e-node-annotation id="label2" content="Center" [offset]="offset2">
</e-node-annotation>
<e-node-annotation id="label3" content="Right" [offset]="offset3">
</e-node-annotation>
</e-node-annotations>
</e-node>
</e-nodes>
<e-connectors>
<e-connector id='connector' type='Orthogonal' [sourcePoint]='{ x: 300, y: 100 }' [targetPoint]='{ x: 400, y: 300 }'>
<e-connector-annotations>
<e-connector-annotation content='connector Top' [offset]='0.2'>
</e-connector-annotation>
<e-connector-annotation content='connector Center' [offset]='0.6'>
</e-connector-annotation>
<e-connector-annotation content='connector Bottom' [offset]='0.8'>
</e-connector-annotation>
</e-connector-annotations>
</e-connector>
</e-connectors>
</ejs-diagram>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
@ViewChild("diagram")
public diagram?: DiagramComponent;
public offset1?: PointModel;
public offset2?: PointModel;
public offset3?: PointModel;
ngOnInit(): void {
this.offset1 = { x: 0.12, y: 0.1}
this.offset2 = { x: 0.5, y: 0.5}
this.offset3 = { x: 0.82, y: 0.9}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));