@antv/s2
Version:
effective spreadsheet render core lib
71 lines • 2.89 kB
JavaScript
import { Group } from '@antv/g';
import { corelib, renderToMountedElement } from '@antv/g2';
import { CellBorderPosition, CellClipBox, CellType, RowCell, customMerge, getOrCreateResizeAreaGroupById, waitForCellMounted, } from '@antv/s2';
import { isFunction } from 'lodash';
import { DEFAULT_G2_SPEC, KEY_GROUP_ROW_AXIS_RESIZE_AREA } from '../constant';
import { getAxisStyle, getAxisXOptions, getAxisYOptions, getCoordinate, getTheme, } from '../utils/chart-options';
import { AxisCellType } from './cell-type';
export class AxisRowCell extends RowCell {
get cellType() {
return AxisCellType.AXIS_ROW_CELL;
}
getBorderPositions() {
return [CellBorderPosition.BOTTOM, CellBorderPosition.LEFT];
}
isBolderText() {
return false;
}
getInteractedCells() {
var _a;
return (_a = this.spreadsheet.interaction) === null || _a === void 0 ? void 0 : _a.getCells([
CellType.ROW_CELL,
AxisCellType.AXIS_ROW_CELL,
]);
}
initCell() {
this.drawBackgroundShape();
this.drawInteractiveBgShape();
this.drawInteractiveBorderShape();
this.drawTextShape();
this.drawBorders();
this.drawResizeAreaInLeaf();
this.update();
}
getResizesArea() {
return getOrCreateResizeAreaGroupById(this.spreadsheet, KEY_GROUP_ROW_AXIS_RESIZE_AREA);
}
drawTextShape() {
if (this.spreadsheet.isPolarCoordinate()) {
super.drawTextShape();
return;
}
this.drawAxisShape();
}
getChartOptions() {
var _a;
const style = this.getStyle();
let customSpec = (_a = this.spreadsheet.options.chart) === null || _a === void 0 ? void 0 : _a.axisRowCellSpec;
if (isFunction(customSpec)) {
customSpec = customSpec(this);
}
return customMerge(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, DEFAULT_G2_SPEC), this.getBBoxByType(CellClipBox.CONTENT_BOX)), getCoordinate(this.spreadsheet)), (this.spreadsheet.isValueInCols()
? getAxisXOptions(this.meta, this.spreadsheet)
: getAxisYOptions(this.meta, this.spreadsheet))), getAxisStyle(style)), getTheme(this.spreadsheet)), customSpec);
}
drawAxisShape() {
const chartOptions = this.getChartOptions();
this.axisShape = this.appendChild(new Group({}));
// delay 到实例被挂载到 parent 后,再渲染 chart
waitForCellMounted(() => {
if (this.destroyed) {
return;
}
// https://g2.antv.antgroup.com/manual/extra-topics/bundle#g2corelib
renderToMountedElement(chartOptions, {
group: this.axisShape,
library: corelib(),
});
});
}
}
//# sourceMappingURL=axis-row-cell.js.map