Create link only from port 'Out'
Sorry for bad english, i want to disallow links to be created by 'In' port, bidirectional links didn't fit in my diagram, i want a way to create a one way directional links .
you can probably do this with a custom port model. See this line for details on how to implement it yourself:
https://github.com/projectstorm/react-diagrams/blob/ed50438744728066c31daafc087c176aa18cc25e/src/models/PortModel.ts#L94
you would basically return true/false to enable or disable linking. You can also control whether a link can be created at all on this line:
https://github.com/projectstorm/react-diagrams/blob/ed50438744728066c31daafc087c176aa18cc25e/src/models/PortModel.ts#L75
^ here you would return null to prevent a link from being created.
This doesn't seem to work for me. When I return null from my PortModel's createLinkModel I get this error:
Uncaught TypeError: Cannot read property 'setSourcePort' of null

I believe this call to link.setSourcePort on line 502 should be moved inside the following IF block:
https://github.com/projectstorm/react-diagrams/blob/a95010652dc16bd47375d7e4715cd02953ea75c2/src/widgets/DiagramWidget.tsx#L501-L504
This doesn't seem to work for me. When I return null from my PortModel's createLinkModel I get this error:
Uncaught TypeError: Cannot read property 'setSourcePort' of null
I believe this call to link.setSourcePort on line 502 should be moved inside the following IF block:
https://github.com/projectstorm/react-diagrams/blob/a95010652dc16bd47375d7e4715cd02953ea75c2/src/widgets/DiagramWidget.tsx#L501-L504
same issue
Same issue!
I've faced the same issue. To solve, you need to create a CustomPortModel (you will need also a <CustomPortWidget /> and a CustomPortFactory as well) and implement the following function:
canLinkToPort = (targetPort: DefaultPortModel) => {
const links = Object.values(this.getLinks() || {});
return (
this.getParent().getID() !== targetPort.getParent().getID() &&
links.length === 1 &&
targetPort.getName() === "in"
);
};
Ps.: you can change the last instruction to match your use case or just assume that all the in ports are called "in".