From 9d972ff739cd0a910f0d199a49a1ce2a5667f524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=98=89=E8=B1=AA?= <42510293+ziyujiahao@users.noreply.github.com> Date: Tue, 16 Dec 2025 17:42:42 +0800 Subject: [PATCH] Pr@dev v2@refactor tooltips (#17623) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * style: 样式调整 * refactor: 优化图表提示 --- .../components/TooltipSelector.vue | 29 +++++++++++++++---- .../views/chart/components/js/formatter.ts | 25 +++++++++------- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/core/core-frontend/src/views/chart/components/editor/editor-style/components/TooltipSelector.vue b/core/core-frontend/src/views/chart/components/editor/editor-style/components/TooltipSelector.vue index 7da217b071..cf32dc5c36 100644 --- a/core/core-frontend/src/views/chart/components/editor/editor-style/components/TooltipSelector.vue +++ b/core/core-frontend/src/views/chart/components/editor/editor-style/components/TooltipSelector.vue @@ -11,10 +11,11 @@ import { formatterType, getUnitTypeList, initFormatCfgUnit, - onChangeFormatCfgUnitLanguage + onChangeFormatCfgUnitLanguage, + mergeTooltipFormat } from '@/views/chart/components/js/formatter' import { fieldType } from '@/utils/attr' -import { defaultTo, partition, map, includes, isEmpty } from 'lodash-es' +import { defaultTo, partition, map, includes, isEmpty, merge } from 'lodash-es' import chartViewManager from '../../../js/panel' import { dvMainStoreWithOut } from '@/store/modules/data-visualization/dvMain' import { storeToRefs } from 'pinia' @@ -105,11 +106,17 @@ const changeDataset = () => { const formatterIds = formatter.map(i => i.id) quotaData.value.forEach(axis => { if (!formatterIds.includes(axis.id)) { - formatter.push({ + const formatterItem = { ...axis, seriesId: axis.id, show: false - }) + } + mergeTooltipFormat( + formatterItem, + props.chart.type, + dvMainStore.canvasStyleData.component.formatterItem + ) + formatter.push(formatterItem) } }) if (formatter[0]) { @@ -263,7 +270,19 @@ const init = () => { // 新增图表 const formatter = state.tooltipForm.seriesTooltipFormatter if (!formatter.length) { - quotaData.value?.forEach(i => formatter.push({ ...i, seriesId: i.id, show: false })) + quotaData.value?.forEach(axis => { + const formatterItem = { + ...axis, + seriesId: axis.id, + show: false + } + mergeTooltipFormat( + formatterItem, + props.chart.type, + dvMainStore.canvasStyleData.component.formatterItem + ) + formatter.push(formatterItem) + }) curSeriesFormatter.value = {} return } diff --git a/core/core-frontend/src/views/chart/components/js/formatter.ts b/core/core-frontend/src/views/chart/components/js/formatter.ts index 57aa895e14..03e67b00a4 100644 --- a/core/core-frontend/src/views/chart/components/js/formatter.ts +++ b/core/core-frontend/src/views/chart/components/js/formatter.ts @@ -256,6 +256,14 @@ export const calcNiceMinValue = (chart, options, tmpOptions) => { return { ...tmpOptions, ...axis } } +const unShowTooltipsFormatter = [ + 'table-info', + 'table-normal', + 'table-pivot', + 'stock-line', + 'bullet-graph', + 'percentage-bar-stack-horizontal' +] /** * 适配图表数字格式化属性 * @param viewInfo @@ -299,16 +307,7 @@ export const formatterViewInfo = (viewInfo, value) => { viewInfo['customAttr']['label']['totalFormatter'], value ) - if ( - ![ - 'table-info', - 'table-normal', - 'table-pivot', - 'stock-line', - 'bullet-graph', - 'percentage-bar-stack-horizontal' - ].includes(viewInfo.type) - ) { + if (!unShowTooltipsFormatter.includes(viewInfo.type)) { viewInfo['customAttr']['tooltip']['tooltipFormatter'] = merge( viewInfo['customAttr']['tooltip']['tooltipFormatter'], value @@ -332,3 +331,9 @@ export const formatterViewInfo = (viewInfo, value) => { value ) } + +export const mergeTooltipFormat = (item, type, value) => { + if (!unShowTooltipsFormatter.includes(type)) { + item['formatterCfg'] = merge(item['formatterCfg'], value) + } +}