in src/sankeyDiagram.ts [1595:1664]
function dragged(node: SankeyDiagramNode) {
node.x = (getEvent()).x;
node.y = (getEvent()).y;
if (node.x < 0) {
node.x = 0;
}
if (node.y < 0) {
node.y = 0;
}
if (node.x + node.width > sankeyVisual.viewport.width) {
node.x = sankeyVisual.viewport.width - node.width;
}
if (node.y + node.height > sankeyVisual.viewport.height) {
node.y = sankeyVisual.viewport.height - node.height;
}
node.settings = {
x: node.x.toFixed(2),
y: node.y.toFixed(2),
name: node.label.name
};
// Update each link related with this node
node.links.forEach((link: SankeyDiagramLink) => {
// select link svg element by ID generated in link creation as Source-Destination
d3.select(`#${SankeyDiagram.createLink(link, true)}`).attr(
// get updated path params based on actual positions of node
"d", (link: SankeyDiagramLink) => {
if (link.direction === SankeyLinkDirrections.Forward) {
return sankeyVisual.getSvgPathForForwardLink(link);
}
if (link.direction === SankeyLinkDirrections.Backward) {
if (link.source.x + link.source.width > link.destination.x) {
return sankeyVisual.getSvgPathForForwardLink(link);
}
return sankeyVisual.getSvgPathForBackwardLink(link);
}
if (link.direction === SankeyLinkDirrections.SelfLink) {
return sankeyVisual.getSvgPathForSelfLink(link, minHeight);
}
}
);
d3.select(`#${SankeyDiagram.createLink(link)}`).attr(
// get updated path params based on actual positions of node
"d", (link: SankeyDiagramLink) => {
if (link.direction === SankeyLinkDirrections.Forward) {
return sankeyVisual.getSvgPathForForwardLink(link);
}
if (link.direction === SankeyLinkDirrections.Backward) {
if (link.source.x + link.source.width > link.destination.x) {
return sankeyVisual.getSvgPathForForwardLink(link);
}
return sankeyVisual.getSvgPathForBackwardLink(link);
}
if (link.direction === SankeyLinkDirrections.SelfLink) {
return sankeyVisual.getSvgPathForSelfLink(link, minHeight);
}
}
);
});
// Translate the object on the actual moved point
d3.select(this).attr(
"transform", translate(node.x, node.y)
);
}