@antv/s2
Version:
effective spreadsheet render core lib
40 lines • 1.61 kB
JavaScript
import { Group } from '@antv/g-lite';
import { corelib, renderToMountedElement } from '@antv/g2';
import { CellClipBox, DataCell, waitForCellMounted, } from '@antv/s2';
import { isPlainObject } from 'lodash';
import { getTheme } from '../utils/chart-options';
export class ChartDataCell extends DataCell {
drawTextShape() {
// 普通数值单元格正常展示
if (!this.isChartData()) {
super.drawTextShape();
return;
}
this.chartShape = this.appendChild(new Group({ style: { zIndex: 1 } }));
const chartOptions = this.getChartOptions();
waitForCellMounted(() => {
if (this.destroyed) {
return;
}
// https://g2.antv.antgroup.com/manual/extra-topics/bundle#g2corelib
renderToMountedElement(chartOptions, {
group: this.chartShape,
library: corelib(),
});
});
}
isChartData() {
const fieldValue = this.getFieldValue();
return isPlainObject(fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.values);
}
getChartData() {
const { fieldValue } = this.meta;
return fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.values;
}
getChartOptions() {
const chartData = this.getChartData();
const cellArea = this.getBBoxByType(CellClipBox.CONTENT_BOX);
return Object.assign(Object.assign(Object.assign({ autoFit: true }, getTheme(this.spreadsheet)), cellArea), chartData);
}
}
//# sourceMappingURL=chart-data-cell.js.map