Skip to content

Commit aec999a

Browse files
authored
Merge pull request #4169 from VisActor/fix/fix-bug-of-click-legend-markline
fix: fix bug of tooltip first show position
2 parents f6f06c5 + 683fa3e commit aec999a

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

packages/vchart/src/component/marker/mark-point/cartesian-mark-point.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class CartesianMarkPoint extends BaseMarkPoint {
3333
let point: IPoint;
3434

3535
if (isXYLayout) {
36-
point = xyLayout(data, relativeSeries, relativeSeries, relativeSeries, autoRange)[0][0];
36+
point = xyLayout(data, relativeSeries, relativeSeries, relativeSeries, autoRange)?.[0]?.[0];
3737
} else if (isCoordinateLayout) {
3838
point = cartesianCoordinateLayout(
3939
data,

packages/vchart/src/plugin/components/tooltip-handler/dom-tooltip-handler.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ export class DomTooltipHandler extends BaseTooltipHandler {
9393
const tooltipSpec = this._component.getSpec() as ITooltipSpec;
9494
const tooltipElement = document.createElement('div');
9595
const themeFontFamily = this._chartOption?.getTheme('fontFamily');
96-
9796
setStyleToDom(tooltipElement, {
9897
left: '0',
9998
top: '0',
@@ -156,35 +155,33 @@ export class DomTooltipHandler extends BaseTooltipHandler {
156155
if (!params.changePositionOnly) {
157156
this._tooltipActual = activeTooltipSpec;
158157
}
159-
const currentVisible = this.getVisibility();
160-
161158
// 位置
162159
const el = this._rootDom;
163160
if (el) {
164161
const { x = 0, y = 0 } = activeTooltipSpec.position ?? {};
162+
let position = { x, y };
163+
const currentVisible = this.getVisibility();
165164
if (tooltipSpec.updateElement) {
166165
// 此处先设定一次位置,防止页面暂时出现滚动条(优先设置上次的位置)
167166
this._updatePosition(this._cacheCustomTooltipPosition ?? { x, y });
168167
// 更新 tooltip dom
169168
tooltipSpec.updateElement(el, activeTooltipSpec, params);
170169
// 重新计算 tooltip 位置
171-
const position = this._getActualTooltipPosition(activeTooltipSpec, params, {
170+
position = this._getActualTooltipPosition(activeTooltipSpec, params, {
172171
width: el.offsetWidth,
173172
height: el.offsetHeight
174173
});
175-
// 更新位置
176-
this._updatePosition(position);
177174
// 更新缓存
178175
this._cacheCustomTooltipPosition = position;
179-
} else {
180-
if (!currentVisible) {
181-
// 当从隐藏切换到显示的时候,需要先设置一次 transition 为 0ms,防止出现从一个非常远的初始位置进行动画
182-
this._rootDom.style.transitionDuration = '0ms';
183-
} else {
184-
this._rootDom.style.transitionDuration = this._domStyle.panel.transitionDuration ?? 'initial';
185-
}
186-
this._updatePosition({ x, y });
187176
}
177+
// 首次从false展示需要先设置一次位置,防止出现从一个非常远的初始位置进行动画
178+
if (!currentVisible && visible) {
179+
this._rootDom.style.transition = 'none';
180+
this._updatePosition(position, false);
181+
this._rootDom.getBoundingClientRect();
182+
}
183+
// 更新位置
184+
this._updatePosition(position);
188185
}
189186
this.setVisibility(visible);
190187
}
@@ -417,10 +414,14 @@ export class DomTooltipHandler extends BaseTooltipHandler {
417414
}
418415
}
419416

420-
protected _updatePosition({ x, y }: ITooltipPositionActual) {
417+
protected _updatePosition({ x, y }: ITooltipPositionActual, resetTransition = true) {
421418
if (this._rootDom) {
422419
// translate3d 性能较好:https://stackoverflow.com/questions/22111256/translate3d-vs-translate-performance
423420
this._rootDom.style.transform = `translate3d(${x}px, ${y}px, 0)`;
421+
if (resetTransition && this._rootDom.style.transition !== '') {
422+
this._rootDom.style.transition = '';
423+
Object.assign(this._rootDom.style, this._domStyle.panel);
424+
}
424425
}
425426
}
426427
}

0 commit comments

Comments
 (0)