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

Source ports and target ports #295

Closed elgransan closed 1 year ago

elgransan commented 1 year ago

Hi, it is possible to set a port as only source and other as only target?

zHaytam commented 1 year ago

Hello,

You can create a custom class and inherit from PortModel, then override CanAttachTo to include whatever logic you need. In your case, a simple bool property IsSource for example can do the job, then the new method could look something like:

public override bool CanAttachTo(PortModel port)
            => base.CanAttachTo(port) && IsSource != port.IsSource;
elgransan commented 1 year ago

Hi thanks it's working perfect using aligments in this way

public override bool CanAttachTo(PortModel port) => Alignment == PortAlignment.Bottom && port.Alignment == PortAlignment.Top;

But I had to remove base method call because I couldn't connect itself, It's the correct way to allow connecting itself?

Thanks!

zHaytam commented 1 year ago

Yes, check out https://github.com/Blazor-Diagrams/Blazor.Diagrams/blob/master/src/Blazor.Diagrams.Core/Models/PortModel.cs#L51

elgransan commented 1 year ago

Perfect thanks a lot!