Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix destroy function to prevent null error during Pie chart animation #2188

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/api.chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/arc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
})
Expand Down