UNPKG

@antv/s2

Version:

effective spreadsheet render core lib

76 lines 3.13 kB
/** * Utils to render all g supported shape * https://github.com/antvis/g */ import { Circle, Line, Polygon, Polyline, Rect, } from '@antv/g'; import { isArray, isEmpty, isFunction } from 'lodash'; import { GuiIcon } from '../common/icons/gui-icon'; import { CustomText } from '../engine/CustomText'; export function renderRect(group, style) { return group === null || group === void 0 ? void 0 : group.appendChild(new Rect({ style, })); } export function renderPolygon(group, style) { return group === null || group === void 0 ? void 0 : group.appendChild(new Polygon({ style })); } export function renderPolyline(group, style) { return group === null || group === void 0 ? void 0 : group.appendChild(new Polyline({ style, })); } export function renderCircle(group, style) { return group === null || group === void 0 ? void 0 : group.appendChild(new Circle({ style, })); } /** * @description 如果在单元格内绘制, 是使用 cell.renderTextShape(options) */ export function renderText(options) { const { group, textShape, style, appendInfo } = options; if (textShape && group) { if (group.contains(textShape)) { group.removeChild(textShape); } } return group === null || group === void 0 ? void 0 : group.appendChild(new CustomText({ style: Object.assign({ /** * 补充 g5.0 内部 measureText 时的必要参数(variant|fontStyle|lineWidth) * 否则创建完 Text 后,实例 getBBox 返回为全 0 * @see https://github.com/antvis/GUI/blob/302ae68d93dbb5675f35fca37e8821d4427d495b/src/util/style.ts#L18-L29 */ fontVariant: 'normal', fontStyle: 'normal', lineWidth: 1 }, style), }, appendInfo || {})); } export function renderLine(group, options) { return group === null || group === void 0 ? void 0 : group.appendChild(new Line({ style: Object.assign({ zIndex: 100 }, options), })); } export function updateShapeAttr(shapeGroup, styleName, styleValue) { if (isEmpty(shapeGroup)) { return; } const shapes = isArray(shapeGroup) ? shapeGroup : [shapeGroup]; shapes.forEach((shape) => { var _a; // https://g-next.antv.vision/zh/docs/api/basic/display-object#%E8%8E%B7%E5%8F%96%E8%AE%BE%E7%BD%AE%E5%B1%9E%E6%80%A7%E5%80%BC (_a = shape === null || shape === void 0 ? void 0 : shape.style) === null || _a === void 0 ? void 0 : _a.setProperty(styleName, styleValue); }); } export function renderIcon(group, iconCfg) { const iconShape = new GuiIcon(iconCfg); group === null || group === void 0 ? void 0 : group.appendChild(iconShape); return iconShape; } export function renderTreeIcon(options) { const { group, iconCfg, isCollapsed, onClick } = options; const iconShape = renderIcon(group, Object.assign(Object.assign({}, iconCfg), { name: isCollapsed ? 'Plus' : 'Minus', cursor: 'pointer' })); if (isFunction(onClick)) { iconShape.addEventListener('click', onClick); } return iconShape; } //# sourceMappingURL=g-renders.js.map