Skip to content

Commit

Permalink
fix(label): 图表开启label配置,多次render后卸载图表导致报错(#6104)
Browse files Browse the repository at this point in the history
  • Loading branch information
王学通 committed Mar 4, 2024
1 parent f6ce41e commit 8846033
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/component/update-label.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Coordinate } from '@antv/coord';
import { IGroup, IShape } from '@antv/g-base';
import { each, get } from '@antv/util';
import { each, get, isArray } from '@antv/util';
import { doAnimate } from '../animate';
import { getReplaceAttrs } from '../util/graphics';

Expand Down Expand Up @@ -60,7 +60,7 @@ export function updateLabel(fromShape: IGroup, toShape: IGroup, cfg: Cfg): void

// append
each(toShape.getChildren(), (child, idx) => {
if (idx >= fromShape.getCount()) {
if (isArray(fromShape.getChildren()) && idx >= fromShape.getCount()) {
if (!child.destroyed) {
fromShape.add(child);
}
Expand Down
48 changes: 48 additions & 0 deletions tests/bugs/6104.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Chart } from '../../src';
import { createDiv } from '../util/dom';


describe('#6104', () => {
it('dual-axes-label.spec', async () => {

const data = [
{ time: '10:10', call: 4, waiting: 2, people: 2 },
{ time: '10:15', call: 2, waiting: 6, people: 3 },
{ time: '10:20', call: 13, waiting: 2, people: 5 },
{ time: '10:25', call: 9, waiting: 9, people: 1 },
{ time: '10:30', call: 5, waiting: 2, people: 3 },
{ time: '10:35', call: 8, waiting: 2, people: 1 },
{ time: '10:40', call: 13, waiting: 1, people: 2 }
];
const chart = new Chart({
container: createDiv(),
autoFit: true,
height: 500
});
chart.clear();
chart.data(data);
chart.interval()
.position('time*waiting')
.color('#3182bd')
.label('waiting', {
style: {
fill: '#f00',
},
})
chart.line()
.position('time*people')
.color('#fdae6b')
.size(3)
.shape('smooth')
.label('waiting', {
style: {
fill: '#0f0',
},
})


chart.render();
chart.render();
chart.destroy();
})
})

0 comments on commit 8846033

Please sign in to comment.