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