How to Add Phase at Runtime Using Context-menu in Angular Diagram?
In this article, you can learn about how to add a phase at runtime using the context menu in Angular Diagram. In Syncfusion® Angular Diagram, you can dynamically add phases to a diagram at runtime using a context menu. This feature enhances user interaction by allowing users to insert phases directly into the swimlane.
To add phase using context menu, you can use addPhases method. In addPhases method, you pass the selected swimlane and new phase data as arguments
In the following code, demonstrates how to add phase using context menu:
public contextMenuClick(args: MenuEventArgs): void {
if ((args.item.id === 'InsertPhaseBefore' || args.item.id === 'InsertPhaseAfter') &&
(this.diagram.selectedItems.nodes[0] as any).isPhase) {
// The currently selected phase
let node = this.diagram.selectedItems.nodes[0];
let swimlane = this.diagram.getObject((this.diagram.selectedItems.nodes[0] as any).parentId);
let shape = (swimlane as any).shape;
let existingPhase = shape.phases[node.columnIndex];
// The currently selected phase
let newPhase = {
id: randomId(),
offset: (existingPhase as any).offset,
header: { style: (existingPhase as any).header.style },
style: (existingPhase as any).style,
};
//To add phase before existing phase
if (args.item.id === 'InsertPhaseBefore') {
newPhase.offset = newPhase.offset - newPhase.offset / 2;
(this.diagram as Diagram).addPhases(swimlane, [newPhase]);
}
else {
//To add phase after existing phase
newPhase.offset = newPhase.offset + newPhase.offset / 2;
if (newPhase.offset >= (swimlane as any).width) {
newPhase.offset = (existingPhase as any).offset - 50;
}
(this.diagram as Diagram).addPhases(swimlane, [newPhase]);
}
this.diagram.clearSelection();
}
}
You can find a working example of this implementation in the provided sample on StackBlitz.
Sample- Click here for sample
Conclusion
I hope you enjoyed about how to add phase at runtime using context-menu in Angular Diagram.
You can refer to our Angular Diagram feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.
You can also explore our Angular Diagram example to understand how to create and manipulate data. For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, BoldDesk Support, or feedback portal. We are always happy to assist you!