@primeui/chart-core 0.0.1-alpha.1
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 +23 -0
- package/README.md +1 -0
- package/dist/animations/index.d.mts +136 -0
- package/dist/animations/index.mjs +18 -0
- package/dist/annotation.utils-Bm0lOO1o.d.mts +290 -0
- package/dist/borderRadius.utils-Cz73LLR_.d.mts +54 -0
- package/dist/canvas-D4vigq47.d.mts +34 -0
- package/dist/canvas.utils-D2WHi2gL.d.mts +167 -0
- package/dist/cartesian/index.d.mts +94 -0
- package/dist/cartesian/index.mjs +93 -0
- package/dist/chunk-22ST6YPP.mjs +304 -0
- package/dist/chunk-2QK2KOBN.mjs +10 -0
- package/dist/chunk-2QRS4YQ5.mjs +18 -0
- package/dist/chunk-3FFJEX4A.mjs +261 -0
- package/dist/chunk-3IYSJ2U7.mjs +567 -0
- package/dist/chunk-3OZLP4I4.mjs +190 -0
- package/dist/chunk-3WEMHXZI.mjs +198 -0
- package/dist/chunk-3Z62EUJN.mjs +138 -0
- package/dist/chunk-4C6EVJ54.mjs +362 -0
- package/dist/chunk-53HW45JB.mjs +102 -0
- package/dist/chunk-55Y3WI6S.mjs +186 -0
- package/dist/chunk-5JCI2DEB.mjs +97 -0
- package/dist/chunk-66T4MRC5.mjs +113 -0
- package/dist/chunk-6HSEJLSR.mjs +376 -0
- package/dist/chunk-6STOLMCA.mjs +187 -0
- package/dist/chunk-7CMVDIOU.mjs +54 -0
- package/dist/chunk-7QQ6ETB4.mjs +228 -0
- package/dist/chunk-A6ZQZFL2.mjs +272 -0
- package/dist/chunk-ADKLH73T.mjs +1 -0
- package/dist/chunk-AGU3NG6D.mjs +22 -0
- package/dist/chunk-AHYIS6EB.mjs +230 -0
- package/dist/chunk-AP3UYWYT.mjs +4 -0
- package/dist/chunk-ARB5T6MP.mjs +326 -0
- package/dist/chunk-ARRGOEFX.mjs +585 -0
- package/dist/chunk-AUF4CHDP.mjs +422 -0
- package/dist/chunk-B4FTADAZ.mjs +561 -0
- package/dist/chunk-BABQKA6K.mjs +339 -0
- package/dist/chunk-BETFQBM2.mjs +197 -0
- package/dist/chunk-BKP26M4K.mjs +413 -0
- package/dist/chunk-BZN2QHGP.mjs +200 -0
- package/dist/chunk-C36VWQ7A.mjs +86 -0
- package/dist/chunk-CHW4RKY3.mjs +16 -0
- package/dist/chunk-CINXJIRR.mjs +120 -0
- package/dist/chunk-DN6AXQYZ.mjs +667 -0
- package/dist/chunk-DP2IZNN3.mjs +92 -0
- package/dist/chunk-DTWTCFRG.mjs +119 -0
- package/dist/chunk-EAMUNLRU.mjs +172 -0
- package/dist/chunk-EDAKJLNA.mjs +17 -0
- package/dist/chunk-ERVQB2VZ.mjs +59 -0
- package/dist/chunk-FFMT6OCO.mjs +92 -0
- package/dist/chunk-FHTC2YDB.mjs +102 -0
- package/dist/chunk-FRST55HY.mjs +16 -0
- package/dist/chunk-HDFGCN2F.mjs +132 -0
- package/dist/chunk-IEGLX7VL.mjs +42 -0
- package/dist/chunk-ILUWFYGY.mjs +220 -0
- package/dist/chunk-IXOWSEHO.mjs +114 -0
- package/dist/chunk-J4RI2C2G.mjs +172 -0
- package/dist/chunk-J65DBT4R.mjs +13 -0
- package/dist/chunk-JGOVWSKH.mjs +179 -0
- package/dist/chunk-JO7VACY2.mjs +25 -0
- package/dist/chunk-JWFBOPM6.mjs +122 -0
- package/dist/chunk-KNDZP446.mjs +895 -0
- package/dist/chunk-KP2TWD4Z.mjs +90 -0
- package/dist/chunk-KQIFO5I3.mjs +225 -0
- package/dist/chunk-KVDEROP6.mjs +59 -0
- package/dist/chunk-LKC7MZKK.mjs +87 -0
- package/dist/chunk-LVMDQ4OJ.mjs +305 -0
- package/dist/chunk-M7B3JF43.mjs +90 -0
- package/dist/chunk-MTGMXRNF.mjs +136 -0
- package/dist/chunk-N3TIT3OH.mjs +1040 -0
- package/dist/chunk-NHRK5KU2.mjs +890 -0
- package/dist/chunk-NKUYIWAP.mjs +243 -0
- package/dist/chunk-NPDZLYIF.mjs +238 -0
- package/dist/chunk-O2X6FF45.mjs +499 -0
- package/dist/chunk-OGJ6IIBW.mjs +176 -0
- package/dist/chunk-OHGCZZPZ.mjs +403 -0
- package/dist/chunk-OWW3K55O.mjs +351 -0
- package/dist/chunk-OXTFAWSK.mjs +60 -0
- package/dist/chunk-PLSDU3C2.mjs +890 -0
- package/dist/chunk-PRDVPOZX.mjs +223 -0
- package/dist/chunk-Q6PPVIHU.mjs +21 -0
- package/dist/chunk-QQBXUDM4.mjs +885 -0
- package/dist/chunk-QS76E3TD.mjs +111 -0
- package/dist/chunk-QWQ6HY4I.mjs +209 -0
- package/dist/chunk-R6Y3R7EW.mjs +135 -0
- package/dist/chunk-RBLZRT5K.mjs +190 -0
- package/dist/chunk-RO4N6YFS.mjs +167 -0
- package/dist/chunk-RQ3CKQOX.mjs +984 -0
- package/dist/chunk-SALTGZFR.mjs +208 -0
- package/dist/chunk-SANZPAJ4.mjs +14 -0
- package/dist/chunk-SDBPQ5CF.mjs +624 -0
- package/dist/chunk-SSLTFJ3U.mjs +364 -0
- package/dist/chunk-SXHVDJGF.mjs +77 -0
- package/dist/chunk-TA4MVAEX.mjs +243 -0
- package/dist/chunk-TAHCOZHF.mjs +1772 -0
- package/dist/chunk-TQ6S34QZ.mjs +152 -0
- package/dist/chunk-UPRXABX5.mjs +90 -0
- package/dist/chunk-VGLSBZDN.mjs +71 -0
- package/dist/chunk-VN7CKCSE.mjs +364 -0
- package/dist/chunk-VVI3OBPJ.mjs +524 -0
- package/dist/chunk-VWF57TS3.mjs +62 -0
- package/dist/chunk-WA3OVISZ.mjs +179 -0
- package/dist/chunk-WCG35U6M.mjs +964 -0
- package/dist/chunk-WFTX4AQJ.mjs +194 -0
- package/dist/chunk-WFVOQ2QZ.mjs +18 -0
- package/dist/chunk-WH3C3Y7P.mjs +149 -0
- package/dist/chunk-WPFUV7K3.mjs +488 -0
- package/dist/chunk-WRULPWHD.mjs +492 -0
- package/dist/chunk-WS64BZXT.mjs +1 -0
- package/dist/chunk-WY4AURRE.mjs +2419 -0
- package/dist/chunk-WYLILAOO.mjs +167 -0
- package/dist/chunk-X4D7FKUS.mjs +62 -0
- package/dist/chunk-X7T34OLW.mjs +139 -0
- package/dist/chunk-XIHBK5D3.mjs +68 -0
- package/dist/chunk-XQQCGFYB.mjs +50 -0
- package/dist/chunk-XTVE4P3L.mjs +214 -0
- package/dist/chunk-XUAASRXW.mjs +579 -0
- package/dist/chunk-Y3L3D4GQ.mjs +685 -0
- package/dist/chunk-YBJ56XJS.mjs +132 -0
- package/dist/chunk-ZQFK6CAE.mjs +1 -0
- package/dist/chunk-ZT2Z7ERM.mjs +874 -0
- package/dist/chunk-ZTL2FQEW.mjs +714 -0
- package/dist/circular/arc/index.d.mts +8 -0
- package/dist/circular/arc/index.mjs +3 -0
- package/dist/circular/index.d.mts +44 -0
- package/dist/circular/index.mjs +13 -0
- package/dist/collect.utils-DiKB4ciO.d.mts +12 -0
- package/dist/computeChartState-BTVIqwyO.d.mts +304 -0
- package/dist/controller-BJE1AZ3q.d.mts +82 -0
- package/dist/controller-BoNigQJr.d.mts +63 -0
- package/dist/controllers/index.d.mts +16 -0
- package/dist/controllers/index.mjs +110 -0
- package/dist/datalabel.utils-CkjGeB8S.d.mts +122 -0
- package/dist/decimation.utils-CcvJVhI4.d.mts +244 -0
- package/dist/geometry-DUUQJXVM.d.mts +60 -0
- package/dist/index-DseIZa1j.d.mts +167 -0
- package/dist/index.d.mts +88 -0
- package/dist/index.mjs +110 -0
- package/dist/orchestrator/index.d.mts +264 -0
- package/dist/orchestrator/index.mjs +33 -0
- package/dist/plugins/index.d.mts +18 -0
- package/dist/plugins/index.mjs +1 -0
- package/dist/property-animations-D433wXzz.d.mts +580 -0
- package/dist/property-store-NORUWFND.d.mts +17 -0
- package/dist/radial/index.d.mts +14 -0
- package/dist/radial/index.mjs +37 -0
- package/dist/renderers/axis/index.d.mts +39 -0
- package/dist/renderers/axis/index.mjs +8 -0
- package/dist/renderers/circular/index.d.mts +13 -0
- package/dist/renderers/circular/index.mjs +13 -0
- package/dist/renderers/index.d.mts +83 -0
- package/dist/renderers/index.mjs +75 -0
- package/dist/renderers/navigator/index.d.mts +103 -0
- package/dist/renderers/navigator/index.mjs +8 -0
- package/dist/resize.utils-D_2qm6rv.d.mts +142 -0
- package/dist/ring.utils-DXvrxMkU.d.mts +138 -0
- package/dist/scale-KFv30jqZ.d.mts +307 -0
- package/dist/scales-Drf8AIhL.d.mts +75 -0
- package/dist/series/bar/canvas/index.d.mts +8 -0
- package/dist/series/bar/canvas/index.mjs +10 -0
- package/dist/series/bar/controller/index.d.mts +105 -0
- package/dist/series/bar/controller/index.mjs +44 -0
- package/dist/series/bar/controller-canvas/index.d.mts +7 -0
- package/dist/series/bar/controller-canvas/index.mjs +49 -0
- package/dist/series/bar/controller-svg/index.d.mts +7 -0
- package/dist/series/bar/controller-svg/index.mjs +49 -0
- package/dist/series/bar/index.d.mts +60 -0
- package/dist/series/bar/index.mjs +13 -0
- package/dist/series/bar/svg/index.d.mts +8 -0
- package/dist/series/bar/svg/index.mjs +11 -0
- package/dist/series/candlestick/canvas/index.d.mts +8 -0
- package/dist/series/candlestick/canvas/index.mjs +8 -0
- package/dist/series/candlestick/controller/index.d.mts +123 -0
- package/dist/series/candlestick/controller/index.mjs +40 -0
- package/dist/series/candlestick/controller-canvas/index.d.mts +7 -0
- package/dist/series/candlestick/controller-canvas/index.mjs +45 -0
- package/dist/series/candlestick/controller-svg/index.d.mts +7 -0
- package/dist/series/candlestick/controller-svg/index.mjs +45 -0
- package/dist/series/candlestick/index.d.mts +11 -0
- package/dist/series/candlestick/index.mjs +10 -0
- package/dist/series/candlestick/svg/index.d.mts +8 -0
- package/dist/series/candlestick/svg/index.mjs +8 -0
- package/dist/series/heatmap/canvas/index.d.mts +16 -0
- package/dist/series/heatmap/canvas/index.mjs +9 -0
- package/dist/series/heatmap/controller/index.d.mts +110 -0
- package/dist/series/heatmap/controller/index.mjs +23 -0
- package/dist/series/heatmap/controller-canvas/index.d.mts +7 -0
- package/dist/series/heatmap/controller-canvas/index.mjs +28 -0
- package/dist/series/heatmap/controller-svg/index.d.mts +7 -0
- package/dist/series/heatmap/controller-svg/index.mjs +28 -0
- package/dist/series/heatmap/index.d.mts +34 -0
- package/dist/series/heatmap/index.mjs +13 -0
- package/dist/series/heatmap/svg/index.d.mts +15 -0
- package/dist/series/heatmap/svg/index.mjs +10 -0
- package/dist/series/line/canvas/index.d.mts +6 -0
- package/dist/series/line/canvas/index.mjs +9 -0
- package/dist/series/line/controller/index.d.mts +111 -0
- package/dist/series/line/controller/index.mjs +47 -0
- package/dist/series/line/controller-canvas/index.d.mts +7 -0
- package/dist/series/line/controller-canvas/index.mjs +54 -0
- package/dist/series/line/controller-svg/index.d.mts +7 -0
- package/dist/series/line/controller-svg/index.mjs +54 -0
- package/dist/series/line/index.d.mts +49 -0
- package/dist/series/line/index.mjs +13 -0
- package/dist/series/line/svg/index.d.mts +6 -0
- package/dist/series/line/svg/index.mjs +9 -0
- package/dist/series/pie/canvas/index.d.mts +8 -0
- package/dist/series/pie/canvas/index.mjs +10 -0
- package/dist/series/pie/controller/index.d.mts +174 -0
- package/dist/series/pie/controller/index.mjs +110 -0
- package/dist/series/pie/controller-canvas/index.d.mts +8 -0
- package/dist/series/pie/controller-canvas/index.mjs +119 -0
- package/dist/series/pie/controller-svg/index.d.mts +8 -0
- package/dist/series/pie/controller-svg/index.mjs +118 -0
- package/dist/series/pie/index.d.mts +59 -0
- package/dist/series/pie/index.mjs +15 -0
- package/dist/series/pie/svg/index.d.mts +6 -0
- package/dist/series/pie/svg/index.mjs +11 -0
- package/dist/series/polar/canvas/index.d.mts +6 -0
- package/dist/series/polar/canvas/index.mjs +7 -0
- package/dist/series/polar/controller/index.d.mts +102 -0
- package/dist/series/polar/controller/index.mjs +46 -0
- package/dist/series/polar/controller-canvas/index.d.mts +8 -0
- package/dist/series/polar/controller-canvas/index.mjs +52 -0
- package/dist/series/polar/controller-svg/index.d.mts +8 -0
- package/dist/series/polar/controller-svg/index.mjs +52 -0
- package/dist/series/polar/index.d.mts +25 -0
- package/dist/series/polar/index.mjs +16 -0
- package/dist/series/polar/svg/index.d.mts +10 -0
- package/dist/series/polar/svg/index.mjs +8 -0
- package/dist/series/radar/canvas/index.d.mts +6 -0
- package/dist/series/radar/canvas/index.mjs +8 -0
- package/dist/series/radar/controller/index.d.mts +121 -0
- package/dist/series/radar/controller/index.mjs +43 -0
- package/dist/series/radar/controller-canvas/index.d.mts +8 -0
- package/dist/series/radar/controller-canvas/index.mjs +51 -0
- package/dist/series/radar/controller-svg/index.d.mts +8 -0
- package/dist/series/radar/controller-svg/index.mjs +51 -0
- package/dist/series/radar/index.d.mts +40 -0
- package/dist/series/radar/index.mjs +13 -0
- package/dist/series/radar/svg/index.d.mts +12 -0
- package/dist/series/radar/svg/index.mjs +9 -0
- package/dist/series/scatter/canvas/index.d.mts +8 -0
- package/dist/series/scatter/canvas/index.mjs +11 -0
- package/dist/series/scatter/controller/index.d.mts +124 -0
- package/dist/series/scatter/controller/index.mjs +44 -0
- package/dist/series/scatter/controller-canvas/index.d.mts +7 -0
- package/dist/series/scatter/controller-canvas/index.mjs +51 -0
- package/dist/series/scatter/controller-svg/index.d.mts +7 -0
- package/dist/series/scatter/controller-svg/index.mjs +51 -0
- package/dist/series/scatter/index.d.mts +25 -0
- package/dist/series/scatter/index.mjs +14 -0
- package/dist/series/scatter/svg/index.d.mts +8 -0
- package/dist/series/scatter/svg/index.mjs +12 -0
- package/dist/series/treemap/canvas/index.d.mts +50 -0
- package/dist/series/treemap/canvas/index.mjs +10 -0
- package/dist/series/treemap/controller/index.d.mts +130 -0
- package/dist/series/treemap/controller/index.mjs +20 -0
- package/dist/series/treemap/controller-canvas/index.d.mts +7 -0
- package/dist/series/treemap/controller-canvas/index.mjs +25 -0
- package/dist/series/treemap/controller-svg/index.d.mts +7 -0
- package/dist/series/treemap/controller-svg/index.mjs +25 -0
- package/dist/series/treemap/index.d.mts +15 -0
- package/dist/series/treemap/index.mjs +12 -0
- package/dist/series/treemap/svg/index.d.mts +15 -0
- package/dist/series/treemap/svg/index.mjs +9 -0
- package/dist/slices-DtewiwJx.d.mts +72 -0
- package/dist/spatialIndex.utils-B_GJkotZ.d.mts +5 -0
- package/dist/squarify.utils-B9CQBpa1.d.mts +50 -0
- package/dist/stacking-CChuAcLN.d.mts +319 -0
- package/dist/streaming.utils-DH-g1gNP.d.mts +49 -0
- package/dist/sync/index.d.mts +130 -0
- package/dist/sync/index.mjs +5 -0
- package/dist/tooltip.renderer-D5wpSlBa.d.mts +210 -0
- package/dist/utils/color/index.d.mts +58 -0
- package/dist/utils/color/index.mjs +4 -0
- package/dist/utils/data/index.d.mts +180 -0
- package/dist/utils/data/index.mjs +7 -0
- package/dist/utils/export/index.d.mts +14 -0
- package/dist/utils/export/index.mjs +6 -0
- package/dist/utils/index.d.mts +49 -0
- package/dist/utils/index.mjs +29 -0
- package/dist/utils/interaction/index.d.mts +255 -0
- package/dist/utils/interaction/index.mjs +9 -0
- package/dist/utils/layout/index.d.mts +3 -0
- package/dist/utils/layout/index.mjs +10 -0
- package/dist/utils/math/index.d.mts +162 -0
- package/dist/utils/math/index.mjs +1 -0
- package/dist/utils/render/index.d.mts +19 -0
- package/dist/utils/render/index.mjs +3 -0
- package/dist/utils/specialized/index.d.mts +37 -0
- package/dist/utils/specialized/index.mjs +66 -0
- package/dist/utils/text/index.d.mts +39 -0
- package/dist/utils/text/index.mjs +8 -0
- package/dist/utils/theme/index.d.mts +295 -0
- package/dist/utils/theme/index.mjs +5 -0
- package/dist/utils/zoom/index.d.mts +90 -0
- package/dist/utils/zoom/index.mjs +3 -0
- package/package.json +56 -0
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
// src/utils/color/parse.ts
|
|
2
|
+
function parseHexColor(hex) {
|
|
3
|
+
let h = hex.replace("#", "");
|
|
4
|
+
if (h.length === 3) {
|
|
5
|
+
h = h[0] + h[0] + h[1] + h[1] + h[2] + h[2];
|
|
6
|
+
}
|
|
7
|
+
const r = parseInt(h.substring(0, 2), 16);
|
|
8
|
+
const g = parseInt(h.substring(2, 4), 16);
|
|
9
|
+
const b = parseInt(h.substring(4, 6), 16);
|
|
10
|
+
return [r, g, b];
|
|
11
|
+
}
|
|
12
|
+
var COLOR_CACHE_MAX_SIZE = 256;
|
|
13
|
+
var colorCache = /* @__PURE__ */ new Map();
|
|
14
|
+
var parsingCanvas = null;
|
|
15
|
+
var parsingContext = null;
|
|
16
|
+
function getParsingContext() {
|
|
17
|
+
if (typeof document === "undefined") return null;
|
|
18
|
+
if (!parsingCanvas) {
|
|
19
|
+
parsingCanvas = document.createElement("canvas");
|
|
20
|
+
parsingCanvas.width = 1;
|
|
21
|
+
parsingCanvas.height = 1;
|
|
22
|
+
parsingContext = parsingCanvas.getContext("2d", { willReadFrequently: true });
|
|
23
|
+
}
|
|
24
|
+
return parsingContext;
|
|
25
|
+
}
|
|
26
|
+
var browserColorParser = {
|
|
27
|
+
parse(color) {
|
|
28
|
+
const ctx = getParsingContext();
|
|
29
|
+
if (!ctx) return null;
|
|
30
|
+
ctx.clearRect(0, 0, 1, 1);
|
|
31
|
+
ctx.fillStyle = color;
|
|
32
|
+
ctx.fillRect(0, 0, 1, 1);
|
|
33
|
+
const data = ctx.getImageData(0, 0, 1, 1).data;
|
|
34
|
+
return { r: data[0], g: data[1], b: data[2] };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var activeColorParser = browserColorParser;
|
|
38
|
+
function setColorParser(parser) {
|
|
39
|
+
activeColorParser = parser ?? browserColorParser;
|
|
40
|
+
}
|
|
41
|
+
function parseColorToRGB(color) {
|
|
42
|
+
const cached = colorCache.get(color);
|
|
43
|
+
if (cached) {
|
|
44
|
+
colorCache.delete(color);
|
|
45
|
+
colorCache.set(color, cached);
|
|
46
|
+
return cached;
|
|
47
|
+
}
|
|
48
|
+
const result = activeColorParser.parse(color);
|
|
49
|
+
if (!result) return null;
|
|
50
|
+
if (colorCache.size >= COLOR_CACHE_MAX_SIZE) {
|
|
51
|
+
const firstKey = colorCache.keys().next().value;
|
|
52
|
+
if (firstKey !== void 0) colorCache.delete(firstKey);
|
|
53
|
+
}
|
|
54
|
+
colorCache.set(color, result);
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
function parseColorToRGBA(color) {
|
|
58
|
+
if (!color || typeof color !== "string") return null;
|
|
59
|
+
const trimmed = color.trim().toLowerCase();
|
|
60
|
+
if (trimmed === "transparent") {
|
|
61
|
+
return { r: 0, g: 0, b: 0, a: 0 };
|
|
62
|
+
}
|
|
63
|
+
if (trimmed.startsWith("#")) {
|
|
64
|
+
const hex = trimmed.slice(1);
|
|
65
|
+
if (!/^[0-9a-f]+$/.test(hex)) return null;
|
|
66
|
+
if (hex.length === 3) {
|
|
67
|
+
return {
|
|
68
|
+
r: parseInt(hex[0] + hex[0], 16),
|
|
69
|
+
g: parseInt(hex[1] + hex[1], 16),
|
|
70
|
+
b: parseInt(hex[2] + hex[2], 16),
|
|
71
|
+
a: 1
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (hex.length === 4) {
|
|
75
|
+
return {
|
|
76
|
+
r: parseInt(hex[0] + hex[0], 16),
|
|
77
|
+
g: parseInt(hex[1] + hex[1], 16),
|
|
78
|
+
b: parseInt(hex[2] + hex[2], 16),
|
|
79
|
+
a: parseInt(hex[3] + hex[3], 16) / 255
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
if (hex.length === 6) {
|
|
83
|
+
return {
|
|
84
|
+
r: parseInt(hex.slice(0, 2), 16),
|
|
85
|
+
g: parseInt(hex.slice(2, 4), 16),
|
|
86
|
+
b: parseInt(hex.slice(4, 6), 16),
|
|
87
|
+
a: 1
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (hex.length === 8) {
|
|
91
|
+
return {
|
|
92
|
+
r: parseInt(hex.slice(0, 2), 16),
|
|
93
|
+
g: parseInt(hex.slice(2, 4), 16),
|
|
94
|
+
b: parseInt(hex.slice(4, 6), 16),
|
|
95
|
+
a: parseInt(hex.slice(6, 8), 16) / 255
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
const rgbMatch = trimmed.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)$/);
|
|
101
|
+
if (rgbMatch) {
|
|
102
|
+
return {
|
|
103
|
+
r: Math.min(255, parseInt(rgbMatch[1], 10)),
|
|
104
|
+
g: Math.min(255, parseInt(rgbMatch[2], 10)),
|
|
105
|
+
b: Math.min(255, parseInt(rgbMatch[3], 10)),
|
|
106
|
+
a: rgbMatch[4] !== void 0 ? parseFloat(rgbMatch[4]) : 1
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
const hslMatch = trimmed.match(/^hsla?\(\s*(\d+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%\s*(?:,\s*([\d.]+)\s*)?\)$/);
|
|
110
|
+
if (hslMatch) {
|
|
111
|
+
const h = parseInt(hslMatch[1], 10) / 360;
|
|
112
|
+
const s = parseFloat(hslMatch[2]) / 100;
|
|
113
|
+
const l = parseFloat(hslMatch[3]) / 100;
|
|
114
|
+
const a = hslMatch[4] !== void 0 ? parseFloat(hslMatch[4]) : 1;
|
|
115
|
+
const { r, g, b } = hslToRgb(h, s, l);
|
|
116
|
+
return { r, g, b, a };
|
|
117
|
+
}
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
function hslToRgb(h, s, l) {
|
|
121
|
+
if (s === 0) {
|
|
122
|
+
const v = Math.round(l * 255);
|
|
123
|
+
return { r: v, g: v, b: v };
|
|
124
|
+
}
|
|
125
|
+
const hueToRgb = (p2, q2, t) => {
|
|
126
|
+
if (t < 0) t += 1;
|
|
127
|
+
if (t > 1) t -= 1;
|
|
128
|
+
if (t < 1 / 6) return p2 + (q2 - p2) * 6 * t;
|
|
129
|
+
if (t < 1 / 2) return q2;
|
|
130
|
+
if (t < 2 / 3) return p2 + (q2 - p2) * (2 / 3 - t) * 6;
|
|
131
|
+
return p2;
|
|
132
|
+
};
|
|
133
|
+
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
134
|
+
const p = 2 * l - q;
|
|
135
|
+
return {
|
|
136
|
+
r: Math.round(hueToRgb(p, q, h + 1 / 3) * 255),
|
|
137
|
+
g: Math.round(hueToRgb(p, q, h) * 255),
|
|
138
|
+
b: Math.round(hueToRgb(p, q, h - 1 / 3) * 255)
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/utils/color/adjust.ts
|
|
143
|
+
function adjustBrightness(color, factor) {
|
|
144
|
+
if (color.startsWith("#")) {
|
|
145
|
+
const [r, g, b] = parseHexColor(color);
|
|
146
|
+
const adjust = (c) => Math.min(255, Math.max(0, Math.round(c * factor)));
|
|
147
|
+
return `#${adjust(r).toString(16).padStart(2, "0")}${adjust(g).toString(16).padStart(2, "0")}${adjust(b).toString(16).padStart(2, "0")}`;
|
|
148
|
+
}
|
|
149
|
+
const rgbMatch = color.match(/rgba?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/);
|
|
150
|
+
if (rgbMatch) {
|
|
151
|
+
const r = Math.min(255, Math.max(0, Math.round(parseInt(rgbMatch[1]) * factor)));
|
|
152
|
+
const g = Math.min(255, Math.max(0, Math.round(parseInt(rgbMatch[2]) * factor)));
|
|
153
|
+
const b = Math.min(255, Math.max(0, Math.round(parseInt(rgbMatch[3]) * factor)));
|
|
154
|
+
const a = rgbMatch[4];
|
|
155
|
+
return a ? `rgba(${r}, ${g}, ${b}, ${a})` : `rgb(${r}, ${g}, ${b})`;
|
|
156
|
+
}
|
|
157
|
+
return color;
|
|
158
|
+
}
|
|
159
|
+
function brightenGradientStops(gradient, factor) {
|
|
160
|
+
return {
|
|
161
|
+
...gradient,
|
|
162
|
+
stops: gradient.stops.map((stop) => ({ ...stop, color: adjustBrightness(stop.color, factor) }))
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function hexToRgba(hex, opacity) {
|
|
166
|
+
const [r, g, b] = parseHexColor(hex);
|
|
167
|
+
return `rgba(${r}, ${g}, ${b}, ${opacity})`;
|
|
168
|
+
}
|
|
169
|
+
function hexToRgbString(hex) {
|
|
170
|
+
const [r, g, b] = parseHexColor(hex);
|
|
171
|
+
return `${r},${g},${b}`;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// src/utils/render/canvas.utils.ts
|
|
175
|
+
function withCanvasState(ctx, fn) {
|
|
176
|
+
ctx.save();
|
|
177
|
+
try {
|
|
178
|
+
return fn();
|
|
179
|
+
} finally {
|
|
180
|
+
ctx.restore();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function readCssNumber(el, varName, fallback) {
|
|
184
|
+
if (!el || typeof window === "undefined") return fallback;
|
|
185
|
+
const raw = getComputedStyle(el).getPropertyValue(varName).trim();
|
|
186
|
+
if (!raw) return fallback;
|
|
187
|
+
const parsed = parseFloat(raw);
|
|
188
|
+
return Number.isFinite(parsed) ? parsed : fallback;
|
|
189
|
+
}
|
|
190
|
+
function getDevicePixelRatio() {
|
|
191
|
+
return Math.min(Math.ceil(globalThis.devicePixelRatio || 1), 3);
|
|
192
|
+
}
|
|
193
|
+
function configureCanvasHiDPI(canvas, width, height, overrideDpr) {
|
|
194
|
+
const dpr = overrideDpr ?? getDevicePixelRatio();
|
|
195
|
+
const scaledWidth = Math.round(width * dpr);
|
|
196
|
+
const scaledHeight = Math.round(height * dpr);
|
|
197
|
+
if (canvas.width !== scaledWidth || canvas.height !== scaledHeight) {
|
|
198
|
+
canvas.width = scaledWidth;
|
|
199
|
+
canvas.height = scaledHeight;
|
|
200
|
+
}
|
|
201
|
+
canvas.style.width = Math.round(width) + "px";
|
|
202
|
+
canvas.style.height = Math.round(height) + "px";
|
|
203
|
+
const ctx = canvas.getContext("2d");
|
|
204
|
+
if (ctx) {
|
|
205
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
206
|
+
}
|
|
207
|
+
return dpr;
|
|
208
|
+
}
|
|
209
|
+
function createCanvasLinearGradient(ctx, x1, y1, x2, y2, stops) {
|
|
210
|
+
const gradient = ctx.createLinearGradient(x1, y1, x2, y2);
|
|
211
|
+
for (const stop of stops) {
|
|
212
|
+
let color = stop.color;
|
|
213
|
+
if (stop.opacity !== void 0 && color.startsWith("#")) {
|
|
214
|
+
color = hexToRgba(color, stop.opacity);
|
|
215
|
+
}
|
|
216
|
+
gradient.addColorStop(stop.offset, color);
|
|
217
|
+
}
|
|
218
|
+
return gradient;
|
|
219
|
+
}
|
|
220
|
+
function createCanvasRadialGradient(ctx, cx, cy, innerRadius, outerRadius, stops) {
|
|
221
|
+
const gradient = ctx.createRadialGradient(cx, cy, innerRadius, cx, cy, outerRadius);
|
|
222
|
+
for (const stop of stops) {
|
|
223
|
+
let color = stop.color;
|
|
224
|
+
if (stop.opacity !== void 0 && color.startsWith("#")) {
|
|
225
|
+
color = hexToRgba(color, stop.opacity);
|
|
226
|
+
}
|
|
227
|
+
gradient.addColorStop(stop.offset, color);
|
|
228
|
+
}
|
|
229
|
+
return gradient;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// src/utils/render/svg.utils.ts
|
|
233
|
+
function svgNode(tag, attributes, children) {
|
|
234
|
+
const attrs = {};
|
|
235
|
+
if (attributes) {
|
|
236
|
+
for (const k in attributes) {
|
|
237
|
+
const v = attributes[k];
|
|
238
|
+
if (v !== void 0) attrs[k] = String(v);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return { tag, attributes: attrs, children: children ? [...children] : [] };
|
|
242
|
+
}
|
|
243
|
+
function setAttr(node, key, value) {
|
|
244
|
+
node.attributes[key] = String(value);
|
|
245
|
+
return node;
|
|
246
|
+
}
|
|
247
|
+
function appendChild(parent, ...children) {
|
|
248
|
+
parent.children.push(...children);
|
|
249
|
+
return parent;
|
|
250
|
+
}
|
|
251
|
+
function prependChild(parent, child) {
|
|
252
|
+
parent.children.unshift(child);
|
|
253
|
+
return parent;
|
|
254
|
+
}
|
|
255
|
+
function addClass(node, cls) {
|
|
256
|
+
const existing = node.attributes["class"];
|
|
257
|
+
node.attributes["class"] = existing ? `${existing} ${cls}` : cls;
|
|
258
|
+
return node;
|
|
259
|
+
}
|
|
260
|
+
function svgClass(...parts) {
|
|
261
|
+
return parts.filter(Boolean).join(" ");
|
|
262
|
+
}
|
|
263
|
+
function createSvgGroup(transform, attributes) {
|
|
264
|
+
return svgNode("g", { ...attributes, ...transform ? { transform } : {} });
|
|
265
|
+
}
|
|
266
|
+
function createSvgPath(d, attributes) {
|
|
267
|
+
return svgNode("path", { d, ...attributes });
|
|
268
|
+
}
|
|
269
|
+
function createSvgText(x, y, content, attributes) {
|
|
270
|
+
const node = svgNode("text", { x, y, ...attributes });
|
|
271
|
+
if (content) node.children.push(content);
|
|
272
|
+
return node;
|
|
273
|
+
}
|
|
274
|
+
function createSvgRect(x, y, width, height, attributes) {
|
|
275
|
+
return svgNode("rect", {
|
|
276
|
+
x,
|
|
277
|
+
y,
|
|
278
|
+
width: Math.max(0, width),
|
|
279
|
+
height: Math.max(0, height),
|
|
280
|
+
...attributes
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
function createSvgCircle(cx, cy, r, attributes) {
|
|
284
|
+
return svgNode("circle", { cx, cy, r, ...attributes });
|
|
285
|
+
}
|
|
286
|
+
function createSvgLine(x1, y1, x2, y2, attributes) {
|
|
287
|
+
return svgNode("line", { x1, y1, x2, y2, ...attributes });
|
|
288
|
+
}
|
|
289
|
+
function createSvgDefs() {
|
|
290
|
+
return svgNode("defs");
|
|
291
|
+
}
|
|
292
|
+
function createSvgLinearGradient(id, x1, y1, x2, y2, stops, options) {
|
|
293
|
+
const useAbsolute = options?.useAbsoluteCoords ?? false;
|
|
294
|
+
const gradient = svgNode("linearGradient", {
|
|
295
|
+
id,
|
|
296
|
+
x1: useAbsolute ? x1 : `${x1 * 100}%`,
|
|
297
|
+
y1: useAbsolute ? y1 : `${y1 * 100}%`,
|
|
298
|
+
x2: useAbsolute ? x2 : `${x2 * 100}%`,
|
|
299
|
+
y2: useAbsolute ? y2 : `${y2 * 100}%`,
|
|
300
|
+
...useAbsolute && { gradientUnits: "userSpaceOnUse" }
|
|
301
|
+
});
|
|
302
|
+
for (const { offset, color, opacity } of stops) {
|
|
303
|
+
gradient.children.push(
|
|
304
|
+
svgNode("stop", {
|
|
305
|
+
offset: `${offset * 100}%`,
|
|
306
|
+
"stop-color": color,
|
|
307
|
+
...opacity !== void 0 && { "stop-opacity": opacity }
|
|
308
|
+
})
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
return gradient;
|
|
312
|
+
}
|
|
313
|
+
function createSvgRadialGradient(id, cx, cy, r, stops, options) {
|
|
314
|
+
const useAbsolute = options?.useAbsoluteCoords ?? false;
|
|
315
|
+
const gradient = svgNode("radialGradient", {
|
|
316
|
+
id,
|
|
317
|
+
cx: useAbsolute ? cx : `${cx * 100}%`,
|
|
318
|
+
cy: useAbsolute ? cy : `${cy * 100}%`,
|
|
319
|
+
r: useAbsolute ? r : `${r * 100}%`,
|
|
320
|
+
...useAbsolute && { gradientUnits: "userSpaceOnUse" }
|
|
321
|
+
});
|
|
322
|
+
for (const { offset, color, opacity } of stops) {
|
|
323
|
+
gradient.children.push(
|
|
324
|
+
svgNode("stop", {
|
|
325
|
+
offset: `${offset * 100}%`,
|
|
326
|
+
"stop-color": color,
|
|
327
|
+
...opacity !== void 0 && { "stop-opacity": opacity }
|
|
328
|
+
})
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
return gradient;
|
|
332
|
+
}
|
|
333
|
+
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
334
|
+
var browserSvgElementFactory = {
|
|
335
|
+
createElement(tag) {
|
|
336
|
+
return document.createElementNS(SVG_NS, tag);
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
var activeSvgElementFactory = browserSvgElementFactory;
|
|
340
|
+
function setSvgElementFactory(factory) {
|
|
341
|
+
activeSvgElementFactory = factory ?? browserSvgElementFactory;
|
|
342
|
+
}
|
|
343
|
+
function createSvgElement(tag) {
|
|
344
|
+
return activeSvgElementFactory.createElement(tag);
|
|
345
|
+
}
|
|
346
|
+
function materializeSvgNode(node) {
|
|
347
|
+
const el = activeSvgElementFactory.createElement(node.tag);
|
|
348
|
+
for (const key in node.attributes) {
|
|
349
|
+
el.setAttribute(key, node.attributes[key]);
|
|
350
|
+
}
|
|
351
|
+
for (const child of node.children) {
|
|
352
|
+
if (typeof child === "string") {
|
|
353
|
+
el.textContent = child;
|
|
354
|
+
} else {
|
|
355
|
+
el.appendChild(materializeSvgNode(child));
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return el;
|
|
359
|
+
}
|
|
360
|
+
function materializeSvgGroup(node) {
|
|
361
|
+
return materializeSvgNode(node);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export { addClass, adjustBrightness, appendChild, brightenGradientStops, configureCanvasHiDPI, createCanvasLinearGradient, createCanvasRadialGradient, createSvgCircle, createSvgDefs, createSvgElement, createSvgGroup, createSvgLine, createSvgLinearGradient, createSvgPath, createSvgRadialGradient, createSvgRect, createSvgText, getDevicePixelRatio, hexToRgbString, hexToRgba, materializeSvgGroup, materializeSvgNode, parseColorToRGB, parseColorToRGBA, parseHexColor, prependChild, readCssNumber, setAttr, setColorParser, setSvgElementFactory, svgClass, svgNode, withCanvasState };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { buildSvgArcPath } from './chunk-LVMDQ4OJ.mjs';
|
|
2
|
+
import { formatPointDescription } from './chunk-OGJ6IIBW.mjs';
|
|
3
|
+
import { createSvgGradientFromColor } from './chunk-O2X6FF45.mjs';
|
|
4
|
+
import { createSvgGroup, createSvgDefs, appendChild, prependChild, setAttr, adjustBrightness, svgClass, createSvgPath } from './chunk-SSLTFJ3U.mjs';
|
|
5
|
+
|
|
6
|
+
// src/series/polar/svg/index.ts
|
|
7
|
+
function renderPolarBarsSvg(layout, hoverState, effectConfig, theme, a11y) {
|
|
8
|
+
const group = createSvgGroup(`translate(${layout.center.x}, ${layout.center.y})`);
|
|
9
|
+
if (layout.gradientColors.size > 0) {
|
|
10
|
+
const defs = createSvgDefs();
|
|
11
|
+
for (const [dsId, gradColor] of layout.gradientColors) {
|
|
12
|
+
const gradId = `polar-grad-${layout.datasetIndex}-${dsId}`;
|
|
13
|
+
const gradNode = createSvgGradientFromColor(gradColor, gradId, { x: 0, y: 0 }, layout.maxRadius);
|
|
14
|
+
appendChild(defs, gradNode);
|
|
15
|
+
}
|
|
16
|
+
prependChild(group, defs);
|
|
17
|
+
}
|
|
18
|
+
if (a11y?.enabled) {
|
|
19
|
+
setAttr(group, "role", "region");
|
|
20
|
+
setAttr(group, "aria-label", "Polar chart data");
|
|
21
|
+
}
|
|
22
|
+
const sharedAxisIdx = hoverState.axisIndex ?? null;
|
|
23
|
+
const anyHover = hoverState.datasetId !== null || sharedAxisIdx !== null;
|
|
24
|
+
const a11yEnabled = !!(a11y?.enabled && layout.bars.length <= (a11y.pointDescriptionThreshold ?? 200));
|
|
25
|
+
for (const bar of layout.bars) {
|
|
26
|
+
if (bar.outerRadius <= bar.innerRadius) continue;
|
|
27
|
+
const isSeriesHover = sharedAxisIdx === null && hoverState.datasetId !== null && hoverState.index == null;
|
|
28
|
+
const isHovered = sharedAxisIdx !== null ? bar.categoryIndex === sharedAxisIdx : isSeriesHover ? hoverState.datasetId === bar.datasetId : hoverState.datasetId === bar.datasetId && hoverState.index === bar.categoryIndex;
|
|
29
|
+
const isInactive = anyHover && !isHovered;
|
|
30
|
+
const gradColor = layout.gradientColors.get(bar.datasetId);
|
|
31
|
+
let fillColor = gradColor ? `url(#polar-grad-${layout.datasetIndex}-${bar.datasetId})` : bar.color;
|
|
32
|
+
let opacity = bar.opacity ?? 1;
|
|
33
|
+
if (anyHover) {
|
|
34
|
+
if (isHovered && bar.hoverColor !== void 0) {
|
|
35
|
+
fillColor = bar.hoverColor;
|
|
36
|
+
} else if (isHovered && effectConfig.hoverBrightness && !gradColor && bar.color !== void 0) {
|
|
37
|
+
fillColor = adjustBrightness(bar.color, effectConfig.hoverBrightness);
|
|
38
|
+
} else if (!isHovered && effectConfig.dimOpacity !== void 0) {
|
|
39
|
+
opacity = opacity * effectConfig.dimOpacity;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const pathD = buildSvgArcPath(
|
|
43
|
+
{
|
|
44
|
+
rotation: bar.startAngle,
|
|
45
|
+
endAngle: bar.endAngle,
|
|
46
|
+
outerRadius: bar.outerRadius,
|
|
47
|
+
innerRadius: bar.innerRadius,
|
|
48
|
+
borderRadius: bar.borderRadius
|
|
49
|
+
},
|
|
50
|
+
false
|
|
51
|
+
);
|
|
52
|
+
const barCls = svgClass("p-chart-arc", `p-chart-series-${bar.seriesIdx}`, fillColor === void 0 && `p-chart-color-${bar.seriesIdx % 10}`, isHovered && "p-chart-point-hover", isInactive && "p-chart-point-inactive");
|
|
53
|
+
const attrs = {
|
|
54
|
+
fill: fillColor ?? theme.series[bar.seriesIdx % theme.series.length],
|
|
55
|
+
stroke: (isHovered ? bar.hoverBorderColor : void 0) ?? bar.borderColor ?? "none",
|
|
56
|
+
"stroke-width": bar.borderStrokeWidth ?? 0,
|
|
57
|
+
class: barCls
|
|
58
|
+
};
|
|
59
|
+
if (bar.borderDash && bar.borderDash.length > 0) attrs["stroke-dasharray"] = bar.borderDash.join(",");
|
|
60
|
+
if (bar.borderDashOffset) attrs["stroke-dashoffset"] = bar.borderDashOffset;
|
|
61
|
+
if (opacity < 1) {
|
|
62
|
+
attrs.opacity = opacity;
|
|
63
|
+
}
|
|
64
|
+
const barEl = createSvgPath(pathD, attrs);
|
|
65
|
+
setAttr(barEl, "data-index", `${bar.datasetId}:${bar.categoryIndex}`);
|
|
66
|
+
if (a11yEnabled) {
|
|
67
|
+
const category = layout.categories[bar.categoryIndex] ?? `Category ${bar.categoryIndex + 1}`;
|
|
68
|
+
const desc = formatPointDescription({ category, value: bar.value, seriesName: bar.datasetId, index: bar.categoryIndex }, a11y.pointDescriptionFormatter);
|
|
69
|
+
setAttr(barEl, "role", "img");
|
|
70
|
+
setAttr(barEl, "aria-label", desc);
|
|
71
|
+
}
|
|
72
|
+
appendChild(group, barEl);
|
|
73
|
+
}
|
|
74
|
+
return group;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { renderPolarBarsSvg };
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { toRad, generateNiceTicks } from './chunk-RQ3CKQOX.mjs';
|
|
2
|
+
|
|
3
|
+
// src/renderers/radial-grid.geometry.ts
|
|
4
|
+
function valueToRadius(value, domain, outerRadius) {
|
|
5
|
+
const [min, max] = domain;
|
|
6
|
+
if (max === min) return 0;
|
|
7
|
+
return Math.max(0, Math.min(outerRadius, (value - min) / (max - min) * outerRadius));
|
|
8
|
+
}
|
|
9
|
+
function buildCircleSvgPath(cx, cy, r) {
|
|
10
|
+
return `M ${cx},${cy - r} A ${r},${r} 0 1 1 ${cx},${cy + r} A ${r},${r} 0 1 1 ${cx},${cy - r} Z`;
|
|
11
|
+
}
|
|
12
|
+
function buildPolygonPath(center, r, sides, angleStep) {
|
|
13
|
+
if (sides < 3) return "";
|
|
14
|
+
const parts = [];
|
|
15
|
+
for (let i = 0; i < sides; i++) {
|
|
16
|
+
const angleRad = toRad(-90 + i * angleStep);
|
|
17
|
+
const x = center.x + Math.cos(angleRad) * r;
|
|
18
|
+
const y = center.y + Math.sin(angleRad) * r;
|
|
19
|
+
parts.push(i === 0 ? `M${x},${y}` : `L${x},${y}`);
|
|
20
|
+
}
|
|
21
|
+
parts.push("Z");
|
|
22
|
+
return parts.join(" ");
|
|
23
|
+
}
|
|
24
|
+
function buildWedgePath(center, rInner, rOuter, angleStartDeg, angleEndDeg) {
|
|
25
|
+
const a1 = toRad(angleStartDeg);
|
|
26
|
+
const a2 = toRad(angleEndDeg);
|
|
27
|
+
const x1o = center.x + Math.cos(a1) * rOuter;
|
|
28
|
+
const y1o = center.y + Math.sin(a1) * rOuter;
|
|
29
|
+
const x2o = center.x + Math.cos(a2) * rOuter;
|
|
30
|
+
const y2o = center.y + Math.sin(a2) * rOuter;
|
|
31
|
+
const largeArc = Math.abs(angleEndDeg - angleStartDeg) > 180 ? 1 : 0;
|
|
32
|
+
if (rInner <= 0) {
|
|
33
|
+
return `M${center.x},${center.y} L${x1o},${y1o} A${rOuter},${rOuter} 0 ${largeArc} 1 ${x2o},${y2o} Z`;
|
|
34
|
+
}
|
|
35
|
+
const x1i = center.x + Math.cos(a1) * rInner;
|
|
36
|
+
const y1i = center.y + Math.sin(a1) * rInner;
|
|
37
|
+
const x2i = center.x + Math.cos(a2) * rInner;
|
|
38
|
+
const y2i = center.y + Math.sin(a2) * rInner;
|
|
39
|
+
return `M${x1i},${y1i} L${x1o},${y1o} A${rOuter},${rOuter} 0 ${largeArc} 1 ${x2o},${y2o} L${x2i},${y2i} A${rInner},${rInner} 0 ${largeArc} 0 ${x1i},${y1i} Z`;
|
|
40
|
+
}
|
|
41
|
+
function resolveBandGeometry(band, layout, yAxis) {
|
|
42
|
+
const outer = layout.radius;
|
|
43
|
+
if (band.r1 != null || band.r2 != null) {
|
|
44
|
+
const f1 = band.r1 ?? 0;
|
|
45
|
+
const f2 = band.r2 ?? 1;
|
|
46
|
+
const rInner = Math.max(0, Math.min(outer, Math.min(f1, f2) * outer));
|
|
47
|
+
const rOuter = Math.max(0, Math.min(outer, Math.max(f1, f2) * outer));
|
|
48
|
+
return rOuter > 0 ? { rInner, rOuter, mode: "annulus" } : null;
|
|
49
|
+
}
|
|
50
|
+
if (band.category != null) {
|
|
51
|
+
if (!yAxis || yAxis.mode !== "perSpoke") return null;
|
|
52
|
+
const ci = layout.categories.indexOf(band.category);
|
|
53
|
+
if (ci < 0) return null;
|
|
54
|
+
const spokeDomain = yAxis.spokes[ci]?.domain;
|
|
55
|
+
if (!spokeDomain) return null;
|
|
56
|
+
const r1 = band.y1 != null ? valueToRadius(band.y1, spokeDomain, outer) : 0;
|
|
57
|
+
const r2 = band.y2 != null ? valueToRadius(band.y2, spokeDomain, outer) : outer;
|
|
58
|
+
const rInner = Math.min(r1, r2);
|
|
59
|
+
const rOuter = Math.max(r1, r2);
|
|
60
|
+
if (rOuter <= 0) return null;
|
|
61
|
+
const halfStep = layout.angleStep / 2;
|
|
62
|
+
const centerAngle = -90 + ci * layout.angleStep;
|
|
63
|
+
return {
|
|
64
|
+
rInner,
|
|
65
|
+
rOuter,
|
|
66
|
+
mode: "wedge",
|
|
67
|
+
angleStartDeg: centerAngle - halfStep,
|
|
68
|
+
angleEndDeg: centerAngle + halfStep
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if ((band.y1 != null || band.y2 != null) && layout.domain && yAxis?.mode === "shared") {
|
|
72
|
+
const r1 = band.y1 != null ? valueToRadius(band.y1, layout.domain, outer) : 0;
|
|
73
|
+
const r2 = band.y2 != null ? valueToRadius(band.y2, layout.domain, outer) : outer;
|
|
74
|
+
const rInner = Math.min(r1, r2);
|
|
75
|
+
const rOuter = Math.max(r1, r2);
|
|
76
|
+
return rOuter > 0 ? { rInner, rOuter, mode: "annulus" } : null;
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
function resolveLineGeometry(line, layout, yAxis) {
|
|
81
|
+
const outer = layout.radius;
|
|
82
|
+
if (line.r != null) {
|
|
83
|
+
const r = Math.max(0, Math.min(outer, line.r * outer));
|
|
84
|
+
return r > 0 ? { mode: "ring", r } : null;
|
|
85
|
+
}
|
|
86
|
+
if (line.category != null) {
|
|
87
|
+
if (line.y == null) return null;
|
|
88
|
+
if (!yAxis || yAxis.mode !== "perSpoke") return null;
|
|
89
|
+
const ci = layout.categories.indexOf(line.category);
|
|
90
|
+
if (ci < 0) return null;
|
|
91
|
+
const spokeDomain = yAxis.spokes[ci]?.domain;
|
|
92
|
+
if (!spokeDomain) return null;
|
|
93
|
+
const r = valueToRadius(line.y, spokeDomain, outer);
|
|
94
|
+
if (r <= 0) return null;
|
|
95
|
+
const angleDeg = -90 + ci * layout.angleStep;
|
|
96
|
+
const angleRad = toRad(angleDeg);
|
|
97
|
+
const dx = Math.cos(angleRad);
|
|
98
|
+
const dy = Math.sin(angleRad);
|
|
99
|
+
const tx = -dy;
|
|
100
|
+
const ty = dx;
|
|
101
|
+
const halfLen = Math.max(8, outer * 0.04);
|
|
102
|
+
const cx = layout.center.x + dx * r;
|
|
103
|
+
const cy = layout.center.y + dy * r;
|
|
104
|
+
return {
|
|
105
|
+
mode: "crossbar",
|
|
106
|
+
x1: cx - tx * halfLen,
|
|
107
|
+
y1: cy - ty * halfLen,
|
|
108
|
+
x2: cx + tx * halfLen,
|
|
109
|
+
y2: cy + ty * halfLen
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
if (line.y != null && layout.domain && yAxis?.mode === "shared") {
|
|
113
|
+
const r = valueToRadius(line.y, layout.domain, outer);
|
|
114
|
+
return r > 0 ? { mode: "ring", r } : null;
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
function resolveSharedRadialGrid(grid, domain, rawDataMax, radius, tickCount) {
|
|
119
|
+
let levelValues = grid.levelValues.slice();
|
|
120
|
+
let levelRadii = grid.levelRadii.slice();
|
|
121
|
+
let outDomain = [domain[0], domain[1]];
|
|
122
|
+
const place = (vals, d) => vals.map((v) => d[1] === d[0] ? 0 : (v - d[0]) / (d[1] - d[0]) * radius);
|
|
123
|
+
if (tickCount != null && tickCount >= 2) {
|
|
124
|
+
const rawMax = rawDataMax ?? domain[1];
|
|
125
|
+
levelValues = generateNiceTicks(domain[0], rawMax, tickCount, true);
|
|
126
|
+
outDomain = [domain[0], levelValues[levelValues.length - 1]];
|
|
127
|
+
levelRadii = place(levelValues, outDomain);
|
|
128
|
+
} else {
|
|
129
|
+
const lastTick = levelValues[levelValues.length - 1];
|
|
130
|
+
if (levelValues.length >= 2 && rawDataMax != null && lastTick != null && lastTick <= rawDataMax) {
|
|
131
|
+
const tickStep = lastTick - levelValues[levelValues.length - 2];
|
|
132
|
+
if (tickStep > 0) {
|
|
133
|
+
levelValues.push(Math.round((lastTick + tickStep) * 1e10) / 1e10);
|
|
134
|
+
outDomain = [domain[0], levelValues[levelValues.length - 1]];
|
|
135
|
+
levelRadii = place(levelValues, outDomain);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return { levelValues, levelRadii, domain: outDomain };
|
|
140
|
+
}
|
|
141
|
+
function buildRadialGridLayout(base, xAxisProps, yAxisProps, yAxesByCategory, chartType) {
|
|
142
|
+
const defaultGridShape = chartType === "radar" ? "polygon" : "circle";
|
|
143
|
+
const xAxis = xAxisProps ? {
|
|
144
|
+
labelFontSize: base.labelFontSize,
|
|
145
|
+
labelPadding: base.labelPadding,
|
|
146
|
+
color: xAxisProps.color,
|
|
147
|
+
visible: xAxisProps.visible ?? true,
|
|
148
|
+
shape: xAxisProps.gridShape ?? defaultGridShape,
|
|
149
|
+
showLine: xAxisProps.showLine ?? true,
|
|
150
|
+
showLabels: xAxisProps.showLabels ?? true
|
|
151
|
+
} : null;
|
|
152
|
+
let domain = base.domain;
|
|
153
|
+
let yAxis = null;
|
|
154
|
+
const isPerSpokeMode = !!base.perSpokeDomains && base.perSpokeDomains.size > 0;
|
|
155
|
+
if (isPerSpokeMode && (yAxisProps || yAxesByCategory && yAxesByCategory.size > 0)) {
|
|
156
|
+
const spokes = [];
|
|
157
|
+
for (let ci = 0; ci < base.categories.length; ci++) {
|
|
158
|
+
const spokeDomain = base.perSpokeDomains.get(ci) ?? base.domain;
|
|
159
|
+
const declared = yAxesByCategory?.get(base.categories[ci]);
|
|
160
|
+
const propsForSpoke = declared ?? yAxisProps;
|
|
161
|
+
const tickCount = propsForSpoke?.tickCount;
|
|
162
|
+
const useExact = tickCount != null && tickCount >= 2;
|
|
163
|
+
const ticks = useExact ? generateNiceTicks(spokeDomain[0], spokeDomain[1], tickCount, true) : generateNiceTicks(spokeDomain[0], spokeDomain[1]);
|
|
164
|
+
const lo = ticks[0] ?? spokeDomain[0];
|
|
165
|
+
const hi = ticks[ticks.length - 1] ?? spokeDomain[1];
|
|
166
|
+
const aligned = [Math.min(spokeDomain[0], lo), Math.max(spokeDomain[1], hi)];
|
|
167
|
+
const span = aligned[1] - aligned[0];
|
|
168
|
+
const radii = ticks.map((v) => span === 0 ? 0 : (v - aligned[0]) / span * base.radius);
|
|
169
|
+
const uniformTickStyle = declared?.tickStyle && typeof declared.tickStyle !== "function" ? declared.tickStyle : void 0;
|
|
170
|
+
const rawTickFormat = declared?.tickFormat;
|
|
171
|
+
spokes.push({
|
|
172
|
+
domain: aligned,
|
|
173
|
+
levelValues: ticks,
|
|
174
|
+
levelRadii: radii,
|
|
175
|
+
tickFormat: typeof rawTickFormat === "function" ? (v) => rawTickFormat(v) : void 0,
|
|
176
|
+
tickColor: uniformTickStyle?.color ?? declared?.color,
|
|
177
|
+
tickFontSize: uniformTickStyle?.fontSize,
|
|
178
|
+
showLine: propsForSpoke?.showLine ?? true,
|
|
179
|
+
showLabels: propsForSpoke?.showLabels ?? true
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
const referenceRingRadii = [0.2, 0.4, 0.6, 0.8].map((f) => f * base.radius);
|
|
183
|
+
const defaultUniformTickStyle = yAxisProps?.tickStyle && typeof yAxisProps.tickStyle !== "function" ? yAxisProps.tickStyle : void 0;
|
|
184
|
+
yAxis = {
|
|
185
|
+
mode: "perSpoke",
|
|
186
|
+
spokes,
|
|
187
|
+
referenceRingRadii,
|
|
188
|
+
shape: yAxisProps?.gridShape ?? defaultGridShape,
|
|
189
|
+
gridColor: yAxisProps?.gridColor,
|
|
190
|
+
gridOpacity: yAxisProps?.gridOpacity ?? 0.6,
|
|
191
|
+
gridStyle: yAxisProps?.gridStyle ?? "solid",
|
|
192
|
+
gridStrokeWidth: yAxisProps?.gridStrokeWidth ?? 0.5,
|
|
193
|
+
tickFontSize: defaultUniformTickStyle?.fontSize ?? base.labelFontSize,
|
|
194
|
+
tickColor: defaultUniformTickStyle?.color ?? yAxisProps?.color,
|
|
195
|
+
visible: yAxisProps?.visible ?? true,
|
|
196
|
+
gridLines: yAxisProps?.gridLines ?? true
|
|
197
|
+
};
|
|
198
|
+
} else if (yAxisProps) {
|
|
199
|
+
let levelValues;
|
|
200
|
+
let levelRadii;
|
|
201
|
+
if (base.gridAnimating) {
|
|
202
|
+
levelValues = base.grid.levelValues.slice();
|
|
203
|
+
levelRadii = base.grid.levelRadii.slice();
|
|
204
|
+
} else {
|
|
205
|
+
const resolved = resolveSharedRadialGrid(base.grid, domain, base.rawDataMax, base.radius, yAxisProps.tickCount);
|
|
206
|
+
levelValues = resolved.levelValues;
|
|
207
|
+
levelRadii = resolved.levelRadii;
|
|
208
|
+
domain = resolved.domain;
|
|
209
|
+
}
|
|
210
|
+
const uniformTickStyle = yAxisProps.tickStyle && typeof yAxisProps.tickStyle !== "function" ? yAxisProps.tickStyle : void 0;
|
|
211
|
+
const rawTickFormat = yAxisProps.tickFormat;
|
|
212
|
+
yAxis = {
|
|
213
|
+
mode: "shared",
|
|
214
|
+
levelValues,
|
|
215
|
+
levelRadii,
|
|
216
|
+
shape: yAxisProps.gridShape ?? defaultGridShape,
|
|
217
|
+
gridColor: yAxisProps.gridColor,
|
|
218
|
+
gridOpacity: yAxisProps.gridOpacity ?? 0.6,
|
|
219
|
+
gridStyle: yAxisProps.gridStyle ?? "solid",
|
|
220
|
+
gridStrokeWidth: yAxisProps.gridStrokeWidth ?? 0.5,
|
|
221
|
+
tickFontSize: uniformTickStyle?.fontSize ?? base.labelFontSize,
|
|
222
|
+
tickColor: uniformTickStyle?.color ?? yAxisProps.color,
|
|
223
|
+
tickFormat: typeof rawTickFormat === "function" ? (v) => rawTickFormat(v) : void 0,
|
|
224
|
+
visible: yAxisProps.visible ?? true,
|
|
225
|
+
showLine: yAxisProps.showLine ?? true,
|
|
226
|
+
gridLines: yAxisProps.gridLines ?? true,
|
|
227
|
+
showLabels: yAxisProps.showLabels ?? true
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
return {
|
|
231
|
+
center: base.center,
|
|
232
|
+
radius: base.radius,
|
|
233
|
+
categories: base.categories,
|
|
234
|
+
angleStep: base.angleStep,
|
|
235
|
+
spokeEndpoints: base.spokeEndpoints,
|
|
236
|
+
fontFamily: base.fontFamily,
|
|
237
|
+
domain,
|
|
238
|
+
xAxis,
|
|
239
|
+
yAxis
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export { buildCircleSvgPath, buildPolygonPath, buildRadialGridLayout, buildWedgePath, resolveBandGeometry, resolveLineGeometry, resolveSharedRadialGrid };
|