e-virt-table
Version:
A powerful data table based on canvas. You can use it as data grid、Microsoft Excel or Google sheets. It supports virtual scroll、cell edit etc.
111 lines • 3.42 kB
JavaScript
export default class BaseCell {
constructor(ctx, x, y, width, height, cellType, fixed) {
Object.defineProperty(this, "ctx", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "x", {
enumerable: true,
configurable: true,
writable: true,
value: 0
});
Object.defineProperty(this, "y", {
enumerable: true,
configurable: true,
writable: true,
value: 0
});
Object.defineProperty(this, "width", {
enumerable: true,
configurable: true,
writable: true,
value: 0
});
Object.defineProperty(this, "height", {
enumerable: true,
configurable: true,
writable: true,
value: 0
});
Object.defineProperty(this, "fixed", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "cellType", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this.ctx = ctx;
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.fixed = fixed;
this.cellType = cellType;
}
isHorizontalVisible() {
if (this.fixed) {
return true;
}
const { stageWidth, fixedLeftWidth, scrollX, fixedRightWidth } = this.ctx;
const offsetWidth = stageWidth;
return !(this.x + this.width - fixedLeftWidth - scrollX <= 0 || this.x - scrollX >= offsetWidth - fixedRightWidth);
}
isVerticalVisible() {
const { stageHeight, scrollY } = this.ctx;
const offsetHeight = stageHeight;
return !(this.y + this.height - scrollY <= 0 || this.y - scrollY >= offsetHeight);
}
getDrawX() {
if (this.fixed === 'left') {
return this.x;
}
if (this.fixed === 'right') {
// 可见区域宽度 -到右边界的距离即(表头宽度 - x坐标)
const { stageWidth, config: { SCROLLER_TRACK_SIZE }, } = this.ctx;
const x = stageWidth - (this.ctx.header.width - this.x) - SCROLLER_TRACK_SIZE;
return x;
}
return this.x - this.ctx.scrollX;
}
getDrawY() {
if (this.cellType === 'header') {
return this.y;
}
// footer固定时
if (this.cellType === 'footer' && this.ctx.config.FOOTER_FIXED) {
return this.y;
}
return this.y - this.ctx.scrollY;
}
getLeftFixedX() {
return this.x - this.ctx.scrollX;
}
/**
* RightFixed时相对StageX
* @returns
*/
getRightFixedX() {
// const { SCROLLER_TRACK_SIZE } = this.grid.config;
// if (!this.grid.header) {
// return 0;
// }
// return (
// this.grid.header.width -
// this.x -
// this.grid.layer.x() -
// (this.grid.header.width - this.x) +
// this.grid.stage.width() -
// SCROLLER_TRACK_SIZE -
// (this.grid.header.width - this.x)
// );
}
}
//# sourceMappingURL=BaseCell.js.map