Skip to content

Commit

Permalink
fix(pie): 修复饼图中心文本交互问题 (#2923)
Browse files Browse the repository at this point in the history
* fix(pie): 修复饼图中心文本交互问题

close: #2285
refactor 文件目录组织

* fix: 修复单测文件引用路径
  • Loading branch information
visiky authored Oct 21, 2021
1 parent 3c1fe83 commit c65f6ab
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion __tests__/unit/plots/pie/html-statistic-spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/plots/pie/interaction-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/plots/pie/interactions/index.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
16 changes: 16 additions & 0 deletions src/plots/pie/interactions/util.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit c65f6ab

Please sign in to comment.