Skip to content

Commit

Permalink
feat: add needUpdateHeight&needUpdateWidth tag in update
Browse files Browse the repository at this point in the history
  • Loading branch information
Rui-Sun committed Dec 25, 2023
1 parent 90782d7 commit a9be9ee
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
3 changes: 3 additions & 0 deletions packages/vtable/src/scenegraph/graphic/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export class Group extends VRenderGroup {
border?: IRect; // table/header/body的border mark,挂载在这里方便更新
needUpdate?: boolean;

needUpdateWidth?: boolean;
needUpdateHeight?: boolean;

/**
* @description: 清空Group下全部子元素
* @return {*}
Expand Down
8 changes: 8 additions & 0 deletions packages/vtable/src/scenegraph/group-creater/column-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ export function resizeCellGroup(
newLineWidth[2] = isLineWidthArray ? lineWidth[2] : lineWidth;
}

const widthChange = rangeWidth !== cellGroup.attribute.width;
const heightChange = rangeHeight !== cellGroup.attribute.height;

cellGroup.setAttributes({
width: rangeWidth,
height: rangeHeight,
Expand All @@ -274,6 +277,11 @@ export function resizeCellGroup(
cellGroup.mergeStartRow = range.start.row;
cellGroup.mergeEndCol = range.end.col;
cellGroup.mergeEndRow = range.end.row;

return {
widthChange,
heightChange
};
}

function dealMerge(range: CellRange, mergeMap: MergeMap, table: BaseTableAPI) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export function computeRowsHeight(
}
}
for (let row = 0; row < table.rowCount; row++) {
const newRowHeight = newHeights[row] ?? table.getRowHeight(row);
const newRowHeight = table.getRowHeight(row);
if (newRowHeight !== oldRowHeights[row]) {
// update the row height in scenegraph
// table._setRowHeight(row, newRowHeight);
Expand Down
17 changes: 14 additions & 3 deletions packages/vtable/src/scenegraph/layout/update-height.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function updateCellHeightForRow(
isHeader: boolean
// autoRowHeight: boolean
) {
cell.setAttribute('height', height);
// cell.setAttribute('height', height);
const cellGroup = cell;
const distHeight = height;

Expand All @@ -98,7 +98,7 @@ export function updateCellHeightForColumn(
detaY: number,
isHeader: boolean
) {
cell.setAttribute('height', height);
// cell.setAttribute('height', height);
const cellGroup = cell;
updateCellHeight(scene, cellGroup, col, row, height, 0, isHeader);
}
Expand All @@ -112,6 +112,13 @@ export function updateCellHeight(
detaY: number,
isHeader: boolean
) {
if (cell.attribute.height === distHeight && !cell.needUpdateHeight) {
return;
}
cell.needUpdateHeight = false;

cell.setAttribute('height', distHeight);

// 更新单元格布局
const type = scene.table.isHeader(col, row)
? scene.table._getHeaderLayoutMap(col, row).headerType
Expand Down Expand Up @@ -262,7 +269,7 @@ function updateMergeCellContentHeight(
// const { height: contentHeight } = cellGroup.attribute;
singleCellGroup.contentHeight = distHeight;

resizeCellGroup(
const { widthChange } = resizeCellGroup(
singleCellGroup,
rangeWidth,
rangeHeight,
Expand All @@ -278,6 +285,10 @@ function updateMergeCellContentHeight(
},
table
);

if (widthChange) {
singleCellGroup.needUpdateWidth = true;
}
}
}
} else {
Expand Down
10 changes: 8 additions & 2 deletions packages/vtable/src/scenegraph/layout/update-width.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,10 @@ function updateCellWidth(
// autoColWidth: boolean,
autoRowHeight: boolean
): boolean {
if (cell.attribute.width === distWidth) {
if (cell.attribute.width === distWidth && !cell.needUpdateWidth) {
return false;
}
cell.needUpdateWidth = false;

cell.setAttribute('width', distWidth);
// const mergeInfo = getCellMergeInfo(scene.table, col, row);
Expand Down Expand Up @@ -440,7 +441,7 @@ function updateMergeCellContentWidth(
// const { width: contentWidth } = cellGroup.attribute;
singleCellGroup.contentWidth = distWidth;

resizeCellGroup(
const { heightChange } = resizeCellGroup(
singleCellGroup,
rangeWidth,
rangeHeight,
Expand All @@ -456,6 +457,11 @@ function updateMergeCellContentWidth(
},
table
);

if (heightChange) {
singleCellGroup.needUpdateHeight = true;
}

isHeightChange = isHeightChange || changed;
}
}
Expand Down

0 comments on commit a9be9ee

Please sign in to comment.