Coder Social home page Coder Social logo

Comments (9)

ctooley21 avatar ctooley21 commented on May 14, 2024 2

@vaibhav-systango I've just launched version 2.0.0 of this library that exposes a getSmartEdge function instead of factories, check the README.

Looking at how the Floating Edges example was created, I think it's just a case of feeding the output of the example's getEdgeParams function into the getSmartEdge input, but I haven't tested it.

Feeding the output of getEdgeParams into getSmartEdge worked perfect, thanks for the note!

Attached is my working solution below:

import React, { useCallback } from "react";
import { useNodes, BezierEdge, useStore } from "reactflow";
import { getSmartEdge } from "@tisoap/react-flow-smart-edge";
import { getEdgeParams } from "./utils";

const myOptions = {
    // your configuration goes here
    nodePadding: 20,
    gridRatio: 15,
};

export default function SmartEdgeWithButtonLabel(props: any) {
    const { style, markerStart, markerEnd, source, target } = props;

    const sourceNode = useStore(
        useCallback((store) => store.nodeInternals.get(source), [source])
    );
    const targetNode = useStore(
        useCallback((store) => store.nodeInternals.get(target), [target])
    );

    const nodes = useNodes();

    const { sx, sy, tx, ty, sourcePos, targetPos } = getEdgeParams(
        sourceNode,
        targetNode
    );

    const getSmartEdgeResponse = getSmartEdge({
        sourcePosition: sourcePos,
        targetPosition: targetPos,
        sourceX: sx,
        sourceY: sy,
        targetX: tx,
        targetY: ty,
        nodes,
        // Pass down options in the getSmartEdge object
        options: myOptions,
    });

    // If the value returned is null, it means "getSmartEdge" was unable to find
    // a valid path, and you should do something else instead
    if (getSmartEdgeResponse === null) {
        return <BezierEdge {...props} />;
    }

    const { svgPathString } = getSmartEdgeResponse;

    return (
        <>
            <path
                style={style}
                className="react-flow__edge-path"
                d={svgPathString}
                markerEnd={markerEnd}
                markerStart={markerStart}
            />
        </>
    );
}

from react-flow-smart-edge.

tisoap avatar tisoap commented on May 14, 2024 1

@vaibhav-systango I've just launched version 2.0.0 of this library that exposes a getSmartEdge function instead of factories, check the README.

Looking at how the Floating Edges example was created, I think it's just a case of feeding the output of the example's getEdgeParams function into the getSmartEdge input, but I haven't tested it.

from react-flow-smart-edge.

tisoap avatar tisoap commented on May 14, 2024

Hey @AnhHuy02 , could you expand more on the problem you're experiencing? From the screenshot you shared it looks like everything is correct: for the edge at the top of "Strategist" node to connect to the bottom of "generating" node it needs to take this path to avoid intersections. Maybe you meant to connect bottom -> top instead of top -> bottom to create a straight line?

from react-flow-smart-edge.

AnhHuy02 avatar AnhHuy02 commented on May 14, 2024

Yes.
But can you add a Floating Edge from React Flow documentation with Smart Edge feature? It will be cool to see the diagram.
https://reactflow.dev/examples/floating-edges

from react-flow-smart-edge.

tisoap avatar tisoap commented on May 14, 2024

I see, so you'd like to see an "smart" equivalent of of React Flow's floating edge. I'm not sure if it would be possible, but I'll add to the backlog and leave this issue open

from react-flow-smart-edge.

vaibhav-systango avatar vaibhav-systango commented on May 14, 2024

any luck on this @tisoap @AnhHuy02

from react-flow-smart-edge.

tisoap avatar tisoap commented on May 14, 2024

@vaibhav-systango Didn't started working on this yet

from react-flow-smart-edge.

vaibhav-systango avatar vaibhav-systango commented on May 14, 2024

it'll be a great help if we can do this, can you guide me the direction incase you're keeping occupied I can try some approach for this. It'll be the coolest to have smart floating edges feature @tisoap @AnhHuy02

from react-flow-smart-edge.

vaibhav-systango avatar vaibhav-systango commented on May 14, 2024

This doesn't seem to help @tisoap

from react-flow-smart-edge.

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.