@antv/s2
Version:
effective spreadsheet render core lib
69 lines • 2.76 kB
JavaScript
import { Group } from '@antv/g';
import { corelib, renderToMountedElement } from '@antv/g2';
import { CellClipBox, customMerge, waitForCellMounted, } from '@antv/s2';
import { isFunction } from 'lodash';
import { DEFAULT_CHART_SPEC } from '../constant';
import { getCoordinate, getScaleY, getTheme, getTooltip, } from '../utils/chart-options';
import { AxisCellType } from './cell-type';
import { ChartDataCell } from './chart-data-cell';
export class PivotChartDataCell extends ChartDataCell {
isChartData() {
return true;
}
getChartData() {
const { data, xField, yField } = this.meta;
return {
data,
encode: {
x: this.spreadsheet.isPolarCoordinate()
? null
: xField,
y: yField,
color: xField,
},
};
}
getChartOptions() {
var _a;
const { yField } = this.meta;
let customSpec = (_a = this.spreadsheet.options.chart) === null || _a === void 0 ? void 0 : _a.dataCellSpec;
if (isFunction(customSpec)) {
customSpec = customSpec(this);
}
return customMerge(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, DEFAULT_CHART_SPEC), this.getBBoxByType(CellClipBox.CONTENT_BOX)), getCoordinate(this.spreadsheet)), this.getChartData()), getScaleY(yField, this.spreadsheet)), getTooltip(this.meta, this.spreadsheet)), getTheme(this.spreadsheet)), customSpec);
}
drawTextShape() {
const chartOptions = this.getChartOptions();
if (!this.chartShape) {
this.chartShape = this.appendChild(new Group({ style: { zIndex: 1 } }));
}
waitForCellMounted(() => {
if (this.destroyed) {
return;
}
// https://g2.antv.antgroup.com/manual/extra-topics/bundle#g2corelib
renderToMountedElement(chartOptions, {
group: this.chartShape,
library: corelib(),
});
});
}
handleSelect(cells) {
var _a;
super.handleSelect(cells);
const currentCellType = (_a = cells === null || cells === void 0 ? void 0 : cells[0]) === null || _a === void 0 ? void 0 : _a.type;
switch (currentCellType) {
// 列多选
case AxisCellType.AXIS_COL_CELL:
this.changeRowColSelectState('colIndex');
break;
// 行多选
case AxisCellType.AXIS_ROW_CELL:
this.changeRowColSelectState('rowIndex');
break;
default:
break;
}
}
}
//# sourceMappingURL=pivot-chart-data-cell.js.map