tisoap / react-flow-smart-edge

Custom Edge for React Flow that never intersects with other nodes
https://tisoap.github.io/react-flow-smart-edge/
MIT License
242 stars 26 forks source link

Option to pass only specific nodes that edges should dodge #28

Closed sushantgulati1 closed 2 years ago

sushantgulati1 commented 2 years ago

Hey @tisoap,

Is there a way/hack to make the edges dodge only some specific nodes instead of all nodes? If not, It'll be nice if we could pass node IDs or a filter function in the factory functions.

tisoap commented 2 years ago

Hey @sushantgulati1 ! Currently there is not, this library always uses all nodes for pathfinding, using React Flow's useNodes hook behind the scenes. I'll add this one to the backlog.

Now I'm curious, what's your use case?

sushantgulati1 commented 2 years ago

Thanks, @tisoap!

The edges in my use case are shown conditionally and when I'm showing them I want to highlight some specific nodes (actually more like not highlighting a set of nodes), and I don't really need the pathfinding algorithm to consider the other ones as they are kind of in the backdrop.

tisoap commented 2 years ago

Hey @sushantgulati1 ! I've released a beta version of the library that exposes a getSmartEdge function, that allows for custom edges. This function takes a nodes argument, so you can use useNodes from React Flow but filter the results to your liking before passing them to getSmartEdge, could you test it out?

Available to test using the beta tag. Install with NPM:

npm install @tisoap/react-flow-smart-edge@beta

New documentation can be found here.

sushantgulati1 commented 2 years ago

Thanks, @tisoap 🙏

Works like a charm.

tisoap commented 2 years ago

@sushantgulati1 Version 2.0.0 was published