UNPKG

@antv/g6-pc

Version:

A Graph Visualization Framework in JavaScript

40 lines (39 loc) 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.cloneGElement = void 0; /** * Clone group and clone the clip shapes of image shapes. * @param group group to be cloned * @returns cloned group with same clipped shapes of original group */ var cloneGElement = exports.cloneGElement = function cloneGElement(element) { var vElement = element.clone(); _applyCloneClip(element, vElement); return vElement; }; /** * Apply the clipShape for image shapes from original element to cloned one (clonedElement). * @param element original element * @param clonedElement cloned element of original element */ var _applyCloneClip = function applyCloneClip(element, clonedElement) { var _a; if (element.isGroup() && clonedElement.isGroup()) { (_a = element.get('children')) === null || _a === void 0 ? void 0 : _a.forEach(function (child, i) { var clonedChild = clonedElement.get('children')[i]; _applyCloneClip(child, clonedChild); }); } var type = element.get('type'); var clonedType = clonedElement.get('type'); if (type !== 'image' || clonedType !== 'image') return; var clipShape = element.get('clipShape'); if (clipShape) { clonedElement.setClip({ type: clipShape.get('type'), attrs: clipShape.attr() }); } };