From af17fe327533ad6da55c1f6fca515e20afb6b6fd Mon Sep 17 00:00:00 2001 From: wisonic Date: Thu, 14 Aug 2025 14:28:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=9B=BE=E8=A1=A8):=20=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E6=9D=A1=E5=BD=A2=E5=9B=BE/=E6=9F=B1=E7=8A=B6=E5=9B=BE?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=82=B9=E5=87=BB=E9=98=B4=E5=BD=B1=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=89=A7=E8=A1=8C=E4=B8=8B=E9=92=BB=E3=80=81=E8=81=94?= =?UTF-8?q?=E5=8A=A8=E3=80=81=E8=B7=B3=E8=BD=AC=20#16489?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/js/panel/charts/bar/bar.ts | 31 +++++++++++++++++++ .../js/panel/charts/bar/horizontal-bar.ts | 31 +++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/bar/bar.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/bar/bar.ts index e22035cd97..daaa28fb17 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/bar/bar.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/bar/bar.ts @@ -37,6 +37,7 @@ import { } from '@/views/chart/components/editor/util/chart' import { clearExtremum, extremumEvt } from '@/views/chart/components/js/extremumUitl' import { Group } from '@antv/g-canvas' +import { getItemsOfView } from '@antv/g2/lib/interaction/action/active-region' const { t } = useI18n() const DEFAULT_DATA: any[] = [] @@ -101,6 +102,36 @@ export class Bar extends G2PlotChartView { const { Column: ColumnClass } = await import('@antv/g2plot/esm/plots/column') newChart = new ColumnClass(container, options) newChart.on('interval:click', action) + // 只处理柱状图,分组和堆叠的阴影部分没有子维度信息 + if (this.name === 'bar' && options.tooltip) { + newChart.on('plot:click', e => { + if (e.target?.cfg?.renderer !== 'canvas') { + return + } + const activeRegion = e.view.backgroundGroup.cfg.children.find( + i => i.cfg.name === 'active-region' + ) + if (activeRegion?.cfg.visible) { + const items = getItemsOfView( + e.view, + { x: e.x, y: e.y }, + e.view.getController('tooltip').getTooltipCfg() + ) + if (items?.length) { + const datum = items[0].data + if (datum && datum.field) { + action({ + x: e.x, + y: e.y, + data: { + data: datum + } + }) + } + } + } + }) + } extremumEvt(newChart, chart, options, container) configPlotTooltipEvent(chart, newChart) return newChart diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/bar/horizontal-bar.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/bar/horizontal-bar.ts index 29947104c0..9f5c8cd204 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/bar/horizontal-bar.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/bar/horizontal-bar.ts @@ -35,6 +35,7 @@ import { DEFAULT_LEGEND_STYLE } from '@/views/chart/components/editor/util/chart' import { Group } from '@antv/g-canvas' +import { getItemsOfView } from '@antv/g2/lib/interaction/action/active-region' const { t } = useI18n() const DEFAULT_DATA = [] @@ -119,6 +120,36 @@ export class HorizontalBar extends G2PlotChartView { }) }) } + // 只处理条形图,分组和堆叠的阴影部分没有子维度信息 + if (this.name === 'bar-horizontal' && options.tooltip) { + newChart.on('plot:click', e => { + if (e.target?.cfg?.renderer !== 'canvas') { + return + } + const activeRegion = e.view.backgroundGroup.cfg.children.find( + i => i.cfg.name === 'active-region' + ) + if (activeRegion?.cfg.visible) { + const items = getItemsOfView( + e.view, + { x: e.x, y: e.y }, + e.view.getController('tooltip').getTooltipCfg() + ) + if (items?.length) { + const datum = items[0].data + if (datum && datum.field) { + action({ + x: e.x, + y: e.y, + data: { + data: datum + } + }) + } + } + } + }) + } configPlotTooltipEvent(chart, newChart) configAxisLabelLengthLimit(chart, newChart) return newChart