1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var g_base_1 = require("@antv/g-base");
|
5 | var Shape = require("./shape");
|
6 | var draw_1 = require("./util/draw");
|
7 | var util_1 = require("@antv/util");
|
8 | var util_2 = require("./util/util");
|
9 | var Group = (function (_super) {
|
10 | tslib_1.__extends(Group, _super);
|
11 | function Group() {
|
12 | return _super !== null && _super.apply(this, arguments) || this;
|
13 | }
|
14 | |
15 |
|
16 |
|
17 |
|
18 | Group.prototype.onCanvasChange = function (changeType) {
|
19 | draw_1.refreshElement(this, changeType);
|
20 | };
|
21 | Group.prototype.getShapeBase = function () {
|
22 | return Shape;
|
23 | };
|
24 | Group.prototype.getGroupBase = function () {
|
25 | return Group;
|
26 | };
|
27 |
|
28 | Group.prototype._applyClip = function (context, clip) {
|
29 | if (clip) {
|
30 | context.save();
|
31 |
|
32 | draw_1.applyAttrsToContext(context, clip);
|
33 |
|
34 | clip.createPath(context);
|
35 | context.restore();
|
36 |
|
37 | context.clip();
|
38 | clip._afterDraw();
|
39 | }
|
40 | };
|
41 |
|
42 |
|
43 | Group.prototype.cacheCanvasBBox = function () {
|
44 | var children = this.cfg.children;
|
45 | var xArr = [];
|
46 | var yArr = [];
|
47 | util_1.each(children, function (child) {
|
48 | var bbox = child.cfg.cacheCanvasBBox;
|
49 |
|
50 |
|
51 | if (bbox && child.cfg.isInView) {
|
52 | xArr.push(bbox.minX, bbox.maxX);
|
53 | yArr.push(bbox.minY, bbox.maxY);
|
54 | }
|
55 | });
|
56 | var bbox = null;
|
57 | if (xArr.length) {
|
58 | var minX = Math.min.apply(null, xArr);
|
59 | var maxX = Math.max.apply(null, xArr);
|
60 | var minY = Math.min.apply(null, yArr);
|
61 | var maxY = Math.max.apply(null, yArr);
|
62 | bbox = {
|
63 | minX: minX,
|
64 | minY: minY,
|
65 | x: minX,
|
66 | y: minY,
|
67 | maxX: maxX,
|
68 | maxY: maxY,
|
69 | width: maxX - minX,
|
70 | height: maxY - minY,
|
71 | };
|
72 | var canvas = this.cfg.canvas;
|
73 | if (canvas) {
|
74 | var viewRange = canvas.getViewRange();
|
75 |
|
76 |
|
77 | this.set('isInView', util_2.intersectRect(bbox, viewRange));
|
78 | }
|
79 | }
|
80 | else {
|
81 | this.set('isInView', false);
|
82 | }
|
83 | this.set('cacheCanvasBBox', bbox);
|
84 | };
|
85 | Group.prototype.draw = function (context, region) {
|
86 | var children = this.cfg.children;
|
87 | var allowDraw = region ? this.cfg.refresh : true;
|
88 |
|
89 |
|
90 |
|
91 | if (children.length && allowDraw) {
|
92 | context.save();
|
93 |
|
94 |
|
95 | draw_1.applyAttrsToContext(context, this);
|
96 | this._applyClip(context, this.getClip());
|
97 | draw_1.drawChildren(context, children, region);
|
98 | context.restore();
|
99 | this.cacheCanvasBBox();
|
100 | }
|
101 |
|
102 |
|
103 | this.cfg.refresh = null;
|
104 |
|
105 | this.set('hasChanged', false);
|
106 | };
|
107 |
|
108 | Group.prototype.skipDraw = function () {
|
109 | this.set('cacheCanvasBBox', null);
|
110 | this.set('hasChanged', false);
|
111 | };
|
112 | return Group;
|
113 | }(g_base_1.AbstractGroup));
|
114 | exports.default = Group;
|
115 |
|
\ | No newline at end of file |