1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getShapeFactory = exports.registerShape = exports.registerShapeFactory = void 0;
|
4 | var tslib_1 = require("tslib");
|
5 | var path_util_1 = require("@antv/path-util");
|
6 | var util_1 = require("@antv/util");
|
7 | var path_1 = require("./util/path");
|
8 |
|
9 | var ShapeFactoryBase = {
|
10 |
|
11 | coordinate: null,
|
12 |
|
13 | defaultShapeType: null,
|
14 |
|
15 | theme: null,
|
16 | |
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | getShapePoints: function (shapeType, shapePoint) {
|
23 | var shape = this.getShape(shapeType);
|
24 | if (shape.getPoints) {
|
25 | return shape.getPoints(shapePoint);
|
26 | }
|
27 | return this.getDefaultPoints(shapePoint);
|
28 | },
|
29 | |
30 |
|
31 |
|
32 |
|
33 |
|
34 | getShape: function (shapeType) {
|
35 | var shape = this[shapeType] || this[this.defaultShapeType];
|
36 | shape.coordinate = this.coordinate;
|
37 | return shape;
|
38 | },
|
39 | |
40 |
|
41 |
|
42 |
|
43 | getDefaultPoints: function () {
|
44 | return [];
|
45 | },
|
46 | |
47 |
|
48 |
|
49 | getDefaultStyle: function (geometryTheme) {
|
50 | return (0, util_1.get)(geometryTheme, [this.defaultShapeType, 'default', 'style'], {});
|
51 | },
|
52 | |
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | getMarker: function (shapeType, markerCfg) {
|
60 | var shape = this.getShape(shapeType);
|
61 | if (!shape.getMarker) {
|
62 | var defaultShapeType = this.defaultShapeType;
|
63 | shape = this.getShape(defaultShapeType);
|
64 | }
|
65 | var theme = this.theme;
|
66 | var shapeStyle = (0, util_1.get)(theme, [shapeType, 'default'], {});
|
67 | var markerStyle = shape.getMarker(markerCfg);
|
68 | return (0, util_1.deepMix)({}, shapeStyle, markerStyle);
|
69 | },
|
70 | |
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 | drawShape: function (shapeType, cfg, container) {
|
79 | var shape = this.getShape(shapeType);
|
80 | return shape.draw(cfg, container);
|
81 | },
|
82 | };
|
83 |
|
84 | var ShapeBase = {
|
85 |
|
86 | coordinate: null,
|
87 | |
88 |
|
89 |
|
90 |
|
91 |
|
92 | parsePath: function (path) {
|
93 | var coordinate = this.coordinate;
|
94 | var parsedPath = (0, path_util_1.parsePathString)(path);
|
95 | if (coordinate.isPolar) {
|
96 | parsedPath = (0, path_1.convertPolarPath)(coordinate, parsedPath);
|
97 | }
|
98 | else {
|
99 | parsedPath = (0, path_1.convertNormalPath)(coordinate, parsedPath);
|
100 | }
|
101 | return parsedPath;
|
102 | },
|
103 | |
104 |
|
105 |
|
106 |
|
107 |
|
108 | parsePoint: function (point) {
|
109 | var coordinate = this.coordinate;
|
110 | return coordinate.convert(point);
|
111 | },
|
112 | |
113 |
|
114 |
|
115 |
|
116 |
|
117 | parsePoints: function (points) {
|
118 | var coordinate = this.coordinate;
|
119 | return points.map(function (point) {
|
120 | return coordinate.convert(point);
|
121 | });
|
122 | },
|
123 | |
124 |
|
125 |
|
126 |
|
127 | draw: function (cfg, container) { },
|
128 | };
|
129 | var ShapeFactoryMap = {};
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 | function registerShapeFactory(factoryName, cfg) {
|
137 | var className = (0, util_1.upperFirst)(factoryName);
|
138 | var geomObj = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, ShapeFactoryBase), cfg), { geometryType: factoryName });
|
139 | ShapeFactoryMap[className] = geomObj;
|
140 | return geomObj;
|
141 | }
|
142 | exports.registerShapeFactory = registerShapeFactory;
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 | function registerShape(factoryName, shapeType, cfg) {
|
151 | var className = (0, util_1.upperFirst)(factoryName);
|
152 | var factory = ShapeFactoryMap[className];
|
153 | var shapeObj = tslib_1.__assign(tslib_1.__assign({}, ShapeBase), cfg);
|
154 | factory[shapeType] = shapeObj;
|
155 | return shapeObj;
|
156 | }
|
157 | exports.registerShape = registerShape;
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 | function getShapeFactory(factoryName) {
|
164 | var className = (0, util_1.upperFirst)(factoryName);
|
165 | return ShapeFactoryMap[className];
|
166 | }
|
167 | exports.getShapeFactory = getShapeFactory;
|
168 |
|
\ | No newline at end of file |