From c64c3480ada1ef718216c160ae46d41d64d5264d Mon Sep 17 00:00:00 2001 From: wisonic-s <51065359+wisonic-s@users.noreply.github.com> Date: Mon, 28 Apr 2025 16:22:24 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9B=BE=E8=A1=A8):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=98=8E=E7=BB=86=E8=A1=A8=E5=BC=80=E5=90=AF=E8=A1=A8=E5=A4=B4?= =?UTF-8?q?=E5=88=86=E7=BB=84=E5=92=8C=E6=80=BB=E8=AE=A1=E5=90=8E=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=A0=BC=E5=8C=BA=E5=9F=9F=E9=AB=98=E5=BA=A6=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E9=94=99=E8=AF=AF=20#15972?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../editor/editor-style/ChartStyle.vue | 1 + .../js/panel/charts/table/table-info.ts | 34 +++++++++++++++++-- .../js/panel/charts/table/table-normal.ts | 21 ++++++++++-- .../js/panel/common/common_table.ts | 24 ------------- 4 files changed, 51 insertions(+), 29 deletions(-) diff --git a/core/core-frontend/src/views/chart/components/editor/editor-style/ChartStyle.vue b/core/core-frontend/src/views/chart/components/editor/editor-style/ChartStyle.vue index 1279bc5872..574992f900 100644 --- a/core/core-frontend/src/views/chart/components/editor/editor-style/ChartStyle.vue +++ b/core/core-frontend/src/views/chart/components/editor/editor-style/ChartStyle.vue @@ -490,6 +490,7 @@ watch( /> { // 开始渲染 const newChart = new TableSheet(containerDom, s2DataConfig, s2Options) // 总计紧贴在单元格后面 - summaryRowStyle(newChart, newData, tableCell, tableHeader, basicStyle.showSummary) + this.summaryRowStyle(newChart, newData, tableCell, tableHeader, basicStyle.showSummary) // 开启自动换行 if (basicStyle.autoWrap && !tableCell.mergeCells) { // 调整表头宽度时,计算表头高度 @@ -513,6 +512,23 @@ export class TableInfo extends S2ChartView { } } + protected summaryRowStyle(newChart: TableSheet, newData, tableCell, tableHeader, showSummary) { + if (!showSummary || !newData.length) return + const columns = newChart.dataCfg.fields.columns + const showHeader = tableHeader.showTableHeader === true + // 不显示表头时,减少一个表头的高度 + const headerAndSummaryHeight = showHeader ? getMaxTreeDepth(columns) + 1 : 1 + newChart.on(S2Event.LAYOUT_BEFORE_RENDER, () => { + const totalHeight = + tableHeader.tableTitleHeight * headerAndSummaryHeight + + tableCell.tableItemHeight * (newData.length - 1) + if (totalHeight < newChart.container.cfg.height) { + newChart.options.height = + totalHeight < newChart.container.cfg.height - 8 ? totalHeight + 8 : totalHeight + } + }) + } + constructor() { super('table-info', []) } @@ -533,3 +549,17 @@ function getStartPosition(node) { } return getStartPosition(node.children[0]) } + +function getMaxTreeDepth(nodes) { + if (!nodes?.length) { + return 0 + } + return Math.max( + ...nodes.map(node => { + if (!node.children?.length) { + return 1 + } + return getMaxTreeDepth(node.children) + 1 + }) + ) +} diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-normal.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-normal.ts index 80f7c6c525..2cf89ee019 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-normal.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-normal.ts @@ -6,8 +6,7 @@ import { CustomDataCell, getSummaryRow, SortTooltip, - SummaryCell, - summaryRowStyle + SummaryCell } from '@/views/chart/components/js/panel/common/common_table' import { S2ChartView, S2DrawOptions } from '@/views/chart/components/js/panel/types/impl/s2' import { parseJson } from '@/views/chart/components/js/util' @@ -187,7 +186,7 @@ export class TableNormal extends S2ChartView { // 开始渲染 const newChart = new TableSheet(containerDom, s2DataConfig, s2Options) // 总计紧贴在单元格后面 - summaryRowStyle(newChart, newData, tableCell, tableHeader, basicStyle.showSummary) + this.summaryRowStyle(newChart, newData, tableCell, tableHeader, basicStyle.showSummary) // 自适应铺满 if (basicStyle.tableColumnMode === 'adapt') { newChart.on(S2Event.LAYOUT_RESIZE_COL_WIDTH, () => { @@ -333,6 +332,22 @@ export class TableNormal extends S2ChartView { } } + protected summaryRowStyle(newChart, newData, tableCell, tableHeader, showSummary) { + if (!showSummary || !newData.length) return + newChart.on(S2Event.LAYOUT_BEFORE_RENDER, () => { + const showHeader = tableHeader.showTableHeader === true + // 不显示表头时,减少一个表头的高度 + const headerAndSummaryHeight = showHeader ? 2 : 1 + const totalHeight = + tableHeader.tableTitleHeight * headerAndSummaryHeight + + tableCell.tableItemHeight * (newData.length - 1) + if (totalHeight < newChart.container.cfg.height) { + newChart.options.height = + totalHeight < newChart.container.cfg.height - 8 ? totalHeight + 8 : totalHeight + } + }) + } + constructor() { super('table-normal', []) } diff --git a/core/core-frontend/src/views/chart/components/js/panel/common/common_table.ts b/core/core-frontend/src/views/chart/components/js/panel/common/common_table.ts index d920548b8e..96d7464e3f 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/common/common_table.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/common/common_table.ts @@ -2249,30 +2249,6 @@ export function getSummaryRow(data, axis, sumCon = []) { return summaryObj } -/** - * 汇总行样式,紧贴在单元格后面 - * @param newChart - * @param newData - * @param tableCell - * @param tableHeader - * @param showSummary - */ -export const summaryRowStyle = (newChart, newData, tableCell, tableHeader, showSummary) => { - if (!showSummary || !newData.length) return - newChart.on(S2Event.LAYOUT_BEFORE_RENDER, () => { - const showHeader = tableHeader.showTableHeader === true - // 不显示表头时,减少一个表头的高度 - const headerAndSummaryHeight = showHeader ? 2 : 1 - const totalHeight = - tableHeader.tableTitleHeight * headerAndSummaryHeight + - tableCell.tableItemHeight * (newData.length - 1) - if (totalHeight < newChart.container.cfg.height) { - newChart.options.height = - totalHeight < newChart.container.cfg.height - 8 ? totalHeight + 8 : totalHeight - } - }) -} - export class SummaryCell extends CustomDataCell { getTextStyle() { const textStyle = cloneDeep(this.theme.colCell.bolderText)