From 81e121466b555a0a47ee7c3d558657bc0a3e874c Mon Sep 17 00:00:00 2001 From: kasmine <736929286@qq.com> Date: Mon, 25 Jan 2021 16:44:44 +0800 Subject: [PATCH] =?UTF-8?q?feat(pie):=20=E9=A5=BC=E5=9B=BE=20geometry=20?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=AF=B9=20elemenent=20=E7=9A=84=20zIndex=20?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E5=8F=8D=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/unit/plots/pie/data-spec.ts | 8 +++++--- __tests__/unit/plots/pie/index-spec.ts | 2 ++ src/plots/pie/adaptor.ts | 10 ++++++++++ src/plots/pie/contants.ts | 3 +++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/__tests__/unit/plots/pie/data-spec.ts b/__tests__/unit/plots/pie/data-spec.ts index bba7586df1..e5d9c25dc6 100644 --- a/__tests__/unit/plots/pie/data-spec.ts +++ b/__tests__/unit/plots/pie/data-spec.ts @@ -32,12 +32,14 @@ describe('饼图 异常数据', () => { pie.render(); - const elements = pie.chart.geometries[0].elements; + const geometry = pie.chart.geometries[0]; + const elements = geometry.elements; expect(elements.length).toBe(5); expect(every(elements, (ele) => ele.getBBox().width > 0)).toBe(true); - const labels = pie.chart.geometries[0].labelsContainer.getChildren(); + const labels = geometry.labelsContainer.getChildren(); expect(every(labels, (label) => (label as IGroup).getChildren()[0].attr('text') === 0)).toBe(true); - + // @ts-ignore + expect(geometry.zIndexReversed).toBe(true); pie.destroy(); }); diff --git a/__tests__/unit/plots/pie/index-spec.ts b/__tests__/unit/plots/pie/index-spec.ts index fd043ea954..95376279d9 100644 --- a/__tests__/unit/plots/pie/index-spec.ts +++ b/__tests__/unit/plots/pie/index-spec.ts @@ -31,6 +31,8 @@ describe('pie', () => { // 绘图数据 expect(elements[0].getModel().style?.fill || elements[0].getModel().color).toBe('blue'); expect(elements[1].getModel().style?.fill || elements[1].getModel().color).toBe('red'); + // @ts-ignore + expect(geometry.zIndexReversed).toBe(true); pie.destroy(); }); diff --git a/src/plots/pie/adaptor.ts b/src/plots/pie/adaptor.ts index 885f8a7c77..b7a8d39bed 100644 --- a/src/plots/pie/adaptor.ts +++ b/src/plots/pie/adaptor.ts @@ -34,6 +34,9 @@ function geometry(params: Params): Params { color, style: pieStyle, }, + args: { + zIndexReversed: true, + }, }, }); @@ -54,6 +57,9 @@ function geometry(params: Params): Params { color, style: pieStyle, }, + args: { + zIndexReversed: true, + }, }, }); @@ -201,6 +207,10 @@ export function pieAnnotation(params: Params): Params { return params; } +/** + * 饼图 tooltip 配置适配,强制 tooltip.shared 为 false + * @param params + */ function adaptorTooltipOptions(params: Params): Params { return get(params, ['options', 'tooltip']) !== false ? deepAssign({}, params, { options: { tooltip: { shared: false } } }) diff --git a/src/plots/pie/contants.ts b/src/plots/pie/contants.ts index 65e4ac10ae..e04cce99ec 100644 --- a/src/plots/pie/contants.ts +++ b/src/plots/pie/contants.ts @@ -1,6 +1,9 @@ import { Plot } from '../../core/plot'; import { deepAssign } from '../../utils'; +/** + * 饼图默认配置项 + */ export const DEFAULT_OPTIONS = deepAssign({}, Plot.getDefaultOptions(), { legend: { position: 'right',