From 39a82cea64f5218f1962c3f4af4bd671d7252211 Mon Sep 17 00:00:00 2001 From: huzz Date: Mon, 20 Jun 2022 18:37:38 +0800 Subject: [PATCH 1/2] fix(continuousView): fix multi visualMap bind hoverLink listener. --- src/component/visualMap/ContinuousView.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/component/visualMap/ContinuousView.ts b/src/component/visualMap/ContinuousView.ts index ac31cd0943..919f04e9f0 100644 --- a/src/component/visualMap/ContinuousView.ts +++ b/src/component/visualMap/ContinuousView.ts @@ -109,6 +109,9 @@ class ContinuousView extends VisualMapView { private _api: ExtensionAPI; + private _ownHoverLinkFromSeriesMouseOver = (e: ElementEvent) => this._hoverLinkFromSeriesMouseOver(e); + + private _ownHideIndicator = () => this._hideIndicator(); doRender( visualMapModel: ContinuousModel, @@ -749,8 +752,8 @@ class ContinuousView extends VisualMapView { const zr = this.api.getZr(); if (this.visualMapModel.option.hoverLink) { - zr.on('mouseover', this._hoverLinkFromSeriesMouseOver, this); - zr.on('mouseout', this._hideIndicator, this); + zr.on('mouseover', this._ownHoverLinkFromSeriesMouseOver, this); + zr.on('mouseout', this._ownHideIndicator, this); } else { this._clearHoverLinkFromSeries(); @@ -866,8 +869,8 @@ class ContinuousView extends VisualMapView { this._hideIndicator(); const zr = this.api.getZr(); - zr.off('mouseover', this._hoverLinkFromSeriesMouseOver); - zr.off('mouseout', this._hideIndicator); + zr.off('mouseover', this._ownHoverLinkFromSeriesMouseOver); + zr.off('mouseout', this._ownHideIndicator); } private _applyTransform(vertex: number[], element: Element, inverse?: boolean, global?: boolean): number[] private _applyTransform(vertex: Direction, element: Element, inverse?: boolean, global?: boolean): Direction @@ -947,4 +950,4 @@ function getCursor(orient: Orient) { return orient === 'vertical' ? 'ns-resize' : 'ew-resize'; } -export default ContinuousView; \ No newline at end of file +export default ContinuousView; From 08280597eeca0783f9ddf84c2787a408634382c2 Mon Sep 17 00:00:00 2001 From: huzz Date: Wed, 22 Jun 2022 11:53:53 +0800 Subject: [PATCH 2/2] add test case --- test/ut/core/utHelper.ts | 22 ++++++++++++++++ .../component/visualMap/setOption.test.ts | 26 +++++++++++++++++-- test/ut/tsconfig.json | 3 ++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/test/ut/core/utHelper.ts b/test/ut/core/utHelper.ts index d933feba5c..d467c7095f 100755 --- a/test/ut/core/utHelper.ts +++ b/test/ut/core/utHelper.ts @@ -27,6 +27,7 @@ import { import { ComponentMainType } from '../../../src/util/types'; import Group from 'zrender/src/graphic/Group'; import Element from 'zrender/src/Element'; +import Handler from 'zrender/src/Handler'; import GlobalModel from '../../../src/model/Global'; @@ -154,3 +155,24 @@ export function getECModel(chart: EChartsType): GlobalModel { // @ts-ignore return chart.getModel(); } + +type EventHandlersMap = Handler['_$handlers']; + +type EventHandlers = T[keyof T]; + +export function getEventHandle(chart: EChartsType, eventName: string, ctx?: T): EventHandlers { + const zr = chart.getZr(); + const handler = zr.handler; + // @ts-ignore + const allHandlers = handler._$handlers; + const eventHandlers = allHandlers[eventName]; + + if (!eventHandlers) { + return []; + } + + if (ctx) { + return eventHandlers.filter(handler => handler.ctx instanceof ctx); + } + return eventHandlers; +} diff --git a/test/ut/spec/component/visualMap/setOption.test.ts b/test/ut/spec/component/visualMap/setOption.test.ts index 0911af0073..9df6fe82ff 100755 --- a/test/ut/spec/component/visualMap/setOption.test.ts +++ b/test/ut/spec/component/visualMap/setOption.test.ts @@ -18,12 +18,13 @@ * under the License. */ -import { createChart, getECModel } from '../../../core/utHelper'; +import { createChart, getECModel, getEventHandle } from '../../../core/utHelper'; import { EChartsType } from '../../../../../src/echarts'; import { EChartsOption } from '../../../../../src/export/option'; import { ContinousVisualMapOption } from '../../../../../src/component/visualMap/ContinuousModel'; import { PiecewiseVisualMapOption } from '../../../../../src/component/visualMap/PiecewiseModel'; import VisualMapModel from '../../../../../src/component/visualMap/VisualMapModel'; +import ContinuousView from '../../../../../src/component/visualMap/ContinuousView'; describe('vsiaulMap_setOption', function () { @@ -286,4 +287,25 @@ describe('vsiaulMap_setOption', function () { done(); }); -}); \ No newline at end of file + it('registerHoverLinkHandle', function (done) { + chart.setOption({ + xAxis: {}, + yAxis: {}, + series: [{type: 'scatter', data: [[12, 223]]}], + visualMap: [ + {type: 'continuous', hoverLink: true}, + {type: 'continuous', hoverLink: true}, + {type: 'continuous', hoverLink: false} + ] + }); + + const mouseoverHandlers = getEventHandle(chart, 'mouseover', ContinuousView); + const mouseoutHandlers = getEventHandle(chart, 'mouseout', ContinuousView); + + expect(mouseoverHandlers.length).toBe(2); + expect(mouseoutHandlers.length).toBe(2); + + done(); + }); + +}); diff --git a/test/ut/tsconfig.json b/test/ut/tsconfig.json index 63885f0a1e..0436b1c434 100644 --- a/test/ut/tsconfig.json +++ b/test/ut/tsconfig.json @@ -7,6 +7,7 @@ "strictBindCallApply": true, "esModuleInterop": true, + "moduleResolution": "node", "baseUrl": "./", "paths": { @@ -18,4 +19,4 @@ ], "exclude": [ ] -} \ No newline at end of file +}