How to restrict the node to dropped on another node in Angular Diagram?
Refer to the following code example to understand how to set node constraints in the node defaults method:
public nodeDefaults(obj: NodeModel): NodeModel {
//style property of node is used to change appearance of the node
obj.style = { fill: "#37909A", strokeColor: "#024249" };
//set node constraints as AllowDrop
obj.constraints = NodeConstraints.Default | NodeConstraints.AllowDrop;
obj.annotations[0].margin = { left: 10, right: 10 };
//style property of annotations used to change appearance of the annotation
obj.annotations[0].style = {
color: "white",
fill: "none",
strokeColor: "none"
};
return obj;
}
Refer to the following code example for how to store the node offset values:
public positionChange(args: IDraggingEventArgs) {
if (args.state === "Start") {
this.offsetX = args.newValue.offsetX;
this.offsetY = args.newValue.offsetY;
}
}
Refer to the following code example and sample:
public drop(args: IDropEventArgs) {
//Argument element is used to get the dropped node.
if (args.element instanceof Node) {
//Reset the node offset values with old values
args.element.offsetX = this.offsetX;
args.element.offsetY = this.offsetY;
this.diagram.dataBind();
}
}
Refer to the working sample for additional details and implementation: [Sample]
Conclusion
We hope you enjoyed learning about how to restrict the node to dropped on another node in Angular Diagram.
You can refer to our Angular 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 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 explore 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!