Description
As @etpinard pointed out during the finance refactor PR #2561 (comment) and #2561 (comment) we have a mess when redrawing cartesian SVG traces, both re: deleting and redrawing existing traces and re: removing completely unused modules.
The first part we can handle by making all the trace modules support more d3-idiomatic enter/exit/each
logic as suggested in this TODO. The second has a few ways to go about it. Quoting @etpinard:
What we need to do is find all the gone modules (i.e. modules with
had??=true
andhas??=false
), loop over them, and then do what we need to do the cleanup the DOM.Better yet -- as more and more trace type will follow scatter and ohlc in not expecting a
selectAll('g.trace').remove()
before each_module.plot()
-- we could add a trace module method (maybe calledcleanDOM
) to each trace modules that need to remove things for the DOM (or destroy WebGL objects).To note, geo subplots (and maybe others?) solve this problem in a different way by using
Plots.generalUpdatePerTraceModule
which calls_module.plot
of visible and gone modules and expects the trace module plot methods to clean up the DOM accordingly (e.g. like here for choropleth traces). At present though, I think addingcleanDOM
to each trace module would be best, as it would allow us to handle thescattergl
and range-slider cases more easily.