Skip to content

Commit 56a32c0

Browse files
committed
fix(axisPointer&tooltip): (1) axisPointer and tooltip should be able to update when mousewheel, since dataZoomInside can modify views on mousewheel, and cause highlighted element to be not able to restore. (2) Fix axisPointer highlighted item can not restore due to outdated dataIndexIndex.
1 parent 9335851 commit 56a32c0

5 files changed

Lines changed: 26 additions & 20 deletions

File tree

src/component/axisPointer/AxisPointerView.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class AxisPointerView extends ComponentView {
3131
render(globalAxisPointerModel: AxisPointerModel, ecModel: GlobalModel, api: ExtensionAPI) {
3232
const globalTooltipModel = ecModel.getComponent('tooltip') as TooltipModel;
3333
const triggerOn = globalAxisPointerModel.get('triggerOn')
34-
|| (globalTooltipModel && globalTooltipModel.get('triggerOn') || 'mousemove|click');
34+
// mousewheel can change view by dataZoom.
35+
|| (globalTooltipModel && globalTooltipModel.get('triggerOn') || 'mousemove|click|mousewheel');
3536

3637
// Register global listener in AxisPointerView to enable
3738
// AxisPointerView to be independent to Tooltip.

src/component/axisPointer/axisTrigger.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ type CollectedCoordInfo = ReturnType<typeof modelHelper['collect']>;
7373
type CollectedAxisInfo = CollectedCoordInfo['axesInfo'][string];
7474

7575
interface AxisTriggerPayload extends Payload {
76-
currTrigger?: 'click' | 'mousemove' | 'leave'
76+
currTrigger?: 'click' | 'mousemove' | 'leave' | 'mousewheel'
7777
/**
7878
* x and y, which are mandatory, specify a point to trigger axisPointer and tooltip.
7979
*/
@@ -453,7 +453,7 @@ function dispatchHighDownActually(
453453
) {
454454
// FIXME
455455
// highlight status modification should be a stage of main process?
456-
// (Consider confilct (e.g., legend and axisPointer) and setOption)
456+
// (Consider conflict (e.g., legend and axisPointer) and setOption)
457457

458458
const zr = api.getZr();
459459
const highDownKey = 'axisPointerLastHighlights' as const;
@@ -465,19 +465,26 @@ function dispatchHighDownActually(
465465
each(axesInfo, function (axisInfo, key) {
466466
const option = axisInfo.axisPointerModel.option;
467467
option.status === 'show' && axisInfo.triggerEmphasis && each(option.seriesDataIndices, function (batchItem) {
468-
const key = batchItem.seriesIndex + ' | ' + batchItem.dataIndex;
469-
newHighlights[key] = batchItem;
468+
newHighlights[batchItem.seriesIndex + '|' + batchItem.dataIndex] = batchItem;
470469
});
471470
});
472471

473472
// Diff.
474-
const toHighlight: BatchItem[] = [];
475-
const toDownplay: BatchItem[] = [];
473+
const toHighlight: Pick<BatchItem, 'seriesIndex' | 'dataIndex'>[] = [];
474+
const toDownplay: Pick<BatchItem, 'seriesIndex' | 'dataIndex'>[] = [];
475+
function makeHighDownItem(batchItem: BatchItem) {
476+
// `dataIndexInside` should be removed, since the last recorded `dataIndexInside` may have
477+
// been changed if `dataZoomInside` changed the view. Only `dataIndex` will suffice.
478+
return {
479+
seriesIndex: batchItem.seriesIndex,
480+
dataIndex: batchItem.dataIndex,
481+
};
482+
}
476483
each(lastHighlights, function (batchItem, key) {
477-
!newHighlights[key] && toDownplay.push(batchItem);
484+
!newHighlights[key] && toDownplay.push(makeHighDownItem(batchItem));
478485
});
479486
each(newHighlights, function (batchItem, key) {
480-
!lastHighlights[key] && toHighlight.push(batchItem);
487+
!lastHighlights[key] && toHighlight.push(makeHighDownItem(batchItem));
481488
});
482489

483490
toDownplay.length && api.dispatchAction({

src/component/axisPointer/globalListener.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { Dictionary } from 'zrender/src/core/types';
2828
type DispatchActionMethod = ExtensionAPI['dispatchAction'];
2929

3030
type Handler = (
31-
currTrigger: 'click' | 'mousemove' | 'leave',
31+
currTrigger: 'click' | 'mousemove' | 'mousewheel' | 'leave',
3232
event: ZRElementEvent,
3333
dispatchAction: DispatchActionMethod
3434
) => void;
@@ -59,13 +59,6 @@ interface Pendings {
5959
const inner = makeInner<InnerStore, ZRenderType>();
6060
const each = zrUtil.each;
6161

62-
/**
63-
* @param {string} key
64-
* @param {module:echarts/ExtensionAPI} api
65-
* @param {Function} handler
66-
* param: {string} currTrigger
67-
* param: {Array.<number>} point
68-
*/
6962
export function register(key: string, api: ExtensionAPI, handler?: Handler) {
7063
if (env.node) {
7164
return;
@@ -89,6 +82,10 @@ function initGlobalListeners(zr: ZRenderType, api?: ExtensionAPI) {
8982

9083
useHandler('click', zrUtil.curry(doEnter, 'click'));
9184
useHandler('mousemove', zrUtil.curry(doEnter, 'mousemove'));
85+
// For example, dataZoom may update series layout while mousewheel,
86+
// axisPointer and tooltip need to follow that updates, otherwise,
87+
// highlighted items (by axisPointer) may have no chance to downplay.
88+
useHandler('mousewheel', zrUtil.curry(doEnter, 'mousewheel'));
9289
// useHandler('mouseout', onLeave);
9390
useHandler('globalout', onLeave);
9491

@@ -134,7 +131,7 @@ function onLeave(
134131
}
135132

136133
function doEnter(
137-
currTrigger: 'click' | 'mousemove' | 'leave',
134+
currTrigger: 'click' | 'mousemove' | 'mousewheel' | 'leave',
138135
record: Record,
139136
e: ZRElementEvent,
140137
dispatchAction: DispatchActionMethod

src/component/tooltip/TooltipModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class TooltipModel extends ComponentModel<TooltipOption> {
106106
trigger: 'item',
107107

108108
// 'click' | 'mousemove' | 'none'
109-
triggerOn: 'mousemove|click',
109+
triggerOn: 'mousemove|click|mousewheel',
110110

111111
alwaysShowContent: false,
112112

src/util/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1586,8 +1586,9 @@ export interface CommonTooltipOption<FormatterParams> {
15861586

15871587
/**
15881588
* When to trigger
1589+
* NOTE: mousewheel may modify view by dataZoom.
15891590
*/
1590-
triggerOn?: 'mousemove' | 'click' | 'none' | 'mousemove|click'
1591+
triggerOn?: 'mousemove' | 'click' | 'none' | 'mousewheel' | 'mousemove|click|mousewheel'
15911592
/**
15921593
* Whether to not hide popup content automatically
15931594
*/

0 commit comments

Comments
 (0)