Skip to content

Commit d1c0214

Browse files
authored
Merge pull request #3669 from VisActor/3653-feature-pivotTable-corner
3653 feature pivot table corner
2 parents 56970b3 + 5383751 commit d1c0214

5 files changed

Lines changed: 56 additions & 23 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "feat: refactor pivotTable corner with no columns or rows case #3653\n\n",
5+
"type": "none",
6+
"packageName": "@visactor/vtable"
7+
}
8+
],
9+
"packageName": "@visactor/vtable",
10+
"email": "892739385@qq.com"
11+
}

packages/vtable-gantt/src/Gantt.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -782,13 +782,13 @@ export class Gantt extends EventTarget {
782782
// index + this.taskListTableInstance.columnHeaderLevelCount
783783
// );
784784
// }
785-
if (this.taskListTableInstance.rowHierarchyType === 'tree' && typeof index === 'number') {
786-
//如果是树形结构 需要获取数据源对应的索引
787-
index = this.taskListTableInstance.getRecordIndexByCell(
788-
0,
789-
index + this.taskListTableInstance.columnHeaderLevelCount
790-
);
791-
}
785+
// if (this.taskListTableInstance.rowHierarchyType === 'tree' && typeof index === 'number') {
786+
// //如果是树形结构 需要获取数据源对应的索引
787+
// index = this.taskListTableInstance.getRecordIndexByCell(
788+
// 0,
789+
// index + this.taskListTableInstance.columnHeaderLevelCount
790+
// );
791+
// }
792792
this.taskListTableInstance.updateRecords([record], [index]);
793793
}
794794
/**
@@ -942,11 +942,20 @@ export class Gantt extends EventTarget {
942942
if (Array.isArray(task_index)) {
943943
const index = (task_index as number[])[0];
944944
const sub_index = (task_index as number[])[1];
945-
this._updateRecordToListTable(record, isValid(sub_index) ? [index, sub_index] : index);
945+
// this._updateRecordToListTable(record, isValid(sub_index) ? [index, sub_index] : index);
946+
this._updateRecordToListTable(record, task_index);
946947
this._refreshTaskBar(index, sub_index);
947948
return;
948949
}
949950
const index = task_index as number;
951+
952+
// if (this.taskListTableInstance.rowHierarchyType === 'tree' && typeof index === 'number') {
953+
// //如果是树形结构 需要获取数据源对应的索引
954+
// index = this.taskListTableInstance.getRecordIndexByCell(
955+
// 0,
956+
// index + this.taskListTableInstance.columnHeaderLevelCount
957+
// );
958+
// }
950959
this._updateRecordToListTable(record, index);
951960
this._refreshTaskBar(index, undefined);
952961
}

packages/vtable/src/layout/pivot-header-layout.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,9 @@ export class PivotHeaderLayoutMap implements LayoutMapAPI {
798798
this.rowHierarchyType === 'grid-tree'
799799
? this._getRowHeaderTreeExpandedMaxLevelCount() || this.rowHeaderLevelCount
800800
: this.rowHeaderLevelCount;
801+
if (colLevelCount === 0 || rowLevelCount === 0) {
802+
return results;
803+
}
801804
if (this.cornerSetting.titleOnDimension === 'all') {
802805
if (this.indicatorsAsCol) {
803806
if (colDimensionKeys) {
@@ -1581,7 +1584,10 @@ export class PivotHeaderLayoutMap implements LayoutMapAPI {
15811584
!this.dataset.customColTree?.length //根据情况来加的判断条件 之前是只兼容没有设置两个自定义树的情况 现在对有自定义树的情况也处理出现角头
15821585
// && !this.dataset.customRowTree?.length
15831586
) {
1584-
if (this.cornerSetting.titleOnDimension === 'row' && this.cornerSetting.forceShowHeader) {
1587+
if (
1588+
(this.cornerSetting.titleOnDimension === 'row' || this.cornerSetting.titleOnDimension === 'all') &&
1589+
this.cornerSetting.forceShowHeader
1590+
) {
15851591
count = 1;
15861592
} else if (
15871593
!this._table.isPivotChart() &&
@@ -1658,7 +1664,10 @@ export class PivotHeaderLayoutMap implements LayoutMapAPI {
16581664
// && !this.dataset.customColTree
16591665
!this.dataset.customRowTree?.length //根据情况来加的判断条件 之前是只兼容没有设置两个自定义树的情况 现在对有自定义树的情况也处理出现角头
16601666
) {
1661-
if (this.cornerSetting.titleOnDimension === 'column' && this.cornerSetting.forceShowHeader) {
1667+
if (
1668+
(this.cornerSetting.titleOnDimension === 'column' || this.cornerSetting.titleOnDimension === 'all') &&
1669+
this.cornerSetting.forceShowHeader
1670+
) {
16621671
count = 1;
16631672
} else if (
16641673
!this._table.isPivotChart() &&
@@ -1714,17 +1723,20 @@ export class PivotHeaderLayoutMap implements LayoutMapAPI {
17141723
this._rowHeaderLevelCount = count;
17151724
}
17161725
get colCount(): number {
1717-
return (
1718-
(this._getColumnHeaderTreeExpandedMaxLevelCount() > 0 ||
1726+
let bodyColCount;
1727+
if (
1728+
this._getColumnHeaderTreeExpandedMaxLevelCount() > 0 ||
17191729
this._table.isPivotChart() ||
17201730
(this.dataset.records as Array<any>)?.length > 0 ||
17211731
(this.dataset.records && !Array.isArray(this.dataset.records))
1722-
? this._columnHeaderCellIds[0]?.length ?? this.columnDimensionTree.tree.size
1723-
: 0) +
1724-
this.rowHeaderLevelCount +
1725-
this.rightHeaderColCount +
1726-
this.leftRowSeriesNumberColumnCount
1727-
); // 小心rightFrozenColCount和colCount的循环引用 造成调用栈溢出
1732+
) {
1733+
bodyColCount =
1734+
(this._columnHeaderCellIds[0]?.length ?? this.columnDimensionTree.tree.size) ||
1735+
(this._indicators?.length > 0 ? 1 : 0);
1736+
} else {
1737+
bodyColCount = 0;
1738+
}
1739+
return bodyColCount + this.rowHeaderLevelCount + this.rightHeaderColCount + this.leftRowSeriesNumberColumnCount; // 小心rightFrozenColCount和colCount的循环引用 造成调用栈溢出
17281740
}
17291741
get rowCount(): number {
17301742
return (
@@ -1740,7 +1752,6 @@ export class PivotHeaderLayoutMap implements LayoutMapAPI {
17401752
this.columnHeaderLevelCount +
17411753
this.bottomHeaderRowCount // 小心bottomFrozenRowCount和rowCount的循环引用 造成调用栈溢出
17421754
);
1743-
// return (this._rowHeaderCellIds?.length ?? 0) + this.columnHeaderLevelCount + this.bottomFrozenRowCount;
17441755
}
17451756
get bodyRowSpanCount() {
17461757
return this.rowDimensionTree.tree.size;

packages/vtable/src/layout/tree-helper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export class DimensionTree {
169169
size += this.setTreeNode(n, size, node);
170170
});
171171
} else {
172-
size = 1;
172+
node.level === -1 ? (size = 0) : (size = 1);
173173
// re.totalLevel = Math.max(re.totalLevel, (node.level ?? -1) + 1);
174174
}
175175
} else if (node.hierarchyState === HierarchyState.expand && children?.length >= 1) {
@@ -224,7 +224,7 @@ export class DimensionTree {
224224
} else {
225225
//树形展示 无children子节点。但不能确定是最后一层的叶子节点 totalLevel还不能确定是计算完整棵树的整体深度
226226
node.hierarchyState = HierarchyState.none;
227-
size = 1;
227+
node.level === -1 ? (size = 0) : (size = 1);
228228
}
229229

230230
node.size = size;

packages/vtable/src/scenegraph/scenegraph.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,8 +1233,10 @@ export class Scenegraph {
12331233
*/
12341234
setBodyAndRowHeaderY(y: number) {
12351235
// correct y, avoid scroll out of range
1236-
const firstBodyCell = this.bodyGroup.firstChild?.firstChild as Group;
1237-
const lastBodyCell = this.bodyGroup.firstChild?.lastChild as Group;
1236+
const firstBodyCell =
1237+
(this.bodyGroup.firstChild?.firstChild as Group) ?? (this.rowHeaderGroup.firstChild?.firstChild as Group);
1238+
const lastBodyCell =
1239+
(this.bodyGroup.firstChild?.lastChild as Group) ?? (this.rowHeaderGroup.firstChild?.lastChild as Group);
12381240
if (
12391241
y === 0 &&
12401242
firstBodyCell &&

0 commit comments

Comments
 (0)