From 002773ff0e0b6c652ff6ab58af274f1a4ef3553e Mon Sep 17 00:00:00 2001 From: wisonic-s Date: Thu, 23 Oct 2025 18:01:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9B=BE=E8=A1=A8):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=9F=A9=E5=BD=A2=E6=A0=91=E5=9B=BE=E6=A0=87=E7=AD=BE=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E8=A7=A6=E5=8F=91=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../panel/charts/g2/distribution/treemap.ts | 56 ++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/distribution/treemap.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/distribution/treemap.ts index 5e4a10d408..60aa0f12cb 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/distribution/treemap.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/distribution/treemap.ts @@ -86,8 +86,8 @@ export class Treemap extends G2ChartView { } } const total = data.reduce((pre, next) => pre + (next.value ?? 0), 0) - const options = this.setupOptions(chart, baseOptions, { total }) const newChart = new G2Chart({ container }) + const options = this.setupOptions(chart, baseOptions, { total, chartObj: newChart }) handleChartDashboardHidden(chart, options) newChart.options(options) newChart.on('polygon:click', action) @@ -337,13 +337,65 @@ export class Treemap extends G2ChartView { return options } + protected configLabelTooltip( + chart: Chart, + options: G2Spec, + context: Record + ): G2Spec { + const { label, tooltip } = parseJson(chart.customAttr) + if (!label.show || !tooltip.show) { + return options + } + defaultsDeep(options, { + interaction: { + tooltip: { + clickLock: true + } + } + }) + const { chartObj } = context + chartObj.on('label:pointermove', e => { + const { target } = e + const parentElement = target.attributes.dependentElement + const offsetX = parentElement.attributes.x + parentElement.attributes.width / 2 + const offsetY = parentElement.attributes.y + parentElement.attributes.height / 2 + const { canvas } = chartObj.getContext() + const { document } = canvas! + const plot = document.querySelector('.plot') + if (!plot) { + return + } + plot.setAttribute('tooltipLocked', true) + chartObj.emit('tooltip:show', { + offsetX, + offsetY, + data: { + data: { + id: e.data.data.id + } + } + }) + }) + chartObj.on('label:pointerout', () => { + const { canvas } = chartObj.getContext() + const { document } = canvas! + const plot = document.querySelector('.plot') + if (plot) { + plot.setAttribute('tooltipLocked', false) + } + chartObj.emit('tooltip:hide') + }) + return options + } + protected setupOptions(chart: Chart, options: G2Spec, context: Record): G2Spec { return flow( this.configTheme, this.configColor, this.configLabel, this.configTooltip, - this.configLegend + this.configLegend, + this.configLabelTooltip )(chart, options, context, this) }