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[]) {