{
const d3SvgNode = d3.select(svg `<svg width=${width} height=400></svg>`);
const sourceData = {
x: width/2-100,
y: 50
};
const targetData = {
x: width/2+100,
y: 200
};
const drag = d3.drag().on('drag', dragged)
const link = d3SvgNode.append('path')
.attr('d', diagonal(sourceData, targetData))
.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)
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);
link.attr('d', diagonal(sourceData, targetData))
}
yield d3SvgNode.node();
}