From 2e88d3cb42386b9900a74dca65872a0f47276710 Mon Sep 17 00:00:00 2001 From: wisonic-s Date: Mon, 19 Feb 2024 13:01:49 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E8=A7=86=E5=9B=BE):=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E8=A7=86=E5=9B=BE=E7=9A=84=E9=BB=98=E8=AE=A4=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core-frontend/src/models/chart/chart-attr.d.ts | 2 +- .../components/js/panel/charts/liquid/liquid.ts | 14 ++++++++++++++ .../components/js/panel/charts/others/funnel.ts | 4 ++++ .../components/js/panel/charts/others/gauge.ts | 14 ++++++++++++++ .../components/js/panel/charts/others/treemap.ts | 14 ++++++++++++++ .../chart/components/js/panel/charts/pie/pie.ts | 8 ++++++++ .../chart/components/js/panel/charts/pie/rose.ts | 7 +++++++ 7 files changed, 62 insertions(+), 1 deletion(-) diff --git a/core/core-frontend/src/models/chart/chart-attr.d.ts b/core/core-frontend/src/models/chart/chart-attr.d.ts index 51c8e5f8b1..5c96d15a1d 100644 --- a/core/core-frontend/src/models/chart/chart-attr.d.ts +++ b/core/core-frontend/src/models/chart/chart-attr.d.ts @@ -532,7 +532,7 @@ declare interface ChartLabelAttr { /** * 标签格式化设置 */ - labelFormatter: BaseFormatter + labelFormatter: Partial /** * 标签保留小数位数 */ diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/liquid/liquid.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/liquid/liquid.ts index 766ea58a48..8bc3c5ef02 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/liquid/liquid.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/liquid/liquid.ts @@ -146,6 +146,20 @@ export class Liquid extends G2PlotChartView { } } + setupDefaultOptions(chart: ChartObj): ChartObj { + chart.customAttr.label = { + ...chart.customAttr.label, + fontSize: 12, + show: true, + labelFormatter: { + type: 'percent', + thousandSeparator: true, + decimalCount: 2 + } + } + return chart + } + protected setupOptions(chart: Chart, options: LiquidOptions): LiquidOptions { return flow(this.configTheme, this.configMisc, this.configLabel)(chart, options) } diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/others/funnel.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/others/funnel.ts index dc3581c0f2..6e2508b04d 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/others/funnel.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/others/funnel.ts @@ -130,6 +130,10 @@ export class Funnel extends G2PlotChartView { if (!['left', 'middle', 'right'].includes(label.position)) { label.position = 'middle' } + customAttr.label = { + ...label, + show: true + } return chart } diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/others/gauge.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/others/gauge.ts index 144ef73ff4..1c51333171 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/others/gauge.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/others/gauge.ts @@ -248,6 +248,20 @@ export class Gauge extends G2PlotChartView { return { ...options, statistic } } + setupDefaultOptions(chart: ChartObj): ChartObj { + chart.customAttr.label = { + ...chart.customAttr.label, + show: true, + labelFormatter: { + type: 'value', + thousandSeparator: true, + decimalCount: 0, + unit: 1 + } + } + return chart + } + protected setupOptions(chart: Chart, options: GaugeOptions, ...extra: any[]): GaugeOptions { return flow( this.configTheme, diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/others/treemap.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/others/treemap.ts index 9041270911..183e178b1f 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/others/treemap.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/others/treemap.ts @@ -199,6 +199,20 @@ export class Treemap extends G2PlotChartView { } return { ...options, label } } + + setupDefaultOptions(chart: ChartObj): ChartObj { + const customAttr = chart.customAttr + const { label } = customAttr + customAttr.label = { + ...label, + show: true, + showDimension: true, + showProportion: true, + reserveDecimalCount: 2 + } + return chart + } + protected setupOptions(chart: Chart, options: TreemapOptions): TreemapOptions { return flow( this.configTheme, diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/pie/pie.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/pie/pie.ts index a84d3b8eeb..d01b48dc62 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/pie/pie.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/pie/pie.ts @@ -116,6 +116,7 @@ export class Pie extends G2PlotChartView { } const label = { type: labelAttr.position === 'outer' ? 'spider' : labelAttr.position, + layout: [{ type: 'limit-in-plot' }], autoRotate: false, style: { fill: labelAttr.color, @@ -222,6 +223,13 @@ export class Pie extends G2PlotChartView { if (!['inner', 'outer'].includes(label.position)) { label.position = 'outer' } + customAttr.label = { + ...label, + show: true, + showDimension: true, + showProportion: true, + reserveDecimalCount: 2 + } return chart } diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/pie/rose.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/pie/rose.ts index eb27a667c8..3916a3ab75 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/pie/rose.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/pie/rose.ts @@ -208,6 +208,13 @@ export class Rose extends G2PlotChartView { if (!['inner', 'outer'].includes(label.position)) { label.position = 'outer' } + customAttr.label = { + ...label, + show: true, + showDimension: true, + showProportion: true, + reserveDecimalCount: 2 + } return chart }