question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Connecting from a Position.Left to a Position.Right Handle creates an unexpected Edge shape

See original GitHub issue

Context

Setup uses:

  • a canvas with connectionMode={ConnectionMode.Loose}
  • custom nodes with Handles on each side, all set as type="source"
  • custom edges using a smooth step path

Observed behaviour

When connecting top -> bottom, left -> right or bottom -> top edges are drawn as expected with arrows pointing to the destination node.

image

When connecting from left to right, the edge shape starts and ends parallel to the node edge and leaves the arrow head pointing perpendicular to the destination node

image Peek 2021-10-25 16-39

Expected behaviour

The path should connect to the node at 90deg, similarly to how it does in other directions

Minimal reproduction environment

https://codesandbox.io/s/falling-frost-i767n

Minimal reproduction code in case Codesandbox is deleted
import * as React from "react";
import ReactFlow, {
  ReactFlowProvider,
  ConnectionMode,
  Background,
  addEdge,
  getMarkerEnd,
  ArrowHeadType,
  getSmoothStepPath,
  Position,
  Handle
} from "react-flow-renderer";

//-------------- custom edge --------------

export function CustomEdge({ id, ...props }) {
  const edgePath = getSmoothStepPath({ ...props });
  const markerEnd = getMarkerEnd(ArrowHeadType.ArrowClosed);

  return (
    <path
      id={id}
      d={edgePath}
      markerEnd={markerEnd}
      fill="none"
      stroke="black"
    />
  );
}

// -------------- / --------------

// -------------- custom node --------------

export function CustomNode({ ...props }) {
  return (
    <div
      {...props}
      style={{ width: "200px", height: "100px", border: "1px solid black" }}
    >
      <Handle id="1" type="source" position={Position.Left} />
      <Handle id="2" type="source" position={Position.Top} />
      <Handle id="3" type="source" position={Position.Right} />
      <Handle id="4" type="source" position={Position.Bottom} />
    </div>
  );
}

// -------------- / --------------

export default function App() {
  const edgeTypes = {
    editable: CustomEdge
  };

  const nodeTypes = {
    custom: CustomNode
  };

  const [elements, setElements] = React.useState([
    { id: "1", position: { x: 100, y: 200 }, data: {}, type: "custom" },
    { id: "2", position: { x: 400, y: 300 }, data: {}, type: "custom" },
    { id: "3", position: { x: 700, y: 400 }, data: {}, type: "custom" },
    { id: "4", position: { x: 1000, y: 500 }, data: {}, type: "custom" }
  ]);

  const onConnect = (edge) =>
    setElements((els) => addEdge({ ...edge, type: "editable" }, els));

  return (
    <div style={{ width: "100%", height: "100vh" }}>
      <ReactFlowProvider>
        <ReactFlow
          nodesConnectable
          edgeTypes={edgeTypes}
          nodeTypes={nodeTypes}
          connectionMode={ConnectionMode.Loose}
          elements={elements}
          onConnect={onConnect}
        >
          <Background />
        </ReactFlow>
      </ReactFlowProvider>
    </div>
  );
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Vazerthoncommented, Oct 29, 2021

Edit: This behaviour happens when connecting from a Position.Left to a Position.Right Handle, not the other way round as I originally wrote

0reactions
Vazerthoncommented, Nov 1, 2021

Thank you so much for the fast turnaround @moklick! Amazing work!

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the difference between position and offset in Konva
Position of a rectangle shape defines its top-left point. ... If you are not using offset you have to recalculate position of it't...
Read more >
Right-to-left Styling - RTL Styling 101
An extensive guide on how to style for RTL in CSS.
Read more >
Advanced layouts with absolute and fixed positioning
The positions of each edge of an absolutely positioned element can be specified with the top , right , bottom and left properties....
Read more >
Align button image to right edge of UIButton - Stack Overflow
Semantic: Force Right-to-Left on View works for me enter image description here.
Read more >
8 Tips for Clean Topology in Blender (Updated for 2021)
If you need to slide an edge into place while keeping it along the same ... Connecting vertices is a common way to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found