cione-comp-lib
Version:
`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`
174 lines (173 loc) • 4.94 kB
JavaScript
import { __extends } from "../../../tslib/tslib.es6.mjs";
import { indexOf } from "../core/util.mjs";
import Element from "../Element.mjs";
import BoundingRect from "../core/BoundingRect.mjs";
var Group = function(_super) {
__extends(Group2, _super);
function Group2(opts) {
var _this = _super.call(this) || this;
_this.isGroup = true;
_this._children = [];
_this.attr(opts);
return _this;
}
Group2.prototype.childrenRef = function() {
return this._children;
};
Group2.prototype.children = function() {
return this._children.slice();
};
Group2.prototype.childAt = function(idx) {
return this._children[idx];
};
Group2.prototype.childOfName = function(name) {
var children = this._children;
for (var i = 0; i < children.length; i++) {
if (children[i].name === name) {
return children[i];
}
}
};
Group2.prototype.childCount = function() {
return this._children.length;
};
Group2.prototype.add = function(child) {
if (child) {
if (child !== this && child.parent !== this) {
this._children.push(child);
this._doAdd(child);
}
}
return this;
};
Group2.prototype.addBefore = function(child, nextSibling) {
if (child && child !== this && child.parent !== this && nextSibling && nextSibling.parent === this) {
var children = this._children;
var idx = children.indexOf(nextSibling);
if (idx >= 0) {
children.splice(idx, 0, child);
this._doAdd(child);
}
}
return this;
};
Group2.prototype.replace = function(oldChild, newChild) {
var idx = indexOf(this._children, oldChild);
if (idx >= 0) {
this.replaceAt(newChild, idx);
}
return this;
};
Group2.prototype.replaceAt = function(child, index) {
var children = this._children;
var old = children[index];
if (child && child !== this && child.parent !== this && child !== old) {
children[index] = child;
old.parent = null;
var zr = this.__zr;
if (zr) {
old.removeSelfFromZr(zr);
}
this._doAdd(child);
}
return this;
};
Group2.prototype._doAdd = function(child) {
if (child.parent) {
child.parent.remove(child);
}
child.parent = this;
var zr = this.__zr;
if (zr && zr !== child.__zr) {
child.addSelfToZr(zr);
}
zr && zr.refresh();
};
Group2.prototype.remove = function(child) {
var zr = this.__zr;
var children = this._children;
var idx = indexOf(children, child);
if (idx < 0) {
return this;
}
children.splice(idx, 1);
child.parent = null;
if (zr) {
child.removeSelfFromZr(zr);
}
zr && zr.refresh();
return this;
};
Group2.prototype.removeAll = function() {
var children = this._children;
var zr = this.__zr;
for (var i = 0; i < children.length; i++) {
var child = children[i];
if (zr) {
child.removeSelfFromZr(zr);
}
child.parent = null;
}
children.length = 0;
return this;
};
Group2.prototype.eachChild = function(cb, context) {
var children = this._children;
for (var i = 0; i < children.length; i++) {
var child = children[i];
cb.call(context, child, i);
}
return this;
};
Group2.prototype.traverse = function(cb, context) {
for (var i = 0; i < this._children.length; i++) {
var child = this._children[i];
var stopped = cb.call(context, child);
if (child.isGroup && !stopped) {
child.traverse(cb, context);
}
}
return this;
};
Group2.prototype.addSelfToZr = function(zr) {
_super.prototype.addSelfToZr.call(this, zr);
for (var i = 0; i < this._children.length; i++) {
var child = this._children[i];
child.addSelfToZr(zr);
}
};
Group2.prototype.removeSelfFromZr = function(zr) {
_super.prototype.removeSelfFromZr.call(this, zr);
for (var i = 0; i < this._children.length; i++) {
var child = this._children[i];
child.removeSelfFromZr(zr);
}
};
Group2.prototype.getBoundingRect = function(includeChildren) {
var tmpRect = new BoundingRect(0, 0, 0, 0);
var children = includeChildren || this._children;
var tmpMat = [];
var rect = null;
for (var i = 0; i < children.length; i++) {
var child = children[i];
if (child.ignore || child.invisible) {
continue;
}
var childRect = child.getBoundingRect();
var transform = child.getLocalTransform(tmpMat);
if (transform) {
BoundingRect.applyTransform(tmpRect, childRect, transform);
rect = rect || tmpRect.clone();
rect.union(tmpRect);
} else {
rect = rect || childRect.clone();
rect.union(childRect);
}
}
return rect || tmpRect;
};
return Group2;
}(Element);
Group.prototype.type = "group";
var Group$1 = Group;
export { Group$1 as default };