this.g = this.svg.selectAll(".dimension")
.data(dimensions)
.enter().append("g")
.attr("class", "dimension")
.attr("transform", function(d) { return "translate(0," + _this.y(d.id) + ")"; })
this.g = this.svg.selectAll(".dimension")
.data(dimensions)
.enter().append("g")
.attr("id","toto")
.attr("class", "dimension")
.attr("transform", function(d) { return "translate(0," + _this.y(d.id) + ")"; })
.call(d3.drag()
.on("start",(d, i) => this.dragstarted(d,i))
.on("drag",(d, i) => this.dragstarted(d,i))
.on("end", (d, i) => this.dragended(d, i)));
this.g = this.svg.selectAll(".dimension")
.data(dimensions)
.enter().append("g")
.attr("id","toto")
.attr("class", "dimension")
.attr("transform", function(d) { return "translate(0," + _this.y(d.id) + ")"; })
.call(d3.drag()
.on("start",this.dragstarted)
.on("drag", this.dragged)
.on("end", this.dragended));
Hi Stephane,
Try normal functions instead of arrow functions
.on("start", function(d, i) {this.dragstarted(d,i)})
This will give you a workable this.
or
.on("start",this.dragstarted.bind(this))
And this will make sure the function is bound to the class, I think this your best option
Regards
Sander
const reference = this;
xstart : number;
function dragstarted(d)
{
.. reference.xstart = d3.event.x;
}
....
d3... .on("start",dragstarted)