How to create and manage child node and group in Vue Diagram?
This article explains how to create and manage child nodes and groups in Vue Diagram. To create and manage group nodes in a Vue Diagram is a powerful feature that enables you to organize and manipulate related nodes collectively. In this tutorial, we’ll explore how to create a group node, drag it, and restrict the dragging behavior of its child nodes individually.
To create a group node, leverage the children property of the node. Here’s a code sample illustrating the creation of a group node along with its child nodes:
let nodes = [
{
id: "node1",
width: 50,
height: 50,
offsetX: 100,
offsetY: 100,
annotations: [{ content: "Seat1" }]
},
{
id: "node2",
width: 50,
height: 50,
offsetX: 200,
offsetY: 100,
annotations: [{ content: "Seat2" }]
},
{
id: "node3",
width: 50,
height: 50,
offsetX: 100,
offsetY: 200,
annotations: [{ content: "Seat3" }]
},
{
id: "node4",
width: 50,
height: 50,
offsetX: 200,
offsetY: 200,
annotations: [{ content: "Seat4" }]
},
{
id: "group", children: ['node1', 'node2', 'node3', 'node4']
},
];
In this example, you can drag both the parent (group) node and its child nodes. However, there might be scenarios where you want to restrict dragging for child nodes individually. This can be achieved using the SelectionChange event and modifying the constraints of the child nodes accordingly.
Here’s a code snippet demonstrating how to change the constraints of child nodes in the SelectionChange event:
function selectionChange(args: ISelectionChangeEventArgs): void {
let node: NodeModel;
if ((args.newValue[0]) && (args.newValue[0] as NodeModel).children !== undefined) {
const group: NodeModel = (args.newValue[0] as NodeModel);
if (group.children) {
group.constraints=NodeConstraints.Default
for (var i=0;i
Conclusion
We hope you enjoyed learning about how to create and manage child nodes and groups 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 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!