@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,492 @@
|
|
|
1
|
+
import { createLinearScale } from './chunk-RQ3CKQOX.mjs';
|
|
2
|
+
|
|
3
|
+
// src/utils/zoom/calculations.ts
|
|
4
|
+
function resolveLimit(limit, originalValue) {
|
|
5
|
+
if (limit === "original") return originalValue;
|
|
6
|
+
return limit;
|
|
7
|
+
}
|
|
8
|
+
function clampZoomWindow(window, limits, originalDomain) {
|
|
9
|
+
let { min, max } = window;
|
|
10
|
+
if (min > max) {
|
|
11
|
+
const tmp = min;
|
|
12
|
+
min = max;
|
|
13
|
+
max = tmp;
|
|
14
|
+
}
|
|
15
|
+
let effectiveMinRange = limits?.minRange;
|
|
16
|
+
if (effectiveMinRange == null && originalDomain) {
|
|
17
|
+
const originalRange = originalDomain[1] - originalDomain[0];
|
|
18
|
+
effectiveMinRange = originalRange / 1e3;
|
|
19
|
+
}
|
|
20
|
+
const range = max - min;
|
|
21
|
+
if (effectiveMinRange != null && range < effectiveMinRange) {
|
|
22
|
+
const center = (min + max) / 2;
|
|
23
|
+
const halfRange = effectiveMinRange / 2;
|
|
24
|
+
min = center - halfRange;
|
|
25
|
+
max = center + halfRange;
|
|
26
|
+
}
|
|
27
|
+
const hardMin = resolveLimit(limits?.min, originalDomain?.[0]) ?? originalDomain?.[0];
|
|
28
|
+
const hardMax = resolveLimit(limits?.max, originalDomain?.[1]) ?? originalDomain?.[1];
|
|
29
|
+
if (hardMin != null && min < hardMin) {
|
|
30
|
+
const shift = hardMin - min;
|
|
31
|
+
min = hardMin;
|
|
32
|
+
max = max + shift;
|
|
33
|
+
}
|
|
34
|
+
if (hardMax != null && max > hardMax) {
|
|
35
|
+
const shift = max - hardMax;
|
|
36
|
+
max = hardMax;
|
|
37
|
+
min = min - shift;
|
|
38
|
+
}
|
|
39
|
+
if (hardMin != null && min < hardMin) min = hardMin;
|
|
40
|
+
if (hardMax != null && max > hardMax) max = hardMax;
|
|
41
|
+
return { min, max };
|
|
42
|
+
}
|
|
43
|
+
function computeWheelZoom(currentWindow, cursorDataValue, zoomFactor, limits, originalDomain) {
|
|
44
|
+
const { min, max } = currentWindow;
|
|
45
|
+
const range = max - min;
|
|
46
|
+
const cursorFraction = range > 0 ? (cursorDataValue - min) / range : 0.5;
|
|
47
|
+
const newRange = range / zoomFactor;
|
|
48
|
+
const newMin = cursorDataValue - cursorFraction * newRange;
|
|
49
|
+
const newMax = cursorDataValue + (1 - cursorFraction) * newRange;
|
|
50
|
+
return clampZoomWindow({ min: newMin, max: newMax }, limits, originalDomain);
|
|
51
|
+
}
|
|
52
|
+
function classifyWheelGesture(e) {
|
|
53
|
+
if (e.ctrlKey) return "zoom";
|
|
54
|
+
if (e.deltaX !== 0) return "pan";
|
|
55
|
+
return "zoom";
|
|
56
|
+
}
|
|
57
|
+
function computeDragZoomWindow(startPixel, endPixel, invert, limits, originalDomain) {
|
|
58
|
+
const v1 = invert(startPixel);
|
|
59
|
+
const v2 = invert(endPixel);
|
|
60
|
+
const min = Math.min(v1, v2);
|
|
61
|
+
const max = Math.max(v1, v2);
|
|
62
|
+
return clampZoomWindow({ min, max }, limits, originalDomain);
|
|
63
|
+
}
|
|
64
|
+
function computePanDelta(currentWindow, deltaPixels, pixelRange, limits, originalDomain) {
|
|
65
|
+
const { min, max } = currentWindow;
|
|
66
|
+
const dataRange = max - min;
|
|
67
|
+
const dataDelta = pixelRange !== 0 ? deltaPixels / pixelRange * dataRange : 0;
|
|
68
|
+
return clampZoomWindow({ min: min - dataDelta, max: max - dataDelta }, limits, originalDomain);
|
|
69
|
+
}
|
|
70
|
+
function isZoomed(state) {
|
|
71
|
+
return state.x !== null || state.y !== null;
|
|
72
|
+
}
|
|
73
|
+
function normalizeZoomState(state, originals) {
|
|
74
|
+
const atFullExtent = (w, domain) => {
|
|
75
|
+
if (!w || !domain) return false;
|
|
76
|
+
const range = domain[1] - domain[0];
|
|
77
|
+
const eps = Math.max(Math.abs(range), 1) * 1e-9;
|
|
78
|
+
return Math.abs(w.min - domain[0]) <= eps && Math.abs(w.max - domain[1]) <= eps;
|
|
79
|
+
};
|
|
80
|
+
const nextX = atFullExtent(state.x, originals.x) ? null : state.x;
|
|
81
|
+
const nextY = atFullExtent(state.y, originals.y) ? null : state.y;
|
|
82
|
+
if (nextX === state.x && nextY === state.y) return state;
|
|
83
|
+
return { x: nextX, y: nextY };
|
|
84
|
+
}
|
|
85
|
+
function isModifierKeyPressed(e, key) {
|
|
86
|
+
if (!key) return false;
|
|
87
|
+
switch (key) {
|
|
88
|
+
case "shift":
|
|
89
|
+
return e.shiftKey;
|
|
90
|
+
case "ctrl":
|
|
91
|
+
return e.ctrlKey;
|
|
92
|
+
case "alt":
|
|
93
|
+
return e.altKey;
|
|
94
|
+
case "meta":
|
|
95
|
+
return e.metaKey;
|
|
96
|
+
default:
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function createInitialZoomState() {
|
|
101
|
+
return { x: null, y: null };
|
|
102
|
+
}
|
|
103
|
+
function normalizeSubConfig(value, defaults) {
|
|
104
|
+
if (value === false) return null;
|
|
105
|
+
if (value === true || value === void 0) return defaults;
|
|
106
|
+
return { ...defaults, ...value };
|
|
107
|
+
}
|
|
108
|
+
function effectiveLimit(userLimit, dataMinRange) {
|
|
109
|
+
if (dataMinRange == null) return userLimit;
|
|
110
|
+
if (userLimit?.minRange != null) return userLimit;
|
|
111
|
+
return { ...userLimit, minRange: dataMinRange };
|
|
112
|
+
}
|
|
113
|
+
function buildZoomScales(layoutData, zoomState) {
|
|
114
|
+
const isVertical = layoutData.orientation === "vertical";
|
|
115
|
+
const timeScale = layoutData.sharedTimeScale;
|
|
116
|
+
const firstValueScale = layoutData.valueScales.values().next().value;
|
|
117
|
+
const scatterXScale = layoutData.scatterXScales?.values().next().value;
|
|
118
|
+
let categoryIndexScale;
|
|
119
|
+
if (!timeScale && !scatterXScale) {
|
|
120
|
+
const origDomain = isVertical ? layoutData.originalDomains?.x : layoutData.originalDomains?.y;
|
|
121
|
+
const catRange = isVertical ? [layoutData.cartesianArea.x, layoutData.cartesianArea.x + layoutData.cartesianArea.width] : [layoutData.cartesianArea.y, layoutData.cartesianArea.y + layoutData.cartesianArea.height];
|
|
122
|
+
if (origDomain) {
|
|
123
|
+
const zoomAxis = isVertical ? zoomState?.x : zoomState?.y;
|
|
124
|
+
const activeDomain = zoomAxis ? [zoomAxis.min, zoomAxis.max] : origDomain;
|
|
125
|
+
const bandScale = layoutData.sharedCategoryScale;
|
|
126
|
+
const bandDomain = bandScale?.domain();
|
|
127
|
+
if (bandScale && bandDomain && bandDomain.length > 0) {
|
|
128
|
+
const bw = bandScale.bandwidth();
|
|
129
|
+
const firstPos = (bandScale(bandDomain[0]) ?? catRange[0]) + bw / 2;
|
|
130
|
+
const lastPos = (bandScale(bandDomain[bandDomain.length - 1]) ?? catRange[1]) + bw / 2;
|
|
131
|
+
categoryIndexScale = createLinearScale(activeDomain, [firstPos, lastPos]);
|
|
132
|
+
} else {
|
|
133
|
+
categoryIndexScale = createLinearScale(activeDomain, catRange);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const xScale = isVertical ? timeScale ?? scatterXScale ?? categoryIndexScale ?? void 0 : firstValueScale;
|
|
138
|
+
const yScale = isVertical ? firstValueScale : timeScale ?? scatterXScale ?? categoryIndexScale ?? void 0;
|
|
139
|
+
return { x: xScale, y: yScale };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/utils/zoom/controller.ts
|
|
143
|
+
function isInsidePlotArea(x, y, plotArea) {
|
|
144
|
+
return x >= plotArea.x && x <= plotArea.x + plotArea.width && y >= plotArea.y && y <= plotArea.y + plotArea.height;
|
|
145
|
+
}
|
|
146
|
+
function computePinchZoomFactor(previousDistance, currentDistance) {
|
|
147
|
+
if (previousDistance <= 0) return 1;
|
|
148
|
+
return currentDistance / previousDistance;
|
|
149
|
+
}
|
|
150
|
+
var ZoomPanController = class {
|
|
151
|
+
constructor(deps) {
|
|
152
|
+
this.dragState = null;
|
|
153
|
+
this.pinchState = null;
|
|
154
|
+
this._zoomCurrent = createInitialZoomState();
|
|
155
|
+
this._rafHandle = 0;
|
|
156
|
+
/** Framework binds this to write settled zoom state to reactive state. */
|
|
157
|
+
this.onSettle = null;
|
|
158
|
+
this.deps = deps;
|
|
159
|
+
}
|
|
160
|
+
updateDeps(deps) {
|
|
161
|
+
this.deps = deps;
|
|
162
|
+
}
|
|
163
|
+
// ========================================================================
|
|
164
|
+
// WHEEL
|
|
165
|
+
// ========================================================================
|
|
166
|
+
handleWheel(mouseX, mouseY, deltaY, modifiers) {
|
|
167
|
+
const { mode, wheelCfg, limits } = this.deps.getConfig();
|
|
168
|
+
if (!wheelCfg?.enabled) return null;
|
|
169
|
+
if (wheelCfg.modifierKey && !isModifierKeyPressed(modifiers, wheelCfg.modifierKey)) return null;
|
|
170
|
+
const plotArea = this.deps.getPlotArea();
|
|
171
|
+
if (!plotArea || !isInsidePlotArea(mouseX, mouseY, plotArea)) return null;
|
|
172
|
+
const scales = this.deps.getScales();
|
|
173
|
+
if (!scales) return null;
|
|
174
|
+
const speed = wheelCfg.speed ?? 0.1;
|
|
175
|
+
const delta = deltaY > 0 ? 1 - speed : 1 + speed;
|
|
176
|
+
const originals = this.deps.getOriginalDomains();
|
|
177
|
+
const newState = { ...this.deps.getZoomState() };
|
|
178
|
+
if ((mode === "x" || mode === "xy") && scales.x) {
|
|
179
|
+
const cursorValue = scales.x.invert(mouseX);
|
|
180
|
+
newState.x = computeWheelZoom(this.deps.getCurrentWindow("x"), cursorValue, delta, effectiveLimit(limits?.x, originals.minRangeX), originals.x);
|
|
181
|
+
}
|
|
182
|
+
if ((mode === "y" || mode === "xy") && scales.y) {
|
|
183
|
+
const cursorValue = scales.y.invert(mouseY);
|
|
184
|
+
newState.y = computeWheelZoom(this.deps.getCurrentWindow("y"), cursorValue, delta, effectiveLimit(limits?.y, originals.minRangeY), originals.y);
|
|
185
|
+
}
|
|
186
|
+
return { newState, settle: false };
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Pan via trackpad two-finger scroll. Only acts once the chart is zoomed —
|
|
190
|
+
* an unzoomed chart has nowhere to pan, so the caller should let the page
|
|
191
|
+
* scroll instead of consuming the event.
|
|
192
|
+
*/
|
|
193
|
+
handleWheelPan(deltaX, deltaY, mouseX, mouseY) {
|
|
194
|
+
const { mode, panCfg, limits } = this.deps.getConfig();
|
|
195
|
+
if (!panCfg?.enabled) return null;
|
|
196
|
+
const plotArea = this.deps.getPlotArea();
|
|
197
|
+
if (!plotArea || !isInsidePlotArea(mouseX, mouseY, plotArea)) return null;
|
|
198
|
+
if (!isZoomed(this.deps.getZoomState())) return null;
|
|
199
|
+
const originals = this.deps.getOriginalDomains();
|
|
200
|
+
const newState = { ...this.deps.getZoomState() };
|
|
201
|
+
if ((mode === "x" || mode === "xy") && deltaX !== 0) {
|
|
202
|
+
newState.x = computePanDelta(this.deps.getCurrentWindow("x"), -deltaX, plotArea.width, effectiveLimit(limits?.x, originals.minRangeX), originals.x);
|
|
203
|
+
}
|
|
204
|
+
if ((mode === "y" || mode === "xy") && deltaY !== 0) {
|
|
205
|
+
newState.y = computePanDelta(this.deps.getCurrentWindow("y"), deltaY, plotArea.height, effectiveLimit(limits?.y, originals.minRangeY), originals.y);
|
|
206
|
+
}
|
|
207
|
+
return { newState, settle: false };
|
|
208
|
+
}
|
|
209
|
+
// ========================================================================
|
|
210
|
+
// POINTER DOWN
|
|
211
|
+
// ========================================================================
|
|
212
|
+
handlePointerDown(x, y, pointerId, button, modifiers, pointerType = "mouse") {
|
|
213
|
+
const noAction = { action: null, capturePointer: false, setDragging: false };
|
|
214
|
+
if (button !== 0) return noAction;
|
|
215
|
+
const plotArea = this.deps.getPlotArea();
|
|
216
|
+
if (!plotArea || !isInsidePlotArea(x, y, plotArea)) return noAction;
|
|
217
|
+
const { panCfg, dragCfg, pinchCfg } = this.deps.getConfig();
|
|
218
|
+
const isTouch = pointerType === "touch";
|
|
219
|
+
if (isTouch && pinchCfg?.enabled && this.dragState?.active && this.dragState.pointerId !== pointerId) {
|
|
220
|
+
const firstId = this.dragState.pointerId;
|
|
221
|
+
const first = { x: this.dragState.lastX, y: this.dragState.lastY };
|
|
222
|
+
const dx = x - first.x;
|
|
223
|
+
const dy = y - first.y;
|
|
224
|
+
this.dragState = null;
|
|
225
|
+
this.pinchState = {
|
|
226
|
+
active: true,
|
|
227
|
+
pointers: /* @__PURE__ */ new Map([
|
|
228
|
+
[firstId, first],
|
|
229
|
+
[pointerId, { x, y }]
|
|
230
|
+
]),
|
|
231
|
+
initialDistance: Math.sqrt(dx * dx + dy * dy),
|
|
232
|
+
initialZoom: { ...this.deps.getZoomState() },
|
|
233
|
+
centerX: (first.x + x) / 2,
|
|
234
|
+
centerY: (first.y + y) / 2
|
|
235
|
+
};
|
|
236
|
+
return { action: "pinch-update", capturePointer: true, setDragging: false };
|
|
237
|
+
}
|
|
238
|
+
if (pinchCfg?.enabled && this.pinchState?.active) {
|
|
239
|
+
this.pinchState.pointers.set(pointerId, { x, y });
|
|
240
|
+
if (this.pinchState.pointers.size === 2) {
|
|
241
|
+
const pts = Array.from(this.pinchState.pointers.values());
|
|
242
|
+
const dx = pts[1].x - pts[0].x;
|
|
243
|
+
const dy = pts[1].y - pts[0].y;
|
|
244
|
+
this.pinchState.initialDistance = Math.sqrt(dx * dx + dy * dy);
|
|
245
|
+
this.pinchState.centerX = (pts[0].x + pts[1].x) / 2;
|
|
246
|
+
this.pinchState.centerY = (pts[0].y + pts[1].y) / 2;
|
|
247
|
+
this.pinchState.initialZoom = { ...this.deps.getZoomState() };
|
|
248
|
+
}
|
|
249
|
+
return { action: "pinch-update", capturePointer: true, setDragging: false };
|
|
250
|
+
}
|
|
251
|
+
const panModifierOk = isTouch || !panCfg?.modifierKey || isModifierKeyPressed(modifiers, panCfg.modifierKey);
|
|
252
|
+
const isPanMode = panCfg?.enabled && panModifierOk && isZoomed(this.deps.getZoomState());
|
|
253
|
+
if (isPanMode) {
|
|
254
|
+
this.dragState = { active: true, mode: "pan", startX: x, startY: y, lastX: x, lastY: y, pointerId };
|
|
255
|
+
return { action: "drag-pan", capturePointer: true, setDragging: true };
|
|
256
|
+
}
|
|
257
|
+
const isDragZoom = !isTouch && dragCfg?.enabled && (!dragCfg.modifierKey || isModifierKeyPressed(modifiers, dragCfg.modifierKey));
|
|
258
|
+
if (isDragZoom) {
|
|
259
|
+
this.dragState = { active: true, mode: "zoom", startX: x, startY: y, lastX: x, lastY: y, pointerId };
|
|
260
|
+
return { action: "drag-zoom", capturePointer: true, setDragging: true };
|
|
261
|
+
}
|
|
262
|
+
if (pinchCfg?.enabled && !this.dragState) {
|
|
263
|
+
this.pinchState = {
|
|
264
|
+
active: true,
|
|
265
|
+
pointers: /* @__PURE__ */ new Map([[pointerId, { x, y }]]),
|
|
266
|
+
initialDistance: 0,
|
|
267
|
+
initialZoom: { ...this.deps.getZoomState() },
|
|
268
|
+
centerX: x,
|
|
269
|
+
centerY: y
|
|
270
|
+
};
|
|
271
|
+
return { action: "pinch-init", capturePointer: true, setDragging: false };
|
|
272
|
+
}
|
|
273
|
+
return noAction;
|
|
274
|
+
}
|
|
275
|
+
// ========================================================================
|
|
276
|
+
// POINTER MOVE
|
|
277
|
+
// ========================================================================
|
|
278
|
+
handlePointerMove(x, y, pointerId) {
|
|
279
|
+
if (this.pinchState?.active && this.pinchState.pointers.size === 2) {
|
|
280
|
+
this.pinchState.pointers.set(pointerId, { x, y });
|
|
281
|
+
const pts = Array.from(this.pinchState.pointers.values());
|
|
282
|
+
const dx = pts[1].x - pts[0].x;
|
|
283
|
+
const dy = pts[1].y - pts[0].y;
|
|
284
|
+
const currentDistance = Math.sqrt(dx * dx + dy * dy);
|
|
285
|
+
if (this.pinchState.initialDistance > 0) {
|
|
286
|
+
const factor = computePinchZoomFactor(this.pinchState.initialDistance, currentDistance);
|
|
287
|
+
const scales = this.deps.getScales();
|
|
288
|
+
const originals = this.deps.getOriginalDomains();
|
|
289
|
+
if (scales) {
|
|
290
|
+
const { mode, limits } = this.deps.getConfig();
|
|
291
|
+
const newState = { ...this.deps.getZoomState() };
|
|
292
|
+
const centerX = (pts[0].x + pts[1].x) / 2;
|
|
293
|
+
const centerY = (pts[0].y + pts[1].y) / 2;
|
|
294
|
+
if ((mode === "x" || mode === "xy") && scales.x) {
|
|
295
|
+
const cursorValue = scales.x.invert(centerX);
|
|
296
|
+
const baseWindow = this.pinchState.initialZoom.x ?? (originals.x ? { min: originals.x[0], max: originals.x[1] } : { min: 0, max: 1 });
|
|
297
|
+
newState.x = computeWheelZoom(baseWindow, cursorValue, factor, effectiveLimit(limits?.x, originals.minRangeX), originals.x);
|
|
298
|
+
}
|
|
299
|
+
if ((mode === "y" || mode === "xy") && scales.y) {
|
|
300
|
+
const cursorValue = scales.y.invert(centerY);
|
|
301
|
+
const baseWindow = this.pinchState.initialZoom.y ?? (originals.y ? { min: originals.y[0], max: originals.y[1] } : { min: 0, max: 1 });
|
|
302
|
+
newState.y = computeWheelZoom(baseWindow, cursorValue, factor, effectiveLimit(limits?.y, originals.minRangeY), originals.y);
|
|
303
|
+
}
|
|
304
|
+
return { zoomResult: { newState, settle: false }, selectionRect: null };
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return { zoomResult: null, selectionRect: null };
|
|
308
|
+
}
|
|
309
|
+
const drag = this.dragState;
|
|
310
|
+
if (!drag?.active || drag.pointerId !== pointerId) return { zoomResult: null, selectionRect: null };
|
|
311
|
+
const plotArea = this.deps.getPlotArea();
|
|
312
|
+
if (!plotArea) return { zoomResult: null, selectionRect: null };
|
|
313
|
+
if (drag.mode === "zoom") {
|
|
314
|
+
const { mode } = this.deps.getConfig();
|
|
315
|
+
const sx = Math.max(plotArea.x, Math.min(drag.startX, x));
|
|
316
|
+
const sy = Math.max(plotArea.y, Math.min(drag.startY, y));
|
|
317
|
+
const ex = Math.max(plotArea.x, Math.min(Math.max(drag.startX, x), plotArea.x + plotArea.width));
|
|
318
|
+
const ey = Math.max(plotArea.y, Math.min(Math.max(drag.startY, y), plotArea.y + plotArea.height));
|
|
319
|
+
const selectionRect = {
|
|
320
|
+
x: mode === "y" ? plotArea.x : sx,
|
|
321
|
+
y: mode === "x" ? plotArea.y : sy,
|
|
322
|
+
width: mode === "y" ? plotArea.width : ex - sx,
|
|
323
|
+
height: mode === "x" ? plotArea.height : ey - sy
|
|
324
|
+
};
|
|
325
|
+
return { zoomResult: null, selectionRect };
|
|
326
|
+
}
|
|
327
|
+
if (drag.mode === "pan") {
|
|
328
|
+
const deltaX = x - drag.lastX;
|
|
329
|
+
const deltaY = y - drag.lastY;
|
|
330
|
+
drag.lastX = x;
|
|
331
|
+
drag.lastY = y;
|
|
332
|
+
const { mode, limits } = this.deps.getConfig();
|
|
333
|
+
const originals = this.deps.getOriginalDomains();
|
|
334
|
+
const newState = { ...this.deps.getZoomState() };
|
|
335
|
+
if ((mode === "x" || mode === "xy") && deltaX !== 0) {
|
|
336
|
+
newState.x = computePanDelta(this.deps.getCurrentWindow("x"), deltaX, plotArea.width, effectiveLimit(limits?.x, originals.minRangeX), originals.x);
|
|
337
|
+
}
|
|
338
|
+
if ((mode === "y" || mode === "xy") && deltaY !== 0) {
|
|
339
|
+
newState.y = computePanDelta(this.deps.getCurrentWindow("y"), -deltaY, plotArea.height, effectiveLimit(limits?.y, originals.minRangeY), originals.y);
|
|
340
|
+
}
|
|
341
|
+
return { zoomResult: { newState, settle: false }, selectionRect: null };
|
|
342
|
+
}
|
|
343
|
+
return { zoomResult: null, selectionRect: null };
|
|
344
|
+
}
|
|
345
|
+
// ========================================================================
|
|
346
|
+
// POINTER UP
|
|
347
|
+
// ========================================================================
|
|
348
|
+
handlePointerUp(x, y, pointerId) {
|
|
349
|
+
const noAction = { zoomResult: null, clearSelection: false, clearDragging: false, clearCursor: false, releasePointerId: pointerId };
|
|
350
|
+
if (this.pinchState?.active) {
|
|
351
|
+
this.pinchState.pointers.delete(pointerId);
|
|
352
|
+
if (this.pinchState.pointers.size < 2) {
|
|
353
|
+
this.pinchState = null;
|
|
354
|
+
return { zoomResult: { newState: this.deps.getZoomState(), settle: true }, clearSelection: false, clearDragging: true, clearCursor: true, releasePointerId: pointerId };
|
|
355
|
+
}
|
|
356
|
+
return { ...noAction, releasePointerId: pointerId };
|
|
357
|
+
}
|
|
358
|
+
const drag = this.dragState;
|
|
359
|
+
if (!drag?.active || drag.pointerId !== pointerId) return noAction;
|
|
360
|
+
let zoomResult = null;
|
|
361
|
+
if (drag.mode === "zoom") {
|
|
362
|
+
const dx = Math.abs(x - drag.startX);
|
|
363
|
+
const dy = Math.abs(y - drag.startY);
|
|
364
|
+
if (dx > 5 || dy > 5) {
|
|
365
|
+
const scales = this.deps.getScales();
|
|
366
|
+
const originals = this.deps.getOriginalDomains();
|
|
367
|
+
if (scales) {
|
|
368
|
+
const { mode, limits } = this.deps.getConfig();
|
|
369
|
+
const newState = { ...this.deps.getZoomState() };
|
|
370
|
+
if ((mode === "x" || mode === "xy") && scales.x) {
|
|
371
|
+
newState.x = computeDragZoomWindow(drag.startX, x, (px) => scales.x.invert(px), effectiveLimit(limits?.x, originals.minRangeX), originals.x);
|
|
372
|
+
}
|
|
373
|
+
if ((mode === "y" || mode === "xy") && scales.y) {
|
|
374
|
+
newState.y = computeDragZoomWindow(drag.startY, y, (px) => scales.y.invert(px), effectiveLimit(limits?.y, originals.minRangeY), originals.y);
|
|
375
|
+
}
|
|
376
|
+
zoomResult = { newState, settle: true };
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
} else if (drag.mode === "pan") {
|
|
380
|
+
zoomResult = { newState: this.deps.getZoomState(), settle: true };
|
|
381
|
+
}
|
|
382
|
+
this.dragState = null;
|
|
383
|
+
return { zoomResult, clearSelection: true, clearDragging: true, clearCursor: true, releasePointerId: pointerId };
|
|
384
|
+
}
|
|
385
|
+
// ========================================================================
|
|
386
|
+
// STATE MACHINE — owned by controller, not by framework hook
|
|
387
|
+
// ========================================================================
|
|
388
|
+
applyZoom(newState, settle = false) {
|
|
389
|
+
const normalized = normalizeZoomState(newState, this.deps.getOriginalDomains());
|
|
390
|
+
this._zoomCurrent = normalized;
|
|
391
|
+
if (settle) {
|
|
392
|
+
if (this._rafHandle) {
|
|
393
|
+
cancelAnimationFrame(this._rafHandle);
|
|
394
|
+
this._rafHandle = 0;
|
|
395
|
+
}
|
|
396
|
+
this.onSettle?.(normalized);
|
|
397
|
+
} else {
|
|
398
|
+
if (this._rafHandle) cancelAnimationFrame(this._rafHandle);
|
|
399
|
+
this._rafHandle = requestAnimationFrame(() => {
|
|
400
|
+
this._rafHandle = 0;
|
|
401
|
+
this.onSettle?.(this._zoomCurrent);
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
resetZoom() {
|
|
406
|
+
if (this._rafHandle) {
|
|
407
|
+
cancelAnimationFrame(this._rafHandle);
|
|
408
|
+
this._rafHandle = 0;
|
|
409
|
+
}
|
|
410
|
+
this.applyZoom(createInitialZoomState(), true);
|
|
411
|
+
}
|
|
412
|
+
updateZoom(state) {
|
|
413
|
+
this.applyZoom(state, true);
|
|
414
|
+
}
|
|
415
|
+
getZoomState() {
|
|
416
|
+
return this._zoomCurrent;
|
|
417
|
+
}
|
|
418
|
+
getCurrentWindow(axis) {
|
|
419
|
+
const current = this._zoomCurrent[axis];
|
|
420
|
+
if (current) return current;
|
|
421
|
+
const originals = this.deps.getOriginalDomains();
|
|
422
|
+
const domain = axis === "x" ? originals.x : originals.y;
|
|
423
|
+
return domain ? { min: domain[0], max: domain[1] } : { min: 0, max: 1 };
|
|
424
|
+
}
|
|
425
|
+
destroyZoomState() {
|
|
426
|
+
if (this._rafHandle) {
|
|
427
|
+
cancelAnimationFrame(this._rafHandle);
|
|
428
|
+
this._rafHandle = 0;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
// ========================================================================
|
|
432
|
+
// ATTACH — wire DOM events; returns detach function
|
|
433
|
+
// ========================================================================
|
|
434
|
+
attach(container, callbacks) {
|
|
435
|
+
const handleWheel = (e) => {
|
|
436
|
+
const rect = container.getBoundingClientRect();
|
|
437
|
+
const mouseX = e.clientX - rect.left;
|
|
438
|
+
const mouseY = e.clientY - rect.top;
|
|
439
|
+
const result = classifyWheelGesture(e) === "pan" ? this.handleWheelPan(e.deltaX, e.deltaY, mouseX, mouseY) : this.handleWheel(mouseX, mouseY, e.deltaY, { shiftKey: e.shiftKey, ctrlKey: e.ctrlKey, altKey: e.altKey, metaKey: e.metaKey });
|
|
440
|
+
if (result) {
|
|
441
|
+
e.preventDefault();
|
|
442
|
+
this.applyZoom(result.newState, result.settle);
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
const handlePointerDown = (e) => {
|
|
446
|
+
if (e.target.closest?.("button,a,input,select")) return;
|
|
447
|
+
const rect = container.getBoundingClientRect();
|
|
448
|
+
const result = this.handlePointerDown(e.clientX - rect.left, e.clientY - rect.top, e.pointerId, e.button, { shiftKey: e.shiftKey, ctrlKey: e.ctrlKey, altKey: e.altKey, metaKey: e.metaKey }, e.pointerType);
|
|
449
|
+
if (result.capturePointer) container.setPointerCapture(e.pointerId);
|
|
450
|
+
if (result.setDragging) {
|
|
451
|
+
callbacks.onDragging(true);
|
|
452
|
+
e.preventDefault();
|
|
453
|
+
}
|
|
454
|
+
if (result.action === "drag-pan") container.style.cursor = "grabbing";
|
|
455
|
+
};
|
|
456
|
+
const handlePointerMove = (e) => {
|
|
457
|
+
const rect = container.getBoundingClientRect();
|
|
458
|
+
const result = this.handlePointerMove(e.clientX - rect.left, e.clientY - rect.top, e.pointerId);
|
|
459
|
+
if (result.selectionRect) callbacks.onSelectionRect(result.selectionRect);
|
|
460
|
+
if (result.zoomResult) this.applyZoom(result.zoomResult.newState, result.zoomResult.settle);
|
|
461
|
+
};
|
|
462
|
+
const handlePointerUp = (e) => {
|
|
463
|
+
const rect = container.getBoundingClientRect();
|
|
464
|
+
const result = this.handlePointerUp(e.clientX - rect.left, e.clientY - rect.top, e.pointerId);
|
|
465
|
+
if (result.zoomResult) this.applyZoom(result.zoomResult.newState, result.zoomResult.settle);
|
|
466
|
+
if (result.clearSelection) callbacks.onSelectionRect(null);
|
|
467
|
+
if (result.clearDragging) callbacks.onDragging(false);
|
|
468
|
+
if (result.clearCursor) container.style.cursor = "";
|
|
469
|
+
try {
|
|
470
|
+
container.releasePointerCapture(result.releasePointerId);
|
|
471
|
+
} catch {
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
const prevTouchAction = container.style.touchAction;
|
|
475
|
+
container.style.touchAction = "none";
|
|
476
|
+
container.addEventListener("wheel", handleWheel, { passive: false });
|
|
477
|
+
container.addEventListener("pointerdown", handlePointerDown);
|
|
478
|
+
container.addEventListener("pointermove", handlePointerMove);
|
|
479
|
+
container.addEventListener("pointerup", handlePointerUp);
|
|
480
|
+
container.addEventListener("pointercancel", handlePointerUp);
|
|
481
|
+
return () => {
|
|
482
|
+
container.style.touchAction = prevTouchAction;
|
|
483
|
+
container.removeEventListener("wheel", handleWheel);
|
|
484
|
+
container.removeEventListener("pointerdown", handlePointerDown);
|
|
485
|
+
container.removeEventListener("pointermove", handlePointerMove);
|
|
486
|
+
container.removeEventListener("pointerup", handlePointerUp);
|
|
487
|
+
container.removeEventListener("pointercancel", handlePointerUp);
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
export { ZoomPanController, buildZoomScales, clampZoomWindow, classifyWheelGesture, computeDragZoomWindow, computePanDelta, computeWheelZoom, createInitialZoomState, effectiveLimit, isModifierKeyPressed, isZoomed, normalizeSubConfig, normalizeZoomState };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|