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 __importDefault = (this && this.__importDefault) || function (mod) {
|
16 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
17 | };
|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
19 | var react_1 = __importDefault(require("react"));
|
20 | var is_string_1 = __importDefault(require("@antv/util/lib/is-string"));
|
21 | var is_function_1 = __importDefault(require("@antv/util/lib/is-function"));
|
22 | var base_1 = __importDefault(require("@antv/g2/lib/geometry/label/base"));
|
23 | var view_1 = __importDefault(require("../context/view"));
|
24 | var core_1 = require("../core");
|
25 | var compareProps_1 = __importDefault(require("../utils/compareProps"));
|
26 | var warning_1 = __importDefault(require("warning"));
|
27 | require("./Label");
|
28 |
|
29 | require("./actions");
|
30 | var cloneDeep_1 = __importDefault(require("../utils/cloneDeep"));
|
31 | core_1.registerGeometryLabel('base', base_1.default);
|
32 | var DEFAULT_SORT_GEOMETRYS = ['line', 'area'];
|
33 | var GeomHelper = (function () {
|
34 | function GeomHelper() {
|
35 | this.config = {};
|
36 | }
|
37 | GeomHelper.prototype.setView = function (view) {
|
38 | this.view = view;
|
39 | this.rootChart = view.rootChart || view;
|
40 | };
|
41 | GeomHelper.prototype.createGeomInstance = function (GemoBaseClassName, cfg) {
|
42 | this.geom = this.view[GemoBaseClassName](cfg);
|
43 | var sortable = cfg.sortable;
|
44 |
|
45 |
|
46 | this.geom.__beforeMapping = this.geom.beforeMapping;
|
47 |
|
48 | this.geom.beforeMapping = function (data) {
|
49 | var xScale = this.getXScale();
|
50 | if (sortable !== false && data && data[0] && DEFAULT_SORT_GEOMETRYS.includes(GemoBaseClassName) && ['time', 'timeCat'].includes(xScale.type)) {
|
51 | this.sort(data);
|
52 | }
|
53 | return this.__beforeMapping(data);
|
54 | };
|
55 | this.GemoBaseClassName = GemoBaseClassName;
|
56 | };
|
57 | GeomHelper.prototype.update = function (newConfig, component) {
|
58 | var _this = this;
|
59 | if (!this.geom) {
|
60 | this.setView(component.context);
|
61 |
|
62 | this.createGeomInstance(component.GemoBaseClassName, newConfig);
|
63 | this.interactionTypes = component.interactionTypes;
|
64 | }
|
65 | compareProps_1.default(this.config, newConfig, ['position', 'shape', 'color', 'label', 'style', 'tooltip', 'size', 'animate', 'state', 'customInfo'], function (value, key) {
|
66 | var _a;
|
67 |
|
68 | warning_1.default(!(key === 'label' && value[0] === true), 'label 值类型错误,应为false | LabelOption | FieldString');
|
69 | (_a = _this.geom)[key].apply(_a, value);
|
70 | });
|
71 | compareProps_1.default(this.config, newConfig, ['adjust'], function (value, key) {
|
72 | if (is_string_1.default(value[0])) {
|
73 | _this.geom[key](value[0]);
|
74 | }
|
75 | else {
|
76 | _this.geom[key](value);
|
77 | }
|
78 | });
|
79 |
|
80 | this.geom.state(newConfig.state || {});
|
81 |
|
82 |
|
83 | this.rootChart.on('processElemens', function () {
|
84 | if (is_function_1.default(newConfig.setElements)) {
|
85 | newConfig.setElements(_this.geom.elements);
|
86 | }
|
87 | });
|
88 |
|
89 |
|
90 | compareProps_1.default(this.config, newConfig, this.interactionTypes, function (value, key) {
|
91 | if (value[0]) {
|
92 | _this.rootChart.interaction(key);
|
93 | }
|
94 | else {
|
95 | _this.rootChart.removeInteraction(key);
|
96 | }
|
97 | });
|
98 |
|
99 | this.config = cloneDeep_1.default(newConfig);
|
100 | };
|
101 | GeomHelper.prototype.destroy = function () {
|
102 | if (this.geom) {
|
103 | this.geom.destroy();
|
104 | this.geom = null;
|
105 | }
|
106 | this.config = {};
|
107 | };
|
108 | return GeomHelper;
|
109 | }());
|
110 | var BaseGeom = (function (_super) {
|
111 | __extends(BaseGeom, _super);
|
112 | function BaseGeom(props) {
|
113 | var _this = _super.call(this, props) || this;
|
114 | _this.interactionTypes = [];
|
115 | _this.geomHelper = new GeomHelper();
|
116 | return _this;
|
117 | }
|
118 | BaseGeom.prototype.componentWillUnmount = function () {
|
119 | this.geomHelper.destroy();
|
120 | };
|
121 | BaseGeom.prototype.render = function () {
|
122 | var _this = this;
|
123 | this.geomHelper.update(this.props, this);
|
124 | return react_1.default.createElement(react_1.default.Fragment, null, react_1.default.Children.map(this.props.children, function (ele) {
|
125 | return react_1.default.isValidElement(ele) ? react_1.default.cloneElement(ele, { parentInstance: _this.geomHelper.geom }) : react_1.default.createElement(react_1.default.Fragment, null);
|
126 | }));
|
127 | };
|
128 | return BaseGeom;
|
129 | }(react_1.default.Component));
|
130 | BaseGeom.contextType = view_1.default;
|
131 | exports.default = BaseGeom;
|
132 |
|
\ | No newline at end of file |