From 5236b007a89425e9e00385005d2a4635ef4fa20a Mon Sep 17 00:00:00 2001 From: jianneng-fit2cloud Date: Thu, 18 Sep 2025 18:17:29 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9B=BE=E8=A1=A8):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=9F=B1=E6=9D=A1=E5=9B=BE=E6=8F=90=E7=A4=BA=E7=9A=84=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E9=9A=90=E8=97=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/js/panel/charts/g2/bar/bar.ts | 11 +++------- .../js/panel/charts/g2/bar/bullet-graph.ts | 22 +++++++++++-------- .../js/panel/charts/g2/bar/group-stack-bar.ts | 14 +++--------- .../charts/g2/bar/percentage-stack-bar.ts | 14 +++--------- .../g2/bar/percentage-stack-horizontal-bar.ts | 9 +------- .../js/panel/charts/g2/bar/progress-bar.ts | 7 +++--- .../js/panel/charts/g2/bar/stack-bar.ts | 15 +++---------- .../charts/g2/bar/stack-horizontal-bar.ts | 1 - 8 files changed, 30 insertions(+), 63 deletions(-) diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/bar.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/bar.ts index 8024f0334e..3079253df8 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/bar.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/bar.ts @@ -83,6 +83,7 @@ export class Bar extends G2ChartView { background: true } }, + tooltip: false, transform: [{ type: 'dodgeX' } as Transform] } as ViewSpec @@ -188,11 +189,11 @@ export class Bar extends G2ChartView { } protected configTooltip(chart: Chart, options: ViewSpec): ViewSpec { + const { children } = options const customAttr: DeepPartial = parseJson(chart.customAttr) const tooltipAttr = customAttr.tooltip const yAxis = chart.yAxis if (!tooltipAttr.show) { - options.children[0].tooltip = false return options } const formatterMap = tooltipAttr.seriesTooltipFormatter @@ -258,13 +259,7 @@ export class Bar extends G2ChartView { } return { ...options, - children: [ - { - ...options.children[0], - ...tooltipOptions - }, - ...options.children.slice(1) - ] + children: [{ ...children[0], ...tooltipOptions }, ...children.slice(1)] } } diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/bullet-graph.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/bullet-graph.ts index a0caf0a7c8..d58710d143 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/bullet-graph.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/bullet-graph.ts @@ -155,7 +155,7 @@ export class BulletGraph extends G2ChartView { } protected configMisc(chart: Chart, options: RuntimeOptions): RuntimeOptions { - const { basicStyle } = parseJson(chart.customAttr) + const { basicStyle, tooltip } = parseJson(chart.customAttr) const { bullet } = parseJson(chart.customAttr).misc const isDynamic = bullet.bar.ranges.showType === 'dynamic' // 背景颜色,固定区间背景时,按大小降序 @@ -228,10 +228,12 @@ export class BulletGraph extends G2ChartView { style: { maxWidth: bullet.bar.measures.size }, - tooltip: { - title: d => d.title, - items: [{ channel: 'y' }] - } + tooltip: tooltip.show + ? { + title: d => d.title, + items: [{ channel: 'y' }] + } + : false } const targetName = chart.yAxisExt[0]?.chartShowName || bullet.bar.target.name || chart.yAxisExt[0]?.name @@ -247,10 +249,12 @@ export class BulletGraph extends G2ChartView { interaction: { legendFilter: false }, - tooltip: { - title: false, - items: [{ channel: 'y' }] - } + tooltip: tooltip.show + ? { + title: false, + items: [{ channel: 'y' }] + } + : false } childrens.push(target) childrens.push(measures) diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/group-stack-bar.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/group-stack-bar.ts index 0164c5bf33..46fd109ce1 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/group-stack-bar.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/group-stack-bar.ts @@ -63,12 +63,10 @@ export class GroupStackBar extends StackBar { } } protected configTooltip(chart: Chart, options: ViewSpec): ViewSpec { + const { children } = options const { tooltip } = parseJson(chart.customAttr) if (!tooltip.show) { - return { - ...options, - tooltip: false - } + return options } const tooltipMap = function (a) { return a @@ -117,13 +115,7 @@ export class GroupStackBar extends StackBar { } return { ...options, - children: [ - { - ...options.children[0], - ...tooltipOptions - }, - ...options.children.slice(1) - ] + children: [{ ...children[0], ...tooltipOptions }, ...children.slice(1)] } } diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/percentage-stack-bar.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/percentage-stack-bar.ts index d2ce328ee6..93f48cda33 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/percentage-stack-bar.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/percentage-stack-bar.ts @@ -69,12 +69,10 @@ export class PercentageStackBar extends GroupStackBar { } protected configTooltip(chart: Chart, options: ViewSpec): ViewSpec { + const { children } = options const { tooltip } = parseJson(chart.customAttr) if (!tooltip.show) { - return { - ...options, - tooltip: false - } + return options } const tooltipMap = function (a) { return a @@ -130,13 +128,7 @@ export class PercentageStackBar extends GroupStackBar { } return { ...options, - children: [ - { - ...options.children[0], - ...tooltipOptions - }, - ...options.children.slice(1) - ] + children: [{ ...children[0], ...tooltipOptions }, ...children.slice(1)] } } diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/percentage-stack-horizontal-bar.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/percentage-stack-horizontal-bar.ts index 80870784d2..0b5b3c60ac 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/percentage-stack-horizontal-bar.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/percentage-stack-horizontal-bar.ts @@ -64,7 +64,6 @@ export class PercentageStackBar extends HorizontalStackBar { const { tooltip } = parseJson(chart.customAttr) const { children } = options if (!tooltip.show) { - children[0].tooltip = false return options } const tooltipMap = function (a) { @@ -121,13 +120,7 @@ export class PercentageStackBar extends HorizontalStackBar { } return { ...options, - children: [ - { - ...options.children[0], - ...tooltipOptions - }, - ...options.children.slice(1) - ] + children: [{ ...children[0], ...tooltipOptions }, ...children.slice(1)] } } diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/progress-bar.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/progress-bar.ts index fcff3d35d2..d61bede184 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/progress-bar.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/progress-bar.ts @@ -164,7 +164,8 @@ export class ProgressBar extends HorizontalStackBar { scale: { color: { range: [] }, y: { nice: true } - } + }, + tooltip: false }, { type: 'interval', @@ -179,7 +180,8 @@ export class ProgressBar extends HorizontalStackBar { scale: { color: { type: 'identity' } }, - animate: false + animate: false, + tooltip: false } ] } @@ -253,7 +255,6 @@ export class ProgressBar extends HorizontalStackBar { const { children } = options const { tooltip } = parseJson(chart.customAttr) if (!tooltip.show) { - children[0].tooltip = false return options } children[0].tooltip = { diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/stack-bar.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/stack-bar.ts index f2b05c15ba..5c5c9076d5 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/stack-bar.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/stack-bar.ts @@ -106,18 +106,15 @@ export class StackBar extends Bar { } protected configTooltip(chart: Chart, options: ViewSpec): ViewSpec { + const { children } = options const { tooltip } = parseJson(chart.customAttr) if (!tooltip.show) { - return { - ...options, - tooltip: false - } + return options } const tooltipMap = function (a) { return a } tooltipMap.title = undefined - const tooltipOptions: ViewSpec = { tooltip: tooltipMap, interaction: { @@ -158,13 +155,7 @@ export class StackBar extends Bar { } return { ...options, - children: [ - { - ...options.children[0], - ...tooltipOptions - }, - ...options.children.slice(1) - ] + children: [{ ...children[0], ...tooltipOptions }, ...children.slice(1)] } } diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/stack-horizontal-bar.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/stack-horizontal-bar.ts index c61155d47e..8f97979715 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/stack-horizontal-bar.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/stack-horizontal-bar.ts @@ -75,7 +75,6 @@ export class HorizontalStackBar extends HorizontalBar { const { children } = options const { tooltip } = parseJson(chart.customAttr) if (!tooltip.show) { - children[0].tooltip = false return options }