ErikGartner / dTree

A library for visualizing data trees with multiple parents, such as family trees. Built on top of D3.
https://treehouse.gartner.io/ErikGartner/58e58be650453b6d49d7
MIT License
521 stars 139 forks source link

feat(#42): use call to keep "this" context in click events #98

Closed MrMartiniMo closed 4 years ago

MrMartiniMo commented 4 years ago

By passing the "this" context, it is possible to query the mouse event.

Example:

dTree.init(jsonData, {
    target: "#target",
    callbacks: {
        nodeClick: function (name, extra, id) {
            console.log(d3.mouse(this))
        },
        nodeRightClick: function (name, extra, id) {
            console.log(d3.mouse(this))
        },
    }
})
ErikGartner commented 4 years ago

I made a separate commit (36a036efcd2e56f93736a61f7dc694d7afe390f1) fixing this issue. Thanks for the help!