UNPKG

@visactor/vtable

Version:

canvas table width high performance

64 lines (59 loc) 6.5 kB
import { calculateCellRangeDistribution } from "../utils/cell-pos"; import { createRect } from "./../../vrender"; import { getCornerRadius } from "./create-select-border"; export function updateCustomSelectBorder(scene, selectRange, style) { const table = scene.table, newStartCol = selectRange.start.col, newStartRow = selectRange.start.row, newEndCol = selectRange.end.col, newEndRow = selectRange.end.row, startCol = (selectRange.skipBodyMerge, Math.max(Math.min(newEndCol, newStartCol), 0)), startRow = Math.max(Math.min(newEndRow, newStartRow), 0), endCol = Math.min(Math.max(newEndCol, newStartCol), table.colCount - 1), endRow = Math.min(Math.max(newEndRow, newStartRow), table.rowCount - 1), {needRowHeader: needRowHeader, needRightRowHeader: needRightRowHeader, needColumnHeader: needColumnHeader, needBottomColumnHeader: needBottomColumnHeader, needBody: needBody, needCornerHeader: needCornerHeader, needRightTopCornerHeader: needRightTopCornerHeader, needLeftBottomCornerHeader: needLeftBottomCornerHeader, needRightBottomCornerHeader: needRightBottomCornerHeader} = calculateCellRangeDistribution(startCol, startRow, endCol, endRow, table); if (needCornerHeader) { createCustomCellSelectBorder(scene, startCol, startRow, Math.min(endCol, table.frozenColCount - 1), Math.min(endRow, table.frozenRowCount - 1), "cornerHeader", `${startCol}${startRow}${endCol}${endRow}`, [ !0, !needColumnHeader, !needRowHeader, !0 ], style); } if (needRightTopCornerHeader) { createCustomCellSelectBorder(scene, Math.max(startCol, table.colCount - table.rightFrozenColCount), startRow, endCol, Math.min(endRow, table.frozenRowCount - 1), "rightTopCorner", `${startCol}${startRow}${endCol}${endRow}`, [ !0, !0, !needRightRowHeader, !needColumnHeader ], style); } if (needLeftBottomCornerHeader) { const cornerEndCol = Math.min(endCol, table.frozenColCount - 1); createCustomCellSelectBorder(scene, startCol, Math.max(startRow, table.rowCount - table.bottomFrozenRowCount), cornerEndCol, endRow, "leftBottomCorner", `${startCol}${startRow}${endCol}${endRow}`, [ !needRowHeader, !needBottomColumnHeader, !0, !0 ], style); } if (needRightBottomCornerHeader) { createCustomCellSelectBorder(scene, Math.max(startCol, table.colCount - table.rightFrozenColCount), Math.max(startRow, table.rowCount - table.bottomFrozenRowCount), endCol, endRow, "rightBottomCorner", `${startCol}${startRow}${endCol}${endRow}`, [ !needRightRowHeader, !0, !0, !needBottomColumnHeader ], style); } if (needColumnHeader) { createCustomCellSelectBorder(scene, Math.max(startCol, table.frozenColCount), startRow, Math.min(endCol, table.colCount - table.rightFrozenColCount - 1), Math.min(endRow, table.frozenRowCount - 1), "columnHeader", `${startCol}${startRow}${endCol}${endRow}`, [ !0, !needRightTopCornerHeader, !needBody, !needCornerHeader ], style); } if (needBottomColumnHeader) { const columnHeaderStartCol = Math.max(startCol, table.frozenColCount), columnHeaderEndCol = Math.min(endCol, table.colCount - table.rightFrozenColCount - 1); createCustomCellSelectBorder(scene, columnHeaderStartCol, Math.max(startRow, table.rowCount - table.bottomFrozenRowCount), columnHeaderEndCol, endRow, "bottomFrozen", `${startCol}${startRow}${endCol}${endRow}`, [ !needBody, !needRightBottomCornerHeader, !0, !needLeftBottomCornerHeader ], style); } if (needRowHeader) { const columnHeaderStartRow = Math.max(startRow, table.frozenRowCount), columnHeaderEndRow = Math.min(endRow, table.rowCount - table.bottomFrozenRowCount - 1); createCustomCellSelectBorder(scene, startCol, columnHeaderStartRow, Math.min(endCol, table.frozenColCount - 1), columnHeaderEndRow, "rowHeader", `${startCol}${startRow}${endCol}${endRow}`, [ !needCornerHeader, !needBody, !needLeftBottomCornerHeader, !0 ], style); } if (needRightRowHeader) { const columnHeaderStartRow = Math.max(startRow, table.frozenRowCount), columnHeaderEndRow = Math.min(endRow, table.rowCount - table.bottomFrozenRowCount - 1); createCustomCellSelectBorder(scene, Math.max(startCol, table.colCount - table.rightFrozenColCount), columnHeaderStartRow, endCol, columnHeaderEndRow, "rightFrozen", `${startCol}${startRow}${endCol}${endRow}`, [ !needRightTopCornerHeader, !0, !needRightBottomCornerHeader, !needBody ], style); } if (needBody) { createCustomCellSelectBorder(scene, Math.max(startCol, table.frozenColCount), Math.max(startRow, table.frozenRowCount), Math.min(endCol, table.colCount - table.rightFrozenColCount - 1), Math.min(endRow, table.rowCount - table.bottomFrozenRowCount - 1), "body", `${startCol}${startRow}${endCol}${endRow}`, [ !needColumnHeader, !needRightRowHeader, !needBottomColumnHeader, !needRowHeader ], style); } } function createCustomCellSelectBorder(scene, start_Col, start_Row, end_Col, end_Row, selectRangeType, selectId, strokes, style) { var _a, _b, _c, _d, _e, _f; const startCol = Math.min(start_Col, end_Col), startRow = Math.min(start_Row, end_Row), endCol = Math.max(start_Col, end_Col), endRow = Math.max(start_Row, end_Row), overlayGroup = scene.getSelectOverlayGroup(selectRangeType), offsetX = scene.tableGroup.attribute.x + (null !== (_a = overlayGroup.attribute.x) && void 0 !== _a ? _a : 0), offsetY = scene.tableGroup.attribute.y + (null !== (_b = overlayGroup.attribute.y) && void 0 !== _b ? _b : 0), firstCellBound = scene.highPerformanceGetCell(startCol, startRow).globalAABBBounds, rect = createRect({ pickable: !1, fill: null !== (_c = style.cellBgColor) && void 0 !== _c && _c, lineWidth: null !== (_d = style.cellBorderLineWidth) && void 0 !== _d ? _d : 0, lineDash: null !== (_e = style.cellBorderLineDash) && void 0 !== _e ? _e : [], stroke: strokes.map((stroke => !!stroke && style.cellBorderColor)), x: firstCellBound.x1 - offsetX, y: firstCellBound.y1 - offsetY, width: 0, height: 0, visible: !0, cornerRadius: getCornerRadius(selectRangeType, null === (_f = scene.table.theme.frameStyle) || void 0 === _f ? void 0 : _f.cornerRadius, start_Col, start_Row, end_Col, end_Row, scene.table) }); scene.customSelectedRangeComponents.set(`${startCol}-${startRow}-${endCol}-${endRow}-${selectId}`, { rect: rect, role: selectRangeType }), overlayGroup.addChild(rect); } //# sourceMappingURL=update-custom-select-border.js.map