Merge pull request #13167 from dataease/pr@dev-v2@fix_table_info_merge_drill

fix(图表): 修复明细表单元格合并后下钻显示异常
This commit is contained in:
wisonic-s 2024-11-06 14:59:52 +08:00 committed by GitHub
commit 3f1e82b11e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 17 additions and 9 deletions

View File

@ -192,6 +192,10 @@ declare interface ChartViewField {
* 字段类型
*/
deType: number
/**
* 分组类型
*/
groupType: 'q' | 'd'
}
declare interface Filter {

View File

@ -210,7 +210,7 @@ export class TableInfo extends S2ChartView<TableSheet> {
// tooltip
this.configTooltip(chart, s2Options)
// 合并单元格
this.configMergeCells(chart, s2Options)
this.configMergeCells(chart, s2Options, s2DataConfig)
// 隐藏表头保留顶部的分割线, 禁用表头横向 resize
if (tableHeader.showTableHeader === false) {
s2Options.style.colCfg.height = 1

View File

@ -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 ||

View File

@ -64,8 +64,8 @@ export abstract class S2ChartView<P extends SpreadSheet> 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[]) {