123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- goog.provide('goog.graphics.ext.Group');
- goog.require('goog.array');
- goog.require('goog.graphics.ext.Element');
- goog.graphics.ext.Group = function(group, opt_wrapper) {
- opt_wrapper = opt_wrapper ||
- group.getGraphicsImplementation().createGroup(group.getWrapper());
- goog.graphics.ext.Element.call(this, group, opt_wrapper);
-
- this.children_ = [];
- };
- goog.inherits(goog.graphics.ext.Group, goog.graphics.ext.Element);
- goog.graphics.ext.Group.prototype.addChild = function(element, opt_chain) {
- if (!goog.array.contains(this.children_, element)) {
- this.children_.push(element);
- }
- var transformed = this.growToFit_(element);
- if (element.isParentDependent()) {
- element.parentTransform();
- }
- if (!opt_chain && element.isPendingTransform()) {
- element.reset();
- }
- if (transformed) {
- this.reset();
- }
- };
- goog.graphics.ext.Group.prototype.removeChild = function(element) {
- goog.array.remove(this.children_, element);
-
- this.getGraphicsImplementation().removeElement(element.getWrapper());
- };
- goog.graphics.ext.Group.prototype.forEachChild = function(f, opt_obj) {
- if (this.children_) {
- goog.array.forEach(this.children_, f, opt_obj);
- }
- };
- goog.graphics.ext.Group.prototype.getWrapper;
- goog.graphics.ext.Group.prototype.reset = function() {
- goog.graphics.ext.Group.superClass_.reset.call(this);
- this.updateChildren();
- };
- goog.graphics.ext.Group.prototype.redraw = function() {
- this.getWrapper().setSize(this.getWidth(), this.getHeight());
- this.transformChildren();
- };
- goog.graphics.ext.Group.prototype.transformChildren = function() {
- this.forEachChild(function(child) {
- if (child.isParentDependent()) {
- child.parentTransform();
- }
- });
- };
- goog.graphics.ext.Group.prototype.updateChildren = function() {
- this.forEachChild(function(child) {
- if (child.isParentDependent() || child.isPendingTransform()) {
- child.reset();
- } else if (child.updateChildren) {
- child.updateChildren();
- }
- });
- };
- goog.graphics.ext.Group.prototype.growToFit_ = function(element) {
- var transformed = false;
- var x = element.getMaxX();
- if (x > this.getWidth()) {
- this.setMinWidth(x);
- transformed = true;
- }
- var y = element.getMaxY();
- if (y > this.getHeight()) {
- this.setMinHeight(y);
- transformed = true;
- }
- return transformed;
- };
- goog.graphics.ext.Group.prototype.getCoordinateWidth = function() {
- return this.getWidth();
- };
- goog.graphics.ext.Group.prototype.getCoordinateHeight = function() {
- return this.getHeight();
- };
- goog.graphics.ext.Group.prototype.clear = function() {
- while (this.children_.length) {
- this.removeChild(this.children_[0]);
- }
- };
|