Currently, I am utilizing the D3 library for moving an element within a Venn diagram. Upon releasing the item after dragging, I aim to determine its position within the diagram.
item.call(d3.drag()
.on("start", this.dragstarted)
.on("drag", this.dragged)
.on("end", this.dragended)
);
These functions are invoked when dragging begins, continues, and concludes.
dragended(d: TCMemberScenario, i: number) {
d3.select(this).classed("active", false);
d.calculateRoles();
this.save();
}
Following the completion of dragging, this function is triggered. I perform some updates within the diagram and then try to call the save method, which is another method within the class. However, the 'this' variable is pointing to the D3 object rather than the class instance, resulting in a "Uncaught TypeError: Cannot read property 'save' of undefined" error.
Is there a way for me to access another method of my class from within the dragended function?