export function getPathDescription()

in src/helpers/edge-helpers.js [190:237]


export function getPathDescription(
  edge: any,
  sourceNode: ITargetPosition | null,
  targetNode: ITargetPosition,
  nodeKey: string,
  nodeSize: number,
  viewWrapperElem: React.RefObject<HTMLDivElement>
) {
  const trgX = targetNode && targetNode.x ? targetNode.x : 0;
  const trgY = targetNode && targetNode.y ? targetNode.y : 0;
  const srcX = sourceNode && sourceNode.x ? sourceNode.x : 0;
  const srcY = sourceNode && sourceNode.y ? sourceNode.y : 0;

  // To calculate the offset for a specific node we use that node as the third parameter
  // and the accompanying node as the second parameter, representing where the line
  // comes from and where it's going to. Don't think of a line as a one-way arrow, but rather
  // a connection between two points. In this case, to obtain the offsets for the src we
  // write trg first, then src second. Vice versa to get the offsets for trg.
  const srcOff = calculateOffset(
    nodeSize || 0,
    targetNode,
    sourceNode,
    nodeKey,
    false,
    viewWrapperElem
  );
  const trgOff = calculateOffset(
    nodeSize || 0,
    sourceNode,
    targetNode,
    nodeKey,
    true,
    viewWrapperElem
  );

  const linePoints = [
    {
      x: srcX - srcOff.xOff,
      y: srcY - srcOff.yOff,
    },
    {
      x: trgX - trgOff.xOff,
      y: trgY - trgOff.yOff,
    },
  ];

  return getLine(linePoints);
}