From e1172c12dc998d220a7ffc8e97c75d89696fa788 Mon Sep 17 00:00:00 2001 From: jianneng-fit2cloud Date: Mon, 27 May 2024 14:30:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9B=BE=E8=A1=A8-=E5=AF=B9=E7=A7=B0?= =?UTF-8?q?=E6=9F=B1=E7=8A=B6=E5=9B=BE):=20=E4=BF=AE=E5=A4=8D=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E7=B1=BB=E5=9E=8B=E5=AD=97=E6=AE=B5=E4=BD=9C=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E6=97=B6=EF=BC=8C=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=8F=8A=E6=8E=92=E5=BA=8F=E6=97=A0=E6=95=88?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../js/panel/charts/bar/bidirectional-bar.ts | 64 +++++++++++++++++-- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/bar/bidirectional-bar.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/bar/bidirectional-bar.ts index 1e3953984c..e35acd82cc 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/bar/bidirectional-bar.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/bar/bidirectional-bar.ts @@ -16,6 +16,7 @@ import { import { flow, hexColorToRGBA, parseJson } from '@/views/chart/components/js/util' import { useI18n } from '@/hooks/web/useI18n' import { valueFormatter } from '@/views/chart/components/js/formatter' +import { Options } from '@antv/g2plot/esm' const { t } = useI18n() /** * 对称柱状图 @@ -118,11 +119,27 @@ export class BidirectionalHorizontalBar extends G2PlotChartView< }, interactions: [{ type: 'active-region' }], yField: ['value', 'valueExt'], - appendPadding: getPadding(chart) + appendPadding: getPadding(chart), + meta: { + field: { + type: 'cat' + } + } + } + const customOptions = this.setupOptions(chart, initOptions) + const options = { + ...customOptions + } + const xAxis = chart.xAxis + if (xAxis?.length === 1 && xAxis[0].deType === 1) { + const values = data2.map(item => item.field) + options.meta = { + field: { + type: 'cat', + values: values.reverse() + } + } } - - const options = this.setupOptions(chart, initOptions) - // 开始渲染 const newChart = new G2BidirectionalBar(container, options) @@ -418,6 +435,45 @@ export class BidirectionalHorizontalBar extends G2PlotChartView< return { ...options, label } } + protected configEmptyDataStrategy( + chart: Chart, + options: BidirectionalBarOptions + ): BidirectionalBarOptions { + const { data } = options as unknown as Options + if (!data?.length) { + return options + } + const strategy = parseJson(chart.senior).functionCfg.emptyDataStrategy + if (strategy === 'ignoreData') { + const emptyFields = data + .filter(obj => obj['value'] === null || obj['valueExt'] === null) + .map(obj => obj['field']) + return { + ...options, + data: data.filter(obj => { + if (emptyFields.includes(obj['field'])) { + return false + } + return true + }) + } + } + const updateValues = (strategy: 'breakLine' | 'setZero', data: any[]) => { + data.forEach(obj => { + if (obj['value'] === null) { + obj['value'] = strategy === 'breakLine' ? null : 0 + } + if (obj['valueExt'] === null) { + obj['valueExt'] = strategy === 'breakLine' ? null : 0 + } + }) + } + if (strategy === 'breakLine' || strategy === 'setZero') { + updateValues(strategy, data) + } + return options + } + protected setupOptions(chart: Chart, options: BidirectionalBarOptions) { return flow( this.configTheme,