Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: levelSpan control tree node header merge #2080

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions packages/vtable/examples/pivot/virtual-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,50 @@ export function createTable() {
dimensionKey: 'Segment',
value: 'Consumer'
},
{
dimensionKey: 'Segment-1',
value: 'Segment-1 (virtual-node)',
virtual: true,
// levelSpan: 2,
children: [
// {
// dimensionKey: 'Segment',
// value: 'Consumer',
// children: [
{
indicatorKey: 'Quantity',
value: 'Quantity'
},
{
indicatorKey: 'Sales',
value: 'Sales'
},
{
indicatorKey: 'Profit',
value: 'Profit'
},
// ]
// },
{
dimensionKey: 'Segment',
value: 'Corporate',
children: [
{
indicatorKey: 'Quantity',
value: 'Quantity'
},
{
indicatorKey: 'Sales',
value: 'Sales'
},
{
indicatorKey: 'Profit',
value: 'Profit'
}
]
}
]
},
{
dimensionKey: 'Segment-1',
value: 'Segment-1 (virtual-node)',
Expand Down
16 changes: 15 additions & 1 deletion packages/vtable/src/layout/pivot-header-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ export class PivotHeaderLayoutMap implements LayoutMapAPI {
this.columnDimensionTree.tree.children,
[],
this.columnHeaderObjs
// this.columnDimensionTree.totalLevel,
// this.indicatorKeys
);
}
// if (typeof this.showColumnHeader !== 'boolean') {
Expand Down Expand Up @@ -543,6 +545,8 @@ export class PivotHeaderLayoutMap implements LayoutMapAPI {
this.rowDimensionTree.tree.children,
[],
this.rowHeaderObjs
// this.columnDimensionTree.totalLevel,
// this.indicatorKeys
);
}
}
Expand Down Expand Up @@ -584,6 +588,8 @@ export class PivotHeaderLayoutMap implements LayoutMapAPI {
header: ITreeLayoutHeadNode[],
roots: number[],
results: HeaderData[]
// totalLevel: number,
// indicatorKeys: string[]
) {
const _this = this;
function _newRow(row: number): number[] {
Expand All @@ -603,7 +609,15 @@ export class PivotHeaderLayoutMap implements LayoutMapAPI {

for (let i = 0; i < header.length; i++) {
const hd = header[i];
dealHeader(hd, _headerCellIds, results, roots, row, this);
dealHeader(
hd,
_headerCellIds,
results,
roots,
row,
this
// totalLevel, indicatorKeys
);
}
}
_addHeadersForTreeMode(
Expand Down
31 changes: 30 additions & 1 deletion packages/vtable/src/layout/tree-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ export function dealHeader(
roots: number[],
row: number,
layoutMap: PivotHeaderLayoutMap
// totalLevel: number,
// indicatorKeys: string[]
) {
// const col = this._columns.length;
const id = hd.id;
Expand Down Expand Up @@ -505,10 +507,35 @@ export function dealHeader(
// }
results[id] = cell;
layoutMap._headerObjects[id] = cell;
_headerCellIds[row][layoutMap.colIndex] = id;
// //这个if判断处理上层维度和指标之间跨级的情况。即表头可能总共有5层,但是有的节点从跟到指标只有三级,那么合并单元格之前是指标单元格跨了三个单元格,现在处理成最后一个维度单元格跨三个单元格
// if (
// ((hd as any).levelSpan ?? 0) <= 1 &&
// row < totalLevel - 1 &&
// hd.indicatorKey &&
// indicatorKeys.includes(hd.indicatorKey) &&
// (hd.children?.length ?? 0) === 0
// ) {
// const newRoots = [...roots];
// const lastId = newRoots[row - 1] ?? id;
// for (; row < totalLevel - 1; row++) {
// if (!_headerCellIds[row]) {
// _headerCellIds[row] = [];
// }
// _headerCellIds[row][layoutMap.colIndex] = lastId;
// newRoots[row] = lastId;
// }
// for (let r = row - 1; r >= 0; r--) {
// _headerCellIds[r][layoutMap.colIndex] = newRoots[r];
// }
// if (!_headerCellIds[row]) {
// _headerCellIds[row] = [];
// }
// } else {
for (let r = row - 1; r >= 0; r--) {
_headerCellIds[r][layoutMap.colIndex] = roots[r];
}
// }
_headerCellIds[row][layoutMap.colIndex] = id;

// 处理汇总小计跨维度层级的情况
if ((hd as any).levelSpan > 1) {
Expand All @@ -527,6 +554,8 @@ export function dealHeader(
(hd as ITreeLayoutHeadNode).children ?? [],
[...roots, ...Array((hd as any).levelSpan ?? 1).fill(id)],
results
// totalLevel,
// indicatorKeys
);
// .forEach(c => results.push(c));
} else {
Expand Down
Loading