How to Add Phase at Runtime Using Context-menu in Vue Diagram?
This article explains how to add a phase at runtime using the context menu in Vue Diagram. In Syncfusion® Vue 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 a phase using the context menu, you can use the addPhases method. In the addPhases method, you pass the selected swimlane and new phase data as arguments.
In the following code, we demonstrate how to add a phase using the context menu:
contextMenuClick: (args) => {
if ((args.item.id === 'InsertPhaseBefore' || args.item.id === 'InsertPhaseAfter') &&
diagramInstance.selectedItems.nodes[0].isPhase) {
// The currently selected phase
let node = diagramInstance.selectedItems.nodes[0];
let swimlane = diagramInstance.getObject(diagramInstance.selectedItems.nodes[0].parentId);
let shape = swimlane.shape;
let existingPhase = shape.phases[node.columnIndex];
// Create a new phase object to be added
let newPhase = {
id: randomId(),
offset: existingPhase.offset,
header: {
style: existingPhase.header.style,
},
style: existingPhase.style,
};
// To add a phase before the existing phase
if (args.item.id === 'InsertPhaseBefore') {
newPhase.offset = newPhase.offset - newPhase.offset / 2;
diagramInstance.addPhases(swimlane, [newPhase]);
} else {
// To add a phase after the existing phase
newPhase.offset = newPhase.offset + newPhase.offset / 2;
if (newPhase.offset >= swimlane.width) {
newPhase.offset = existingPhase.offset - 50;
}
diagramInstance.addPhases(swimlane, [newPhase]);
}
diagramInstance.clearSelection();
}
}
};
Refer to the working sample for additional details and implementation: Click here for sample
Conclusion
We hope you enjoyed learning about how to add a phase at runtime using the context menu in Vue Diagram.
You can refer to our Vue Diagram feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications. You can also explore our Vue 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 explore our other controls.
f 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!