Merge pull request #13068 from dataease/pr@dev-v2@refactor_table_info_merge_index_number

refactor(图表): 明细表合并单元格序号列序号计算逻辑优化
This commit is contained in:
wisonic-s 2024-11-01 18:17:19 +08:00 committed by GitHub
commit c23c61c757
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 5 deletions

View File

@ -14,7 +14,11 @@ import { S2ChartView, S2DrawOptions } from '../../types/impl/s2'
import { TABLE_EDITOR_PROPERTY, TABLE_EDITOR_PROPERTY_INNER } from './common'
import { useI18n } from '@/hooks/web/useI18n'
import { isNumber } from 'lodash-es'
import { copyContent, SortTooltip } from '@/views/chart/components/js/panel/common/common_table'
import {
copyContent,
getRowIndex,
SortTooltip
} from '@/views/chart/components/js/panel/common/common_table'
const { t } = useI18n()
class ImageCell extends TableDataCell {
@ -192,7 +196,12 @@ export class TableInfo extends S2ChartView<TableSheet> {
return new ImageCell(viewMeta, viewMeta?.spreadsheet)
}
if (viewMeta.colIndex === 0 && s2Options.showSeriesNumber) {
viewMeta.fieldValue = pageInfo.pageSize * (pageInfo.currentPage - 1) + viewMeta.rowIndex + 1
if (tableCell.mergeCells) {
viewMeta.fieldValue = getRowIndex(s2Options.mergedCellsInfo, viewMeta)
} else {
viewMeta.fieldValue =
pageInfo.pageSize * (pageInfo.currentPage - 1) + viewMeta.rowIndex + 1
}
}
return new TableDataCell(viewMeta, viewMeta?.spreadsheet)
}

View File

@ -32,7 +32,9 @@ import {
TableDataCell,
MergedCell,
getPolygonPoints,
renderPolygon
renderPolygon,
MergedCellInfo,
ViewMeta
} from '@antv/s2'
import { keys, intersection, filter, cloneDeep, merge, find, repeat } from 'lodash-es'
import { createVNode, render } from 'vue'
@ -1419,12 +1421,12 @@ export function configMergeCells(chart: Chart, options: S2Options) {
const xAxis = chart.xAxis
const quotaIndex = xAxis.findIndex(axis => axis.groupType === 'q')
const data = chart.data?.tableRow
if (quotaIndex <= 0 || !data?.length) {
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)
const axisToMerge = xAxis.filter((a, i) => a.hide !== true && (i < quotaIndex || quotaIndex === -1))
axisToMerge.forEach((a, i) => {
const preMergedColInfo = mergedColInfo[i]
const curMergedColInfo = []
@ -1476,11 +1478,33 @@ export function configMergeCells(chart: Chart, options: S2Options) {
}
options.mergedCellsInfo = mergedCellsInfo
options.mergedCell = (sheet, cells, meta) => {
if (showIndex && meta.colIndex === 0) {
meta.fieldValue = getRowIndex(mergedCellsInfo, meta)
}
return new CustomMergedCell(sheet, cells, meta)
}
}
}
export function getRowIndex(mergedCellsInfo: MergedCellInfo[][], meta: ViewMeta): number {
let curRangeStartIndex = 0
const lostCells = mergedCellsInfo.reduce((p, n) => {
if (n[0].colIndex !== 0) {
return p
}
const start = n[0].rowIndex
const end = n[n.length - 1].rowIndex
const lost = end - start
if (meta.rowIndex >= start && meta.rowIndex <= end) {
curRangeStartIndex = start
}
if (meta.rowIndex > end) {
return p + lost
}
return p
}, 0)
return curRangeStartIndex - lostCells + 1
}
class CustomMergedCell extends MergedCell {
protected drawBackgroundShape() {
const allPoints = getPolygonPoints(this.cells)