Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions src/component/tooltip/TooltipView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import {
} from '../../util/types';
import GlobalModel from '../../model/Global';
import ExtensionAPI from '../../core/ExtensionAPI';
import TooltipModel, {TooltipOption} from './TooltipModel';
import TooltipModel, { TooltipOption } from './TooltipModel';
import Element from 'zrender/src/Element';
import { AxisBaseModel } from '../../coord/AxisBaseModel';
// import { isDimensionStacked } from '../../data/helper/dataStackHelper';
Expand All @@ -63,7 +63,7 @@ const each = zrUtil.each;
const parsePercent = numberUtil.parsePercent;

const proxyRect = new graphic.Rect({
shape: {x: -1, y: -1, width: 2, height: 2}
shape: { x: -1, y: -1, width: 2, height: 2 }
});

interface DataIndex {
Expand Down Expand Up @@ -165,6 +165,7 @@ class TooltipView extends ComponentView {
private _showTimout: number;

private _lastDataByCoordSys: DataByCoordSys[];
private _cbParamsList: TooltipCallbackDataParams[];

init(ecModel: GlobalModel, api: ExtensionAPI) {
if (env.node) {
Expand Down Expand Up @@ -599,7 +600,7 @@ class TooltipView extends ComponentView {
const allMarkupText = markupTextArrLegacy.join(blockBreak);

this._showOrMove(singleTooltipModel, function (this: TooltipView) {
if (this._updateContentNotChangedOnAxis(dataByCoordSys)) {
if (this._updateContentNotChangedOnAxis(dataByCoordSys, cbParamsList)) {
this._updatePosition(
singleTooltipModel,
positionExpr,
Expand Down Expand Up @@ -882,7 +883,7 @@ class TooltipView extends ComponentView {
boxLayoutPosition.width = contentSize[0];
boxLayoutPosition.height = contentSize[1];
const layoutRect = layoutUtil.getLayoutRect(
boxLayoutPosition, {width: viewWidth, height: viewHeight}
boxLayoutPosition, { width: viewWidth, height: viewHeight }
);
x = layoutRect.x;
y = layoutRect.y;
Expand Down Expand Up @@ -923,18 +924,20 @@ class TooltipView extends ComponentView {

// FIXME
// Should we remove this but leave this to user?
private _updateContentNotChangedOnAxis(dataByCoordSys: DataByCoordSys[]) {
private _updateContentNotChangedOnAxis(dataByCoordSys: DataByCoordSys[],
cbParamsList: TooltipCallbackDataParams[]) {
const lastCoordSys = this._lastDataByCoordSys;
const lastCbParamsList = this._cbParamsList;
let contentNotChanged = !!lastCoordSys
&& lastCoordSys.length === dataByCoordSys.length;

contentNotChanged && each(lastCoordSys, function (lastItemCoordSys, indexCoordSys) {
contentNotChanged && each(lastCoordSys, (lastItemCoordSys, indexCoordSys) => {
const lastDataByAxis = lastItemCoordSys.dataByAxis || [] as DataByAxis[];
const thisItemCoordSys = dataByCoordSys[indexCoordSys] || {} as DataByCoordSys;
const thisDataByAxis = thisItemCoordSys.dataByAxis || [] as DataByAxis[];
contentNotChanged = contentNotChanged && lastDataByAxis.length === thisDataByAxis.length;

contentNotChanged && each(lastDataByAxis, function (lastItem, indexAxis) {
contentNotChanged && each(lastDataByAxis, (lastItem, indexAxis) => {
const thisItem = thisDataByAxis[indexAxis] || {} as DataByAxis;
const lastIndices = lastItem.seriesDataIndices || [] as DataIndex[];
const newIndices = thisItem.seriesDataIndices || [] as DataIndex[];
Expand All @@ -945,16 +948,25 @@ class TooltipView extends ComponentView {
&& lastItem.axisId === thisItem.axisId
&& lastIndices.length === newIndices.length;

contentNotChanged && each(lastIndices, function (lastIdxItem, j) {
contentNotChanged && each(lastIndices, (lastIdxItem, j) => {
const newIdxItem = newIndices[j];
contentNotChanged = contentNotChanged
&& lastIdxItem.seriesIndex === newIdxItem.seriesIndex
&& lastIdxItem.dataIndex === newIdxItem.dataIndex;
});

// check is cbParams data value changed
lastCbParamsList && zrUtil.each(lastItem.seriesDataIndices, (idxItem) => {
const cbParams = cbParamsList[idxItem.seriesIndex];
if (cbParams && lastCbParamsList[idxItem.seriesIndex].data !== cbParams.data) {
contentNotChanged = false;
}
});
Comment on lines +959 to +964
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The late review is just FYI.

  1. This traversal each looks repeated with the above each (L951-L956). Maybe we can move this logic there as one of the conditions of contentNotChanged.

  2. Assuming 1 is not required, it's better to avoid invoking each if contentNotChanged has been already false and should use for loop rather than each so that we can return once contentNotChanged becomes false.

  3. We should consider the case that seriesData isn't changed but seriesName is changed, in which the tooltip should be also updated.

seriesName change

});
});

this._lastDataByCoordSys = dataByCoordSys;
this._cbParamsList = cbParamsList;

return !!contentNotChanged;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!! is not necessary. It must be boolean here.

}
Expand Down