Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pie): 修复饼图中心文本交互问题 #2923

Merged
merged 2 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}