rendx-shape 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/main.cjs +574 -0
- package/dist/main.d.cts +229 -0
- package/dist/main.d.ts +229 -0
- package/dist/main.js +511 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present wei.liang (https://github.com/weiliang0121)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/main.cjs
ADDED
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/main.ts
|
|
21
|
+
var main_exports = {};
|
|
22
|
+
__export(main_exports, {
|
|
23
|
+
createArc: () => createArc,
|
|
24
|
+
createArea: () => createArea,
|
|
25
|
+
createBoxX: () => createBoxX,
|
|
26
|
+
createBoxY: () => createBoxY,
|
|
27
|
+
createCircle: () => createCircle,
|
|
28
|
+
createCircleSymbol: () => createCircleSymbol,
|
|
29
|
+
createClosedEyeSymbol: () => createClosedEyeSymbol,
|
|
30
|
+
createCrossSymbol: () => createCrossSymbol,
|
|
31
|
+
createDiamondSymbol: () => createDiamondSymbol,
|
|
32
|
+
createDownTriangleSymbol: () => createDownTriangleSymbol,
|
|
33
|
+
createEyeSymbol: () => createEyeSymbol,
|
|
34
|
+
createHLineSymbol: () => createHLineSymbol,
|
|
35
|
+
createIndicatorBox: () => createIndicatorBox,
|
|
36
|
+
createInvertedTriangleSymbol: () => createInvertedTriangleSymbol,
|
|
37
|
+
createLeftTriangleSymbol: () => createLeftTriangleSymbol,
|
|
38
|
+
createLine: () => createLine,
|
|
39
|
+
createRect: () => createRect,
|
|
40
|
+
createRectNormal: () => createRectNormal,
|
|
41
|
+
createRectRounded: () => createRectRounded,
|
|
42
|
+
createResetSymbol: () => createResetSymbol,
|
|
43
|
+
createRightTriangleSymbol: () => createRightTriangleSymbol,
|
|
44
|
+
createRing: () => createRing,
|
|
45
|
+
createSector: () => createSector,
|
|
46
|
+
createSectorNormal: () => createSectorNormal,
|
|
47
|
+
createSectorRounded: () => createSectorRounded,
|
|
48
|
+
createSegmentArea: () => createSegmentArea,
|
|
49
|
+
createSegmentLine: () => createSegmentLine,
|
|
50
|
+
createSelectSymbol: () => createSelectSymbol,
|
|
51
|
+
createShape: () => createShape,
|
|
52
|
+
createSquareSymbol: () => createSquareSymbol,
|
|
53
|
+
createStarSymbol: () => createStarSymbol,
|
|
54
|
+
createSymbol: () => createSymbol,
|
|
55
|
+
createTriangleSymbol: () => createTriangleSymbol,
|
|
56
|
+
createUpTriangleSymbol: () => createUpTriangleSymbol,
|
|
57
|
+
createVLineSymbol: () => createVLineSymbol,
|
|
58
|
+
createWyeSymbol: () => createWyeSymbol,
|
|
59
|
+
fillSymbols: () => fillSymbols
|
|
60
|
+
});
|
|
61
|
+
module.exports = __toCommonJS(main_exports);
|
|
62
|
+
|
|
63
|
+
// src/primitives/circle.ts
|
|
64
|
+
var createCircle = (path, { cx, cy, r }) => {
|
|
65
|
+
path.M(cx, cy - r);
|
|
66
|
+
path.A(r, r, 0, 1, 0, cx, cy + r);
|
|
67
|
+
path.A(r, r, 0, 1, 0, cx, cy - r);
|
|
68
|
+
path.Z();
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// src/primitives/rect.ts
|
|
72
|
+
var import_rendx_core = require("rendx-core");
|
|
73
|
+
var createRectNormal = (path, { x, y, width, height }) => {
|
|
74
|
+
path.M(x, y);
|
|
75
|
+
path.L(x + width, y);
|
|
76
|
+
path.L(x + width, y + height);
|
|
77
|
+
path.L(x, y + height);
|
|
78
|
+
path.Z();
|
|
79
|
+
};
|
|
80
|
+
var createRectRounded = (path, { x, y, width, height, rx, ry }) => {
|
|
81
|
+
if ((0, import_rendx_core.isNum)(rx)) rx = [rx, rx, rx, rx];
|
|
82
|
+
if ((0, import_rendx_core.isNum)(ry)) ry = [ry, ry, ry, ry];
|
|
83
|
+
const [rx1, rx2, rx3 = rx1, rx4 = rx2] = rx.map(Number).map((r) => Math.min(r, width / 2));
|
|
84
|
+
const [ry1, ry2, ry3 = ry1, ry4 = ry2] = ry.map(Number).map((r) => Math.min(r, height / 2));
|
|
85
|
+
path.M(x + rx1, y);
|
|
86
|
+
path.L(x + width - rx2, y);
|
|
87
|
+
path.A(rx2, ry2, 0, 0, 1, x + width, y + ry2);
|
|
88
|
+
path.L(x + width, y + height - ry3);
|
|
89
|
+
path.A(rx3, ry3, 0, 0, 1, x + width - rx3, y + height);
|
|
90
|
+
path.L(x + rx4, y + height);
|
|
91
|
+
path.A(rx4, ry4, 0, 0, 1, x, y + height - ry4);
|
|
92
|
+
path.L(x, y + ry1);
|
|
93
|
+
path.A(rx1, ry1, 0, 0, 1, x + rx1, y);
|
|
94
|
+
path.Z();
|
|
95
|
+
};
|
|
96
|
+
var createRect = (path, options) => {
|
|
97
|
+
const { rx, ry } = options;
|
|
98
|
+
if (!(0, import_rendx_core.isUndef)(rx) && rx !== 0 && !(0, import_rendx_core.isUndef)(ry) && ry !== 0) createRectRounded(path, options);
|
|
99
|
+
else createRectNormal(path, options);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// src/polar/arc.ts
|
|
103
|
+
var createArc = (path, options) => {
|
|
104
|
+
const { cx, cy, r, startAngle, endAngle, radius } = options;
|
|
105
|
+
const r1 = r * radius;
|
|
106
|
+
const t0 = startAngle;
|
|
107
|
+
const t1 = endAngle;
|
|
108
|
+
if (Math.abs(t1 - t0) >= 2 * Math.PI) return createCircle(path, { cx, cy, r: r1 });
|
|
109
|
+
const largeArcFlag = Math.abs(t1 - t0) % (2 * Math.PI) > Math.PI ? 1 : 0;
|
|
110
|
+
path.M(cx + r1 * Math.cos(t0), cy + r1 * Math.sin(t0));
|
|
111
|
+
path.A(r1, r1, 0, largeArcFlag, 1, cx + r1 * Math.cos(t1), cy + r1 * Math.sin(t1));
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// src/polar/ring.ts
|
|
115
|
+
var createRing = (path, options) => {
|
|
116
|
+
const { cx, cy, r, innerRadius, outerRadius } = options;
|
|
117
|
+
const r0 = innerRadius * r;
|
|
118
|
+
const r1 = outerRadius * r;
|
|
119
|
+
path.M(cx, cy - r1);
|
|
120
|
+
path.A(r1, r1, 0, 1, 0, cx, cy + r1);
|
|
121
|
+
path.L(cx, cy + r0);
|
|
122
|
+
path.A(r0, r0, 0, 1, 1, cx, cy - r0);
|
|
123
|
+
path.Z();
|
|
124
|
+
path.M(cx, cy - r0);
|
|
125
|
+
path.A(r0, r0, 0, 1, 1, cx, cy + r0);
|
|
126
|
+
path.L(cx, cy + r1);
|
|
127
|
+
path.A(r1, r1, 0, 1, 0, cx, cy - r1);
|
|
128
|
+
path.Z();
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// src/polar/sector.ts
|
|
132
|
+
var import_rendx_core2 = require("rendx-core");
|
|
133
|
+
var createSectorNormal = (path, options) => {
|
|
134
|
+
const { cx, cy, r, startAngle, endAngle, innerRadius, outerRadius } = options;
|
|
135
|
+
const r0 = innerRadius * r;
|
|
136
|
+
const r1 = outerRadius * r;
|
|
137
|
+
const t0 = startAngle;
|
|
138
|
+
const t1 = endAngle;
|
|
139
|
+
if (Math.abs(t1 - t0) >= 2 * Math.PI) return createRing(path, { cx, cy, r, innerRadius, outerRadius });
|
|
140
|
+
const largeArcFlag = (t1 - t0) % (2 * Math.PI) > Math.PI ? 1 : 0;
|
|
141
|
+
path.M(cx + r1 * Math.cos(t0), cy + r1 * Math.sin(t0));
|
|
142
|
+
path.A(r1, r1, 0, largeArcFlag, 1, cx + r1 * Math.cos(t1), cy + r1 * Math.sin(t1));
|
|
143
|
+
if (r0 === 0) {
|
|
144
|
+
path.L(cx, cy);
|
|
145
|
+
} else {
|
|
146
|
+
path.L(cx + r0 * Math.cos(t1), cy + r0 * Math.sin(t1));
|
|
147
|
+
path.A(r0, r0, 0, largeArcFlag, 0, cx + r0 * Math.cos(t0), cy + r0 * Math.sin(t0));
|
|
148
|
+
}
|
|
149
|
+
path.Z();
|
|
150
|
+
};
|
|
151
|
+
var tangent = (t, t0, r, rc, outer, left) => {
|
|
152
|
+
const rc0 = outer ? r * Math.sin(t / 2) / (1 + Math.sin(t / 2)) : r * Math.sin(t / 2) / (1 - Math.sin(t / 2));
|
|
153
|
+
if (rc > rc0) rc = rc0;
|
|
154
|
+
const sign = outer ? 1 : -1;
|
|
155
|
+
const ot = Math.asin(rc / (r + sign * rc));
|
|
156
|
+
const t1 = left ? (t0 + ot) % (2 * Math.PI) : (t0 - ot) % (2 * Math.PI);
|
|
157
|
+
const r0 = (r + sign * rc) * Math.cos(ot);
|
|
158
|
+
return {
|
|
159
|
+
ot,
|
|
160
|
+
cx: (r + sign * rc) * Math.cos(t1),
|
|
161
|
+
cy: (r + sign * rc) * Math.sin(t1),
|
|
162
|
+
x0: r0 * Math.cos(t0),
|
|
163
|
+
y0: r0 * Math.sin(t0),
|
|
164
|
+
x1: r * Math.cos(t1),
|
|
165
|
+
y1: r * Math.sin(t1),
|
|
166
|
+
rc
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
var epsilon = 1e-6;
|
|
170
|
+
var createSectorRounded = (path, options) => {
|
|
171
|
+
const { cx, cy, r, startAngle, endAngle, innerRadius, outerRadius } = options;
|
|
172
|
+
let { rc } = options;
|
|
173
|
+
if ((0, import_rendx_core2.isNum)(rc)) rc = [rc, rc, rc, rc];
|
|
174
|
+
const r0 = innerRadius * r;
|
|
175
|
+
const r1 = outerRadius * r;
|
|
176
|
+
const t0 = startAngle;
|
|
177
|
+
const t1 = endAngle;
|
|
178
|
+
const dt = Math.abs(t1 - t0);
|
|
179
|
+
const dr = Math.abs(r1 - r0);
|
|
180
|
+
if (Math.abs(t1 - t0) >= 2 * Math.PI) return createRing(path, { cx, cy, r, innerRadius, outerRadius });
|
|
181
|
+
const [rc01, rc00, rc11 = rc01, rc10 = rc00] = rc.map((x) => Math.max(0, Math.min(x, dr / 2)));
|
|
182
|
+
if (dt < 1e-6) return;
|
|
183
|
+
const c01 = tangent(dt, t0, r1, rc01, true, true);
|
|
184
|
+
const c11 = tangent(dt, t1, r1, rc11, true, false);
|
|
185
|
+
let largeArcFlag = dt - c01.ot - c11.ot > Math.PI - epsilon ? 1 : 0;
|
|
186
|
+
path.M(cx + c01.x0, cy + c01.y0);
|
|
187
|
+
path.A(c01.rc, c01.rc, 0, 0, 1, cx + c01.x1, cy + c01.y1);
|
|
188
|
+
path.A(r1, r1, 0, largeArcFlag, 1, cx + c11.x1, cy + c11.y1);
|
|
189
|
+
path.A(c11.rc, c11.rc, 0, 0, 1, cx + c11.x0, cy + c11.y0);
|
|
190
|
+
if (r0 === 0) {
|
|
191
|
+
path.L(cx, cy);
|
|
192
|
+
} else {
|
|
193
|
+
const c00 = tangent(dt, t0, r0, rc00, false, true);
|
|
194
|
+
const c10 = tangent(dt, t1, r0, rc10, false, false);
|
|
195
|
+
largeArcFlag = dt - c00.ot - c10.ot > Math.PI - epsilon ? 1 : 0;
|
|
196
|
+
path.L(cx + c10.x0, cy + c10.y0);
|
|
197
|
+
path.A(c10.rc, c10.rc, 0, 0, 1, cx + c10.x1, cy + c10.y1);
|
|
198
|
+
path.A(r0, r0, 0, largeArcFlag, 0, cx + c00.x1, cy + c00.y1);
|
|
199
|
+
path.A(c00.rc, c00.rc, 0, 0, 1, cx + c00.x0, cy + c00.y0);
|
|
200
|
+
}
|
|
201
|
+
path.Z();
|
|
202
|
+
};
|
|
203
|
+
var createSector = (path, options) => {
|
|
204
|
+
const { rc, startAngle, endAngle, padAngle = 0 } = options;
|
|
205
|
+
const da = Math.abs(endAngle - startAngle) - padAngle;
|
|
206
|
+
if (da <= 1e-4) return;
|
|
207
|
+
const hp = padAngle / 2;
|
|
208
|
+
options.startAngle = startAngle + hp;
|
|
209
|
+
options.endAngle = endAngle - hp;
|
|
210
|
+
if (!(0, import_rendx_core2.isUndef)(rc) && rc !== 0) createSectorRounded(path, options);
|
|
211
|
+
else createSectorNormal(path, options);
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// src/data/line.ts
|
|
215
|
+
var import_rendx_curve = require("rendx-curve");
|
|
216
|
+
var createLine = (path, options) => {
|
|
217
|
+
const { curve = "linear", closed = false, points } = options;
|
|
218
|
+
if (Reflect.has(import_rendx_curve.curveMap, curve)) import_rendx_curve.curveMap[curve](path, points);
|
|
219
|
+
if (points.length === 1) path.Z();
|
|
220
|
+
if (closed) path.Z();
|
|
221
|
+
};
|
|
222
|
+
var createSegmentLine = (path, options) => {
|
|
223
|
+
const { curve, closed = false, segments } = options;
|
|
224
|
+
const len = segments.length;
|
|
225
|
+
for (let i = 0; i < len; i++) createLine(path, { curve, points: segments[i] });
|
|
226
|
+
if (closed) path.Z();
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
// src/data/area.ts
|
|
230
|
+
var import_rendx_curve2 = require("rendx-curve");
|
|
231
|
+
var createArea = (path, options) => {
|
|
232
|
+
const { upperPoints, lowerPoints, curve = "linear", upperCurve = curve, lowerCurve = curve } = options;
|
|
233
|
+
if (Reflect.has(import_rendx_curve2.curveMap, upperCurve)) import_rendx_curve2.curveMap[upperCurve](path, upperPoints);
|
|
234
|
+
const [x, y] = lowerPoints.at(-1);
|
|
235
|
+
path.L(x, y);
|
|
236
|
+
if (Reflect.has(import_rendx_curve2.curveMap, lowerCurve)) import_rendx_curve2.curveMap[lowerCurve](path, lowerPoints.reverse(), false);
|
|
237
|
+
path.Z();
|
|
238
|
+
};
|
|
239
|
+
var createSegmentArea = (path, options) => {
|
|
240
|
+
const { upperSegments, lowerSegments, curve = "linear", upperCurve = curve, lowerCurve = curve } = options;
|
|
241
|
+
const length = Math.min(upperSegments.length, lowerSegments.length);
|
|
242
|
+
for (let i = 0; i < length; i++) {
|
|
243
|
+
createArea(path, { upperPoints: upperSegments[i], lowerPoints: lowerSegments[i], curve, upperCurve, lowerCurve });
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
// src/data/box.ts
|
|
248
|
+
var createBoxX = (path, options) => {
|
|
249
|
+
const { cx, minY, maxY, q1Y, q2Y, q3Y, x, y, width, height } = options;
|
|
250
|
+
path.clear();
|
|
251
|
+
path.M(x, y).H(x + width).V(y + height).H(x).Z();
|
|
252
|
+
path.M(cx, maxY).V(q3Y);
|
|
253
|
+
path.M(cx, minY).V(q1Y);
|
|
254
|
+
path.M(x, maxY).H(x + width);
|
|
255
|
+
path.M(x, q2Y).H(x + width);
|
|
256
|
+
path.M(x, minY).H(x + width);
|
|
257
|
+
};
|
|
258
|
+
var createBoxY = (path, options) => {
|
|
259
|
+
const { cy, minX, maxX, q1X, q2X, q3X, x, y, width, height } = options;
|
|
260
|
+
path.clear();
|
|
261
|
+
path.M(x, y).H(x + width).V(y + height).H(x).Z();
|
|
262
|
+
path.M(maxX, cy).H(q3X);
|
|
263
|
+
path.M(minX, cy).H(q1X);
|
|
264
|
+
path.M(maxX, y).V(y + height);
|
|
265
|
+
path.M(q2X, y).V(y + height);
|
|
266
|
+
path.M(minX, y).V(y + height);
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
// src/factory.ts
|
|
270
|
+
var shapeCreators = /* @__PURE__ */ new Map([
|
|
271
|
+
["circle", createCircle],
|
|
272
|
+
["rect", createRect],
|
|
273
|
+
["arc", createArc],
|
|
274
|
+
["sector", createSector],
|
|
275
|
+
["line", createLine],
|
|
276
|
+
["segmentLine", createSegmentLine],
|
|
277
|
+
["area", createArea],
|
|
278
|
+
["segmentArea", createSegmentArea],
|
|
279
|
+
["boxX", createBoxX],
|
|
280
|
+
["boxY", createBoxY]
|
|
281
|
+
]);
|
|
282
|
+
var createShape = (path, type, options) => {
|
|
283
|
+
const creator = shapeCreators.get(type);
|
|
284
|
+
if (!creator) throw new Error(`Unknown shape type: ${type}`);
|
|
285
|
+
creator(path, options);
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
// src/symbols/circle.ts
|
|
289
|
+
var createCircleSymbol = createCircle;
|
|
290
|
+
|
|
291
|
+
// src/symbols/cross.ts
|
|
292
|
+
var createCrossSymbol = (path, { cx, cy, r }) => {
|
|
293
|
+
const lw = r * 0.382;
|
|
294
|
+
path.M(cx - r, cy - lw);
|
|
295
|
+
path.L(cx - lw, cy - lw);
|
|
296
|
+
path.L(cx - lw, cy - r);
|
|
297
|
+
path.L(cx + lw, cy - r);
|
|
298
|
+
path.L(cx + lw, cy - lw);
|
|
299
|
+
path.L(cx + r, cy - lw);
|
|
300
|
+
path.L(cx + r, cy + lw);
|
|
301
|
+
path.L(cx + lw, cy + lw);
|
|
302
|
+
path.L(cx + lw, cy + r);
|
|
303
|
+
path.L(cx - lw, cy + r);
|
|
304
|
+
path.L(cx - lw, cy + lw);
|
|
305
|
+
path.L(cx - r, cy + lw);
|
|
306
|
+
path.Z();
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
// src/symbols/diamond.ts
|
|
310
|
+
var createDiamondSymbol = (path, { cx, cy, r }) => {
|
|
311
|
+
path.M(cx - r, cy);
|
|
312
|
+
path.L(cx, cy - r);
|
|
313
|
+
path.L(cx + r, cy);
|
|
314
|
+
path.L(cx, cy + r);
|
|
315
|
+
path.Z();
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
// src/symbols/square.ts
|
|
319
|
+
var createSquareSymbol = (path, { cx, cy, r }) => {
|
|
320
|
+
path.M(cx - r, cy - r);
|
|
321
|
+
path.L(cx + r, cy - r);
|
|
322
|
+
path.L(cx + r, cy + r);
|
|
323
|
+
path.L(cx - r, cy + r);
|
|
324
|
+
path.Z();
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
// src/symbols/triangle.ts
|
|
328
|
+
var createTriangle = (path, cx, cy, r, points) => {
|
|
329
|
+
path.M(cx + points[0][0] * r, cy + points[0][1] * r);
|
|
330
|
+
for (let i = 1; i < points.length; i++) path.L(cx + points[i][0] * r, cy + points[i][1] * r);
|
|
331
|
+
path.Z();
|
|
332
|
+
};
|
|
333
|
+
var createUpTriangleSymbol = (path, { cx, cy, r }) => {
|
|
334
|
+
createTriangle(path, +cx, +cy, +r, [
|
|
335
|
+
[0, -1],
|
|
336
|
+
[-1, 1],
|
|
337
|
+
[1, 1]
|
|
338
|
+
]);
|
|
339
|
+
};
|
|
340
|
+
var createDownTriangleSymbol = (path, { cx, cy, r }) => {
|
|
341
|
+
createTriangle(path, +cx, +cy, +r, [
|
|
342
|
+
[0, 1],
|
|
343
|
+
[-1, -1],
|
|
344
|
+
[1, -1]
|
|
345
|
+
]);
|
|
346
|
+
};
|
|
347
|
+
var createLeftTriangleSymbol = (path, { cx, cy, r }) => {
|
|
348
|
+
createTriangle(path, +cx, +cy, +r, [
|
|
349
|
+
[-1, 0],
|
|
350
|
+
[1, -1],
|
|
351
|
+
[1, 1]
|
|
352
|
+
]);
|
|
353
|
+
};
|
|
354
|
+
var createRightTriangleSymbol = (path, { cx, cy, r }) => {
|
|
355
|
+
createTriangle(path, +cx, +cy, +r, [
|
|
356
|
+
[1, 0],
|
|
357
|
+
[-1, -1],
|
|
358
|
+
[-1, 1]
|
|
359
|
+
]);
|
|
360
|
+
};
|
|
361
|
+
var createTriangleSymbol = createUpTriangleSymbol;
|
|
362
|
+
var createInvertedTriangleSymbol = createDownTriangleSymbol;
|
|
363
|
+
|
|
364
|
+
// src/symbols/line.ts
|
|
365
|
+
var createHLineSymbol = (path, { cx, cy, r }) => {
|
|
366
|
+
path.M(cx - r, cy);
|
|
367
|
+
path.L(cx + r, cy);
|
|
368
|
+
path.Z();
|
|
369
|
+
};
|
|
370
|
+
var createVLineSymbol = (path, { cx, cy, r }) => {
|
|
371
|
+
path.M(cx, cy - r);
|
|
372
|
+
path.L(cx, cy + r);
|
|
373
|
+
path.Z();
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
// src/symbols/eye.ts
|
|
377
|
+
var createEyeSymbol = (path, { cx, cy, r }) => {
|
|
378
|
+
path.M(cx, cy - r);
|
|
379
|
+
path.A(r, r, 0, 1, 0, cx, cy + r);
|
|
380
|
+
path.A(r, r, 0, 1, 0, cx, cy - r);
|
|
381
|
+
path.Z();
|
|
382
|
+
};
|
|
383
|
+
var createClosedEyeSymbol = (path, { cx, cy, r }) => {
|
|
384
|
+
const rx = r * 2 / 3;
|
|
385
|
+
const ry = r / 2;
|
|
386
|
+
const r2 = r / 5;
|
|
387
|
+
const dx = r * 2 / 3 + 2;
|
|
388
|
+
const dy = r / 5 + 2;
|
|
389
|
+
path.M(cx - rx, cy);
|
|
390
|
+
path.A(rx, ry, 0, 1, 0, cx + rx, cy);
|
|
391
|
+
path.A(rx, ry, 0, 1, 0, cx - rx, cy);
|
|
392
|
+
path.M(cx - r2, cy);
|
|
393
|
+
path.A(r2, r2, 0, 1, 1, cx + r2, cy);
|
|
394
|
+
path.A(r2, r2, 0, 1, 1, cx - r2, cy);
|
|
395
|
+
path.M(cx - dx, cy + dy);
|
|
396
|
+
path.L(cx + dx, cy - dy);
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
// src/symbols/reset.ts
|
|
400
|
+
var createResetSymbol = (path, { cx, cy, r }) => {
|
|
401
|
+
path.M(cx - 0.5 * r, cy + 0.2 * r);
|
|
402
|
+
path.L(cx - 0.5 * r, cy + r);
|
|
403
|
+
path.L(cx + r, cy + r);
|
|
404
|
+
path.L(cx + r, cy - 0.5 * r);
|
|
405
|
+
path.L(cx - 0.8 * r, cy - 0.5 * r);
|
|
406
|
+
path.M(cx - 0.2 * r, cy - 0.8 * r);
|
|
407
|
+
path.L(cx - 0.8 * r, cy - 0.5 * r);
|
|
408
|
+
path.L(cx - 0.2 * r, cy - 0.2 * r);
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
// src/symbols/select.ts
|
|
412
|
+
var createSelectSymbol = (path, { cx, cy, r }) => {
|
|
413
|
+
path.M(cx - 0.5 * r, cy + 0.2 * r);
|
|
414
|
+
path.L(cx - 0.5 * r, cy + r);
|
|
415
|
+
path.L(cx + r, cy + r);
|
|
416
|
+
path.L(cx + r, cy - 0.5 * r);
|
|
417
|
+
path.L(cx + 0.2 * r, cy - 0.5 * r);
|
|
418
|
+
path.M(cx - r, cy - 0.5 * r);
|
|
419
|
+
path.L(cx, cy - 0.5 * r);
|
|
420
|
+
path.M(cx - 0.5 * r, cy - r);
|
|
421
|
+
path.L(cx - 0.5 * r, cy);
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
// src/symbols/star.ts
|
|
425
|
+
var STAR_COS = [];
|
|
426
|
+
var STAR_SIN = [];
|
|
427
|
+
for (let i = 0; i < 5; i++) {
|
|
428
|
+
const a0 = (i * 72 - 18) * Math.PI / 180;
|
|
429
|
+
const a1 = a0 + 36 * Math.PI / 180;
|
|
430
|
+
STAR_COS.push(Math.cos(a0), 0.5 * Math.cos(a1));
|
|
431
|
+
STAR_SIN.push(Math.sin(a0), 0.5 * Math.sin(a1));
|
|
432
|
+
}
|
|
433
|
+
var createStarSymbol = (path, { cx, cy, r }) => {
|
|
434
|
+
path.M(cx + r * STAR_COS[0], cy + r * STAR_SIN[0]);
|
|
435
|
+
for (let i = 1; i < 10; i++) {
|
|
436
|
+
path.L(cx + r * STAR_COS[i], cy + r * STAR_SIN[i]);
|
|
437
|
+
}
|
|
438
|
+
path.Z();
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
// src/symbols/wye.ts
|
|
442
|
+
var sin = 0.5;
|
|
443
|
+
var cos = Math.sqrt(3) / 2;
|
|
444
|
+
var createWyeSymbol = (path, { cx, cy, r }) => {
|
|
445
|
+
const lineWidth = r * (1 - 0.618);
|
|
446
|
+
const r1 = r;
|
|
447
|
+
const r2 = 1 / cos * lineWidth;
|
|
448
|
+
const r3 = r - r2 * sin;
|
|
449
|
+
const r4 = r - lineWidth * (cos / sin);
|
|
450
|
+
path.M(cx - r2 * cos, cy + r2 * sin);
|
|
451
|
+
path.L(cx - r2 * cos, cy + r1);
|
|
452
|
+
path.L(cx + r2 * cos, cy + r1);
|
|
453
|
+
path.L(cx + r2 * cos, cy + r2 * sin);
|
|
454
|
+
path.L(cx + 2 * lineWidth + r4 * cos, cy - r4 * sin);
|
|
455
|
+
path.L(cx + r3 * cos, cy - r2 - r3 * sin);
|
|
456
|
+
path.L(cx, cy - r2);
|
|
457
|
+
path.L(cx - r3 * cos, cy - r2 - r3 * sin);
|
|
458
|
+
path.L(cx - 2 * lineWidth - r4 * cos, cy - r4 * sin);
|
|
459
|
+
path.Z();
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
// src/symbols/index.ts
|
|
463
|
+
var fillSymbolMap = {
|
|
464
|
+
circle: createCircleSymbol,
|
|
465
|
+
cross: createCrossSymbol,
|
|
466
|
+
diamond: createDiamondSymbol,
|
|
467
|
+
square: createSquareSymbol,
|
|
468
|
+
triangle: createUpTriangleSymbol,
|
|
469
|
+
iTriangle: createDownTriangleSymbol,
|
|
470
|
+
upTriangle: createUpTriangleSymbol,
|
|
471
|
+
downTriangle: createDownTriangleSymbol,
|
|
472
|
+
leftTriangle: createLeftTriangleSymbol,
|
|
473
|
+
rightTriangle: createRightTriangleSymbol
|
|
474
|
+
};
|
|
475
|
+
var featureSymbolMap = {
|
|
476
|
+
line: createHLineSymbol,
|
|
477
|
+
hLine: createHLineSymbol,
|
|
478
|
+
vLine: createVLineSymbol,
|
|
479
|
+
eye: createEyeSymbol,
|
|
480
|
+
closedEye: createClosedEyeSymbol,
|
|
481
|
+
reset: createResetSymbol,
|
|
482
|
+
select: createSelectSymbol
|
|
483
|
+
};
|
|
484
|
+
var fillSymbols = Object.keys(fillSymbolMap);
|
|
485
|
+
var createSymbol = (path, symbol, options) => {
|
|
486
|
+
if (fillSymbolMap[symbol]) fillSymbolMap[symbol](path, options);
|
|
487
|
+
else if (featureSymbolMap[symbol]) featureSymbolMap[symbol](path, options);
|
|
488
|
+
else fillSymbolMap.circle(path, options);
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
// src/general/indicator-box.ts
|
|
492
|
+
var createIndicatorBox = (path, options) => {
|
|
493
|
+
const { anchor, anchorSize: s, width: w, height: h } = options;
|
|
494
|
+
const s2 = s / 2;
|
|
495
|
+
const w2 = w / 2;
|
|
496
|
+
const h2 = h / 2;
|
|
497
|
+
if (anchor === "top") {
|
|
498
|
+
path.M(-w2, s);
|
|
499
|
+
path.L(-s2, s);
|
|
500
|
+
path.L(0, 0);
|
|
501
|
+
path.L(s2, s);
|
|
502
|
+
path.L(w2, s);
|
|
503
|
+
path.L(w2, h + s);
|
|
504
|
+
path.L(-w2, h + s);
|
|
505
|
+
path.Z();
|
|
506
|
+
} else if (anchor === "bottom") {
|
|
507
|
+
path.M(-w2, -h - s);
|
|
508
|
+
path.L(w2, -h - s);
|
|
509
|
+
path.L(w2, -s);
|
|
510
|
+
path.L(s2, -s);
|
|
511
|
+
path.L(0, 0);
|
|
512
|
+
path.L(-s2, -s);
|
|
513
|
+
path.L(-w2, -s);
|
|
514
|
+
path.Z();
|
|
515
|
+
} else if (anchor === "left") {
|
|
516
|
+
path.M(s, -h2);
|
|
517
|
+
path.L(s, -s2);
|
|
518
|
+
path.L(0, 0);
|
|
519
|
+
path.L(s, s2);
|
|
520
|
+
path.L(s, h2);
|
|
521
|
+
path.L(w + s, h2);
|
|
522
|
+
path.L(w + s, -h2);
|
|
523
|
+
path.Z();
|
|
524
|
+
} else if (anchor === "right") {
|
|
525
|
+
path.M(-w - s, -h2);
|
|
526
|
+
path.L(-w - s, h2);
|
|
527
|
+
path.L(-s, h2);
|
|
528
|
+
path.L(-s, s2);
|
|
529
|
+
path.L(0, 0);
|
|
530
|
+
path.L(-s, -s2);
|
|
531
|
+
path.L(-s, -h2);
|
|
532
|
+
path.Z();
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
536
|
+
0 && (module.exports = {
|
|
537
|
+
createArc,
|
|
538
|
+
createArea,
|
|
539
|
+
createBoxX,
|
|
540
|
+
createBoxY,
|
|
541
|
+
createCircle,
|
|
542
|
+
createCircleSymbol,
|
|
543
|
+
createClosedEyeSymbol,
|
|
544
|
+
createCrossSymbol,
|
|
545
|
+
createDiamondSymbol,
|
|
546
|
+
createDownTriangleSymbol,
|
|
547
|
+
createEyeSymbol,
|
|
548
|
+
createHLineSymbol,
|
|
549
|
+
createIndicatorBox,
|
|
550
|
+
createInvertedTriangleSymbol,
|
|
551
|
+
createLeftTriangleSymbol,
|
|
552
|
+
createLine,
|
|
553
|
+
createRect,
|
|
554
|
+
createRectNormal,
|
|
555
|
+
createRectRounded,
|
|
556
|
+
createResetSymbol,
|
|
557
|
+
createRightTriangleSymbol,
|
|
558
|
+
createRing,
|
|
559
|
+
createSector,
|
|
560
|
+
createSectorNormal,
|
|
561
|
+
createSectorRounded,
|
|
562
|
+
createSegmentArea,
|
|
563
|
+
createSegmentLine,
|
|
564
|
+
createSelectSymbol,
|
|
565
|
+
createShape,
|
|
566
|
+
createSquareSymbol,
|
|
567
|
+
createStarSymbol,
|
|
568
|
+
createSymbol,
|
|
569
|
+
createTriangleSymbol,
|
|
570
|
+
createUpTriangleSymbol,
|
|
571
|
+
createVLineSymbol,
|
|
572
|
+
createWyeSymbol,
|
|
573
|
+
fillSymbols
|
|
574
|
+
});
|