dagrejs / dagre-d3

A D3-based renderer for Dagre
MIT License
2.85k stars 587 forks source link

Edge from one points #372

Closed dimensi closed 5 years ago

dimensi commented 5 years ago

Hi, how to make the edges come out of one point? Like this? image

dimensi commented 5 years ago

Resolve it with custom createEdgePath function.

render.createEdgePaths(createEdgePaths);

function createEdgePaths(selection, g) {
 ....
calcPoints(g, e)
...
}

function calcPoints(g, e) {
  const tail = g.node(e.v);
  const head = g.node(e.w);
  const startPoint = { x: tail.x + (tail.width / 2), y: tail.y }
  const endPoint = { x: head.x - (head.width / 2), y: head.y }
  return diagonal(startPoint, endPoint)
}

function diagonal(start, end) {
  return `M ${start.x} ${start.y}
  C ${(start.x + end.x) / 2} ${start.y},
    ${(start.x + end.x) / 2} ${end.y},
    ${end.x} ${end.y}`
}

https://github.com/dagrejs/dagre-d3/blob/master/lib/create-edge-paths.js#L68-L77