@antv/s2
Version:
effective spreadsheet render core lib
51 lines • 2.38 kB
JavaScript
import { find } from 'lodash';
import { ColCell } from '../cell/col-cell';
import { HORIZONTAL_RESIZE_AREA_KEY_PRE } from '../common/constant';
import { formattedFieldValue } from '../utils/cell/header-cell';
import { renderRect } from '../utils/g-renders';
import { getSortTypeIcon } from '../utils/sort-action';
export class TableColCell extends ColCell {
handleRestOptions(...[headerConfig]) {
this.headerConfig = Object.assign({}, headerConfig);
const { field } = this.meta;
const sortParams = this.spreadsheet.dataCfg.sortParams;
const sortParam = find(sortParams, (item) => (item === null || item === void 0 ? void 0 : item.sortFieldId) === field);
const type = getSortTypeIcon(sortParam, true);
this.headerConfig.sortParam = Object.assign(Object.assign(Object.assign({}, this.headerConfig.sortParam), (sortParam || {})), { type });
}
getFormattedFieldValue() {
return formattedFieldValue(this.meta, this.spreadsheet.dataSet.getFieldName(this.meta.field));
}
isSortCell() {
return true;
}
showSortIcon() {
const { extra } = this.meta;
const { options } = this.spreadsheet;
const { showDefaultHeaderActionIcon } = options;
if (!(extra === null || extra === void 0 ? void 0 : extra.isCustomNode)) {
return showDefaultHeaderActionIcon;
}
// 自定义列头时, 只在叶子节点展示
return showDefaultHeaderActionIcon && this.meta.isLeaf;
}
getTextStyle() {
var _a;
const textOverflowStyle = this.getCellTextWordWrapStyle();
const style = (_a = this.getStyle()) === null || _a === void 0 ? void 0 : _a.bolderText;
return Object.assign(Object.assign({}, textOverflowStyle), style);
}
getHorizontalResizeAreaName() {
return `${HORIZONTAL_RESIZE_AREA_KEY_PRE}${this.meta.id}`;
}
drawBackgroundShape() {
const { backgroundColor, backgroundColorOpacity } = this.getStyle().cell || {};
this.backgroundShape = renderRect(this, Object.assign(Object.assign({}, this.getBBoxByType()), { fill: backgroundColor, fillOpacity: backgroundColorOpacity }));
}
drawTextOrCustomRenderer() {
// 明细表列头仅允许文本
this.drawTextShape();
this.afterDrawText();
}
}
//# sourceMappingURL=table-col-cell.js.map