How to create and manage child and group dragging in Angular Diagram?
This article explains how to create and manage child and group dragging in Angular Diagram. Creating and managing group nodes in Angular 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:
public nodes: NodeModel[] = [
{
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:
public selectionChange(args: ISelectionChangeEventArgs) {
let node;
if ((args.newValue[0]) && (args.newValue[0] as any).children !== undefined) {
const group = args.newValue[0] as any;
if (group.children) {
group.constraints = NodeConstraints.Default
for (var i = 0; i < group.children.length; i++) {
node = this.diagram.getObject(group.children[i]);
if (node.constraints) {
node.constraints = NodeConstraints.Default;
}
}
}
} else if (!((args.newValue[0] as any).children)) {
(args.newValue[0]).constraints = NodeConstraints.Select | NodeConstraints.Drag;
}
}
By utilizing the SelectionChange event, you can dynamically adjust the constraints of child nodes when the group node is selected, providing a flexible and interactive diagramming experience.
Refer to the working sample for additional details and implementation: Sample
Conclusion
We hope you enjoyed learning about how to restrict child node dragging, whereas allowing group dragging 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 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!