This is an automated email from the ASF dual-hosted git repository. shenyi pushed a commit to branch next in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
The following commit(s) were added to refs/heads/next by this push: new 3f616bb fix(tooltip): fix label won't trigger tooltip bug. 3f616bb is described below commit 3f616bb0b431f73cd920a2d61c073ad594300368 Author: pissang <bm2736...@gmail.com> AuthorDate: Wed Sep 30 12:40:15 2020 +0800 fix(tooltip): fix label won't trigger tooltip bug. --- src/component/tooltip/TooltipView.ts | 66 +++--------------------------------- src/echarts.ts | 23 +++---------- src/util/event.ts | 37 ++++++++++++++++++++ 3 files changed, 45 insertions(+), 81 deletions(-) diff --git a/src/component/tooltip/TooltipView.ts b/src/component/tooltip/TooltipView.ts index d915c41..e85767b 100644 --- a/src/component/tooltip/TooltipView.ts +++ b/src/component/tooltip/TooltipView.ts @@ -54,6 +54,7 @@ import { shouldTooltipConfine } from './helper'; import { DataByCoordSys, DataByAxis } from '../axisPointer/axisTrigger'; import { normalizeTooltipFormatResult } from '../../model/mixin/dataFormat'; import { createTooltipMarkup, buildTooltipMarkup, TooltipMarkupStyleCreator } from './tooltipMarkup'; +import { findEventDispatcher } from '../../util/event'; const bind = zrUtil.bind; const each = zrUtil.each; @@ -428,7 +429,7 @@ class TooltipView extends ComponentView { this._showAxisTooltip(dataByCoordSys, e); } // Always show item tooltip if mouse is on the element with dataIndex - else if (el && getECData(el).dataIndex != null) { + else if (el && findEventDispatcher(el, (target) => getECData(target).dataIndex != null)) { this._lastDataByCoordSys = null; this._showSeriesItemTooltip(e, el, dispatchAction); } @@ -481,17 +482,6 @@ class TooltipView extends ComponentView { const markupStyleCreator = new TooltipMarkupStyleCreator(); each(dataByCoordSys, function (itemCoordSys) { - // let coordParamList = []; - // let coordDefaultHTML = []; - // let coordTooltipModel = buildTooltipModel([ - // e.tooltipOption, - // itemCoordSys.tooltipOption, - // ecModel.getComponent(itemCoordSys.coordSysMainType, itemCoordSys.coordSysIndex), - // globalTooltipModel - // ]); - // let displayMode = coordTooltipModel.get('displayMode'); - // let paramsList = displayMode === 'single' ? infoBySeriesList : []; - each(itemCoordSys.dataByAxis, function (axisItem) { const axisModel = ecModel.getComponent(axisItem.axisDim + 'Axis', axisItem.axisIndex) as AxisBaseModel; const axisValue = axisItem.value; @@ -539,27 +529,6 @@ class TooltipView extends ComponentView { markupTextArrLegacy.push(seriesTooltipResult.markupText); } cbParamsList.push(cbParams); - - // const data = series.getData(); - // const dims = zrUtil.map(series.coordinateSystem.dimensions, function (coordDim) { - // return data.mapDimension(coordDim); - // }); - // let isStacked = false; - // const stackResultDim = data.getCalculationInfo('stackResultDimension'); - // if (isDimensionStacked(data, dims[0])) { - // isStacked = true; - // dims[0] = stackResultDim; - // } - // if (isDimensionStacked(data, dims[1])) { - // isStacked = true; - // dims[1] = stackResultDim; - // } - // dataParams.coordinateSystem = series.coordinateSystem; - // dataParams.position = findPointFromSeries({ - // seriesIndex: idxItem.seriesIndex, - // dataIndex: dataIndex, - // isStacked - // }, ecModel).point; }); }); }); @@ -606,8 +575,9 @@ class TooltipView extends ComponentView { el: ECElement, dispatchAction: ExtensionAPI['dispatchAction'] ) { + const dispatcher = findEventDispatcher(el, (target) => getECData(target).dataIndex != null); const ecModel = this._ecModel; - const ecData = getECData(el); + const ecData = getECData(dispatcher); // Use dataModel in element if possible // Used when mouseover on a element like markPoint or edge // In which case, the data is not main data in series. @@ -787,34 +757,6 @@ class TooltipView extends ComponentView { color: tooltipDataParams.color || tooltipDataParams.borderColor }; } - - // if (!zrUtil.isArray(tooltipDataParams)) { - // if (!tooltipDataParams.position) { - // return { - // color: tooltipDataParams.color || tooltipDataParams.borderColor - // }; - // } - // return { - // color: tooltipDataParams.color || tooltipDataParams.borderColor - // }; - // } - - // const distanceArr = zrUtil.map(tooltipDataParams, function (params) { - // let dim = ''; - // if (params.coordinateSystem && params.coordinateSystem.type === 'cartesian2d') { - // dim = params.coordinateSystem.getBaseAxis().dim; - // } - // const posIndex = +(dim === 'x'); - // const distance = Math.abs(params.position[posIndex] - point[posIndex]); - // delete params.position; - // delete params.coordinateSystem; - // return distance; - // }); - - // const index = zrUtil.indexOf(distanceArr, Math.min(...distanceArr)); - // return { - // color: tooltipDataParams[index]?.color || tooltipDataParams[index]?.borderColor || '#fff' - // }; } private _updatePosition( diff --git a/src/echarts.ts b/src/echarts.ts index f64966b..206408e 100644 --- a/src/echarts.ts +++ b/src/echarts.ts @@ -104,6 +104,7 @@ import { registerExternalTransform } from './data/helper/transform'; import { createLocaleObject, SYSTEM_LANG, LocaleOption } from './locale'; import type {EChartsFullOption} from './option'; +import { findEventDispatcher } from './util/event'; declare let global: any; type ModelFinder = modelUtil.ModelFinder; @@ -1798,25 +1799,9 @@ class ECharts extends Eventful { }; bindMouseEvent = function (zr: zrender.ZRenderType, ecIns: ECharts): void { - // Find a dispatcher that's on the most top. - function getDispatcher(target: Element, det: (target: Element) => boolean) { - let found; - while (target) { - if (det(target)) { - found = target; - } - if (target.__hostTarget) { - target = target.__hostTarget; - } - else { - target = target.parent; - } - } - return found; - } zr.on('mouseover', function (e) { const el = e.target; - const dispatcher = getDispatcher(el, isHighDownDispatcher); + const dispatcher = findEventDispatcher(el, isHighDownDispatcher); if (dispatcher) { const ecData = getECData(dispatcher); // Try blur all in the related series. Then emphasis the hoverred. @@ -1830,7 +1815,7 @@ class ECharts extends Eventful { } }).on('mouseout', function (e) { const el = e.target; - const dispatcher = getDispatcher(el, isHighDownDispatcher); + const dispatcher = findEventDispatcher(el, isHighDownDispatcher); if (dispatcher) { const ecData = getECData(dispatcher); toggleSeriesBlurState( @@ -1843,7 +1828,7 @@ class ECharts extends Eventful { } }).on('click', function (e) { const el = e.target; - const dispatcher = getDispatcher( + const dispatcher = findEventDispatcher( el, (target) => getECData(target).dataIndex != null ); if (dispatcher) { diff --git a/src/util/event.ts b/src/util/event.ts new file mode 100644 index 0000000..b1aac38 --- /dev/null +++ b/src/util/event.ts @@ -0,0 +1,37 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +import Element from 'zrender/src/Element'; + +// Find a dispatcher that's on the most top. +export function findEventDispatcher(target: Element, det: (target: Element) => boolean) { + let found; + while (target) { + if (det(target)) { + found = target; + } + if (target.__hostTarget) { + target = target.__hostTarget; + } + else { + target = target.parent; + } + } + return found; +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@echarts.apache.org For additional commands, e-mail: commits-h...@echarts.apache.org