UNPKG

7.18 kBJavaScriptView Raw
1"use strict";
2var __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};
13Object.defineProperty(exports, "__esModule", { value: true });
14exports.unregisterSymbol = exports.registerSymbol = exports.useMarker = exports.Symbols = void 0;
15const g_1 = require("@antv/g");
16const 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};
24point.style = ['fill'];
25const hollowPoint = point.bind(undefined);
26hollowPoint.style = ['stroke', 'lineWidth'];
27const 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};
36square.style = ['fill'];
37const rect = square.bind(undefined);
38rect.style = ['fill'];
39const hollowSquare = square.bind(undefined);
40hollowSquare.style = ['stroke', 'lineWidth'];
41const 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};
51diamond.style = ['fill'];
52const hollowDiamond = diamond.bind(undefined);
53hollowDiamond.style = ['stroke', 'lineWidth'];
54const 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};
63triangle.style = ['fill'];
64const hollowTriangle = triangle.bind(undefined);
65hollowTriangle.style = ['stroke', 'lineWidth'];
66const 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};
75triangleDown.style = ['fill'];
76const hollowTriangleDown = triangleDown.bind(undefined);
77hollowTriangleDown.style = ['stroke', 'lineWidth'];
78const 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};
90hexagon.style = ['fill'];
91const hollowHexagon = hexagon.bind(undefined);
92hollowHexagon.style = ['stroke', 'lineWidth'];
93const 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};
103bowtie.style = ['fill'];
104const hollowBowtie = bowtie.bind(undefined);
105hollowBowtie.style = ['stroke', 'lineWidth'];
106const line = (x, y, r) => {
107 return [
108 ['M', x, y + r],
109 ['L', x, y - r],
110 ];
111};
112line.style = ['stroke', 'lineWidth'];
113const 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};
121cross.style = ['stroke', 'lineWidth'];
122const 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};
132tick.style = ['stroke', 'lineWidth'];
133const 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};
141plus.style = ['stroke', 'lineWidth'];
142const hyphen = (x, y, r) => {
143 return [
144 ['M', x - r, y],
145 ['L', x + r, y],
146 ];
147};
148hyphen.style = ['stroke', 'lineWidth'];
149const dot = (x, y, r) => {
150 return [
151 ['M', x - r, y],
152 ['L', x + r, y],
153 ];
154};
155dot.style = ['stroke', 'lineWidth'];
156const dash = dot.bind(undefined);
157dash.style = ['stroke', 'lineWidth'];
158const 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};
165smooth.style = ['stroke', 'lineWidth'];
166const 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};
174hv.style = ['stroke', 'lineWidth'];
175const 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};
183vh.style = ['stroke', 'lineWidth'];
184const 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};
194hvh.style = ['stroke', 'lineWidth'];
195const 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};
205vhv.style = ['stroke', 'lineWidth'];
206exports.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]);
235function 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}
247exports.useMarker = useMarker;
248function registerSymbol(type, marker) {
249 exports.Symbols.set(type, marker);
250}
251exports.registerSymbol = registerSymbol;
252function unregisterSymbol(type) {
253 exports.Symbols.delete(type);
254}
255exports.unregisterSymbol = unregisterSymbol;
256//# sourceMappingURL=marker.js.map
\No newline at end of file