fix(图表): 修复明细表单元格合并后下钻显示异常

This commit is contained in:
wisonic 2024-11-06 14:58:13 +08:00
parent 03b8d8923b
commit 4ef209d217
4 changed files with 17 additions and 9 deletions

View File

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

View File

@ -210,7 +210,7 @@ export class TableInfo extends S2ChartView<TableSheet> {
// tooltip // tooltip
this.configTooltip(chart, s2Options) this.configTooltip(chart, s2Options)
// 合并单元格 // 合并单元格
this.configMergeCells(chart, s2Options) this.configMergeCells(chart, s2Options, s2DataConfig)
// 隐藏表头保留顶部的分割线, 禁用表头横向 resize // 隐藏表头保留顶部的分割线, 禁用表头横向 resize
if (tableHeader.showTableHeader === false) { if (tableHeader.showTableHeader === false) {
s2Options.style.colCfg.height = 1 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 { mergeCells } = parseJson(chart.customAttr).tableCell
const { showIndex } = parseJson(chart.customAttr).tableHeader const { showIndex } = parseJson(chart.customAttr).tableHeader
if (mergeCells) { if (mergeCells) {
const xAxis = chart.xAxis const fields = chart.data.fields || []
const quotaIndex = xAxis.findIndex(axis => axis.groupType === 'q') 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 const data = chart.data?.tableRow
if (quotaIndex === 0 || !data?.length) { if (quotaIndex === 0 || !data?.length) {
return return
} }
const mergedColInfo: number[][][] = [[[0, data.length - 1]]] const mergedColInfo: number[][][] = [[[0, data.length - 1]]]
const mergedCellsInfo = [] 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) => { axisToMerge.forEach((a, i) => {
const preMergedColInfo = mergedColInfo[i] const preMergedColInfo = mergedColInfo[i]
const curMergedColInfo = [] const curMergedColInfo = []
mergedColInfo.push(curMergedColInfo) mergedColInfo.push(curMergedColInfo)
preMergedColInfo.forEach(range => { preMergedColInfo.forEach(range => {
const [start, end] = range const [start, end] = range
let lastVal = data[start][a.dataeaseName] let lastVal = data[start][a.field]
let lastIndex = start let lastIndex = start
for (let index = start; index <= end; index++) { for (let index = start; index <= end; index++) {
const curVal = data[index][a.dataeaseName] const curVal = data[index][a.field]
if (curVal !== lastVal || index === end) { if (curVal !== lastVal || index === end) {
const curRange = index - lastIndex const curRange = index - lastIndex
if (curRange > 1 || if (curRange > 1 ||

View File

@ -64,8 +64,8 @@ export abstract class S2ChartView<P extends SpreadSheet> extends AntVAbstractCha
return getConditions(chart) return getConditions(chart)
} }
protected configMergeCells(chart: Chart, option: S2Options) { protected configMergeCells(chart: Chart, option: S2Options, dataConfig: S2DataConfig) {
configMergeCells(chart, option) configMergeCells(chart, option, dataConfig)
} }
protected showTooltip(s2Instance: P, event, metaConfig: Meta[]) { protected showTooltip(s2Instance: P, event, metaConfig: Meta[]) {