@antv/s2
Version:
effective spreadsheet render core lib
65 lines • 2.72 kB
JavaScript
import { __rest } from "tslib";
import { Group } from '@antv/g';
import { last } from 'lodash';
import { KEY_GROUP_GRID_GROUP, PANEL_GRID_GROUP_Z_INDEX, } from '../common/constant';
import { renderLine } from '../utils/g-renders';
export class GridGroup extends Group {
constructor(cfg) {
const { name, s2 } = cfg, rest = __rest(cfg, ["name", "s2"]);
super({
name,
style: rest,
});
this.gridInfo = {
cols: [],
rows: [],
};
this.updateGrid = (gridInfo, id = KEY_GROUP_GRID_GROUP) => {
var _a, _b;
if (!this.gridGroup || !this.getElementById(id)) {
this.gridGroup = this.appendChild(new Group({
id,
style: {
zIndex: PANEL_GRID_GROUP_Z_INDEX,
},
}));
}
else {
this.gridGroup.removeChildren();
}
const width = (_a = last(gridInfo.cols)) !== null && _a !== void 0 ? _a : 0;
const height = (_b = last(gridInfo.rows)) !== null && _b !== void 0 ? _b : 0;
const { theme } = this.s2;
const style = theme.dataCell.cell;
const verticalBorderWidth = style === null || style === void 0 ? void 0 : style.verticalBorderWidth;
this.gridInfo = gridInfo;
const halfVerticalBorderWidthBorderWidth = verticalBorderWidth / 2;
this.gridInfo.cols.forEach((x) => {
renderLine(this.gridGroup, {
x1: x - halfVerticalBorderWidthBorderWidth,
x2: x - halfVerticalBorderWidthBorderWidth,
y1: 0,
y2: height,
stroke: style.verticalBorderColor,
strokeOpacity: style.verticalBorderColorOpacity,
lineWidth: verticalBorderWidth,
});
});
const horizontalBorderWidth = style === null || style === void 0 ? void 0 : style.horizontalBorderWidth;
const halfHorizontalBorderWidth = horizontalBorderWidth / 2;
this.gridInfo.rows.forEach((y) => {
renderLine(this.gridGroup, {
x1: 0,
x2: width,
y1: y - halfHorizontalBorderWidth,
y2: y - halfHorizontalBorderWidth,
stroke: style.horizontalBorderColor,
strokeOpacity: style.horizontalBorderColorOpacity,
lineWidth: horizontalBorderWidth,
});
});
};
this.s2 = s2;
}
}
//# sourceMappingURL=grid-group.js.map