spiermar / d3-flame-graph

A D3.js plugin that produces flame graphs from hierarchical data.
Apache License 2.0
880 stars 119 forks source link

Tooltip elements not cleaned up on flamegraph.destroy() #189

Closed nickgirardo closed 2 years ago

nickgirardo commented 3 years ago

Describe the bug When calling .destroy() on the graph, the associated tip is not removed from the DOM

To Reproduce Steps to reproduce the behavior:

  1. Before creating a flamegraph, check document.querySelectorAll('.d3-flame-graph-tip').length. This should be 0.
  2. Create a new flamegraph with a tooltip
  3. Check document.querySelectorAll('.d3-flame-graph-tip').length again. There should now be 1 tooltip found
  4. Call .destroy() on the graph, confirm that it is removed from the DOM
  5. Check document.querySelectorAll('.d3-flame-graph-tip').length again. Note that it is still 1. Although the graph has been removed, the tooltip remains in the DOM
  6. This can be repeated as desired, when each new graph is created the number of tooltips will increment.

Expected behavior Tooltips are correctly removed from the DOM after their associated graph is destroyed. At step 3 of the above, the command should return 0 and repeatedly creating and destroying graphs should not cause the result to grow infinitely.

Screenshots image

Desktop (please complete the following information):

Additional context Sorry for spamming you with all of these issues :( I'm fairly new to d3 otherwise I'd try to do a better job submitting prs instead of just sending in all of these reports :(

spiermar commented 2 years ago

Thanks @nickgirardo! I usually clean the tooltip outside the flame graph code, since it was created outside too, but I added a hook to destroy it if .destroy() is called on the flame graph.