Giter VIP home page Giter VIP logo

Comments (3)

moklick avatar moklick commented on August 13, 2024

Hey @natsu-k

that's some crazy nodes :) Thanks for the feedback. We will check that.

from react-flow.

natsu-k avatar natsu-k commented on August 13, 2024

Thanks for getting back to me @moklick

I just threw that together super quickly to demonstrate what I noticed occurring. I've been really inspired by this library. I've been using it and your example on custom nodes along with a background API to create a version of this that lets you build your node graph within the react app itself and then save it back to json. Things like being able to change text and colour of the nodes, and toggle the 4 handles between "off, source, and target".

I was looking a bit closer at the code behind the bezier curve tonight to see why the output was generating like so.

https://github.com/wbkd/react-flow/blob/39b6106f6f0b08fbe9eaa17a0f62de5c27509f8a/src/components/Edges/BezierEdge.tsx#L28-L33

I noticed the condition:

else if (leftAndRight.includes(sourcePosition) || leftAndRight.includes(targetPosition))

So if either the source or target position (but not both, as that is caught in the previous if statement) are left or right, then generate a bezier curve with both of the centre control points placed at the same location ${sourceX},${targetY}. This would only generate a correct looking curve for half of the possible configurations.

SOURCE position TARGET position Curve
LEFT TOP inverted
LEFT BOTTOM inverted
RIGHT TOP inverted
RIGHT BOTTOM inverted
TOP LEFT correct
TOP RIGHT correct
BOTTOM LEFT correct
BOTTOM RIGHT correct

So it looks like you might be able to resolve it by adding in an extra condition and adjusting the original on Line 31:

    } else if (!(leftAndRight.includes(sourcePosition)) && leftAndRight.includes(targetPosition)) {
      dAttr = `M${sourceX},${sourceY} C${sourceX},${targetY} ${sourceX},${targetY} ${targetX},${targetY}`;
    } else if (leftAndRight.includes(sourcePosition) && !(leftAndRight.includes(targetPosition))) {
      dAttr = `M${sourceX},${sourceY} C${targetX},${sourceY} ${targetX},${sourceY} ${targetX},${targetY}`;
    }

There might be a better way of writing this code, but I just wanted to contribute what I have figured out so far.

from react-flow.

moklick avatar moklick commented on August 13, 2024

Thanks for your input! We just released a v3.0.0 (because we had a breaking change regarding custom nodes). The nodes now should be connected correctly: https://react-flow.netlify.app/horizontal

from react-flow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.