Skip to content

Commit

Permalink
Merge pull request #15683 from apache/fix-tooltip
Browse files Browse the repository at this point in the history
fix(tooltip): tooltip may be lagged and shake in Chrome(with the devtools open) and Firefox.
  • Loading branch information
100pah committed Sep 14, 2021
2 parents 233d2a1 + f4590f1 commit 6641951
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/component/tooltip/TooltipView.ts
Expand Up @@ -57,6 +57,7 @@ import { DataByCoordSys, DataByAxis } from '../axisPointer/axisTrigger';
import { normalizeTooltipFormatResult } from '../../model/mixin/dataFormat';
import { createTooltipMarkup, buildTooltipMarkup, TooltipMarkupStyleCreator } from './tooltipMarkup';
import { findEventDispatcher } from '../../util/event';
import { throttle } from '../../util/throttle';

const bind = zrUtil.bind;
const each = zrUtil.each;
Expand Down Expand Up @@ -167,6 +168,8 @@ class TooltipView extends ComponentView {
private _lastDataByCoordSys: DataByCoordSys[];
private _cbParamsList: TooltipCallbackDataParams[];

private _updatePosition: ReturnType<typeof throttle> | TooltipView['_doUpdatePosition'];

init(ecModel: GlobalModel, api: ExtensionAPI) {
if (env.node) {
return;
Expand Down Expand Up @@ -214,6 +217,17 @@ class TooltipView extends ComponentView {
this._initGlobalListener();

this._keepShow();

// PENDING
// `mousemove` event will be triggered very frequently when the mouse moves fast,
// which causes that the updatePosition was also called very frequently.
// In Chrome with devtools open and Firefox, tooltip looks lagged and shaked around. See #14695.
// To avoid the frequent triggering,
// consider throttling it in 50ms. (the tested result may need to validate)
this._updatePosition =
this._renderMode === 'html'
? throttle(bind(this._doUpdatePosition, this), 50)
: this._doUpdatePosition;
}

private _initGlobalListener() {
Expand Down Expand Up @@ -856,7 +870,7 @@ class TooltipView extends ComponentView {
}
}

private _updatePosition(
private _doUpdatePosition(
tooltipModel: Model<TooltipOption>,
positionExpr: TooltipOption['position'],
x: number, // Mouse x
Expand Down
121 changes: 121 additions & 0 deletions test/tooltip-lag-glitch.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6641951

Please sign in to comment.