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