From db1600bf3c87dc40ca0ca1824f74209ea941043d Mon Sep 17 00:00:00 2001 From: visiky <736929286@qq.com> Date: Sun, 17 Oct 2021 12:16:49 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(pie):=20=E4=BF=AE=E5=A4=8D=E9=A5=BC?= =?UTF-8?q?=E5=9B=BE=E4=B8=AD=E5=BF=83=E6=96=87=E6=9C=AC=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close: #2285 refactor 文件目录组织 --- .../legend-active.ts} | 2 +- .../statistic-active.ts} | 14 +++++++++++--- src/plots/pie/interactions/index.ts | 4 ++-- src/plots/pie/interactions/util.ts | 16 ++++++++++++++++ 4 files changed, 30 insertions(+), 6 deletions(-) rename src/plots/pie/interactions/{pie-legend-action.ts => actions/legend-active.ts} (97%) rename src/plots/pie/interactions/{pie-statistic-action.ts => actions/statistic-active.ts} (86%) create mode 100644 src/plots/pie/interactions/util.ts diff --git a/src/plots/pie/interactions/pie-legend-action.ts b/src/plots/pie/interactions/actions/legend-active.ts similarity index 97% rename from src/plots/pie/interactions/pie-legend-action.ts rename to src/plots/pie/interactions/actions/legend-active.ts index 9cab273363..48359f5516 100644 --- a/src/plots/pie/interactions/pie-legend-action.ts +++ b/src/plots/pie/interactions/actions/legend-active.ts @@ -1,7 +1,7 @@ import { IElement, IGroup } from '@antv/g-base'; import { Util, Element, Action } from '@antv/g2'; import { isEqual } from '@antv/util'; -import { transform } from '../../../utils/matrix'; +import { transform } from '../../../../utils/matrix'; /** * 饼图 图例激活 action diff --git a/src/plots/pie/interactions/pie-statistic-action.ts b/src/plots/pie/interactions/actions/statistic-active.ts similarity index 86% rename from src/plots/pie/interactions/pie-statistic-action.ts rename to src/plots/pie/interactions/actions/statistic-active.ts index 827c54491a..73ce7e7495 100644 --- a/src/plots/pie/interactions/pie-statistic-action.ts +++ b/src/plots/pie/interactions/actions/statistic-active.ts @@ -1,8 +1,10 @@ import { View, Action, Util, Types } from '@antv/g2'; import { each, get } from '@antv/util'; -import { PieOptions } from '..'; -import { Annotation } from '../../../types/annotation'; -import { renderStatistic } from '../../../utils/statistic'; +import { Annotation } from '../../../../types/annotation'; +import { renderStatistic } from '../../../../utils/statistic'; +import { PieOptions } from '../../types'; +import { getCurrentElement } from '../util'; + /** * Pie 中心文本事件的 Action */ @@ -60,6 +62,12 @@ export class StatisticAction extends Action { renderStatistic(view, { statistic, plotType: 'pie' }, data); view.render(true); } + + // 交互的时候,把 shape 提前 + const ele = getCurrentElement(this.context); + if (ele) { + ele.shape.toFront(); + } } public reset() { diff --git a/src/plots/pie/interactions/index.ts b/src/plots/pie/interactions/index.ts index 044ba85419..4d9048dac3 100644 --- a/src/plots/pie/interactions/index.ts +++ b/src/plots/pie/interactions/index.ts @@ -1,6 +1,6 @@ import { registerAction, registerInteraction } from '@antv/g2'; -import { PieLegendAction } from './pie-legend-action'; -import { StatisticAction } from './pie-statistic-action'; +import { PieLegendAction } from './actions/legend-active'; +import { StatisticAction } from './actions/statistic-active'; export const PIE_STATISTIC = 'pie-statistic'; diff --git a/src/plots/pie/interactions/util.ts b/src/plots/pie/interactions/util.ts new file mode 100644 index 0000000000..af9ec2a026 --- /dev/null +++ b/src/plots/pie/interactions/util.ts @@ -0,0 +1,16 @@ +import { Element } from '@antv/g2'; + +/** + * 获取当前事件相关的图表元素 + * @param context 交互的上下文 + * @ignore + */ +export function getCurrentElement(context): Element | undefined { + const event = context.event; + let element; + const target = event.target; + if (target) { + element = target.get('element'); + } + return element; +} From 6ad1cf7bf087d364ae665dcfc3fc518ff819fd4f Mon Sep 17 00:00:00 2001 From: visiky <736929286@qq.com> Date: Tue, 19 Oct 2021 07:26:02 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=8D=95=E6=B5=8B?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=BC=95=E7=94=A8=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/unit/plots/pie/html-statistic-spec.ts | 2 +- __tests__/unit/plots/pie/interaction-spec.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/__tests__/unit/plots/pie/html-statistic-spec.ts b/__tests__/unit/plots/pie/html-statistic-spec.ts index c33cad198f..d3a2d7ac1d 100644 --- a/__tests__/unit/plots/pie/html-statistic-spec.ts +++ b/__tests__/unit/plots/pie/html-statistic-spec.ts @@ -1,6 +1,6 @@ import InteractionContext from '@antv/g2/lib/interaction/context'; import { Pie } from '../../../../src'; -import { StatisticAction } from '../../../../src/plots/pie/interactions/pie-statistic-action'; +import { StatisticAction } from '../../../../src/plots/pie/interactions/actions/statistic-active'; import { POSITIVE_NEGATIVE_DATA } from '../../../data/common'; import { createDiv } from '../../../utils/dom'; import { delay } from '../../../utils/delay'; diff --git a/__tests__/unit/plots/pie/interaction-spec.ts b/__tests__/unit/plots/pie/interaction-spec.ts index 86a0e9c226..60c15a517d 100644 --- a/__tests__/unit/plots/pie/interaction-spec.ts +++ b/__tests__/unit/plots/pie/interaction-spec.ts @@ -4,7 +4,7 @@ import { deepMix } from '@antv/util'; import { delay } from '../../../utils/delay'; import { createDiv } from '../../../utils/dom'; import { Pie } from '../../../../src'; -import { StatisticAction } from '../../../../src/plots/pie/interactions/pie-statistic-action'; +import { StatisticAction } from '../../../../src/plots/pie/interactions/actions/statistic-active'; import { transformStatisticOptions } from '../../../../src/plots/pie/adaptor'; describe('register interaction', () => {