Skip to content

Commit

Permalink
feat(event): 添加 plot:enter 和 plot:leave 事件
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ authored and hustcc committed Apr 2, 2020
1 parent 8e6cddf commit 1f9b96b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
29 changes: 20 additions & 9 deletions src/chart/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1449,20 +1449,31 @@ export class View extends Base {
// 对于 mouseenter, mouseleave 的计算处理
if (type === 'mousemove' || type === 'touchmove') {
if (this.isPreMouseInPlot && !currentInPlot) {
const eventName = type === 'mousemove' ? PLOT_EVENTS.MOUSE_LEAVE : PLOT_EVENTS.TOUCH_END;
e.type = eventName;
this.emit(eventName, e);
} else if (!this.isPreMouseInPlot && currentInPlot) {
e.type = PLOT_EVENTS.MOUSE_ENTER;
this.emit(PLOT_EVENTS.MOUSE_ENTER, e);
if (type === 'mousemove') {
e.type = PLOT_EVENTS.MOUSE_LEAVE;
this.emit(PLOT_EVENTS.MOUSE_LEAVE, e);
}
e.type = PLOT_EVENTS.LEAVE;
this.emit(PLOT_EVENTS.LEAVE, e);
} else if (!this.isPreMouseInPlot && currentInPlot) {
if (type === 'mousemove') {
e.type = PLOT_EVENTS.MOUSE_ENTER;
this.emit(PLOT_EVENTS.MOUSE_ENTER, e);
}
e.type = PLOT_EVENTS.ENTER;
this.emit(PLOT_EVENTS.ENTER, e);
}
// 赋新的状态值
this.isPreMouseInPlot = currentInPlot;
} else if (type === 'mouseleave' || type === 'touchend') { // 可能不在 currentInPlot 中
if (this.isPreMouseInPlot) {
const eventName = type === 'mouseleave' ? PLOT_EVENTS.MOUSE_LEAVE : PLOT_EVENTS.TOUCH_END;
e.type = eventName;
this.emit(eventName, e);
if (type === 'mouseleave') {
e.type = PLOT_EVENTS.MOUSE_LEAVE;
this.emit(PLOT_EVENTS.MOUSE_LEAVE, e);
}
e.type = PLOT_EVENTS.LEAVE;
this.emit(PLOT_EVENTS.LEAVE, e);

this.isPreMouseInPlot = false;
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ export enum PLOT_EVENTS {
// click 事件
CLICK = 'plot:click',
DBLCLICK = 'plot:dblclick',
CONTEXTMENU = 'plot:contextmenu'
CONTEXTMENU = 'plot:contextmenu',

LEAVE = 'plot:leave',
ENTER = 'plot:enter',
}

/** 参与分组的图形属性名 */
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ registerInteraction('tooltip', {
{ trigger: 'plot:touchmove', action: 'tooltip:show', throttle: { wait: 50, leading: true, trailing: false } },
],
end: [
{ trigger: 'plot:mouseleave', action: 'tooltip:hide' },
{ trigger: 'plot:touchend', action: 'tooltip:hide' }
{ trigger: 'plot:leave', action: 'tooltip:hide' },
{ trigger: 'plot:touchend', action: 'tooltip:hide' },
],
});

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/interaction/action/tooltip-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('test tooltip action', () => {
});

it('hide', () => {
chart.emit('plot:mouseleave', {
chart.emit('plot:leave', {
x: 138,
y: 383,
});
Expand Down

0 comments on commit 1f9b96b

Please sign in to comment.