From 8846033d02efdb8db27597379917ea039f39c55a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AD=A6=E9=80=9A?= Date: Mon, 4 Mar 2024 10:45:52 +0800 Subject: [PATCH] =?UTF-8?q?fix(label):=20=E5=9B=BE=E8=A1=A8=E5=BC=80?= =?UTF-8?q?=E5=90=AFlabel=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=A4=9A=E6=AC=A1rend?= =?UTF-8?q?er=E5=90=8E=E5=8D=B8=E8=BD=BD=E5=9B=BE=E8=A1=A8=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E6=8A=A5=E9=94=99(#6104)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/component/update-label.ts | 4 +-- tests/bugs/6104.spec.ts | 48 +++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 tests/bugs/6104.spec.ts diff --git a/src/component/update-label.ts b/src/component/update-label.ts index 83aebf21a8..e34af4e78e 100644 --- a/src/component/update-label.ts +++ b/src/component/update-label.ts @@ -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'; @@ -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); } diff --git a/tests/bugs/6104.spec.ts b/tests/bugs/6104.spec.ts new file mode 100644 index 0000000000..c469f11ae7 --- /dev/null +++ b/tests/bugs/6104.spec.ts @@ -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(); + }) +})