heavyai-charting
heavyai-charting copied to clipboard
destroyChart() on Map/Scatter seems to be incomplete
- Operating System and version: Ubuntu 16.04
- Browser and version: Firefox 60.0.1
- Steps to reproduce:
- Create a Map or Scatter, e.g. one of the
pointMapChart+pointLayerin the examples - Destroy the chart with
pointMapChart.destroyChart() - 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 thedestroyChart()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.