@antv/s2
Version:
effective spreadsheet render core lib
60 lines • 2.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAdjustedScrollOffset = exports.getAdjustedRowScrollX = exports.getIndexRangeWithOffsets = exports.getSubTotalNodeWidthOrHeightByLevel = void 0;
const lodash_1 = require("lodash");
const getSubTotalNodeWidthOrHeightByLevel = (sampleNodesForAllLevels, level, key) => sampleNodesForAllLevels
.filter((node) => node.level >= level)
.map((value) => value[key])
.reduce((sum, current) => sum + current, 0);
exports.getSubTotalNodeWidthOrHeightByLevel = getSubTotalNodeWidthOrHeightByLevel;
/**
* 根据视窗高度计算需要展示的数据数组下标
* 如有2个节点,每个高度30
* @param heights 所有单元格的高度偏移量数组 [0, 30, 60]
* @param minHeight 视窗高度起点
* @param maxHeight 视窗高度终点
* @returns
*/
const getIndexRangeWithOffsets = (heights, minHeight, maxHeight) => {
if (maxHeight <= 0) {
return {
start: 0,
end: 0,
};
}
let yMin = (0, lodash_1.findIndex)(heights, (height, idx) => {
const y = minHeight;
return y >= height && y < heights[idx + 1];
}, 0);
yMin = Math.max(yMin, 0);
let yMax = maxHeight === minHeight
? yMin
: (0, lodash_1.findIndex)(heights, (height, idx) => {
const y = maxHeight;
return y > height && y <= heights[idx + 1];
}, yMin);
yMax = Math.min(yMax === -1 ? Infinity : yMax, heights.length - 2);
return {
start: yMin,
end: yMax,
};
};
exports.getIndexRangeWithOffsets = getIndexRangeWithOffsets;
const getAdjustedRowScrollX = (rowHeaderScrollX, cornerBBox) => {
const { width, originalWidth } = cornerBBox;
const scrollX = Math.min(originalWidth - width, rowHeaderScrollX);
if (scrollX < 0) {
return 0;
}
return scrollX;
};
exports.getAdjustedRowScrollX = getAdjustedRowScrollX;
const getAdjustedScrollOffset = (scrollY, contentLength, containerLength) => {
const offset = Math.min(contentLength - containerLength, scrollY);
if (offset < 0) {
return 0;
}
return offset;
};
exports.getAdjustedScrollOffset = getAdjustedScrollOffset;
//# sourceMappingURL=facet.js.map