heavyai-charting icon indicating copy to clipboard operation
heavyai-charting copied to clipboard

destroyChart() on Map/Scatter seems to be incomplete

Open theweaklink opened this issue 7 years ago • 0 comments

  • Operating System and version: Ubuntu 16.04
  • Browser and version: Firefox 60.0.1
  • Steps to reproduce:
  1. Create a Map or Scatter, e.g. one of the pointMapChart + pointLayer in the examples
  2. Destroy the chart with pointMapChart.destroyChart()
  3. Re-create a brand new chart => Error related to chartBody being undefined, the new chart still displays properly
  • Description of issue: It looks like destroying the chart does not clean up the chart registry and therefore the old chart is still attempted to be rendered (and fails because it was previoulsy destroyed). After some digging, it looks like a simple call to deregisterChart() in the destroyChart() method solves the problem:
  _chart.destroyChart = function() {
    deregisterChart(_chart, _chart.chartGroup())
    ...  

Also, I found out that if we switch between a Scatter and a Map (i-e: destroy the scatter, create a new map in the same <div> container), the X and Y axis of the scatter are now shown on the maps. Since the axis are elements in the container, adding the following to the destroyChart() seems to make things right:

  _chart.destroyChart = function() {
    deregisterChart(_chart, _chart.chartGroup())
    _chart
      .root()
      .attr("style", "")
      .attr("class", "")
      .html("")
    ...

I am not enough familiar with the chart rendering elements and lifecycle to know if this is actually a correct fix and whether it is the only calls to make. I hope it helps though.

theweaklink avatar May 18 '18 17:05 theweaklink