Skip to content

Commit 2a6c5e1

Browse files
authored
fix(load): Update call sequence to be after data are unloaded
Unload callback should ran after data are unloaded Fix #4052
1 parent d6aa201 commit 2a6c5e1

File tree

2 files changed

+61
-7
lines changed

2 files changed

+61
-7
lines changed

src/ChartInternal/data/load.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,6 @@ export default {
156156
return;
157157
}
158158

159-
const targets = $el.svg.selectAll(targetIds.map(id => $$.selectorTarget(id)));
160-
161-
$T(targets)
162-
.style("opacity", "0")
163-
.remove()
164-
.call(endall, done);
165-
166159
targetIds.forEach(id => {
167160
const suffixId = $$.getTargetSelectorSuffix(id);
168161

@@ -189,5 +182,12 @@ export default {
189182

190183
// Update current state chart type and elements list after redraw
191184
$$.updateTypesElements();
185+
186+
const targets = $el.svg.selectAll(targetIds.map(id => $$.selectorTarget(id)));
187+
188+
$T(targets)
189+
.style("opacity", "0")
190+
.remove()
191+
.call(endall, done);
192192
}
193193
};

test/api/load-spec.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import {beforeEach, beforeAll, describe, expect, it} from "vitest";
77
import {select as d3Select} from "d3-selection";
88
import {format as d3Format} from "d3-format";
9+
import sinon from "sinon";
910
import {$AREA, $AXIS, $COMMON, $CIRCLE, $EVENT, $LEGEND, $LINE} from "../../src/config/classes";
1011
import util from "../assets/util";
1112

@@ -1275,4 +1276,57 @@ describe("API load", function() {
12751276
});
12761277
}));
12771278
});
1279+
1280+
describe("Unload callback sequence with transition duration 0", () => {
1281+
beforeAll(() => {
1282+
args = {
1283+
data: {
1284+
columns: [
1285+
["data1", 30, 200, 100, 400, 150, 250],
1286+
["data2", 50, 20, 10, 40, 15, 25]
1287+
],
1288+
empty: {
1289+
label: {
1290+
text: "No Data"
1291+
}
1292+
}
1293+
},
1294+
transition: {
1295+
duration: 0
1296+
}
1297+
};
1298+
});
1299+
1300+
it("should show 'No Data' text after unload callback when transition.duration=0", () => new Promise(done => {
1301+
const doneSpy = sinon.spy();
1302+
const {$el} = chart.internal;
1303+
1304+
// Verify "No Data" text is not visible initially
1305+
let emptyText = $el.main.select("text.bb-text.bb-empty");
1306+
expect(emptyText.empty() || emptyText.style("display") === "none").to.be.true;
1307+
1308+
// when
1309+
chart.unload({
1310+
ids: ["data1", "data2"],
1311+
done() {
1312+
doneSpy();
1313+
1314+
// Check if "No Data" text is visible after unload callback
1315+
// This tests the fix where unload callback should run after data are unloaded
1316+
const {$el} = this.internal;
1317+
const emptyText = $el.main.select("text.bb-text.bb-empty");
1318+
1319+
expect(doneSpy.calledOnce).to.be.true;
1320+
expect(emptyText.empty()).to.be.false;
1321+
expect(emptyText.text()).to.be.equal("No Data");
1322+
expect(emptyText.style("display")).to.not.equal("none");
1323+
1324+
// Verify that all data has been unloaded
1325+
expect(this.data().length).to.be.equal(0);
1326+
1327+
done(1);
1328+
}
1329+
});
1330+
}));
1331+
});
12781332
});

0 commit comments

Comments
 (0)