From 5b8adc357dcafdb7a91487faf8ef7b73b9dfb671 Mon Sep 17 00:00:00 2001 From: junjun Date: Thu, 21 Jul 2022 14:13:07 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=A7=86=E5=9B=BE):=20=E6=95=B0=E5=80=BC?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/chart/chart/common/common_antv.js | 87 +++++++++++++++++++ .../components/drag-item/QuotaExtItem.vue | 2 +- .../chart/components/drag-item/QuotaItem.vue | 2 +- 3 files changed, 89 insertions(+), 2 deletions(-) diff --git a/frontend/src/views/chart/chart/common/common_antv.js b/frontend/src/views/chart/chart/common/common_antv.js index 79c92db299..69a69be62d 100644 --- a/frontend/src/views/chart/chart/common/common_antv.js +++ b/frontend/src/views/chart/chart/common/common_antv.js @@ -132,6 +132,31 @@ export function getLabel(chart) { fill: l.color, fontSize: parseInt(l.fontSize) } + // label value formatter + if (chart.type && chart.type !== 'waterfall') { + label.formatter = function(param) { + let yAxis + let res = param.value + try { + yAxis = JSON.parse(chart.yaxis) + } catch (e) { + yAxis = JSON.parse(JSON.stringify(chart.yaxis)) + } + + for (let i = 0; i < yAxis.length; i++) { + const f = yAxis[i] + if (f.name === param.category) { + if (f.formatterCfg) { + res = valueFormatter(param.value, f.formatterCfg) + } else { + res = valueFormatter(param.value, formatterItem) + } + break + } + } + return res + } + } } else { label = false } @@ -150,6 +175,68 @@ export function getTooltip(chart) { const t = JSON.parse(JSON.stringify(customAttr.tooltip)) if (t.show) { tooltip = {} + // tooltip value formatter + if (chart.type && chart.type !== 'waterfall') { + tooltip.formatter = function(param) { + let yAxis + let res + try { + yAxis = JSON.parse(chart.yaxis) + } catch (e) { + yAxis = JSON.parse(JSON.stringify(chart.yaxis)) + } + + let obj + if (chart.type === 'word-cloud') { + obj = { name: param.text, value: param.value } + for (let i = 0; i < yAxis.length; i++) { + const f = yAxis[i] + if (f.formatterCfg) { + res = valueFormatter(param.value, f.formatterCfg) + } else { + res = valueFormatter(param.value, formatterItem) + } + } + } else if (chart.type.includes('treemap')) { + obj = { name: param.name, value: param.value } + for (let i = 0; i < yAxis.length; i++) { + const f = yAxis[i] + if (f.formatterCfg) { + res = valueFormatter(param.value, f.formatterCfg) + } else { + res = valueFormatter(param.value, formatterItem) + } + } + } else if (chart.type.includes('pie') || chart.type.includes('funnel')) { + obj = { name: param.field, value: param.value } + for (let i = 0; i < yAxis.length; i++) { + const f = yAxis[i] + if (f.formatterCfg) { + res = valueFormatter(param.value, f.formatterCfg) + } else { + res = valueFormatter(param.value, formatterItem) + } + } + } else if (chart.type.includes('bar') || chart.type.includes('line') || chart.type.includes('scatter') || chart.type.includes('radar')) { + obj = { name: param.category, value: param.value } + for (let i = 0; i < yAxis.length; i++) { + const f = yAxis[i] + if (f.name === param.category) { + if (f.formatterCfg) { + res = valueFormatter(param.value, f.formatterCfg) + } else { + res = valueFormatter(param.value, formatterItem) + } + break + } + } + } else { + res = param.value + } + obj.value = res + return obj + } + } } else { tooltip = false } diff --git a/frontend/src/views/chart/components/drag-item/QuotaExtItem.vue b/frontend/src/views/chart/components/drag-item/QuotaExtItem.vue index 8f093a08ce..6da2657a2e 100644 --- a/frontend/src/views/chart/components/drag-item/QuotaExtItem.vue +++ b/frontend/src/views/chart/components/drag-item/QuotaExtItem.vue @@ -100,7 +100,7 @@ {{ $t('chart.filter') }}... - + {{ $t('chart.value_formatter') }}... diff --git a/frontend/src/views/chart/components/drag-item/QuotaItem.vue b/frontend/src/views/chart/components/drag-item/QuotaItem.vue index 95831b6a2f..80b65eb55b 100644 --- a/frontend/src/views/chart/components/drag-item/QuotaItem.vue +++ b/frontend/src/views/chart/components/drag-item/QuotaItem.vue @@ -100,7 +100,7 @@ {{ $t('chart.filter') }}... - + {{ $t('chart.value_formatter') }}...