group.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. "use strict";
  2. exports.__esModule = true;
  3. exports["default"] = void 0;
  4. var _common = require("../../util/common");
  5. var _rect = _interopRequireDefault(require("./shape/rect"));
  6. var _container = _interopRequireDefault(require("./container"));
  7. var _vector = _interopRequireDefault(require("../util/vector2"));
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  9. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  10. var Group = /*#__PURE__*/function (_Rect) {
  11. _inheritsLoose(Group, _Rect);
  12. function Group() {
  13. return _Rect.apply(this, arguments) || this;
  14. }
  15. var _proto = Group.prototype;
  16. _proto._initProperties = function _initProperties() {
  17. this._attrs = {
  18. type: 'group',
  19. zIndex: 0,
  20. visible: true,
  21. destroyed: false,
  22. isGroup: true,
  23. canFill: true,
  24. canStroke: true,
  25. attrs: {},
  26. children: []
  27. };
  28. };
  29. _proto.getBBox = function getBBox() {
  30. var self = this;
  31. var minX = Infinity;
  32. var maxX = -Infinity;
  33. var minY = Infinity;
  34. var maxY = -Infinity;
  35. var children = self.get('children');
  36. for (var i = 0, length = children.length; i < length; i++) {
  37. var child = children[i];
  38. if (child.get('visible')) {
  39. var box = child.getBBox();
  40. if (!box) {
  41. continue;
  42. }
  43. var leftTop = [box.minX, box.minY];
  44. var leftBottom = [box.minX, box.maxY];
  45. var rightTop = [box.maxX, box.minY];
  46. var rightBottom = [box.maxX, box.maxY];
  47. var matrix = child.attr('matrix');
  48. _vector["default"].transformMat2d(leftTop, leftTop, matrix);
  49. _vector["default"].transformMat2d(leftBottom, leftBottom, matrix);
  50. _vector["default"].transformMat2d(rightTop, rightTop, matrix);
  51. _vector["default"].transformMat2d(rightBottom, rightBottom, matrix);
  52. minX = Math.min(leftTop[0], leftBottom[0], rightTop[0], rightBottom[0], minX);
  53. maxX = Math.max(leftTop[0], leftBottom[0], rightTop[0], rightBottom[0], maxX);
  54. minY = Math.min(leftTop[1], leftBottom[1], rightTop[1], rightBottom[1], minY);
  55. maxY = Math.max(leftTop[1], leftBottom[1], rightTop[1], rightBottom[1], maxY);
  56. }
  57. }
  58. return {
  59. minX: minX,
  60. minY: minY,
  61. maxX: maxX,
  62. maxY: maxY,
  63. x: minX,
  64. y: minY,
  65. width: maxX - minX,
  66. height: maxY - minY
  67. };
  68. };
  69. _proto.createPath = function createPath(context) {
  70. var attrs = this.get('attrs'); // 只有在有fillStyle或strokeStyle 时才需要绘制
  71. if (!attrs.fillStyle && !attrs.strokeStyle) {
  72. return;
  73. }
  74. _Rect.prototype.createPath.call(this, context);
  75. };
  76. _proto.drawInner = function drawInner(context) {
  77. _Rect.prototype.drawInner.call(this, context);
  78. this.drawChildren(context);
  79. };
  80. _proto.destroy = function destroy() {
  81. if (this.get('destroyed')) {
  82. return;
  83. }
  84. this.clear();
  85. _Rect.prototype.destroy.call(this);
  86. };
  87. return Group;
  88. }(_rect["default"]);
  89. (0, _common.mix)(Group.prototype, _container["default"], {
  90. getGroupClass: function getGroupClass() {
  91. return Group;
  92. }
  93. });
  94. var _default = Group;
  95. exports["default"] = _default;