Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a Smart equivalent to React Flow's Floating Edge #13

Open
AnhHuy02 opened this issue Mar 6, 2022 · 9 comments
Open

Create a Smart equivalent to React Flow's Floating Edge #13

AnhHuy02 opened this issue Mar 6, 2022 · 9 comments
Labels
enhancement New feature or request pinned This should not be closed by bots on inactivity
Projects

Comments

@AnhHuy02
Copy link

AnhHuy02 commented Mar 6, 2022

There is a case that two adjacent nodes are not showing a straight edge. Instead it just move around and connect behind the node.
image

@tisoap
Copy link
Owner

tisoap commented Mar 7, 2022

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?

@AnhHuy02
Copy link
Author

AnhHuy02 commented Mar 8, 2022

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

@tisoap
Copy link
Owner

tisoap commented Mar 9, 2022

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

@tisoap tisoap added the enhancement New feature or request label Mar 9, 2022
@tisoap tisoap changed the title Smart egde somehow not smart Create a Smart equivalent to React Flow's Floating Edge Apr 3, 2022
@tisoap tisoap added the pinned This should not be closed by bots on inactivity label May 16, 2022
@vaibhav-systango
Copy link

any luck on this @tisoap @AnhHuy02

@tisoap
Copy link
Owner

tisoap commented Jun 10, 2022

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

@tisoap tisoap added this to New in Kanban Jun 10, 2022
@vaibhav-systango
Copy link

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

@tisoap
Copy link
Owner

tisoap commented Jun 12, 2022

@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.

@vaibhav-systango
Copy link

This doesn't seem to help @tisoap

@ctooley21
Copy link

@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}
            />
        </>
    );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pinned This should not be closed by bots on inactivity
Projects
No open projects
Kanban
  
To Do
Development

No branches or pull requests

4 participants