projectstorm / react-diagrams

a super simple, no-nonsense diagramming library written in react that just works
https://projectstorm.cloud/react-diagrams
MIT License
8.71k stars 1.18k forks source link

Smart Routing issues #721

Open lieyongchang opened 4 years ago

lieyongchang commented 4 years ago

I am currently using react-diagram version: 6.2.0

error

Steps to reproduce:

  1. click this link to navigate to the demo.
  2. select any port and create a new link

Expected result: new link should be able to smart route Actual result: new link did not smart route

This is the demo I have been using as guide. Any advice to factor in run time smart routing is appreciated

dylanvorster commented 4 years ago

the demo is actually just missing code, will get onto that

vadimshvetsov commented 3 years ago

TLDR; It works like that because by default DefaultLinkModel is used for new link creation.

When you drag from port, engine fires an action: https://github.com/projectstorm/react-diagrams/blob/63dbe41df017db10212e93b22b282c0f3c363b1b/packages/react-diagrams-core/src/states/DragNewLinkState.ts#L48

Then from DefaultPortModel it fires createLinkModel method with creating instance of DefaultLinkModel() https://github.com/projectstorm/react-diagrams/blob/63dbe41df017db10212e93b22b282c0f3c363b1b/packages/react-diagrams-defaults/src/port/DefaultPortModel.ts#L68-L74

You need to extend DefaultPortModel with your own createLinkModel implementation for returning PathFindingLinkModel as default.