Blazor-Diagrams / Blazor.Diagrams

A fully customizable and extensible all-purpose diagrams library for Blazor
https://blazor-diagrams.zhaytam.com
MIT License
919 stars 176 forks source link

How to get both attached node models from a link information. #342

Closed ATEEKGIT closed 10 months ago

ATEEKGIT commented 10 months ago

My nodes are custom model is holding data inside , when nodes are linked i need to some how know programmatically which node attached to which node , i tried Diagram.Nodes.First().Links and then lost where is next node information is stored.

any idea to identify programmatically , the both nodes models attached to a link as source and target

currently I am trying version 3 and its just excellent , please accept a heartly thanks from my side.

zHaytam commented 10 months ago

If you are connecting links between 2 nodes directly:

var sourceNode = (link.SourceAnchor as ShapeIntersectionAnchor)!.Node;
// OR
var sourceNode = link.SourceAnchor.Model as NodeModel; // or your custom type

If you're using ports:

var sourceNode = (link.SourceAnchor as SinglePortAnchor)!.Port.Parent;
// OR
var sourceNode = (link.SourceAnchor.Model as PortModel)!.Parent; // or your custom type
ATEEKGIT commented 10 months ago

thanks , this worked for me , TaskPort is my custom port.

var targetNode = (link.Target.Model as TaskPort).Parent;