UNPKG

6.22 kBJavaScriptView Raw
1"use strict";
2var __extends = (this && this.__extends) || (function () {
3 var extendStatics = function (d, b) {
4 extendStatics = Object.setPrototypeOf ||
5 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7 return extendStatics(d, b);
8 };
9 return function (d, b) {
10 extendStatics(d, b);
11 function __() { this.constructor = d; }
12 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13 };
14})();
15var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
16 if (k2 === undefined) k2 = k;
17 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
18}) : (function(o, m, k, k2) {
19 if (k2 === undefined) k2 = k;
20 o[k2] = m[k];
21}));
22var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
23 Object.defineProperty(o, "default", { enumerable: true, value: v });
24}) : function(o, v) {
25 o["default"] = v;
26});
27var __importStar = (this && this.__importStar) || function (mod) {
28 if (mod && mod.__esModule) return mod;
29 var result = {};
30 if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
31 __setModuleDefault(result, mod);
32 return result;
33};
34var __rest = (this && this.__rest) || function (s, e) {
35 var t = {};
36 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
37 t[p] = s[p];
38 if (s != null && typeof Object.getOwnPropertySymbols === "function")
39 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
40 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
41 t[p[i]] = s[p[i]];
42 }
43 return t;
44};
45var __importDefault = (this && this.__importDefault) || function (mod) {
46 return (mod && mod.__esModule) ? mod : { "default": mod };
47};
48Object.defineProperty(exports, "__esModule", { value: true });
49var react_1 = __importDefault(require("react"));
50var for_in_1 = __importDefault(require("@antv/util/lib/for-in"));
51var is_function_1 = __importDefault(require("@antv/util/lib/is-function"));
52var debounce_1 = __importDefault(require("@antv/util/lib/debounce"));
53var is_array_1 = __importDefault(require("@antv/util/lib/is-array"));
54var unique_id_1 = __importDefault(require("@antv/util/lib/unique-id"));
55var group_1 = __importStar(require("../context/group"));
56var events_1 = require("./Base/events");
57var Group = /** @class */ (function (_super) {
58 __extends(Group, _super);
59 function Group(props) {
60 var _this = _super.call(this, props) || this;
61 _this.state = {
62 isReady: false,
63 };
64 _this.handleRender = debounce_1.default(function () {
65 if (!_this.instance) {
66 var _a = _this.props, group = _a.group, zIndex = _a.zIndex, name_1 = _a.name;
67 // children.push 中push 找不到
68 _this.instance = group.chart.canvas.addGroup({ zIndex: zIndex, name: name_1 });
69 group.chart.canvas.sort();
70 _this.setState({ isReady: true });
71 }
72 else {
73 _this.forceUpdate();
74 }
75 }, 300);
76 _this.configGroup = function (props) {
77 var _a;
78 var rotate = props.rotate, animate = props.animate, rotateAtPoint = props.rotateAtPoint, scale = props.scale, translate = props.translate, move = props.move;
79 if (rotate) {
80 _this.instance.rotate(rotate);
81 }
82 if (is_array_1.default(rotateAtPoint)) {
83 // @ts-ignore
84 (_a = _this.instance).rotateAtPoint.apply(_a, rotateAtPoint);
85 }
86 if (scale) {
87 _this.instance.rotate(scale);
88 }
89 if (translate) {
90 _this.instance.translate(translate[0], translate[1]);
91 }
92 if (move) {
93 _this.instance.move(move.x, move.y);
94 }
95 if (animate) {
96 var toAttrs = animate.toAttrs, animateCfg = __rest(animate, ["toAttrs"]);
97 _this.instance.animate(toAttrs, animateCfg);
98 }
99 };
100 _this.bindEvents = function () {
101 _this.instance.off();
102 for_in_1.default(events_1.EVENTS, function (v, k) {
103 if (is_function_1.default(_this.props[k])) {
104 _this.instance.on(v, _this.props[k]);
105 }
106 });
107 };
108 var group = props.group, zIndex = props.zIndex, name = props.name;
109 _this.id = unique_id_1.default('group');
110 if (group.isChartCanvas) {
111 group.chart.on('afterrender', _this.handleRender);
112 }
113 else {
114 _this.instance = group.addGroup({ zIndex: zIndex, name: name });
115 _this.configGroup(props);
116 }
117 return _this;
118 }
119 Group.prototype.componentWillUnmount = function () {
120 var group = this.props.group;
121 if (group.isChartCanvas) {
122 group.chart.off('afterrender', this.handleRender);
123 }
124 if (this.instance) {
125 this.instance.remove(true);
126 }
127 };
128 Group.prototype.getInstance = function () {
129 return this.instance;
130 };
131 Group.prototype.render = function () {
132 var group = this.props.group;
133 if (this.instance) {
134 this.instance.clear();
135 this.bindEvents();
136 }
137 return (group.isChartCanvas && this.state.isReady) || (!group.isChartCanvas)
138 ? react_1.default.createElement(group_1.default.Provider, { value: this.instance },
139 react_1.default.createElement(react_1.default.Fragment, { key: unique_id_1.default(this.id) }, this.props.children)) : react_1.default.createElement(react_1.default.Fragment, null);
140 };
141 Group.defaultProps = {
142 zIndex: 3,
143 };
144 return Group;
145}(react_1.default.Component));
146exports.default = group_1.withGroupContext(Group);
147//# sourceMappingURL=Group.js.map
\No newline at end of file