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

perf: 优化自动计算单元格坐标时的性能 #2463

Merged
merged 1 commit into from
Dec 11, 2023
Merged
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
18 changes: 10 additions & 8 deletions packages/s2-core/src/facet/pivot-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,11 @@ export class PivotFacet extends FrozenFacet {
*/
private autoCalculateColNodeWidthAndX(colLeafNodes: Node[]) {
let prevColParent: Node = null;
let i = 0;
const leafNodes = colLeafNodes.slice(0);

while (leafNodes.length) {
const node = leafNodes.shift();
wjgogogo marked this conversation as resolved.
Show resolved Hide resolved
while (i < leafNodes.length) {
const node = leafNodes[i++];
const parentNode = node.parent;
if (prevColParent !== parentNode && parentNode) {
leafNodes.push(parentNode);
Expand Down Expand Up @@ -642,20 +643,21 @@ export class PivotFacet extends FrozenFacet {
* @param rowLeafNodes
*/
private autoCalculateRowNodeHeightAndY(rowLeafNodes: Node[]) {
// 3、in grid type, all no-leaf node's height, y are auto calculated
let prevRowParent = null;
let i = 0;
const leafNodes = rowLeafNodes.slice(0);
while (leafNodes.length) {
const node = leafNodes.shift();
while (i < leafNodes.length) {
const node = leafNodes[i++];
const parent = node.parent;
if (prevRowParent !== parent && parent) {
leafNodes.push(parent);
// parent's y = first child's y
parent.y = parent.children[0].y;
// parent's height = all children's height
parent.height = parent.children
.map((value) => value.height)
.reduce((sum, current) => sum + current, 0);
parent.height = parent.children.reduce(
wjgogogo marked this conversation as resolved.
Show resolved Hide resolved
(sum, current) => sum + current.height,
0,
);
prevRowParent = parent;
}
}
Expand Down
Loading