1 | "use strict";
|
2 | var __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 | })();
|
15 | var __assign = (this && this.__assign) || function () {
|
16 | __assign = Object.assign || function(t) {
|
17 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
18 | s = arguments[i];
|
19 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
20 | t[p] = s[p];
|
21 | }
|
22 | return t;
|
23 | };
|
24 | return __assign.apply(this, arguments);
|
25 | };
|
26 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
27 | if (k2 === undefined) k2 = k;
|
28 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
29 | }) : (function(o, m, k, k2) {
|
30 | if (k2 === undefined) k2 = k;
|
31 | o[k2] = m[k];
|
32 | }));
|
33 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
34 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
35 | }) : function(o, v) {
|
36 | o["default"] = v;
|
37 | });
|
38 | var __importStar = (this && this.__importStar) || function (mod) {
|
39 | if (mod && mod.__esModule) return mod;
|
40 | var result = {};
|
41 | if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
42 | __setModuleDefault(result, mod);
|
43 | return result;
|
44 | };
|
45 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
46 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
47 | };
|
48 | Object.defineProperty(exports, "__esModule", { value: true });
|
49 | var react_1 = __importDefault(require("react"));
|
50 | require("./reactElement/component");
|
51 | var annotation_1 = __importDefault(require("@antv/g2/lib/chart/controller/annotation"));
|
52 | var _ = __importStar(require("@antv/util"));
|
53 | var view_1 = __importDefault(require("../../context/view"));
|
54 | var core_1 = require("../../core");
|
55 | core_1.registerComponentController('annotation', annotation_1.default);
|
56 |
|
57 | var Annotation = (function (_super) {
|
58 | __extends(Annotation, _super);
|
59 | function Annotation() {
|
60 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
61 | _this.annotationType = 'line';
|
62 | return _this;
|
63 | }
|
64 | Annotation.prototype.componentDidMount = function () {
|
65 | var chartIns = this.getChartIns();
|
66 | this.id = _.uniqueId('annotation');
|
67 | this.annotation = chartIns.annotation();
|
68 |
|
69 | if (this.annotationType === 'ReactElement') {
|
70 | this.annotation.annotation(__assign({ type: 'html', isReactElement: true }, this.props));
|
71 | }
|
72 | else {
|
73 | this.annotation.annotation(__assign({ type: this.annotationType }, this.props));
|
74 | }
|
75 | this.annotation.option[this.annotation.option.length - 1].__id = this.id;
|
76 | };
|
77 | Annotation.prototype.componentDidUpdate = function () {
|
78 | var _this = this;
|
79 | var index = null;
|
80 | this.annotation.option.forEach(function (item, i) {
|
81 | if (item.__id === _this.id) {
|
82 | index = i;
|
83 | }
|
84 | });
|
85 | if (this.annotationType === 'ReactElement') {
|
86 | this.annotation.option[index] = __assign(__assign({ type: 'html', isReactElement: true }, this.props), { __id: this.id });
|
87 | }
|
88 | else {
|
89 | this.annotation.option[index] = __assign(__assign({ type: this.annotationType }, this.props), { __id: this.id });
|
90 | }
|
91 | };
|
92 | Annotation.prototype.componentWillUnmount = function () {
|
93 | var _this = this;
|
94 | var index = null;
|
95 | if (!this.annotation) {
|
96 | return;
|
97 | }
|
98 | this.annotation.option.forEach(function (item, i) {
|
99 | if (item.__id === _this.id) {
|
100 | index = i;
|
101 | }
|
102 | });
|
103 | if (index !== null) {
|
104 | this.annotation.option.splice(index, 1);
|
105 | }
|
106 | this.annotation = null;
|
107 | };
|
108 | Annotation.prototype.getChartIns = function () {
|
109 | return this.context;
|
110 | };
|
111 | Annotation.prototype.render = function () {
|
112 | return react_1.default.createElement(react_1.default.Fragment, null);
|
113 | };
|
114 | return Annotation;
|
115 | }(react_1.default.Component));
|
116 | Annotation.contextType = view_1.default;
|
117 | exports.default = Annotation;
|
118 |
|
\ | No newline at end of file |