From 1f9b96be4bac0155dd0063a1197341e6639499ff Mon Sep 17 00:00:00 2001 From: simaQ Date: Thu, 2 Apr 2020 18:25:07 +0800 Subject: [PATCH] =?UTF-8?q?feat(event):=20=E6=B7=BB=E5=8A=A0=20plot:enter?= =?UTF-8?q?=20=E5=92=8C=20plot:leave=20=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chart/view.ts | 29 +++++++++++++------ src/constant.ts | 5 +++- src/index.ts | 4 +-- tests/unit/interaction/action/tooltip-spec.ts | 2 +- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/chart/view.ts b/src/chart/view.ts index 20d87bac90..a3a055167a 100644 --- a/src/chart/view.ts +++ b/src/chart/view.ts @@ -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; } } diff --git a/src/constant.ts b/src/constant.ts index e45d729aa8..f96c64c650 100644 --- a/src/constant.ts +++ b/src/constant.ts @@ -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', } /** 参与分组的图形属性名 */ diff --git a/src/index.ts b/src/index.ts index db3b547181..252278e089 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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' }, ], }); diff --git a/tests/unit/interaction/action/tooltip-spec.ts b/tests/unit/interaction/action/tooltip-spec.ts index 7e7468ce36..311a8e8974 100644 --- a/tests/unit/interaction/action/tooltip-spec.ts +++ b/tests/unit/interaction/action/tooltip-spec.ts @@ -41,7 +41,7 @@ describe('test tooltip action', () => { }); it('hide', () => { - chart.emit('plot:mouseleave', { + chart.emit('plot:leave', { x: 138, y: 383, });