From 74f840e0fc89fcd2fcdb6eccee6861550dc4db8d Mon Sep 17 00:00:00 2001 From: wisonic-s Date: Wed, 25 Oct 2023 15:49:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8A=98=E7=BA=BF=E5=9B=BE=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E5=AD=90=E7=BB=B4=E5=BA=A6=E6=97=B6=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E7=B1=BB=E5=88=AB=E6=98=BE=E7=A4=BA=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/CollapseSwitchItem.vue | 2 +- .../components/js/panel/charts/line/line.ts | 60 ++++++++++++++++++- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/core/core-frontend/src/components/collapse-switch-item/src/CollapseSwitchItem.vue b/core/core-frontend/src/components/collapse-switch-item/src/CollapseSwitchItem.vue index 03e4972117..4476ca562f 100644 --- a/core/core-frontend/src/components/collapse-switch-item/src/CollapseSwitchItem.vue +++ b/core/core-frontend/src/components/collapse-switch-item/src/CollapseSwitchItem.vue @@ -49,7 +49,7 @@ const switchValue = computed({ :effect="themes" size="small" v-model="switchValue" - @click.stop="e => onSwitchChange(e)" + @click.stop="onSwitchChange" /> diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/line/line.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/line/line.ts index 4e43f0b772..600b280ebb 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/line/line.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/line/line.ts @@ -5,7 +5,7 @@ import { import { Line as G2Line, LineOptions } from '@antv/g2plot/esm/plots/line' import { getPadding } from '../../common/common_antv' import { flow, hexColorToRGBA, parseJson } from '@/views/chart/components/js/util' -import { cloneDeep } from 'lodash-es' +import { cloneDeep, isEmpty } from 'lodash-es' import { valueFormatter } from '@/views/chart/components/js/formatter' import { LINE_AXIS_TYPE, @@ -214,11 +214,67 @@ export class Line extends G2PlotChartView { return tmpOptions } + protected configTooltip(chart: Chart, options: LineOptions): LineOptions { + const customAttr: DeepPartial = parseJson(chart.customAttr) + const tooltipAttr = customAttr.tooltip + if (!tooltipAttr.show) { + return { + ...options, + tooltip: false + } + } + const xAxisExt = chart.xAxisExt + const formatterMap = tooltipAttr.seriesTooltipFormatter + ?.filter(i => i.show) + .reduce((pre, next) => { + pre[next.id] = next + return pre + }, {}) as Record + const tooltip: LineOptions['tooltip'] = { + showTitle: true, + customItems(originalItems) { + if (!tooltipAttr.seriesTooltipFormatter?.length) { + return originalItems + } + const head = originalItems[0] + // 非原始数据 + if (!head.data.quotaList) { + return originalItems + } + const result = [] + originalItems + .filter(item => formatterMap[item.data.quotaList[0].id]) + .forEach(item => { + const formatter = formatterMap[item.data.quotaList[0].id] + const value = valueFormatter(parseFloat(item.value as string), formatter.formatterCfg) + let name = isEmpty(formatter.chartShowName) ? formatter.name : formatter.chartShowName + if (xAxisExt?.length > 0) { + name = item.data.category + } + result.push({ ...item, name, value }) + }) + head.data.dynamicTooltipValue?.forEach(item => { + const formatter = formatterMap[item.fieldId] + if (formatter) { + const value = valueFormatter(parseFloat(item.value), formatter.formatterCfg) + const name = isEmpty(formatter.chartShowName) ? formatter.name : formatter.chartShowName + result.push({ color: 'grey', name, value }) + } + }) + return result + } + } + return { + ...options, + tooltip + } + } + protected setupOptions(chart: Chart, options: LineOptions): LineOptions { return flow( this.configTheme, this.configLabel, - this.configMultiSeriesTooltip, + this.configTooltip, this.configBasicStyle, this.configCustomColors, this.configLegend,