@visactor/vtable
Version:
canvas table width high performance
147 lines (138 loc) • 11.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.updateCellHeight = exports.updateCellHeightForColumn = exports.updateCellHeightForRow = exports.updateRowHeight = void 0;
const get_cell_merge_1 = require("../utils/get-cell-merge"), get_prop_1 = require("../utils/get-prop"), padding_1 = require("../utils/padding"), text_icon_layout_1 = require("../utils/text-icon-layout"), custom_1 = require("../component/custom"), image_cell_1 = require("../group-creater/cell-type/image-cell"), tableHelper_1 = require("../../core/tableHelper"), is_merge_cell_group_1 = require("../utils/is-merge-cell-group"), cell_helper_1 = require("../group-creater/cell-helper"), merge_range_1 = require("../../tools/merge-range"), factory_1 = require("../../core/factory");
function updateRowHeight(scene, row, detaY, skipTableHeightMap) {
skipTableHeightMap || scene.table._setRowHeight(row, scene.table.getRowHeight(row) + detaY, !0);
for (let col = 0; col < scene.table.colCount; col++) {
const cell = scene.getCell(col, row);
if ("empty" === cell.role) continue;
const mergeInfo = (0, get_cell_merge_1.getCellMergeInfo)(scene.table, col, row);
if (mergeInfo && mergeInfo.start.col !== col) continue;
updateCellHeightForRow(scene, cell, col, row, cell.attribute.height + detaY, detaY, scene.table.isHeader(col, row)),
scene.updateCellContentWhileResize(col, row);
}
let rowStart = 0, rowEnd = 0;
row < scene.table.frozenRowCount ? (rowStart = row + 1, rowEnd = scene.table.frozenRowCount - 1) : row >= scene.table.rowCount - scene.table.bottomFrozenRowCount ? (rowStart = row + 1,
rowEnd = scene.table.rowCount - 1) : (rowStart = row + 1, rowEnd = Math.min(scene.proxy.rowEnd, scene.table.rowCount - scene.table.bottomFrozenRowCount - 1));
for (let colIndex = 0; colIndex < scene.table.colCount; colIndex++) for (let rowIndex = rowStart; rowIndex <= rowEnd; rowIndex++) {
const cellGroup = scene.highPerformanceGetCell(colIndex, rowIndex);
"cell" === cellGroup.role && cellGroup.setAttribute("y", cellGroup.attribute.y + detaY);
}
}
function updateCellHeightForRow(scene, cell, col, row, height, detaY, isHeader) {
cell && updateCellHeight(scene, cell, col, row, height, detaY, isHeader);
}
function updateCellHeightForColumn(scene, cell, col, row, height, detaY, isHeader) {
updateCellHeight(scene, cell, col, row, height, 0, isHeader);
}
function updateCellHeight(scene, cell, col, row, distHeight, detaY, isHeader) {
var _a, _b, _c, _d, _e;
if (cell.attribute.height === distHeight && !cell.needUpdateHeight) return;
cell.needUpdateHeight = !1, cell.setAttribute("height", distHeight);
const isVtableMerge = null === (_a = scene.table.getCellRawRecord(col, row)) || void 0 === _a ? void 0 : _a.vtableMerge, isCustomMerge = !!scene.table.getCustomMerge(col, row), type = isVtableMerge || isCustomMerge ? "text" : scene.table.isHeader(col, row) ? null !== (_b = scene.table._getHeaderLayoutMap(col, row).headerType) && void 0 !== _b ? _b : "text" : null !== (_c = scene.table.getBodyColumnType(col, row)) && void 0 !== _c ? _c : "text";
if ("progressbar" === type) {
const columnDefine = scene.table.getBodyColumnDefine(col, row), style = scene.table._getCellStyle(col, row), value = scene.table.getCellValue(col, row), dataValue = scene.table.getCellOriginValue(col, row), padding = (0,
padding_1.getQuadProps)((0, get_prop_1.getProp)("padding", style, col, row, scene.table));
let range;
(null == columnDefine ? void 0 : columnDefine.mergeCell) && (range = scene.table.getCellRange(col, row));
const newBarCell = factory_1.Factory.getFunction("createProgressBarCell")(columnDefine, style, cell.attribute.width, value, dataValue, col, row, padding, scene.table, range), oldBarCell = cell.getChildByName("progress-bar");
cell.insertBefore(newBarCell, oldBarCell), cell.removeChild(oldBarCell), oldBarCell.removeAllChild(),
oldBarCell.release(), updateMergeCellContentHeight(cell, distHeight, detaY, scene.table.isAutoRowHeight(row), !0, scene.table);
} else if ("sparkline" === type) {
cell.removeAllChild();
const headerStyle = scene.table._getCellStyle(col, row), padding = (0, padding_1.getQuadProps)((0,
get_prop_1.getProp)("padding", headerStyle, col, row, scene.table));
factory_1.Factory.getFunction("createSparkLineCellGroup")(cell, cell.parent, cell.attribute.x, cell.attribute.y, col, row, cell.attribute.width, cell.attribute.height, padding, scene.table, (0,
tableHelper_1.getStyleTheme)(headerStyle, scene.table, col, row, get_prop_1.getProp).theme, !1);
} else if ("image" === type || "video" === type) (0, image_cell_1.updateImageCellContentWhileResize)(cell, col, row, 0, detaY, scene.table); else if ("axis" === (null === (_d = cell.firstChild) || void 0 === _d ? void 0 : _d.name)) null === (_e = cell.firstChild) || void 0 === _e || _e.originAxis.resize(cell.attribute.width, cell.attribute.height); else {
let renderDefault = !0;
const customContainer = cell.getChildByName(custom_1.CUSTOM_CONTAINER_NAME) || cell.getChildByName(custom_1.CUSTOM_MERGE_CONTAINER_NAME);
if (customContainer) {
let customElementsGroup;
cell.removeChild(customContainer);
const customMergeRange = (0, cell_helper_1.getCustomCellMergeCustom)(col, row, cell, scene.table);
if (customMergeRange) for (let mergeRow = customMergeRange.start.row; mergeRow <= customMergeRange.end.row; mergeRow++) {
if (mergeRow === row) continue;
const mergedCell = scene.getCell(col, mergeRow), customContainer = mergedCell.getChildByName(custom_1.CUSTOM_CONTAINER_NAME) || mergedCell.getChildByName(custom_1.CUSTOM_MERGE_CONTAINER_NAME);
customContainer.removeAllChild(), mergedCell.removeChild(customContainer), (0, cell_helper_1.getCustomCellMergeCustom)(col, mergeRow, mergedCell, scene.table);
} else {
let customRender, customLayout;
const cellLocation = scene.table.getCellLocation(col, row), {vtableMerge: vtableMerge} = scene.table.getCellRawRecord(col, row) || {};
if (vtableMerge && scene.table.options.groupTitleCustomLayout) customLayout = scene.table.options.groupTitleCustomLayout; else if ("body" !== cellLocation) {
const define = scene.table.getHeaderDefine(col, row);
customRender = null == define ? void 0 : define.headerCustomRender, customLayout = null == define ? void 0 : define.headerCustomLayout;
} else {
const define = scene.table.getBodyColumnDefine(col, row);
customRender = (null == define ? void 0 : define.customRender) || scene.table.customRender,
customLayout = null == define ? void 0 : define.customLayout;
}
if ((customRender || customLayout) && (0, is_merge_cell_group_1.isMergeCellGroup)(cell)) for (let mergeCol = cell.mergeStartCol; mergeCol <= cell.mergeEndCol; mergeCol++) for (let mergeRow = cell.mergeStartRow; mergeRow <= cell.mergeEndRow; mergeRow++) mergeRow !== row && scene.updateCellContent(mergeCol, mergeRow);
if (customLayout || customRender) {
const style = scene.table._getCellStyle(col, row), padding = (0, padding_1.getQuadProps)((0,
get_prop_1.getProp)("padding", style, col, row, scene.table));
let width = cell.attribute.width, height = cell.attribute.height;
(0, is_merge_cell_group_1.isMergeCellGroup)(cell) && (width = scene.table.getColsWidth(cell.mergeStartCol, cell.mergeEndCol),
height = scene.table.getRowsHeight(cell.mergeStartRow, cell.mergeEndRow));
const customResult = (0, custom_1.dealWithCustom)(customLayout, customRender, col, row, width, height, !1, scene.table.isAutoRowHeight(row), padding, (0,
is_merge_cell_group_1.isMergeCellGroup)(cell) ? {
start: {
col: cell.mergeStartCol,
row: cell.mergeStartRow
},
end: {
col: cell.mergeEndCol,
row: cell.mergeEndRow
}
} : void 0, scene.table);
customElementsGroup = customResult.elementsGroup, renderDefault = customResult.renderDefault;
}
cell.childrenCount > 0 && customElementsGroup ? cell.insertBefore(customElementsGroup, cell.firstChild) : customElementsGroup && cell.appendChild(customElementsGroup);
}
}
updateMergeCellContentHeight(cell, distHeight, detaY, scene.table.isAutoRowHeight(row), renderDefault, scene.table);
}
}
function updateMergeCellContentHeight(cellGroup, distHeight, detaY, autoRowHeight, renderDefault, table) {
if ((0, is_merge_cell_group_1.isMergeCellGroup)(cellGroup)) {
distHeight = 0;
for (let row = cellGroup.mergeStartRow; row <= cellGroup.mergeEndRow; row++) distHeight += table.getRowHeight(row);
const {colStart: colStart, colEnd: colEnd, rowStart: rowStart, rowEnd: rowEnd} = (0,
merge_range_1.getCellMergeRange)(cellGroup, table.scenegraph);
for (let col = colStart; col <= colEnd; col++) for (let row = rowStart; row <= rowEnd; row++) {
const singleCellGroup = table.scenegraph.getCell(col, row);
if ("cell" !== singleCellGroup.role) continue;
if (singleCellGroup.forEachChildren((child => {
child.setAttributes({
dx: 0,
dy: 0
});
})), renderDefault) {
const style = table._getCellStyle(colStart, rowStart), padding = (0, padding_1.getQuadProps)((0,
get_prop_1.getProp)("padding", style, col, row, table));
(0, text_icon_layout_1.updateCellContentHeight)(singleCellGroup, distHeight, detaY, autoRowHeight, padding, style.textAlign, style.textBaseline, table);
}
const rangeHeight = table.getRowHeight(row), rangeWidth = table.getColWidth(col);
singleCellGroup.contentHeight = distHeight;
const {widthChange: widthChange} = (0, cell_helper_1.resizeCellGroup)(singleCellGroup, rangeWidth, rangeHeight, {
start: {
col: cellGroup.mergeStartCol,
row: cellGroup.mergeStartRow
},
end: {
col: cellGroup.mergeEndCol,
row: cellGroup.mergeEndRow
}
}, table);
widthChange && (singleCellGroup.needUpdateWidth = !0);
}
} else {
const style = table._getCellStyle(cellGroup.col, cellGroup.row), padding = (0, padding_1.getQuadProps)((0,
get_prop_1.getProp)("padding", style, cellGroup.col, cellGroup.row, table));
(0, text_icon_layout_1.updateCellContentHeight)(cellGroup, distHeight, detaY, autoRowHeight, padding, style.textAlign, style.textBaseline, table);
}
}
exports.updateRowHeight = updateRowHeight, exports.updateCellHeightForRow = updateCellHeightForRow,
exports.updateCellHeightForColumn = updateCellHeightForColumn, exports.updateCellHeight = updateCellHeight;
//# sourceMappingURL=update-height.js.map