@visactor/vtable
Version:
canvas table width high performance
65 lines (60 loc) • 5.15 kB
JavaScript
export function adjustMoveHeaderTarget(source, target, table) {
const sourceCellRange = table.getCellRange(source.col, source.row);
if (table.isColumnHeader(source.col, source.row) || "column" === table.stateManager.columnMove.movingColumnOrRow && 0 === source.row) {
const targetCellRange = table.getCellRange(target.col, sourceCellRange.start.row);
target.row >= table.columnHeaderLevelCount && (target.row = Math.max(table.columnHeaderLevelCount - 1, 0)),
target.col >= source.col ? target.col = targetCellRange.end.col : target.col = targetCellRange.start.col;
} else if (table.isRowHeader(source.col, source.row)) {
const layoutMap = table.internalProps.layoutMap, targetCellRange = table.getCellRange(sourceCellRange.start.col, target.row);
if (target.col >= table.rowHeaderLevelCount + layoutMap.leftRowSeriesNumberColumnCount && (target.col = table.rowHeaderLevelCount + layoutMap.leftRowSeriesNumberColumnCount - 1),
"tree" === layoutMap.rowHierarchyType) {
const sourceRowHeaderPaths = layoutMap.getCellHeaderPathsWithTreeNode(source.col, source.row).rowHeaderPaths, targetRowHeaderPaths = layoutMap.getCellHeaderPathsWithTreeNode(target.col, target.row).rowHeaderPaths;
if (sourceRowHeaderPaths.length <= targetRowHeaderPaths.length) {
const targetPathNode = targetRowHeaderPaths[sourceRowHeaderPaths.length - 1];
targetPathNode && (target.row >= source.row ? target.row = targetPathNode.startInTotal + targetPathNode.size - 1 + table.columnHeaderLevelCount : target.row = targetPathNode.startInTotal + table.columnHeaderLevelCount);
}
} else target.row >= source.row ? target.row = targetCellRange.end.row : target.row = targetCellRange.start.row;
}
return target;
}
export function adjustWidthResizedColMap(moveContext, table) {
if (table.internalProps._widthResizedColMap.size > 0) {
const resizedColIndexs = Array.from(table.internalProps._widthResizedColMap.keys());
table.internalProps._widthResizedColMap.clear();
for (let i = 0; i < resizedColIndexs.length; i++) {
const colIndex = resizedColIndexs[i];
let newColIndex;
const {sourceIndex: sourceIndex, targetIndex: targetIndex, sourceSize: sourceSize} = moveContext;
newColIndex = colIndex >= sourceIndex && colIndex < sourceIndex + sourceSize ? targetIndex + (colIndex - sourceIndex) : sourceIndex < targetIndex ? colIndex >= sourceIndex + sourceSize && colIndex < targetIndex || colIndex >= targetIndex ? colIndex - sourceSize : colIndex : colIndex >= targetIndex && colIndex < sourceIndex ? colIndex + sourceSize : colIndex,
table.internalProps._widthResizedColMap.add(newColIndex);
}
}
}
export function adjustHeightResizedRowMap(moveContext, table) {
if (table.internalProps._heightResizedRowMap.size > 0) {
const resizedRowIndexs = Array.from(table.internalProps._heightResizedRowMap.keys());
table.internalProps._heightResizedRowMap.clear();
for (let i = 0; i < resizedRowIndexs.length; i++) {
const rowIndex = resizedRowIndexs[i];
let newRowIndex;
const {sourceIndex: sourceIndex, targetIndex: targetIndex, sourceSize: sourceSize} = moveContext;
newRowIndex = rowIndex >= sourceIndex && rowIndex < sourceIndex + sourceSize ? targetIndex + (rowIndex - sourceIndex) : sourceIndex < targetIndex ? rowIndex >= sourceIndex + sourceSize && rowIndex < targetIndex || rowIndex >= targetIndex ? rowIndex - sourceSize : rowIndex : rowIndex >= targetIndex && rowIndex < sourceIndex ? rowIndex + sourceSize : rowIndex,
table.internalProps._heightResizedRowMap.add(newRowIndex);
}
}
}
export function adjustHeightResizedRowMapWithAddRecordIndex(table, recordIndex, records) {
const resizedRowIndexs = Array.from(table.internalProps._heightResizedRowMap.keys()), rowIndex = recordIndex + (table.transpose ? table.rowHeaderLevelCount : table.columnHeaderLevelCount);
for (let i = 0; i < resizedRowIndexs.length; i++) resizedRowIndexs[i] >= rowIndex && (table.internalProps._heightResizedRowMap.delete(resizedRowIndexs[i]),
table.internalProps._heightResizedRowMap.add(resizedRowIndexs[i] + records.length));
}
export function adjustHeightResizedRowMapWithDeleteRecordIndex(table, recordIndexs) {
const headerCount = table.transpose ? table.rowHeaderLevelCount : table.columnHeaderLevelCount;
recordIndexs.sort(((a, b) => b - a));
for (let i = 0; i < recordIndexs.length; i++) {
const rowIndex = recordIndexs[i] + headerCount, resizedRowIndexs = Array.from(table.internalProps._heightResizedRowMap.keys());
for (let j = 0; j < resizedRowIndexs.length; j++) resizedRowIndexs[j] === rowIndex ? table.internalProps._heightResizedRowMap.delete(resizedRowIndexs[j]) : resizedRowIndexs[j] > rowIndex && (table.internalProps._heightResizedRowMap.delete(resizedRowIndexs[j]),
table.internalProps._heightResizedRowMap.add(resizedRowIndexs[j] - 1));
}
}
//# sourceMappingURL=adjust-header.js.map