@visactor/vtable
Version:
canvas table width high performance
19 lines (14 loc) • 1.16 kB
JavaScript
import { computeColWidth } from "../../layout/compute-col-width";
import { computeRowHeight } from "../../layout/compute-row-height";
const colSamplingNumber = 10, rowSamplingNumber = 10;
export function getDefaultWidth(table) {
const {rowCount: rowCount, colCount: colCount} = table, widths = [], deltaCol = Math.max(1, Math.ceil(rowCount / 10)), deltaRow = Math.max(1, Math.ceil(colCount / 10));
for (let col = 0; col < colCount; col += deltaCol) for (let row = 0; row < rowCount; row += deltaRow) widths.push(computeColWidth(col, row, row, table));
return Math.ceil(widths.reduce(((a, b) => a + b), 0) / widths.length * 1.2);
}
export function getDefaultHeight(table) {
const {rowCount: rowCount, colCount: colCount} = table, heights = [], deltaCol = Math.max(1, Math.ceil(rowCount / 10)), deltaRow = Math.max(1, Math.ceil(colCount / 10));
for (let col = 0; col < colCount; col += deltaCol) for (let row = 0; row < rowCount; row += deltaRow) heights.push(computeRowHeight(row, col, col, table));
return Math.ceil(heights.reduce(((a, b) => a + b), 0) / heights.length * 1.2);
}
//# sourceMappingURL=default-width-height.js.map