{
const d3SvgNode = d3.select(svg`<svg width=${width} height=400></svg>`);
const sourceData = {
x: width / 2 + 0,
y: 150
};
const midData = {
x: width / 2 + 200,
y: 50
};
const targetData = {
x: width / 2 - 200,
y: 250
};
const drag = d3.drag().on("drag", dragged);
const link = d3SvgNode
.append("path")
.attr("d", diagonal(sourceData, targetData, midData))
.attr("fill", "none")
.attr("stroke", "steelblue");
const source = d3SvgNode
.append("circle")
.datum(sourceData)
.attr("r", 10)
.attr("cx", sourceData.x)
.attr("cy", sourceData.y)
.attr("fill", "steelblue")
.attr("cursor", "move")
.call(drag);
const target = d3SvgNode
.append("circle")
.datum(targetData)
.attr("r", 10)
.attr("cx", targetData.x)
.attr("cy", targetData.y)
.attr("fill", "steelblue")
.attr("cursor", "move")
.call(drag);
const mid = d3SvgNode
.append("circle")
.datum(midData)
.attr("r", 10)
.attr("cx", midData.x)
.attr("cy", midData.y)
.attr("fill", "steelblue")
.attr("cursor", "move")
.call(drag);
function dragged(d) {
d.x = d3.event.x;
d.y = d3.event.y;
update();
}
function update() {
source.attr("cx", sourceData.x).attr("cy", sourceData.y);
target.attr("cx", targetData.x).attr("cy", targetData.y);
mid.attr("cx", midData.x).attr("cy", midData.y);
link.attr("d", diagonal(sourceData, targetData, midData));
}
yield d3SvgNode.node();
}