@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,714 @@
|
|
|
1
|
+
import { hasCollisions } from './chunk-R6Y3R7EW.mjs';
|
|
2
|
+
import { measureTextWidth, measureFontMetrics, svgAnchorToCanvasAlign } from './chunk-XTVE4P3L.mjs';
|
|
3
|
+
import { DEFAULT_TITLE_LABEL_GAP, resolveFontSize, DEFAULT_TITLE_FONT_SIZE, resolveFontFamily, resolveAxisColor, DEFAULT_TICK_LENGTH, DEFAULT_LABEL_PADDING, DEFAULT_TICK_FONT_SIZE } from './chunk-NKUYIWAP.mjs';
|
|
4
|
+
import { defaultLightTheme } from './chunk-O2X6FF45.mjs';
|
|
5
|
+
import { createSvgGroup, appendChild, createSvgRect, createSvgLine, setAttr, createSvgText, withCanvasState } from './chunk-SSLTFJ3U.mjs';
|
|
6
|
+
import { crisp, detectTickUnit, isPeriodBoundary, formatTimeTick, generateIntervalTicks } from './chunk-RQ3CKQOX.mjs';
|
|
7
|
+
|
|
8
|
+
// src/renderers/axis/geometry.ticks.ts
|
|
9
|
+
function resolveTickStyle(style, axisColor, globalFont) {
|
|
10
|
+
return {
|
|
11
|
+
fontSize: style?.fontSize ?? resolveFontSize(DEFAULT_TICK_FONT_SIZE, globalFont),
|
|
12
|
+
fontFamily: resolveFontFamily(style?.fontFamily, globalFont),
|
|
13
|
+
fontWeight: style?.fontWeight !== void 0 ? String(style.fontWeight) : "normal",
|
|
14
|
+
color: style?.color ?? axisColor,
|
|
15
|
+
padding: style?.padding ?? DEFAULT_LABEL_PADDING,
|
|
16
|
+
tickLength: style?.tickLength ?? DEFAULT_TICK_LENGTH
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function calculateMinorGridLines(majorPositions, count, isHorizontal, chartArea) {
|
|
20
|
+
if (majorPositions.length < 2 || count < 1) return [];
|
|
21
|
+
const { x, y, width, height } = chartArea;
|
|
22
|
+
const lines = [];
|
|
23
|
+
for (let i = 0; i < majorPositions.length - 1; i++) {
|
|
24
|
+
const start = majorPositions[i];
|
|
25
|
+
const end = majorPositions[i + 1];
|
|
26
|
+
const step = (end - start) / (count + 1);
|
|
27
|
+
for (let j = 1; j <= count; j++) {
|
|
28
|
+
const pos = start + step * j;
|
|
29
|
+
if (isHorizontal) {
|
|
30
|
+
lines.push({ x1: pos, y1: y, x2: pos, y2: y + height });
|
|
31
|
+
} else {
|
|
32
|
+
lines.push({ x1: x, y1: pos, x2: x + width, y2: pos });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return lines;
|
|
37
|
+
}
|
|
38
|
+
function calculateMinorTicks(minorPositions, position, chartArea, tickLength, tickInside) {
|
|
39
|
+
const { x, y, width, height } = chartArea;
|
|
40
|
+
const dir = tickInside ? -1 : 1;
|
|
41
|
+
return minorPositions.map((pos) => {
|
|
42
|
+
switch (position) {
|
|
43
|
+
case "bottom":
|
|
44
|
+
return { x1: pos, y1: y + height, x2: pos, y2: y + height + tickLength * dir };
|
|
45
|
+
case "top":
|
|
46
|
+
return { x1: pos, y1: y, x2: pos, y2: y - tickLength * dir };
|
|
47
|
+
case "left":
|
|
48
|
+
return { x1: x, y1: pos, x2: x - tickLength * dir, y2: pos };
|
|
49
|
+
case "right":
|
|
50
|
+
return { x1: x + width, y1: pos, x2: x + width + tickLength * dir, y2: pos };
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function adjustForRotation(anchor, baseline, rotation, position) {
|
|
55
|
+
if (rotation === 0) return { anchor, baseline };
|
|
56
|
+
const isHorizontal = position === "top" || position === "bottom";
|
|
57
|
+
if (isHorizontal) {
|
|
58
|
+
if (position === "bottom") {
|
|
59
|
+
return { anchor: rotation < 0 ? "end" : "start", baseline: "middle" };
|
|
60
|
+
}
|
|
61
|
+
return { anchor: rotation < 0 ? "start" : "end", baseline: "middle" };
|
|
62
|
+
}
|
|
63
|
+
return { anchor, baseline: "middle" };
|
|
64
|
+
}
|
|
65
|
+
function calculateTicks(scale, position, chartArea, props, style, locale) {
|
|
66
|
+
const { x, y, width, height } = chartArea;
|
|
67
|
+
const axisLength = position === "top" || position === "bottom" ? width : height;
|
|
68
|
+
const userTickCount = props.tickCount;
|
|
69
|
+
const tickCount = userTickCount ?? Math.max(5, Math.min(15, Math.floor(axisLength / 40)));
|
|
70
|
+
const exactTickCount = userTickCount !== void 0;
|
|
71
|
+
const formatter = props.tickFormat;
|
|
72
|
+
const manualRotation = props.tickRotation ?? 0;
|
|
73
|
+
const rawTickStyle = props.tickStyle;
|
|
74
|
+
const tickStyleFn = typeof rawTickStyle === "function" ? rawTickStyle : void 0;
|
|
75
|
+
const baseProps = props;
|
|
76
|
+
const tl = style.tickLength;
|
|
77
|
+
const lp = style.padding;
|
|
78
|
+
const tickInside = (baseProps.tickPosition ?? "outside") === "inside";
|
|
79
|
+
const tickDir = tickInside ? -1 : 1;
|
|
80
|
+
const labelOff = (tickInside ? 0 : tl) + lp;
|
|
81
|
+
const isBand = typeof scale.bandwidth === "function";
|
|
82
|
+
const values = [];
|
|
83
|
+
if (isBand) {
|
|
84
|
+
const bandScale = scale;
|
|
85
|
+
const categories = bandScale.domain();
|
|
86
|
+
const bw = bandScale.bandwidth();
|
|
87
|
+
for (let i = 0; i < categories.length; i++) {
|
|
88
|
+
const cat = categories[i];
|
|
89
|
+
const catBw = bandScale.bandwidthAt?.(i) ?? bw;
|
|
90
|
+
values.push({ value: cat, pos: bandScale(cat) + catBw / 2 });
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
const linearScale = scale;
|
|
94
|
+
const isTimeAxis = baseProps.type === "time";
|
|
95
|
+
if (isTimeAxis) {
|
|
96
|
+
const ticks = linearScale.ticks(tickCount);
|
|
97
|
+
const tickUnit = detectTickUnit(ticks);
|
|
98
|
+
const timezone = baseProps.timezone;
|
|
99
|
+
const formatOverrides = baseProps.dateTimeFormats;
|
|
100
|
+
for (const ts of ticks) {
|
|
101
|
+
const boundary = isPeriodBoundary(ts, tickUnit);
|
|
102
|
+
const label = boundary ? formatTimeTick(ts, boundary, timezone, formatOverrides, locale) : formatTimeTick(ts, tickUnit, timezone, formatOverrides, locale);
|
|
103
|
+
values.push({ value: label, pos: linearScale(ts), raw: ts });
|
|
104
|
+
}
|
|
105
|
+
const dataFirst = linearScale.dataFirstTs;
|
|
106
|
+
const dataLast = linearScale.dataLastTs;
|
|
107
|
+
if (dataFirst != null && dataLast != null) {
|
|
108
|
+
const inRange = values.filter((v) => v.raw != null && v.raw >= dataFirst && v.raw <= dataLast);
|
|
109
|
+
if (inRange.length > 0) {
|
|
110
|
+
values.length = 0;
|
|
111
|
+
values.push(...inRange);
|
|
112
|
+
} else {
|
|
113
|
+
const boundary = isPeriodBoundary(dataLast, tickUnit);
|
|
114
|
+
const label = boundary ? formatTimeTick(dataLast, boundary, timezone, formatOverrides, locale) : formatTimeTick(dataLast, tickUnit, timezone, formatOverrides, locale);
|
|
115
|
+
values.length = 0;
|
|
116
|
+
values.push({ value: label, pos: linearScale(dataLast), raw: dataLast });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
} else {
|
|
120
|
+
const interval = baseProps.tickInterval;
|
|
121
|
+
const rawTicks = interval !== void 0 ? generateIntervalTicks(linearScale.domain()[0], linearScale.domain()[1], interval) : linearScale.ticks(tickCount, exactTickCount);
|
|
122
|
+
for (const v of rawTicks) {
|
|
123
|
+
values.push({ value: v, pos: linearScale(v), raw: v });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const isH = position === "top" || position === "bottom";
|
|
128
|
+
const minBound = isH ? x : y;
|
|
129
|
+
const maxBound = isH ? x + width : y + height;
|
|
130
|
+
const filtered = values.filter(({ pos }) => pos >= minBound - 0.5 && pos <= maxBound + 0.5);
|
|
131
|
+
const isHorizontal = isH;
|
|
132
|
+
const hasCustomRender = !!baseProps.render;
|
|
133
|
+
const autoSkip = baseProps.autoSkip ?? true;
|
|
134
|
+
const userMinGridDistance = baseProps.minGridDistance;
|
|
135
|
+
const labelMinSpacing = baseProps.labelMinSpacing ?? 14;
|
|
136
|
+
let effectiveRotation = manualRotation;
|
|
137
|
+
let step = 1;
|
|
138
|
+
if (autoSkip && !hasCustomRender && filtered.length > 1) {
|
|
139
|
+
if (userMinGridDistance !== void 0) {
|
|
140
|
+
const maxTicks = Math.max(1, Math.floor(axisLength / userMinGridDistance));
|
|
141
|
+
step = Math.max(1, Math.ceil(filtered.length / maxTicks));
|
|
142
|
+
} else if (isHorizontal) {
|
|
143
|
+
const sampleLabel = formatter ? typeof formatter === "function" ? formatter(filtered[0].value, 0) : String(filtered[0].value) : formatValue(filtered[0].value, locale);
|
|
144
|
+
const sampleWidth = measureTextWidth(sampleLabel, style.fontSize, style.fontWeight, style.fontFamily);
|
|
145
|
+
const textHeight = style.fontSize * 1.2;
|
|
146
|
+
const footprint0 = sampleWidth;
|
|
147
|
+
const mgd0 = footprint0 + labelMinSpacing;
|
|
148
|
+
const maxTicks0 = Math.max(1, Math.floor(axisLength / mgd0));
|
|
149
|
+
const step0 = Math.max(1, Math.ceil(filtered.length / maxTicks0));
|
|
150
|
+
if (step0 === 1) {
|
|
151
|
+
if (manualRotation === 0 && (baseProps.autoRotate ?? true)) {
|
|
152
|
+
const preLabels = filtered.map((v, idx) => formatter ? typeof formatter === "function" ? formatter(v.value, idx) : String(v.value) : formatValue(v.value, locale));
|
|
153
|
+
if (hasCollisions(
|
|
154
|
+
preLabels,
|
|
155
|
+
filtered.map((v) => v.pos),
|
|
156
|
+
style.fontSize,
|
|
157
|
+
style.fontWeight,
|
|
158
|
+
style.fontFamily,
|
|
159
|
+
0,
|
|
160
|
+
labelMinSpacing,
|
|
161
|
+
true
|
|
162
|
+
)) {
|
|
163
|
+
effectiveRotation = baseProps.autoRotateAngle ?? -45;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
step = 1;
|
|
167
|
+
} else if (manualRotation === 0 && (baseProps.autoRotate ?? true)) {
|
|
168
|
+
const rotAngle = baseProps.autoRotateAngle ?? -45;
|
|
169
|
+
const radians = Math.abs(rotAngle * Math.PI / 180);
|
|
170
|
+
const footprintR = sampleWidth * Math.cos(radians) + textHeight * Math.sin(radians);
|
|
171
|
+
const mgdR = footprintR + labelMinSpacing;
|
|
172
|
+
const maxTicksR = Math.max(1, Math.floor(axisLength / mgdR));
|
|
173
|
+
const stepR = Math.max(1, Math.ceil(filtered.length / maxTicksR));
|
|
174
|
+
if (stepR < step0) {
|
|
175
|
+
effectiveRotation = rotAngle;
|
|
176
|
+
step = stepR;
|
|
177
|
+
} else {
|
|
178
|
+
step = step0;
|
|
179
|
+
}
|
|
180
|
+
} else {
|
|
181
|
+
if (manualRotation !== 0) {
|
|
182
|
+
const radians = Math.abs(manualRotation * Math.PI / 180);
|
|
183
|
+
const footprintM = sampleWidth * Math.cos(radians) + textHeight * Math.sin(radians);
|
|
184
|
+
const mgdM = footprintM + labelMinSpacing;
|
|
185
|
+
const maxTicksM = Math.max(1, Math.floor(axisLength / mgdM));
|
|
186
|
+
step = Math.max(1, Math.ceil(filtered.length / maxTicksM));
|
|
187
|
+
} else {
|
|
188
|
+
step = step0;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
} else {
|
|
192
|
+
const textHeight = style.fontSize * 1.2;
|
|
193
|
+
const mgd = textHeight + labelMinSpacing;
|
|
194
|
+
const maxTicks = Math.max(1, Math.floor(axisLength / mgd));
|
|
195
|
+
step = Math.max(1, Math.ceil(filtered.length / maxTicks));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const showFirst = baseProps.showFirstLabel ?? true;
|
|
199
|
+
const showLast = baseProps.showLastLabel ?? true;
|
|
200
|
+
const result = [];
|
|
201
|
+
for (let i = 0; i < filtered.length; i += step) {
|
|
202
|
+
const { value, pos } = filtered[i];
|
|
203
|
+
const isFirst = i === 0;
|
|
204
|
+
const isLast = i >= filtered.length - step;
|
|
205
|
+
const isHidden = isFirst && !showFirst || isLast && !showLast;
|
|
206
|
+
const label = isHidden ? "" : formatter ? typeof formatter === "function" ? formatter(value, i) : String(value) : formatValue(value, locale);
|
|
207
|
+
const perTickStyle = tickStyleFn ? tickStyleFn(value, i) : void 0;
|
|
208
|
+
let baseAnchor;
|
|
209
|
+
let baseBaseline;
|
|
210
|
+
let labelX;
|
|
211
|
+
let labelY;
|
|
212
|
+
let x1, y1, x2, y2;
|
|
213
|
+
switch (position) {
|
|
214
|
+
case "bottom":
|
|
215
|
+
x1 = pos;
|
|
216
|
+
y1 = y + height;
|
|
217
|
+
x2 = pos;
|
|
218
|
+
y2 = y + height + tl * tickDir;
|
|
219
|
+
labelX = Math.round(pos);
|
|
220
|
+
labelY = Math.round(y + height + labelOff);
|
|
221
|
+
baseAnchor = "middle";
|
|
222
|
+
baseBaseline = "top";
|
|
223
|
+
break;
|
|
224
|
+
case "top":
|
|
225
|
+
x1 = pos;
|
|
226
|
+
y1 = y;
|
|
227
|
+
x2 = pos;
|
|
228
|
+
y2 = y - tl * tickDir;
|
|
229
|
+
labelX = Math.round(pos);
|
|
230
|
+
labelY = Math.round(y - labelOff);
|
|
231
|
+
baseAnchor = "middle";
|
|
232
|
+
baseBaseline = "alphabetic";
|
|
233
|
+
break;
|
|
234
|
+
case "left":
|
|
235
|
+
x1 = x;
|
|
236
|
+
y1 = pos;
|
|
237
|
+
x2 = x - tl * tickDir;
|
|
238
|
+
y2 = pos;
|
|
239
|
+
labelX = Math.round(x - labelOff);
|
|
240
|
+
labelY = Math.round(pos);
|
|
241
|
+
baseAnchor = "end";
|
|
242
|
+
baseBaseline = "middle";
|
|
243
|
+
break;
|
|
244
|
+
case "right":
|
|
245
|
+
x1 = x + width;
|
|
246
|
+
y1 = pos;
|
|
247
|
+
x2 = x + width + tl * tickDir;
|
|
248
|
+
y2 = pos;
|
|
249
|
+
labelX = Math.round(x + width + labelOff);
|
|
250
|
+
labelY = Math.round(pos);
|
|
251
|
+
baseAnchor = "start";
|
|
252
|
+
baseBaseline = "middle";
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
const { anchor, baseline } = adjustForRotation(baseAnchor, baseBaseline, effectiveRotation, position);
|
|
256
|
+
result.push({
|
|
257
|
+
value,
|
|
258
|
+
position: pos,
|
|
259
|
+
label,
|
|
260
|
+
x1,
|
|
261
|
+
y1,
|
|
262
|
+
x2,
|
|
263
|
+
y2,
|
|
264
|
+
labelX,
|
|
265
|
+
labelY,
|
|
266
|
+
anchor,
|
|
267
|
+
baseline,
|
|
268
|
+
rotation: effectiveRotation !== 0 ? effectiveRotation : void 0,
|
|
269
|
+
fontSize: perTickStyle?.fontSize ?? style.fontSize,
|
|
270
|
+
fontFamily: perTickStyle?.fontFamily ?? style.fontFamily,
|
|
271
|
+
fontWeight: perTickStyle?.fontWeight !== void 0 ? String(perTickStyle.fontWeight) : style.fontWeight,
|
|
272
|
+
labelColor: perTickStyle?.color ?? style.color,
|
|
273
|
+
tickColor: perTickStyle?.tickColor,
|
|
274
|
+
tickStrokeWidth: perTickStyle?.tickStrokeWidth,
|
|
275
|
+
tickIndex: i,
|
|
276
|
+
rawValue: filtered[i].raw
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
return result;
|
|
280
|
+
}
|
|
281
|
+
function formatValue(value, locale) {
|
|
282
|
+
if (typeof value === "number") {
|
|
283
|
+
return value.toLocaleString(locale, { maximumFractionDigits: 2 });
|
|
284
|
+
}
|
|
285
|
+
return String(value);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// src/renderers/axis/geometry.space.ts
|
|
289
|
+
function calculateRotatedLabelSpace(labels, fontSize, fontWeight, fontFamily, rotation, isVertical) {
|
|
290
|
+
const radians = Math.abs(rotation * Math.PI / 180);
|
|
291
|
+
const sinR = Math.sin(radians);
|
|
292
|
+
const cosR = Math.cos(radians);
|
|
293
|
+
const textHeight = fontSize * 1.2;
|
|
294
|
+
let maxSpace = 0;
|
|
295
|
+
for (const label of labels) {
|
|
296
|
+
const textWidth = measureTextWidth(label, fontSize, fontWeight, fontFamily);
|
|
297
|
+
const needed = isVertical ? textWidth * cosR + textHeight * sinR : textWidth * sinR + textHeight * cosR;
|
|
298
|
+
if (needed > maxSpace) maxSpace = needed;
|
|
299
|
+
}
|
|
300
|
+
return maxSpace;
|
|
301
|
+
}
|
|
302
|
+
function calculateAxisSpace(position, hasTitle, optionsOrLabels, extraTitleOffset, globalFont) {
|
|
303
|
+
const options = Array.isArray(optionsOrLabels) ? { tickLabels: optionsOrLabels } : optionsOrLabels ?? {};
|
|
304
|
+
const style = resolveTickStyle(options.tickStyle, void 0, globalFont);
|
|
305
|
+
const isVertical = position === "left" || position === "right";
|
|
306
|
+
const isHorizontal = !isVertical;
|
|
307
|
+
let effectiveRotation = options.tickRotation ?? 0;
|
|
308
|
+
if (options.autoRotate && isHorizontal && options.tickLabels && options.tickLabels.length > 1 && options.tickPositions && effectiveRotation === 0) {
|
|
309
|
+
const labelMinSpacing = options.labelMinSpacing ?? 14;
|
|
310
|
+
if (hasCollisions(options.tickLabels, options.tickPositions, style.fontSize, style.fontWeight, style.fontFamily, 0, labelMinSpacing, true)) {
|
|
311
|
+
effectiveRotation = options.autoRotateAngle ?? -45;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
let labelSize;
|
|
315
|
+
if (effectiveRotation !== 0 && options.tickLabels && options.tickLabels.length > 0) {
|
|
316
|
+
labelSize = calculateRotatedLabelSpace(options.tickLabels, style.fontSize, style.fontWeight, style.fontFamily, effectiveRotation, isVertical);
|
|
317
|
+
} else if (isVertical && options.tickLabels && options.tickLabels.length > 0) {
|
|
318
|
+
labelSize = 0;
|
|
319
|
+
for (const label of options.tickLabels) {
|
|
320
|
+
const w = measureTextWidth(label, style.fontSize, style.fontWeight, style.fontFamily);
|
|
321
|
+
if (w > labelSize) labelSize = w;
|
|
322
|
+
}
|
|
323
|
+
} else {
|
|
324
|
+
labelSize = style.fontSize;
|
|
325
|
+
}
|
|
326
|
+
const effectiveTickLength = options.showTicks === false ? 0 : style.tickLength;
|
|
327
|
+
const space = effectiveTickLength + style.padding + labelSize;
|
|
328
|
+
if (hasTitle) {
|
|
329
|
+
return space + (extraTitleOffset ?? 0) + (options.titleGap ?? DEFAULT_TITLE_LABEL_GAP) + resolveFontSize(DEFAULT_TITLE_FONT_SIZE, globalFont);
|
|
330
|
+
}
|
|
331
|
+
return space;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// src/renderers/axis/geometry.ts
|
|
335
|
+
function resolveGridDash(style) {
|
|
336
|
+
switch (style) {
|
|
337
|
+
case "dashed":
|
|
338
|
+
return [6, 4];
|
|
339
|
+
case "dotted":
|
|
340
|
+
return [2, 3];
|
|
341
|
+
default:
|
|
342
|
+
return [];
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
function calculateAxisLayout(scale, position, chartArea, props, extraTitleOffset, globalFont, locale) {
|
|
346
|
+
const { x, y, width, height } = chartArea;
|
|
347
|
+
const isHorizontal = position === "top" || position === "bottom";
|
|
348
|
+
const axisColor = props.color;
|
|
349
|
+
const gridColor = props.gridColor;
|
|
350
|
+
const rawTickStyle = props.tickStyle;
|
|
351
|
+
const uniformStyle = typeof rawTickStyle === "function" ? void 0 : rawTickStyle;
|
|
352
|
+
const tickStyle = resolveTickStyle(uniformStyle, axisColor, globalFont);
|
|
353
|
+
const axisLine = isHorizontal ? { x1: x, y1: position === "bottom" ? y + height : y, x2: x + width, y2: position === "bottom" ? y + height : y } : { x1: position === "left" ? x : x + width, y1: y, x2: position === "left" ? x : x + width, y2: y + height };
|
|
354
|
+
const ticks = calculateTicks(scale, position, chartArea, props, tickStyle, locale);
|
|
355
|
+
const baseProps = props;
|
|
356
|
+
const gridLines = props.gridLines ? ticks.map((t) => isHorizontal ? { x1: t.position, y1: y, x2: t.position, y2: y + height } : { x1: x, y1: t.position, x2: x + width, y2: t.position }) : [];
|
|
357
|
+
const gridStyle = baseProps.gridStyle ?? "solid";
|
|
358
|
+
const gridWidth = baseProps.gridStrokeWidth ?? 1;
|
|
359
|
+
const gridOpacity = baseProps.gridOpacity ?? 1;
|
|
360
|
+
const minorGridEnabled = baseProps.minorGridLines ?? false;
|
|
361
|
+
const minorGridCount = baseProps.minorGridCount ?? 4;
|
|
362
|
+
let minorGridLinePositions = [];
|
|
363
|
+
if (minorGridEnabled && gridLines.length >= 2) {
|
|
364
|
+
const majorPositions = ticks.map((t) => t.position);
|
|
365
|
+
minorGridLinePositions = calculateMinorGridLines(majorPositions, minorGridCount, isHorizontal, chartArea);
|
|
366
|
+
}
|
|
367
|
+
const minorTicksEnabled = baseProps.minorTicks ?? false;
|
|
368
|
+
const tickInsideForMinor = (baseProps.tickPosition ?? "outside") === "inside";
|
|
369
|
+
let minorTickMarks = [];
|
|
370
|
+
if (minorTicksEnabled && minorGridLinePositions.length > 0) {
|
|
371
|
+
const minorPositions = minorGridLinePositions.map((line) => isHorizontal ? line.x1 : line.y1);
|
|
372
|
+
minorTickMarks = calculateMinorTicks(minorPositions, position, chartArea, baseProps.minorTickLength ?? 3, tickInsideForMinor);
|
|
373
|
+
}
|
|
374
|
+
const alternateColor = baseProps.alternateGridColor;
|
|
375
|
+
const alternateOpacity = baseProps.alternateGridOpacity ?? 0.05;
|
|
376
|
+
const alternateFillBands = [];
|
|
377
|
+
if (alternateColor && ticks.length >= 2) {
|
|
378
|
+
const positions = ticks.map((t) => t.position);
|
|
379
|
+
for (let i = 0; i < positions.length - 1; i++) {
|
|
380
|
+
if (i % 2 !== 0) continue;
|
|
381
|
+
const start = positions[i];
|
|
382
|
+
const end = positions[i + 1];
|
|
383
|
+
if (isHorizontal) {
|
|
384
|
+
alternateFillBands.push({ x: Math.min(start, end), y, width: Math.abs(end - start), height, color: alternateColor, opacity: alternateOpacity });
|
|
385
|
+
} else {
|
|
386
|
+
alternateFillBands.push({ x, y: Math.min(start, end), width, height: Math.abs(end - start), color: alternateColor, opacity: alternateOpacity });
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
const title = props.label ? calculateTitle(props.label, position, chartArea, ticks, tickStyle, extraTitleOffset, props.titleGap) : void 0;
|
|
391
|
+
return {
|
|
392
|
+
position,
|
|
393
|
+
axisLine,
|
|
394
|
+
ticks,
|
|
395
|
+
gridLines,
|
|
396
|
+
title,
|
|
397
|
+
tickStyle,
|
|
398
|
+
color: axisColor,
|
|
399
|
+
gridColor,
|
|
400
|
+
gridStyle,
|
|
401
|
+
gridStrokeWidth: gridWidth,
|
|
402
|
+
gridOpacity,
|
|
403
|
+
minorGridLines: minorGridLinePositions,
|
|
404
|
+
minorGridColor: baseProps.minorGridColor ?? gridColor,
|
|
405
|
+
minorGridStrokeWidth: baseProps.minorGridStrokeWidth ?? 0.5,
|
|
406
|
+
minorGridOpacity: baseProps.minorGridOpacity ?? 0.15,
|
|
407
|
+
minorGridStyle: baseProps.minorGridStyle ?? "solid",
|
|
408
|
+
minorTicks: minorTickMarks,
|
|
409
|
+
minorTickColor: baseProps.minorTickColor ?? axisColor,
|
|
410
|
+
minorTickStrokeWidth: baseProps.minorTickStrokeWidth ?? 1,
|
|
411
|
+
alternateFillBands,
|
|
412
|
+
titleFontSize: resolveFontSize(DEFAULT_TITLE_FONT_SIZE, globalFont),
|
|
413
|
+
fontFamily: resolveFontFamily(void 0, globalFont),
|
|
414
|
+
showLabels: baseProps.showLabels
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
function calculateTitle(text, position, chartArea, ticks, tickStyle, extraOffset = 0, titleGap = DEFAULT_TITLE_LABEL_GAP) {
|
|
418
|
+
const { x, y, width, height } = chartArea;
|
|
419
|
+
const isVertical = position === "left" || position === "right";
|
|
420
|
+
let labelExtent = 0;
|
|
421
|
+
if (ticks.length > 0) {
|
|
422
|
+
if (isVertical) {
|
|
423
|
+
for (const tick of ticks) {
|
|
424
|
+
const w = measureTextWidth(tick.label, tick.fontSize, tick.fontWeight, tick.fontFamily);
|
|
425
|
+
if (w > labelExtent) labelExtent = w;
|
|
426
|
+
}
|
|
427
|
+
} else {
|
|
428
|
+
if (ticks[0]?.rotation) {
|
|
429
|
+
for (const tick of ticks) {
|
|
430
|
+
const w = measureTextWidth(tick.label, tick.fontSize, tick.fontWeight, tick.fontFamily);
|
|
431
|
+
const h = Math.abs(w * Math.sin((tick.rotation ?? 0) * Math.PI / 180)) + tick.fontSize * Math.abs(Math.cos((tick.rotation ?? 0) * Math.PI / 180));
|
|
432
|
+
if (h > labelExtent) labelExtent = h;
|
|
433
|
+
}
|
|
434
|
+
} else {
|
|
435
|
+
labelExtent = tickStyle.fontSize;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
const dynamicOffset = tickStyle.tickLength + tickStyle.padding + labelExtent + extraOffset + titleGap;
|
|
440
|
+
switch (position) {
|
|
441
|
+
case "bottom":
|
|
442
|
+
return { text, x: x + width / 2, y: y + height + dynamicOffset, rotation: 0 };
|
|
443
|
+
case "top":
|
|
444
|
+
return { text, x: x + width / 2, y: y - dynamicOffset, rotation: 0 };
|
|
445
|
+
case "left":
|
|
446
|
+
return { text, x: x - dynamicOffset, y: y + height / 2, rotation: -90 };
|
|
447
|
+
case "right":
|
|
448
|
+
return { text, x: x + width + dynamicOffset, y: y + height / 2, rotation: 90 };
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// src/renderers/axis/svg.ts
|
|
453
|
+
function renderAxisSvg(layout, theme = defaultLightTheme, options, axisIndex) {
|
|
454
|
+
const group = createSvgGroup();
|
|
455
|
+
const effectiveOpacity = layout.opacity ?? 1;
|
|
456
|
+
if (!options?.skipGrid) {
|
|
457
|
+
for (const band of layout.alternateFillBands) {
|
|
458
|
+
appendChild(group, createSvgRect(band.x, band.y, band.width, band.height, { class: "p-chart-band-fill", fill: band.color, opacity: band.opacity }));
|
|
459
|
+
}
|
|
460
|
+
if (layout.minorGridLines.length > 0) {
|
|
461
|
+
const minorAttrs = {
|
|
462
|
+
class: "p-chart-grid-line-minor",
|
|
463
|
+
"stroke-width": layout.minorGridStrokeWidth,
|
|
464
|
+
opacity: layout.minorGridOpacity,
|
|
465
|
+
stroke: layout.minorGridColor ?? theme.gridMinor
|
|
466
|
+
};
|
|
467
|
+
const minorDash = resolveGridDash(layout.minorGridStyle);
|
|
468
|
+
if (minorDash.length > 0) {
|
|
469
|
+
minorAttrs["stroke-dasharray"] = minorDash.join(" ");
|
|
470
|
+
}
|
|
471
|
+
for (const line of layout.minorGridLines) {
|
|
472
|
+
const w = layout.minorGridStrokeWidth;
|
|
473
|
+
appendChild(group, createSvgLine(crisp(line.x1, w), crisp(line.y1, w), crisp(line.x2, w), crisp(line.y2, w), minorAttrs));
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if (layout.gridLines.length > 0) {
|
|
477
|
+
const gridAttrs = {
|
|
478
|
+
class: "p-chart-grid-line",
|
|
479
|
+
"stroke-width": layout.gridStrokeWidth,
|
|
480
|
+
opacity: layout.gridOpacity,
|
|
481
|
+
stroke: layout.gridColor ?? theme.grid
|
|
482
|
+
};
|
|
483
|
+
const dashArray = resolveGridDash(layout.gridStyle);
|
|
484
|
+
if (dashArray.length > 0) {
|
|
485
|
+
gridAttrs["stroke-dasharray"] = dashArray.join(" ");
|
|
486
|
+
}
|
|
487
|
+
for (const line of layout.gridLines) {
|
|
488
|
+
const w = layout.gridStrokeWidth;
|
|
489
|
+
const lineAttrs = line.opacity === void 0 ? gridAttrs : { ...gridAttrs, opacity: layout.gridOpacity * line.opacity };
|
|
490
|
+
appendChild(group, createSvgLine(crisp(line.x1, w), crisp(line.y1, w), crisp(line.x2, w), crisp(line.y2, w), lineAttrs));
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (options?.gridOnly) {
|
|
495
|
+
if (effectiveOpacity < 1) {
|
|
496
|
+
setAttr(group, "opacity", effectiveOpacity);
|
|
497
|
+
}
|
|
498
|
+
return group;
|
|
499
|
+
}
|
|
500
|
+
if (effectiveOpacity < 0.01) return group;
|
|
501
|
+
if (!options?.skipAxisLine) {
|
|
502
|
+
const al = layout.axisLine;
|
|
503
|
+
appendChild(
|
|
504
|
+
group,
|
|
505
|
+
createSvgLine(crisp(al.x1), crisp(al.y1), crisp(al.x2), crisp(al.y2), {
|
|
506
|
+
class: "p-chart-axis-line",
|
|
507
|
+
stroke: layout.color ?? resolveAxisColor(theme, axisIndex)
|
|
508
|
+
})
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
for (const tick of layout.ticks) {
|
|
512
|
+
if (!options?.skipTicks) {
|
|
513
|
+
const tickMarkAttrs = {
|
|
514
|
+
class: "p-chart-tick",
|
|
515
|
+
stroke: tick.tickColor ?? layout.color ?? resolveAxisColor(theme, axisIndex)
|
|
516
|
+
};
|
|
517
|
+
if (tick.tickStrokeWidth) {
|
|
518
|
+
tickMarkAttrs["stroke-width"] = tick.tickStrokeWidth;
|
|
519
|
+
}
|
|
520
|
+
const tw = tick.tickStrokeWidth ?? 1;
|
|
521
|
+
appendChild(group, createSvgLine(crisp(tick.x1, tw), crisp(tick.y1, tw), crisp(tick.x2, tw), crisp(tick.y2, tw), tickMarkAttrs));
|
|
522
|
+
}
|
|
523
|
+
if (!options?.skipLabels && layout.showLabels !== false) {
|
|
524
|
+
const { topToAlpha, midToAlpha } = measureFontMetrics(tick.fontSize, tick.fontFamily, tick.fontWeight);
|
|
525
|
+
const rawDy = tick.baseline === "top" ? topToAlpha : tick.baseline === "middle" ? midToAlpha : 0;
|
|
526
|
+
const finalY = Math.round(tick.labelY + rawDy);
|
|
527
|
+
const textAttrs = {
|
|
528
|
+
class: "p-chart-tick-label",
|
|
529
|
+
"text-anchor": tick.anchor,
|
|
530
|
+
"dominant-baseline": "auto",
|
|
531
|
+
fill: tick.labelColor ?? theme.tickLabel,
|
|
532
|
+
"font-size": tick.fontSize,
|
|
533
|
+
"font-family": tick.fontFamily,
|
|
534
|
+
"font-weight": tick.fontWeight
|
|
535
|
+
};
|
|
536
|
+
if (tick.opacity !== void 0 && tick.opacity < 1) {
|
|
537
|
+
textAttrs.opacity = tick.opacity;
|
|
538
|
+
}
|
|
539
|
+
if (tick.rotation) {
|
|
540
|
+
textAttrs.transform = `rotate(${tick.rotation}, ${tick.labelX}, ${finalY})`;
|
|
541
|
+
}
|
|
542
|
+
appendChild(group, createSvgText(tick.labelX, finalY, tick.label, textAttrs));
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
if (layout.minorTicks.length > 0) {
|
|
546
|
+
const minorTickAttrs = {
|
|
547
|
+
class: "p-chart-tick-minor",
|
|
548
|
+
"stroke-width": layout.minorTickStrokeWidth,
|
|
549
|
+
stroke: layout.minorTickColor ?? resolveAxisColor(theme, axisIndex)
|
|
550
|
+
};
|
|
551
|
+
for (const mt of layout.minorTicks) {
|
|
552
|
+
const mw = layout.minorTickStrokeWidth ?? 1;
|
|
553
|
+
appendChild(group, createSvgLine(crisp(mt.x1, mw), crisp(mt.y1, mw), crisp(mt.x2, mw), crisp(mt.y2, mw), minorTickAttrs));
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
if (layout.title) {
|
|
557
|
+
const { midToAlpha: titleMidToAlpha } = measureFontMetrics(layout.titleFontSize, layout.fontFamily, "bold");
|
|
558
|
+
const titleFinalY = Math.round(layout.title.y + titleMidToAlpha);
|
|
559
|
+
const attrs = {
|
|
560
|
+
class: "p-chart-axis-title",
|
|
561
|
+
"text-anchor": "middle",
|
|
562
|
+
"dominant-baseline": "auto",
|
|
563
|
+
fill: layout.color ?? resolveAxisColor(theme, axisIndex),
|
|
564
|
+
"font-weight": "bold",
|
|
565
|
+
"font-size": layout.titleFontSize,
|
|
566
|
+
"font-family": layout.fontFamily
|
|
567
|
+
};
|
|
568
|
+
if (options?.rtl) {
|
|
569
|
+
attrs.direction = "rtl";
|
|
570
|
+
attrs["unicode-bidi"] = "embed";
|
|
571
|
+
}
|
|
572
|
+
if (layout.title.rotation !== 0) {
|
|
573
|
+
attrs.transform = `rotate(${layout.title.rotation}, ${layout.title.x}, ${titleFinalY})`;
|
|
574
|
+
}
|
|
575
|
+
appendChild(group, createSvgText(layout.title.x, titleFinalY, layout.title.text, attrs));
|
|
576
|
+
}
|
|
577
|
+
if (effectiveOpacity < 1) {
|
|
578
|
+
setAttr(group, "opacity", effectiveOpacity);
|
|
579
|
+
}
|
|
580
|
+
return group;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
// src/renderers/axis/canvas.ts
|
|
584
|
+
function renderAxisCanvas(ctx, layout, options, theme = defaultLightTheme, axisIndex) {
|
|
585
|
+
withCanvasState(ctx, () => {
|
|
586
|
+
const effectiveOpacity = layout.opacity ?? 1;
|
|
587
|
+
if (effectiveOpacity < 0.01 && !options?.gridOnly) return;
|
|
588
|
+
ctx.globalAlpha *= effectiveOpacity;
|
|
589
|
+
if (!options?.skipGrid) {
|
|
590
|
+
for (const band of layout.alternateFillBands) {
|
|
591
|
+
withCanvasState(ctx, () => {
|
|
592
|
+
ctx.globalAlpha *= band.opacity;
|
|
593
|
+
ctx.fillStyle = band.color;
|
|
594
|
+
ctx.fillRect(band.x, band.y, band.width, band.height);
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
if (layout.minorGridLines.length > 0) {
|
|
598
|
+
withCanvasState(ctx, () => {
|
|
599
|
+
ctx.strokeStyle = layout.minorGridColor ?? theme.gridMinor;
|
|
600
|
+
ctx.lineWidth = layout.minorGridStrokeWidth;
|
|
601
|
+
ctx.globalAlpha *= layout.minorGridOpacity;
|
|
602
|
+
ctx.setLineDash(resolveGridDash(layout.minorGridStyle));
|
|
603
|
+
ctx.beginPath();
|
|
604
|
+
for (const line of layout.minorGridLines) {
|
|
605
|
+
ctx.moveTo(crisp(line.x1, layout.minorGridStrokeWidth), crisp(line.y1, layout.minorGridStrokeWidth));
|
|
606
|
+
ctx.lineTo(crisp(line.x2, layout.minorGridStrokeWidth), crisp(line.y2, layout.minorGridStrokeWidth));
|
|
607
|
+
}
|
|
608
|
+
ctx.stroke();
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
if (layout.gridLines.length > 0) {
|
|
612
|
+
withCanvasState(ctx, () => {
|
|
613
|
+
ctx.strokeStyle = layout.gridColor ?? theme.grid;
|
|
614
|
+
ctx.lineWidth = layout.gridStrokeWidth;
|
|
615
|
+
ctx.globalAlpha *= layout.gridOpacity;
|
|
616
|
+
ctx.setLineDash(resolveGridDash(layout.gridStyle));
|
|
617
|
+
const hasPerLineOpacity = layout.gridLines.some((l) => l.opacity !== void 0);
|
|
618
|
+
if (!hasPerLineOpacity) {
|
|
619
|
+
ctx.beginPath();
|
|
620
|
+
for (const line of layout.gridLines) {
|
|
621
|
+
ctx.moveTo(crisp(line.x1, layout.gridStrokeWidth), crisp(line.y1, layout.gridStrokeWidth));
|
|
622
|
+
ctx.lineTo(crisp(line.x2, layout.gridStrokeWidth), crisp(line.y2, layout.gridStrokeWidth));
|
|
623
|
+
}
|
|
624
|
+
ctx.stroke();
|
|
625
|
+
} else {
|
|
626
|
+
const baseAlpha = ctx.globalAlpha;
|
|
627
|
+
for (const line of layout.gridLines) {
|
|
628
|
+
ctx.globalAlpha = line.opacity === void 0 ? baseAlpha : baseAlpha * line.opacity;
|
|
629
|
+
ctx.beginPath();
|
|
630
|
+
ctx.moveTo(crisp(line.x1, layout.gridStrokeWidth), crisp(line.y1, layout.gridStrokeWidth));
|
|
631
|
+
ctx.lineTo(crisp(line.x2, layout.gridStrokeWidth), crisp(line.y2, layout.gridStrokeWidth));
|
|
632
|
+
ctx.stroke();
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
if (options?.gridOnly) return;
|
|
639
|
+
if (!options?.skipAxisLine) {
|
|
640
|
+
ctx.strokeStyle = layout.color ?? resolveAxisColor(theme, axisIndex);
|
|
641
|
+
ctx.lineWidth = 1;
|
|
642
|
+
ctx.beginPath();
|
|
643
|
+
ctx.moveTo(crisp(layout.axisLine.x1), crisp(layout.axisLine.y1));
|
|
644
|
+
ctx.lineTo(crisp(layout.axisLine.x2), crisp(layout.axisLine.y2));
|
|
645
|
+
ctx.stroke();
|
|
646
|
+
}
|
|
647
|
+
if (!options?.skipTicks) {
|
|
648
|
+
for (const tick of layout.ticks) {
|
|
649
|
+
const markColor = tick.tickColor ?? layout.color ?? resolveAxisColor(theme, axisIndex);
|
|
650
|
+
const markWidth = tick.tickStrokeWidth ?? 1;
|
|
651
|
+
ctx.strokeStyle = markColor;
|
|
652
|
+
ctx.lineWidth = markWidth;
|
|
653
|
+
ctx.beginPath();
|
|
654
|
+
ctx.moveTo(crisp(tick.x1, markWidth), crisp(tick.y1, markWidth));
|
|
655
|
+
ctx.lineTo(crisp(tick.x2, markWidth), crisp(tick.y2, markWidth));
|
|
656
|
+
ctx.stroke();
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
if (layout.minorTicks.length > 0) {
|
|
660
|
+
ctx.strokeStyle = layout.minorTickColor ?? resolveAxisColor(theme, axisIndex);
|
|
661
|
+
ctx.lineWidth = layout.minorTickStrokeWidth;
|
|
662
|
+
ctx.beginPath();
|
|
663
|
+
for (const mt of layout.minorTicks) {
|
|
664
|
+
ctx.moveTo(crisp(mt.x1, layout.minorTickStrokeWidth), crisp(mt.y1, layout.minorTickStrokeWidth));
|
|
665
|
+
ctx.lineTo(crisp(mt.x2, layout.minorTickStrokeWidth), crisp(mt.y2, layout.minorTickStrokeWidth));
|
|
666
|
+
}
|
|
667
|
+
ctx.stroke();
|
|
668
|
+
}
|
|
669
|
+
if (!options?.skipLabels && layout.showLabels !== false) {
|
|
670
|
+
const labelBaseAlpha = ctx.globalAlpha;
|
|
671
|
+
for (const tick of layout.ticks) {
|
|
672
|
+
const { topToAlpha, midToAlpha } = measureFontMetrics(tick.fontSize, tick.fontFamily, tick.fontWeight);
|
|
673
|
+
const rawDy = tick.baseline === "top" ? topToAlpha : tick.baseline === "middle" ? midToAlpha : 0;
|
|
674
|
+
const finalY = Math.round(tick.labelY + rawDy);
|
|
675
|
+
ctx.fillStyle = tick.labelColor ?? theme.tickLabel;
|
|
676
|
+
ctx.font = `${tick.fontWeight} ${tick.fontSize}px ${tick.fontFamily}`;
|
|
677
|
+
ctx.textAlign = svgAnchorToCanvasAlign(tick.anchor);
|
|
678
|
+
ctx.textBaseline = "alphabetic";
|
|
679
|
+
ctx.globalAlpha = tick.opacity === void 0 ? labelBaseAlpha : labelBaseAlpha * tick.opacity;
|
|
680
|
+
if (tick.rotation) {
|
|
681
|
+
ctx.save();
|
|
682
|
+
ctx.translate(tick.labelX, finalY);
|
|
683
|
+
ctx.rotate(tick.rotation * Math.PI / 180);
|
|
684
|
+
ctx.fillText(tick.label, 0, 0);
|
|
685
|
+
ctx.restore();
|
|
686
|
+
} else {
|
|
687
|
+
ctx.fillText(tick.label, tick.labelX, finalY);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
ctx.globalAlpha = labelBaseAlpha;
|
|
691
|
+
}
|
|
692
|
+
if (layout.title) {
|
|
693
|
+
const { midToAlpha: titleMidToAlpha } = measureFontMetrics(layout.titleFontSize, layout.fontFamily, "bold");
|
|
694
|
+
const titleFinalY = Math.round(layout.title.y + titleMidToAlpha);
|
|
695
|
+
if (options?.rtl) ctx.direction = "rtl";
|
|
696
|
+
ctx.fillStyle = layout.color ?? resolveAxisColor(theme, axisIndex);
|
|
697
|
+
ctx.font = `bold ${layout.titleFontSize}px ${layout.fontFamily}`;
|
|
698
|
+
ctx.textAlign = "center";
|
|
699
|
+
ctx.textBaseline = "alphabetic";
|
|
700
|
+
if (layout.title.rotation !== 0) {
|
|
701
|
+
ctx.save();
|
|
702
|
+
ctx.translate(layout.title.x, titleFinalY);
|
|
703
|
+
ctx.rotate(layout.title.rotation * Math.PI / 180);
|
|
704
|
+
ctx.fillText(layout.title.text, 0, 0);
|
|
705
|
+
ctx.restore();
|
|
706
|
+
} else {
|
|
707
|
+
ctx.fillText(layout.title.text, layout.title.x, titleFinalY);
|
|
708
|
+
}
|
|
709
|
+
if (options?.rtl) ctx.direction = "ltr";
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
export { calculateAxisLayout, calculateAxisSpace, renderAxisCanvas, renderAxisSvg };
|