@antv/s2
Version:
effective spreadsheet render core lib
52 lines • 2.07 kB
JavaScript
import { __awaiter } from "tslib";
import { Path } from '@antv/g';
import { CellClipBox } from '../common/interface';
import { getPreparedText } from '../utils/cell/customRenderer';
export class BaseRenderer {
getLoading(cell) {
var _a;
const { x, y, height, width } = this.getCellInfo(cell);
const r = Math.min(height, width) * 0.25;
const centerX = x + width / 2;
const centerY = y + height / 2;
const loadingLine = new Path({
style: {
d: `M${centerX} ${centerY - r}
A${r} ${r} 0 0 1 ${centerX + r} ${centerY}`,
stroke: (_a = cell.getIconStyle()) === null || _a === void 0 ? void 0 : _a.fill,
transformOrigin: `${centerX} ${centerY}`,
},
});
cell.appendChild(loadingLine);
setTimeout(() => {
loadingLine.animate([{ transform: 'rotate(0)' }, { transform: 'rotate(360deg)' }], {
duration: 1000,
iterations: Infinity,
});
});
return loadingLine;
}
process(renderer, cell) {
return __awaiter(this, void 0, void 0, function* () {
const loadingLine = this.getLoading(cell);
const element = yield this.prepare(renderer, cell);
const config = this.generateConfig(renderer, cell, element);
cell.removeChild(loadingLine);
loadingLine.destroy();
this.render(cell, config);
});
}
destroy() { }
getCellInfo(cell) {
var _a;
const fieldValue = cell.getFieldValue();
const text = (_a = fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.toString()) !== null && _a !== void 0 ? _a : '';
return Object.assign({ text }, cell.getBBoxByType(CellClipBox.CONTENT_BOX));
}
prepareText(renderer, cell) {
const { text } = this.getCellInfo(cell);
return getPreparedText(renderer.prepareText, text);
}
}
BaseRenderer.mediaCache = new Map();
//# sourceMappingURL=BaseRenderer.js.map