Browse Source

fix destroy function to prevent null error during pie animation

pull/2188/head
Victor Tang 7 years ago
parent
commit
8ef424bf6a
  1. 18
      src/api.chart.js
  2. 2
      src/arc.js
  3. 4
      src/interaction.js

18
src/api.chart.js

@ -14,6 +14,9 @@ c3_chart_fn.flush = function () {
c3_chart_fn.destroy = function () {
var $$ = this.internal;
var defaultConfig = $$.getDefaultConfig();
//subsequent checks to config should check this instead of !config
defaultConfig.destroyed = true;
window.clearInterval($$.intervalForObserveInserted);
@ -37,7 +40,20 @@ c3_chart_fn.destroy = function () {
// MEMO: this is needed because the reference of some elements will not be released, then memory leak will happen.
Object.keys($$).forEach(function (key) {
$$[key] = null;
if(key === "config")
{
$$[key] = defaultConfig;
}
else if(key === "data")
{
$$[key] = {
targets: []
};
}
else
{
$$[key] = null;
}
});
return null;

2
src/arc.js

@ -31,7 +31,7 @@ c3_chart_internal_fn.updateAngle = function (d) {
found = false, index = 0,
gMin, gMax, gTic, gValue;
if (!config) {
if (config.destroyed) { // chart is destroyed
return null;
}

4
src/interaction.js

@ -133,7 +133,7 @@ c3_chart_internal_fn.generateEventRectsForSingleX = function (eventRectEnter) {
})
.on('mouseout', function (d) {
var index = d.index;
if (!$$.config) { return; } // chart is destroyed
if ($$.config.destroyed) { return; } // chart is destroyed
if ($$.hasArcType()) { return; }
$$.hideXGridFocus();
$$.hideTooltip();
@ -245,7 +245,7 @@ c3_chart_internal_fn.generateEventRectsForMultipleXs = function (eventRectEnter)
.attr('height', $$.height)
.attr('class', CLASS.eventRect)
.on('mouseout', function () {
if (!$$.config) { return; } // chart is destroyed
if ($$.config.destroyed) { return; } // chart is destroyed
if ($$.hasArcType()) { return; }
mouseout();
})

Loading…
Cancel
Save