From 4ef209d21775aacdaa88dd7b8bb9dd8d8576088c Mon Sep 17 00:00:00 2001 From: wisonic Date: Wed, 6 Nov 2024 14:58:13 +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=8D=95=E5=85=83=E6=A0=BC=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E5=90=8E=E4=B8=8B=E9=92=BB=E6=98=BE=E7=A4=BA=E5=BC=82?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/core-frontend/src/models/chart/chart.d.ts | 4 ++++ .../js/panel/charts/table/table-info.ts | 2 +- .../components/js/panel/common/common_table.ts | 16 ++++++++++------ .../chart/components/js/panel/types/impl/s2.ts | 4 ++-- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/core/core-frontend/src/models/chart/chart.d.ts b/core/core-frontend/src/models/chart/chart.d.ts index 8add766bbc..359037e9cb 100644 --- a/core/core-frontend/src/models/chart/chart.d.ts +++ b/core/core-frontend/src/models/chart/chart.d.ts @@ -192,6 +192,10 @@ declare interface ChartViewField { * 字段类型 */ deType: number + /** + * 分组类型 + */ + groupType: 'q' | 'd' } declare interface Filter { diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-info.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-info.ts index ad9b102a1b..025052c7b6 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-info.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-info.ts @@ -210,7 +210,7 @@ export class TableInfo extends S2ChartView { // tooltip this.configTooltip(chart, s2Options) // 合并单元格 - this.configMergeCells(chart, s2Options) + this.configMergeCells(chart, s2Options, s2DataConfig) // 隐藏表头,保留顶部的分割线, 禁用表头横向 resize if (tableHeader.showTableHeader === false) { s2Options.style.colCfg.height = 1 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 b5397678da..22120abd4a 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 @@ -1426,29 +1426,33 @@ export async function exportPivotExcel(instance: PivotSheet, chart: ChartObj) { } } -export function configMergeCells(chart: Chart, options: S2Options) { +export function configMergeCells(chart: Chart, options: S2Options, dataConfig: S2DataConfig) { const { mergeCells } = parseJson(chart.customAttr).tableCell const { showIndex } = parseJson(chart.customAttr).tableHeader if (mergeCells) { - const xAxis = chart.xAxis - const quotaIndex = xAxis.findIndex(axis => axis.groupType === 'q') + const fields = chart.data.fields || [] + const fielsMap = fields.reduce((p, n) => { + p[n.dataeaseName] = n + return p + }, {}) || {} + const quotaIndex = dataConfig.meta.findIndex(m => fielsMap[m.field].groupType === 'q') const data = chart.data?.tableRow if (quotaIndex === 0 || !data?.length) { return } const mergedColInfo: number[][][] = [[[0, data.length - 1]]] const mergedCellsInfo = [] - const axisToMerge = xAxis.filter((a, i) => a.hide !== true && (i < quotaIndex || quotaIndex === -1)) + const axisToMerge = dataConfig.meta.filter((_, i) => i < quotaIndex || quotaIndex === -1) axisToMerge.forEach((a, i) => { const preMergedColInfo = mergedColInfo[i] const curMergedColInfo = [] mergedColInfo.push(curMergedColInfo) preMergedColInfo.forEach(range => { const [start, end] = range - let lastVal = data[start][a.dataeaseName] + let lastVal = data[start][a.field] let lastIndex = start for (let index = start; index <= end; index++) { - const curVal = data[index][a.dataeaseName] + const curVal = data[index][a.field] if (curVal !== lastVal || index === end) { const curRange = index - lastIndex if (curRange > 1 || diff --git a/core/core-frontend/src/views/chart/components/js/panel/types/impl/s2.ts b/core/core-frontend/src/views/chart/components/js/panel/types/impl/s2.ts index cbd8c005aa..275557c5a4 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/types/impl/s2.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/types/impl/s2.ts @@ -64,8 +64,8 @@ export abstract class S2ChartView

extends AntVAbstractCha return getConditions(chart) } - protected configMergeCells(chart: Chart, option: S2Options) { - configMergeCells(chart, option) + protected configMergeCells(chart: Chart, option: S2Options, dataConfig: S2DataConfig) { + configMergeCells(chart, option, dataConfig) } protected showTooltip(s2Instance: P, event, metaConfig: Meta[]) {