1 | "use strict";
|
2 | var __rest = (this && this.__rest) || function (s, e) {
|
3 | var t = {};
|
4 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
5 | t[p] = s[p];
|
6 | if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
7 | for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
8 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
9 | t[p[i]] = s[p[i]];
|
10 | }
|
11 | return t;
|
12 | };
|
13 | Object.defineProperty(exports, "__esModule", { value: true });
|
14 | exports.unregisterSymbol = exports.registerSymbol = exports.useMarker = exports.Symbols = void 0;
|
15 | const g_1 = require("@antv/g");
|
16 | const point = (x, y, r) => {
|
17 | return [
|
18 | ['M', x - r, y],
|
19 | ['A', r, r, 0, 1, 0, x + r, y],
|
20 | ['A', r, r, 0, 1, 0, x - r, y],
|
21 | ['Z'],
|
22 | ];
|
23 | };
|
24 | point.style = ['fill'];
|
25 | const hollowPoint = point.bind(undefined);
|
26 | hollowPoint.style = ['stroke', 'lineWidth'];
|
27 | const square = (x, y, r) => {
|
28 | return [
|
29 | ['M', x - r, y - r],
|
30 | ['L', x + r, y - r],
|
31 | ['L', x + r, y + r],
|
32 | ['L', x - r, y + r],
|
33 | ['Z'],
|
34 | ];
|
35 | };
|
36 | square.style = ['fill'];
|
37 | const rect = square.bind(undefined);
|
38 | rect.style = ['fill'];
|
39 | const hollowSquare = square.bind(undefined);
|
40 | hollowSquare.style = ['stroke', 'lineWidth'];
|
41 | const diamond = (x, y, r) => {
|
42 | const hr = r * 0.618;
|
43 | return [
|
44 | ['M', x - hr, y],
|
45 | ['L', x, y - r],
|
46 | ['L', x + hr, y],
|
47 | ['L', x, y + r],
|
48 | ['Z'],
|
49 | ];
|
50 | };
|
51 | diamond.style = ['fill'];
|
52 | const hollowDiamond = diamond.bind(undefined);
|
53 | hollowDiamond.style = ['stroke', 'lineWidth'];
|
54 | const triangle = (x, y, r) => {
|
55 | const diffY = r * Math.sin((1 / 3) * Math.PI);
|
56 | return [
|
57 | ['M', x - r, y + diffY],
|
58 | ['L', x, y - diffY],
|
59 | ['L', x + r, y + diffY],
|
60 | ['Z'],
|
61 | ];
|
62 | };
|
63 | triangle.style = ['fill'];
|
64 | const hollowTriangle = triangle.bind(undefined);
|
65 | hollowTriangle.style = ['stroke', 'lineWidth'];
|
66 | const triangleDown = (x, y, r) => {
|
67 | const diffY = r * Math.sin((1 / 3) * Math.PI);
|
68 | return [
|
69 | ['M', x - r, y - diffY],
|
70 | ['L', x + r, y - diffY],
|
71 | ['L', x, y + diffY],
|
72 | ['Z'],
|
73 | ];
|
74 | };
|
75 | triangleDown.style = ['fill'];
|
76 | const hollowTriangleDown = triangleDown.bind(undefined);
|
77 | hollowTriangleDown.style = ['stroke', 'lineWidth'];
|
78 | const hexagon = (x, y, r) => {
|
79 | const diffX = (r / 2) * Math.sqrt(3);
|
80 | return [
|
81 | ['M', x, y - r],
|
82 | ['L', x + diffX, y - r / 2],
|
83 | ['L', x + diffX, y + r / 2],
|
84 | ['L', x, y + r],
|
85 | ['L', x - diffX, y + r / 2],
|
86 | ['L', x - diffX, y - r / 2],
|
87 | ['Z'],
|
88 | ];
|
89 | };
|
90 | hexagon.style = ['fill'];
|
91 | const hollowHexagon = hexagon.bind(undefined);
|
92 | hollowHexagon.style = ['stroke', 'lineWidth'];
|
93 | const bowtie = (x, y, r) => {
|
94 | const diffY = r - 1.5;
|
95 | return [
|
96 | ['M', x - r, y - diffY],
|
97 | ['L', x + r, y + diffY],
|
98 | ['L', x + r, y - diffY],
|
99 | ['L', x - r, y + diffY],
|
100 | ['Z'],
|
101 | ];
|
102 | };
|
103 | bowtie.style = ['fill'];
|
104 | const hollowBowtie = bowtie.bind(undefined);
|
105 | hollowBowtie.style = ['stroke', 'lineWidth'];
|
106 | const line = (x, y, r) => {
|
107 | return [
|
108 | ['M', x, y + r],
|
109 | ['L', x, y - r],
|
110 | ];
|
111 | };
|
112 | line.style = ['stroke', 'lineWidth'];
|
113 | const cross = (x, y, r) => {
|
114 | return [
|
115 | ['M', x - r, y - r],
|
116 | ['L', x + r, y + r],
|
117 | ['M', x + r, y - r],
|
118 | ['L', x - r, y + r],
|
119 | ];
|
120 | };
|
121 | cross.style = ['stroke', 'lineWidth'];
|
122 | const tick = (x, y, r) => {
|
123 | return [
|
124 | ['M', x - r / 2, y - r],
|
125 | ['L', x + r / 2, y - r],
|
126 | ['M', x, y - r],
|
127 | ['L', x, y + r],
|
128 | ['M', x - r / 2, y + r],
|
129 | ['L', x + r / 2, y + r],
|
130 | ];
|
131 | };
|
132 | tick.style = ['stroke', 'lineWidth'];
|
133 | const plus = (x, y, r) => {
|
134 | return [
|
135 | ['M', x - r, y],
|
136 | ['L', x + r, y],
|
137 | ['M', x, y - r],
|
138 | ['L', x, y + r],
|
139 | ];
|
140 | };
|
141 | plus.style = ['stroke', 'lineWidth'];
|
142 | const hyphen = (x, y, r) => {
|
143 | return [
|
144 | ['M', x - r, y],
|
145 | ['L', x + r, y],
|
146 | ];
|
147 | };
|
148 | hyphen.style = ['stroke', 'lineWidth'];
|
149 | const dot = (x, y, r) => {
|
150 | return [
|
151 | ['M', x - r, y],
|
152 | ['L', x + r, y],
|
153 | ];
|
154 | };
|
155 | dot.style = ['stroke', 'lineWidth'];
|
156 | const dash = dot.bind(undefined);
|
157 | dash.style = ['stroke', 'lineWidth'];
|
158 | const smooth = (x, y, r) => {
|
159 | return [
|
160 | ['M', x - r, y],
|
161 | ['A', r / 2, r / 2, 0, 1, 1, x, y],
|
162 | ['A', r / 2, r / 2, 0, 1, 0, x + r, y],
|
163 | ];
|
164 | };
|
165 | smooth.style = ['stroke', 'lineWidth'];
|
166 | const hv = (x, y, r) => {
|
167 | return [
|
168 | ['M', x - r - 1, y - 2.5],
|
169 | ['L', x, y - 2.5],
|
170 | ['L', x, y + 2.5],
|
171 | ['L', x + r + 1, y + 2.5],
|
172 | ];
|
173 | };
|
174 | hv.style = ['stroke', 'lineWidth'];
|
175 | const vh = (x, y, r) => {
|
176 | return [
|
177 | ['M', x - r - 1, y + 2.5],
|
178 | ['L', x, y + 2.5],
|
179 | ['L', x, y - 2.5],
|
180 | ['L', x + r + 1, y - 2.5],
|
181 | ];
|
182 | };
|
183 | vh.style = ['stroke', 'lineWidth'];
|
184 | const hvh = (x, y, r) => {
|
185 | return [
|
186 | ['M', x - (r + 1), y + 2.5],
|
187 | ['L', x - r / 2, y + 2.5],
|
188 | ['L', x - r / 2, y - 2.5],
|
189 | ['L', x + r / 2, y - 2.5],
|
190 | ['L', x + r / 2, y + 2.5],
|
191 | ['L', x + r + 1, y + 2.5],
|
192 | ];
|
193 | };
|
194 | hvh.style = ['stroke', 'lineWidth'];
|
195 | const vhv = (x, y, r) => {
|
196 | return [
|
197 | ['M', x - 5, y + 2.5],
|
198 | ['L', x - 5, y],
|
199 | ['L', x, y],
|
200 | ['L', x, y - 3],
|
201 | ['L', x, y + 3],
|
202 | ['L', x + 6.5, y + 3],
|
203 | ];
|
204 | };
|
205 | vhv.style = ['stroke', 'lineWidth'];
|
206 | exports.Symbols = new Map([
|
207 | ['bowtie', bowtie],
|
208 | ['cross', cross],
|
209 | ['dash', dash],
|
210 | ['diamond', diamond],
|
211 | ['dot', dot],
|
212 | ['hexagon', hexagon],
|
213 | ['hollowBowtie', hollowBowtie],
|
214 | ['hollowDiamond', hollowDiamond],
|
215 | ['hollowHexagon', hollowHexagon],
|
216 | ['hollowPoint', hollowPoint],
|
217 | ['hollowSquare', hollowSquare],
|
218 | ['hollowTriangle', hollowTriangle],
|
219 | ['hollowTriangleDown', hollowTriangleDown],
|
220 | ['hv', hv],
|
221 | ['hvh', hvh],
|
222 | ['hyphen', hyphen],
|
223 | ['line', line],
|
224 | ['plus', plus],
|
225 | ['point', point],
|
226 | ['rect', rect],
|
227 | ['smooth', smooth],
|
228 | ['square', square],
|
229 | ['tick', tick],
|
230 | ['triangleDown', triangleDown],
|
231 | ['triangle', triangle],
|
232 | ['vh', vh],
|
233 | ['vhv', vhv],
|
234 | ]);
|
235 | function useMarker(type, _a) {
|
236 | var { d, fill, lineWidth, path, stroke, color } = _a, style = __rest(_a, ["d", "fill", "lineWidth", "path", "stroke", "color"]);
|
237 | const symbol = exports.Symbols.get(type) || exports.Symbols.get('point');
|
238 | return (...args) => {
|
239 | const path = new g_1.Path({
|
240 | style: Object.assign(Object.assign({}, style), { d: symbol(...args), stroke: symbol.style.includes('stroke') ? color || stroke : '', fill: symbol.style.includes('fill') ? color || fill : '', lineWidth: symbol.style.includes('lineWidth')
|
241 | ? lineWidth || lineWidth || 2
|
242 | : 0 }),
|
243 | });
|
244 | return path;
|
245 | };
|
246 | }
|
247 | exports.useMarker = useMarker;
|
248 | function registerSymbol(type, marker) {
|
249 | exports.Symbols.set(type, marker);
|
250 | }
|
251 | exports.registerSymbol = registerSymbol;
|
252 | function unregisterSymbol(type) {
|
253 | exports.Symbols.delete(type);
|
254 | }
|
255 | exports.unregisterSymbol = unregisterSymbol;
|
256 |
|
\ | No newline at end of file |