UNPKG

@antv/s2

Version:

effective spreadsheet render core lib

78 lines 3.02 kB
import { Group } from '@antv/g'; import { corelib, renderToMountedElement } from '@antv/g2'; import { CellBorderPosition, CellClipBox, CellType, ColCell, customMerge, getOrCreateResizeAreaGroupById, waitForCellMounted, } from '@antv/s2'; import { isFunction } from 'lodash'; import { DEFAULT_G2_SPEC, KEY_GROUP_COL_AXIS_RESIZE_AREA } from '../constant'; import { getAxisStyle, getAxisXOptions, getAxisYOptions, getCoordinate, getTheme, } from '../utils/chart-options'; import { AxisCellType } from './cell-type'; export class AxisColCell extends ColCell { get cellType() { return AxisCellType.AXIS_COL_CELL; } getBorderPositions() { return [ CellBorderPosition.TOP, CellBorderPosition.BOTTOM, CellBorderPosition.RIGHT, ]; } isBolderText() { return false; } getInteractedCells() { var _a; return (_a = this.spreadsheet.interaction) === null || _a === void 0 ? void 0 : _a.getCells([ CellType.COL_CELL, AxisCellType.AXIS_COL_CELL, ]); } initCell() { this.drawBackgroundShape(); this.drawInteractiveBgShape(); this.drawInteractiveBorderShape(); this.drawTextShape(); this.drawBorders(); this.drawResizeArea(); this.update(); } getColResizeArea() { return getOrCreateResizeAreaGroupById(this.spreadsheet, KEY_GROUP_COL_AXIS_RESIZE_AREA); } isCrossColumnLeafNode() { return false; } 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.axisColCellSpec; 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() ? getAxisYOptions(this.meta, this.spreadsheet) : getAxisXOptions(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-col-cell.js.map