d3plus / d3plus-react

React components for d3plus visualizations.
MIT License
31 stars 6 forks source link

hide tooltips associated with visualization when removing the visualization #18

Open NoobTW opened 6 years ago

NoobTW commented 6 years ago

Hi, I'm using treemap in this package. It works well but after I hide the treemap, the tooltip doesn't hide. The .d3plus-tooltip is still there in the DOM.

davelandry commented 6 years ago

@NoobTW can you share the code you have written to hide the Treemap?

NoobTW commented 6 years ago

Not sure if I did this right, but here's the code: https://github.com/NoobTW/od-freq/blob/master/src/App.js#L110

davelandry commented 6 years ago

Thanks for sharing @NoobTW. In the meantime, before the fix is implemented, you might be able to hack it (I haven't tested this though). At the top of the render function, save the handleClick function to a variable:

const handleClick = this.handleClick.bind(this);

And then try this for your click function:

on:
  click: function(d) {
    this._tooltipClass.data([]).render();
    handleClick(d);
  }
}

This is all based on the default internal click function, which has access to the tooltip through it's context: https://github.com/d3plus/d3plus-viz/blob/master/src/on/click.js

NoobTW commented 6 years ago

Thanks for the hack, but I'm unable to access this in click function.

on: {
    click: function(d) {
        // this._tooltipClass.data([]).render();
        console.log(this)  // This is undefined.
        handleClick(d); // Still works because I saved it to a variable.
    }
}