I created a line in d3 that I want to drag.
var line = d3.select("svg")
.append("line")
.attr("x1",10)
.attr("y1",10)
.attr("x2",200)
.attr("y2",200)
.attr("stroke-width",10)
.attr("stroke","black")
.call(drag);
The problem that I have right now is how to move both points (x1, y1) (x2, y2) from the line relative to my mouse position, since I probably also need the dragstart mouse position.
let drag = d3.behavior.drag()
.on('dragstart', null)
.on('drag', function(){
let x1New = d3.select(this).attr('x1')+ ???;
let y1New = d3.select(this).attr('y1')+ ???;
let x2New = d3.select(this).attr('x2')+ ???;
let y2New = d3.select(this).attr('y2')+ ???;
line.attr("x1",x1New)
.attr("y1",y1New)
.attr("x2",x2New)
.attr("y2",y2New);
})
.on('dragend', function(){
});
I hope you help me with this.
source
share