@antv/s2
Version:
effective spreadsheet render core lib
71 lines • 2.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PivotChartDataCell = void 0;
const g_1 = require("@antv/g");
const g2_1 = require("@antv/g2");
const s2_1 = require("@antv/s2");
const lodash_1 = require("lodash");
const constant_1 = require("../constant");
const chart_options_1 = require("../utils/chart-options");
const cell_type_1 = require("./cell-type");
const chart_data_cell_1 = require("./chart-data-cell");
class PivotChartDataCell extends chart_data_cell_1.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 ((0, lodash_1.isFunction)(customSpec)) {
customSpec = customSpec(this);
}
return (0, s2_1.customMerge)(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, constant_1.DEFAULT_CHART_SPEC), this.getBBoxByType(s2_1.CellClipBox.CONTENT_BOX)), (0, chart_options_1.getCoordinate)(this.spreadsheet)), this.getChartData()), (0, chart_options_1.getScaleY)(yField, this.spreadsheet)), (0, chart_options_1.getTooltip)(this.meta, this.spreadsheet)), (0, chart_options_1.getTheme)(this.spreadsheet)), customSpec);
}
drawTextShape() {
const chartOptions = this.getChartOptions();
this.chartShape = this.appendChild(new g_1.Group({ style: { zIndex: 1 } }));
(0, s2_1.waitForCellMounted)(() => {
if (this.destroyed) {
return;
}
// https://g2.antv.antgroup.com/manual/extra-topics/bundle#g2corelib
(0, g2_1.renderToMountedElement)(chartOptions, {
group: this.chartShape,
library: (0, g2_1.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 cell_type_1.AxisCellType.AXIS_COL_CELL:
this.changeRowColSelectState('colIndex');
break;
// 行多选
case cell_type_1.AxisCellType.AXIS_ROW_CELL:
this.changeRowColSelectState('rowIndex');
break;
default:
break;
}
}
}
exports.PivotChartDataCell = PivotChartDataCell;
//# sourceMappingURL=pivot-chart-data-cell.js.map