diff --git a/common/changes/@visactor/vchart/fix-tooltip-element-height_2025-07-28-09-48.json b/common/changes/@visactor/vchart/fix-tooltip-element-height_2025-07-28-09-48.json new file mode 100644 index 0000000000..2db11a16bf --- /dev/null +++ b/common/changes/@visactor/vchart/fix-tooltip-element-height_2025-07-28-09-48.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "fix: fix height of tooltip element when set transform of container, fix #4109\n\n", + "type": "none", + "packageName": "@visactor/vchart" + } + ], + "packageName": "@visactor/vchart", + "email": "dingling112@gmail.com" +} \ No newline at end of file diff --git a/packages/vchart/src/plugin/components/tooltip-handler/dom-tooltip-handler.ts b/packages/vchart/src/plugin/components/tooltip-handler/dom-tooltip-handler.ts index cdd3d44ac2..96dda10b64 100644 --- a/packages/vchart/src/plugin/components/tooltip-handler/dom-tooltip-handler.ts +++ b/packages/vchart/src/plugin/components/tooltip-handler/dom-tooltip-handler.ts @@ -128,7 +128,7 @@ export class DomTooltipHandler extends BaseTooltipHandler { this._updateDomStringByCol(actualTooltip); } - this._updateDomStyle('height'); + this._updateDomStyle('height', changePositionOnly); const rect = this._rootDom?.getBoundingClientRect(); @@ -312,7 +312,7 @@ export class DomTooltipHandler extends BaseTooltipHandler { contentDom.parentNode.removeChild(contentDom); } } - protected _updateDomStyle(sizeKey: 'width' | 'height' = 'width') { + protected _updateDomStyle(sizeKey: 'width' | 'height' = 'width', refreshSize: boolean) { const rootDom = this._rootDom; const contentDom = [...(rootDom.children as any)].find(child => child.className.includes(TOOLTIP_CONTENT_BOX_CLASS_NAME) @@ -372,6 +372,11 @@ export class DomTooltipHandler extends BaseTooltipHandler { const cols = row.children ?? ([] as HTMLElement[]); for (let j = 0; j < cols.length; j++) { + if (refreshSize) { + // 每次更新,需要更新单元格的高度,防止同步高度的时候没有更新 + cols[j].style[sizeKey] = 'initial'; + } + const width = cols[j].getBoundingClientRect()[sizeKey]; if (widthByCol[j] === undefined || widthByCol[j] < width) { widthByCol[j] = width; @@ -408,7 +413,7 @@ export class DomTooltipHandler extends BaseTooltipHandler { if (this.getVisibility()) { this._updateDomStringByCol(this._tooltipActual); - this._updateDomStyle('height'); + this._updateDomStyle('height', false); } }