@antv/s2
Version:
effective spreadsheet render core lib
135 lines • 5.55 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RowHeader = void 0;
const g_1 = require("@antv/g");
const lodash_1 = require("lodash");
const cell_1 = require("../../cell");
const common_1 = require("../../common");
const utils_1 = require("../utils");
const base_1 = require("./base");
const util_1 = require("./util");
/**
* Row Header for SpreadSheet
*/
class RowHeader extends base_1.BaseHeader {
initGroups() {
this.scrollGroup = this.appendChild(new g_1.Group({
name: common_1.KEY_GROUP_ROW_SCROLL,
style: { zIndex: common_1.FRONT_GROUND_GROUP_SCROLL_Z_INDEX },
}));
this.frozenGroup = this.appendChild(new g_1.Group({
name: common_1.KEY_GROUP_ROW_FROZEN,
style: { zIndex: common_1.FRONT_GROUND_GROUP_FROZEN_Z_INDEX },
}));
this.frozenTrailingGroup = this.appendChild(new g_1.Group({
name: common_1.KEY_GROUP_ROW_FROZEN_TRAILING,
style: { zIndex: common_1.FRONT_GROUND_GROUP_FROZEN_Z_INDEX },
}));
const { spreadsheet } = this.getHeaderConfig();
this.extraFrozenNodes = (0, util_1.getExtraFrozenRowNodes)(spreadsheet.facet);
}
getCellInstance(node) {
const headerConfig = this.getHeaderConfig();
const { spreadsheet } = headerConfig;
const { rowCell } = spreadsheet.options;
return ((rowCell === null || rowCell === void 0 ? void 0 : rowCell(node, spreadsheet, headerConfig)) ||
new cell_1.RowCell(node, spreadsheet, headerConfig));
}
// row'cell only show when visible
isCellInRect(node) {
const { width, viewportHeight, position, scrollY = 0, scrollX = 0, spreadsheet, } = this.getHeaderConfig();
const frozenGroupAreas = spreadsheet.facet
.frozenGroupAreas;
return (
// bottom
viewportHeight +
scrollY -
frozenGroupAreas[common_1.FrozenGroupArea.TrailingRow].height >
node.y &&
// top
scrollY + frozenGroupAreas[common_1.FrozenGroupArea.Row].height <
node.y + node.height &&
// left
width + scrollX - position.x > node.x &&
// right
scrollX - position.x < node.x + node.width);
}
getCellGroup(item) {
if (item.isFrozenHead) {
return this.frozenGroup;
}
if (item.isFrozenTrailing) {
return this.frozenTrailingGroup;
}
return this.scrollGroup;
}
layout() {
const { nodes } = this.getHeaderConfig();
const appendNode = (node) => {
const group = this.getCellGroup(node);
const cell = this.getCellInstance(node);
node.belongsCell = cell;
group.appendChild(cell);
this.emitRenderEvent(cell);
};
// row'cell only show when visible
(0, lodash_1.each)(nodes, (node) => {
if (this.isCellInRect(node) && node.height !== 0) {
appendNode(node);
}
});
(0, lodash_1.each)(this.extraFrozenNodes, (node) => {
if (node.height !== 0) {
appendNode(node);
}
});
}
emitRenderEvent(cell) {
const { spreadsheet } = this.getHeaderConfig();
spreadsheet.emit(common_1.S2Event.ROW_CELL_RENDER, cell);
spreadsheet.emit(common_1.S2Event.LAYOUT_CELL_RENDER, cell);
}
offset() {
const { scrollX = 0, scrollY = 0, position, spreadsheet, viewportHeight, } = this.getHeaderConfig();
const translateX = position.x - scrollX;
const paginationScrollY = spreadsheet.facet.getPaginationScrollY();
const facet = spreadsheet.facet;
const trailingRowOffset = (0, util_1.getFrozenTrailingRowOffset)(facet, viewportHeight, paginationScrollY);
(0, utils_1.translateGroup)(this.scrollGroup, translateX, position.y - scrollY);
(0, utils_1.translateGroup)(this.frozenGroup, translateX, position.y - paginationScrollY);
(0, utils_1.translateGroup)(this.frozenTrailingGroup, translateX, position.y - trailingRowOffset);
}
clip() {
const { width, viewportHeight, position, spreadsheet } = this.getHeaderConfig();
const frozenGroupAreas = spreadsheet.facet
.frozenGroupAreas;
const frozenRowGroupHeight = frozenGroupAreas[common_1.FrozenGroupArea.Row].height;
const frozenTrailingRowGroupHeight = frozenGroupAreas[common_1.FrozenGroupArea.TrailingRow].height;
this.scrollGroup.style.clipPath = new g_1.Rect({
style: {
x: spreadsheet.facet.cornerBBox.x,
y: position.y + frozenRowGroupHeight,
width,
height: viewportHeight - frozenRowGroupHeight - frozenTrailingRowGroupHeight,
},
});
this.frozenGroup.style.clipPath = new g_1.Rect({
style: {
x: spreadsheet.facet.cornerBBox.x,
y: position.y,
width,
height: frozenRowGroupHeight,
},
});
this.frozenTrailingGroup.style.clipPath = new g_1.Rect({
style: {
x: spreadsheet.facet.cornerBBox.x,
y: position.y + viewportHeight - frozenTrailingRowGroupHeight,
width,
height: frozenTrailingRowGroupHeight,
},
});
}
}
exports.RowHeader = RowHeader;
//# sourceMappingURL=row.js.map