From 825fc65963edee3f134c77ed0dc47e91bd174ffd Mon Sep 17 00:00:00 2001 From: ulleo Date: Mon, 22 Jan 2024 15:30:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A1=A8=E6=A0=BC=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=A0=BC=E6=8F=90=E7=A4=BA=E6=98=BE=E7=A4=BA=E4=B8=8D=E5=AE=8C?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/chart/chart/table/table-info.js | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/core/frontend/src/views/chart/chart/table/table-info.js b/core/frontend/src/views/chart/chart/table/table-info.js index aa338ae9b7..cfb436362d 100644 --- a/core/frontend/src/views/chart/chart/table/table-info.js +++ b/core/frontend/src/views/chart/chart/table/table-info.js @@ -1,20 +1,9 @@ -import { TableSheet, BaseEvent, S2Event, PivotSheet, DataCell, EXTRA_FIELD, TOTAL_VALUE } from '@antv/s2' +import { TableSheet, S2Event, PivotSheet, DataCell, EXTRA_FIELD, TOTAL_VALUE } from '@antv/s2' import { getCustomTheme, getSize } from '@/views/chart/chart/common/common_table' import { DEFAULT_COLOR_CASE, DEFAULT_TOTAL } from '@/views/chart/chart/chart' import { formatterItem, valueFormatter } from '@/views/chart/chart/formatter' import { handleTableEmptyStrategy, hexColorToRGBA } from '@/views/chart/chart/util' -import { maxBy, minBy } from 'lodash' - -class RowHoverInteraction extends BaseEvent { - bindEvents() { - this.spreadsheet.on(S2Event.ROW_CELL_HOVER, (event) => { - this.spreadsheet.tooltip.show({ - position: { x: 0, y: 0 }, - content: '...' - }) - }) - } -} +import { maxBy, minBy, find } from 'lodash-es' export function baseTableInfo(s2, container, chart, action, tableData, pageInfo) { const containerDom = document.getElementById(container) @@ -152,7 +141,7 @@ export function baseTableInfo(s2, container, chart, action, tableData, pageInfo) s2.on(S2Event.COL_CELL_HOVER, event => showTooltip(s2, event)) } if (size.tableCellTooltip?.show) { - s2.on(S2Event.DATA_CELL_HOVER, event => showTooltipValue(s2, event)) + s2.on(S2Event.DATA_CELL_HOVER, event => showTooltipValue(s2, event, meta)) } // theme const customTheme = getCustomTheme(chart) @@ -343,7 +332,7 @@ export function baseTableNormal(s2, container, chart, action, tableData) { s2.on(S2Event.COL_CELL_HOVER, event => showTooltip(s2, event)) } if (size.tableCellTooltip?.show) { - s2.on(S2Event.DATA_CELL_HOVER, event => showTooltipValue(s2, event)) + s2.on(S2Event.DATA_CELL_HOVER, event => showTooltipValue(s2, event, meta)) } // theme const customTheme = getCustomTheme(chart) @@ -562,7 +551,7 @@ export function baseTablePivot(s2, container, chart, action, headerAction, table s2.on(S2Event.COL_CELL_HOVER, event => showTooltip(s2, event, fieldMap)) } if (size.tableCellTooltip?.show) { - s2.on(S2Event.DATA_CELL_HOVER, event => showTooltipValue(s2, event)) + s2.on(S2Event.DATA_CELL_HOVER, event => showTooltipValue(s2, event, meta)) } // theme const customTheme = getCustomTheme(chart) @@ -821,9 +810,14 @@ function mappingColor(value, defaultColor, field, type, filedValueMap, rowData) return color } -function showTooltipValue(s2Instance, event) { +function showTooltipValue(s2Instance, event, meta) { const cell = s2Instance.getCell(event.target) - const content = cell.actualText + const valueField = cell.getMeta().valueField + const value = cell.getMeta().data[valueField] + const metaObj = find(meta, m => + m.field === valueField + ) + const content = metaObj.formatter(value) s2Instance.showTooltip({ position: { x: event.clientX,