diff --git a/common/changes/@visactor/vchart/fix-dom-tooltip-title-order_2025-05-28-03-46.json b/common/changes/@visactor/vchart/fix-dom-tooltip-title-order_2025-05-28-03-46.json new file mode 100644 index 0000000000..44e03bb0a3 --- /dev/null +++ b/common/changes/@visactor/vchart/fix-dom-tooltip-title-order_2025-05-28-03-46.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "fix: fix the order of title in mark tooltip when dimension tooltip has no title, fix #3991\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 6117d22905..17a51b7fbb 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 @@ -202,6 +202,7 @@ export class DomTooltipHandler extends BaseTooltipHandler { const rowStyle = this._domStyle.row; const chilren = [...(this._rootDom.children as any)] as HTMLElement[]; let titleDom = chilren.find(child => child.className.includes(TOOLTIP_TITLE_CLASS_NAME)); + let contentDom = chilren.find(child => child.className.includes(TOOLTIP_CONTENT_BOX_CLASS_NAME)); if (!titleDom && title.visible !== false) { titleDom = document.createElement('h2'); @@ -209,7 +210,13 @@ export class DomTooltipHandler extends BaseTooltipHandler { titleDom.appendChild(span); titleDom.classList.add(TOOLTIP_TITLE_CLASS_NAME); - this._rootDom.appendChild(titleDom); + + // 将 titleDom 插入到 this._rootDom 中作为第一个节点 + if (this._rootDom.firstChild) { + this._rootDom.insertBefore(titleDom, this._rootDom.firstChild); + } else { + this._rootDom.appendChild(titleDom); + } } if (titleDom && title.visible !== false) { @@ -223,7 +230,6 @@ export class DomTooltipHandler extends BaseTooltipHandler { titleDom.parentNode.removeChild(titleDom); } - let contentDom = chilren.find(child => child.className.includes(TOOLTIP_CONTENT_BOX_CLASS_NAME)); const columns = ['shape', 'key', 'value']; if (!contentDom && hasContent) {