From 82a395a70207aa78fdfa66b11d01c335eccf64d8 Mon Sep 17 00:00:00 2001 From: jianneng-fit2cloud Date: Fri, 24 May 2024 17:40:29 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=9B=BE=E8=A1=A8-=E8=BF=9B=E5=BA=A6?= =?UTF-8?q?=E6=9D=A1):=20=E6=94=AF=E6=8C=81=E7=A9=BA=E7=BD=AE=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=8A=9F=E8=83=BD=E5=8F=8A=E8=AE=BE=E7=BD=AE=E5=9B=BE?= =?UTF-8?q?=E5=BD=A2=E4=B8=8D=E9=80=8F=E6=98=8E=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../js/panel/charts/bar/progress-bar.ts | 59 +++++++++++++++---- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/bar/progress-bar.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/bar/progress-bar.ts index 9dea6034a2..7039f4d1d9 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/bar/progress-bar.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/bar/progress-bar.ts @@ -9,6 +9,7 @@ import { } from '@/views/chart/components/js/panel/charts/bar/common' import { cloneDeep, defaultTo } from 'lodash-es' import { valueFormatter } from '@/views/chart/components/js/formatter' +import { Options } from '@antv/g2plot/esm' const { t } = useI18n() @@ -38,6 +39,7 @@ export class ProgressBar extends G2PlotChartView { 'tooltip-selector', 'y-axis-selector', 'title-selector', + 'function-cfg', 'jump-set', 'linkage' ] @@ -45,10 +47,11 @@ export class ProgressBar extends G2PlotChartView { ...BAR_EDITOR_PROPERTY_INNER, 'legend-selector': null, 'background-overall-component': ['all'], - 'basic-style-selector': ['colors', 'gradient'], + 'basic-style-selector': ['colors', 'alpha', 'gradient'], 'label-selector': ['hPosition', 'color', 'fontSize'], 'tooltip-selector': ['fontSize', 'color', 'backgroundColor', 'tooltipFormatter'], - 'y-axis-selector': ['name', 'color', 'fontSize', 'axisForm', 'axisLabel', 'position'] + 'y-axis-selector': ['name', 'color', 'fontSize', 'axisForm', 'axisLabel', 'position'], + 'function-cfg': ['emptyDataStrategy'] } axis: AxisType[] = [...BAR_AXIS_TYPE, 'yAxisExt'] protected baseOptions: BarOptions = { @@ -133,18 +136,14 @@ export class ProgressBar extends G2PlotChartView { const basicStyle = parseJson(chart.customAttr).basicStyle let color1 = basicStyle.colors?.map((ele, index) => { if (index === 1) { - return hexColorToRGBA(ele, 10) + return hexColorToRGBA(ele, basicStyle.alpha > 10 ? 10 : basicStyle.alpha) } else { - return ele + return hexColorToRGBA(ele, basicStyle.alpha) } }) if (basicStyle.gradient) { - color1 = color1.map((ele, index) => { - if (index === 1) { - return ele - } - const tmp = hexColorToRGBA(ele, basicStyle.alpha) - return setGradientColor(tmp, true, 0) + color1 = color1.map((ele, _index) => { + return setGradientColor(ele, true, 0) }) } options = { @@ -186,7 +185,7 @@ export class ProgressBar extends G2PlotChartView { const result = [] originalItems.forEach(item => { if (item.data) { - const value = valueFormatter(item.data.originalValue, tooltipAttr.tooltipFormatter) + const value = valueFormatter(item.data.value, tooltipAttr.tooltipFormatter) if (item.data.id === yAxis.id) { result.push({ ...item, @@ -275,6 +274,41 @@ export class ProgressBar extends G2PlotChartView { } } + protected configEmptyDataStrategy(chart: Chart, options: BarOptions): BarOptions { + 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).map(obj => obj['field']) + return { + ...options, + data: data.filter(obj => { + if (emptyFields.includes(obj['field'])) { + return false + } + return true + }) + } + } + if (strategy === 'breakLine') { + data.forEach(obj => { + if (obj['value'] === null) { + obj['value'] = null + } + }) + } + if (strategy === 'setZero') { + data.forEach(obj => { + if (obj['value'] === null) { + obj['value'] = 0 + } + }) + } + return options + } + protected setupOptions(chart: Chart, options: BarOptions): BarOptions { return flow( this.configTheme, @@ -282,7 +316,8 @@ export class ProgressBar extends G2PlotChartView { this.configLabel, this.configTooltip, this.configLegend, - this.configYAxis + this.configYAxis, + this.configEmptyDataStrategy )(chart, options) }