blazeplot 0.1.11 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -48
- package/dist/core/DataCursor.d.ts.map +1 -1
- package/dist/core/OhlcDataset.d.ts +51 -0
- package/dist/core/OhlcDataset.d.ts.map +1 -0
- package/dist/core/RingBuffer.d.ts +7 -1
- package/dist/core/RingBuffer.d.ts.map +1 -1
- package/dist/core/SeriesStore.d.ts +15 -5
- package/dist/core/SeriesStore.d.ts.map +1 -1
- package/dist/core/StaticDataset.d.ts.map +1 -1
- package/dist/core/search.d.ts +3 -0
- package/dist/core/search.d.ts.map +1 -0
- package/dist/core/types.d.ts +10 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +604 -267
- package/dist/index.js.map +1 -1
- package/dist/plugins/interactions.d.ts +1 -1
- package/dist/plugins/interactions.d.ts.map +1 -1
- package/dist/plugins/interactions.js +44 -41
- package/dist/plugins/interactions.js.map +1 -1
- package/dist/plugins/legend.js +6 -3
- package/dist/plugins/legend.js.map +1 -1
- package/dist/plugins/tooltip.js +32 -17
- package/dist/plugins/tooltip.js.map +1 -1
- package/dist/render/Renderer.d.ts +9 -3
- package/dist/render/Renderer.d.ts.map +1 -1
- package/dist/ui/AxisOverlay.d.ts +2 -1
- package/dist/ui/AxisOverlay.d.ts.map +1 -1
- package/dist/ui/Chart.d.ts +27 -12
- package/dist/ui/Chart.d.ts.map +1 -1
- package/dist/ui/Interactions.d.ts +2 -1
- package/dist/ui/Interactions.d.ts.map +1 -1
- package/dist/ui/Legend.d.ts.map +1 -1
- package/dist/ui/Tooltip.d.ts +2 -0
- package/dist/ui/Tooltip.d.ts.map +1 -1
- package/package.json +4 -2
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { interactionsPlugin } from '../ui/Interactions.js';
|
|
2
|
-
export type { InteractionsPluginOptions } from '../ui/Interactions.js';
|
|
2
|
+
export type { InteractionAxisOption, InteractionsPluginOptions } from '../ui/Interactions.js';
|
|
3
3
|
//# sourceMappingURL=interactions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactions.d.ts","sourceRoot":"","sources":["../../src/plugins/interactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,YAAY,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"interactions.d.ts","sourceRoot":"","sources":["../../src/plugins/interactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,YAAY,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
//#region src/ui/Interactions.ts
|
|
2
2
|
var e = 1;
|
|
3
|
-
function t(e
|
|
3
|
+
function t(e) {
|
|
4
|
+
return typeof e == "function" ? e() : e ?? "xy";
|
|
5
|
+
}
|
|
6
|
+
function n(e, t) {
|
|
4
7
|
return {
|
|
5
8
|
dx: t === "y" ? 0 : e.dx,
|
|
6
9
|
dy: t === "x" ? 0 : e.dy
|
|
7
10
|
};
|
|
8
11
|
}
|
|
9
|
-
function
|
|
12
|
+
function r(e) {
|
|
10
13
|
return {
|
|
11
14
|
xMin: e.xMin,
|
|
12
15
|
xMax: e.xMax,
|
|
@@ -14,12 +17,12 @@ function n(e) {
|
|
|
14
17
|
yMax: e.yMax
|
|
15
18
|
};
|
|
16
19
|
}
|
|
17
|
-
function
|
|
20
|
+
function i(e, t, n, r) {
|
|
18
21
|
if (n.width <= 0 || n.height <= 0) return null;
|
|
19
22
|
let i = Math.max(0, Math.min(e - n.left, n.width)), a = Math.max(0, Math.min(t - n.top, n.height));
|
|
20
23
|
return [r.xMin + i / n.width * (r.xMax - r.xMin), r.yMax - a / n.height * (r.yMax - r.yMin)];
|
|
21
24
|
}
|
|
22
|
-
function
|
|
25
|
+
function a(e, t, n, r) {
|
|
23
26
|
let i = Math.min(t[0], n[0]), a = Math.max(t[0], n[0]), o = Math.min(t[1], n[1]), s = Math.max(t[1], n[1]);
|
|
24
27
|
return {
|
|
25
28
|
xMin: r === "y" ? e.xMin : i,
|
|
@@ -28,24 +31,24 @@ function i(e, t, n, r) {
|
|
|
28
31
|
yMax: r === "x" ? e.yMax : s
|
|
29
32
|
};
|
|
30
33
|
}
|
|
31
|
-
function
|
|
32
|
-
return { install(
|
|
33
|
-
let
|
|
34
|
-
f.className = "blazeplot-selection", f.style.position = "absolute", f.style.display = "none", f.style.pointerEvents = "none", f.style.zIndex = "24", f.style.border = `1px solid ${
|
|
34
|
+
function o(o = {}) {
|
|
35
|
+
return { install(s) {
|
|
36
|
+
let c = o.minDragDistancePx ?? 6, l = s.canvas, u = s.xAxisElement, d = s.yAxisElement, f = document.createElement("div"), p = `blazeplot-axis-hover-${e++}`, m = document.createElement("style"), h = u.style.pointerEvents, g = d.style.pointerEvents, _ = u.style.cursor, v = d.style.cursor, y = u.style.filter, b = d.style.filter, x = null, S = null;
|
|
37
|
+
f.className = "blazeplot-selection", f.style.position = "absolute", f.style.display = "none", f.style.pointerEvents = "none", f.style.zIndex = "24", f.style.border = `1px solid ${o.selectionStroke ?? "rgba(147, 197, 253, 0.95)"}`, f.style.background = o.selectionFill ?? "rgba(59, 130, 246, 0.18)", s.plotElement.appendChild(f), m.textContent = `.${p} > div { color: ${o.axisHoverColor ?? "#f8fafc"} !important; }`, o.axisInteractions !== !1 && o.axisHover !== !1 && s.rootElement.appendChild(m), o.axisInteractions !== !1 && (u.style.pointerEvents = "auto", d.style.pointerEvents = "auto", u.style.cursor = "ew-resize", d.style.cursor = "ns-resize");
|
|
35
38
|
let C = () => {
|
|
36
|
-
S ??=
|
|
37
|
-
}, w = (e,
|
|
38
|
-
let r =
|
|
39
|
-
return
|
|
40
|
-
}, T = (e) =>
|
|
39
|
+
S ??= r(s.getViewport());
|
|
40
|
+
}, w = (e, t) => {
|
|
41
|
+
let r = n(e, t);
|
|
42
|
+
return o.viewportPolicy?.beforePan?.(s.getCamera(), r) ?? r;
|
|
43
|
+
}, T = (e) => o.viewportPolicy?.beforeZoom?.(s.getCamera(), e) ?? e, E = () => {
|
|
41
44
|
f.style.display = "none";
|
|
42
45
|
}, D = (e, t) => {
|
|
43
|
-
if (
|
|
44
|
-
let n = t ?
|
|
46
|
+
if (o.axisHover === !1) return;
|
|
47
|
+
let n = t ? o.axisHoverFilter ?? "brightness(1.18)" : null;
|
|
45
48
|
e.classList.toggle(p, t), e === u ? u.style.filter = n ?? y : e === d && (d.style.filter = n ?? b);
|
|
46
49
|
}, O = () => D(u, !0), k = () => D(u, !1), A = () => D(d, !0), j = () => D(d, !1), M = (e) => {
|
|
47
|
-
let
|
|
48
|
-
f.style.left = `${
|
|
50
|
+
let n = l.getBoundingClientRect(), r = Math.max(0, Math.min(e.startX - n.left, n.width)), i = Math.max(0, Math.min(e.startY - n.top, n.height)), a = Math.max(0, Math.min(e.currentX - n.left, n.width)), s = Math.max(0, Math.min(e.currentY - n.top, n.height)), c = t(o.axis), u = c === "y" ? 0 : Math.min(r, a), d = c === "x" ? 0 : Math.min(i, s), p = c === "y" ? n.width : Math.abs(a - r), m = c === "x" ? n.height : Math.abs(s - i);
|
|
51
|
+
f.style.left = `${u}px`, f.style.top = `${d}px`, f.style.width = `${p}px`, f.style.height = `${m}px`, f.style.display = "block";
|
|
49
52
|
}, N = (e, t, n) => {
|
|
50
53
|
C(), e.preventDefault(), n !== l && D(n, !0), n.setPointerCapture(e.pointerId), x = {
|
|
51
54
|
mode: "pan",
|
|
@@ -57,11 +60,11 @@ function a(a = {}) {
|
|
|
57
60
|
};
|
|
58
61
|
}, P = (e) => {
|
|
59
62
|
if (!(x || e.button !== 0)) {
|
|
60
|
-
if (e.shiftKey &&
|
|
61
|
-
N(e,
|
|
63
|
+
if (e.shiftKey && o.shiftDragPan !== !1) {
|
|
64
|
+
N(e, t(o.axis), l);
|
|
62
65
|
return;
|
|
63
66
|
}
|
|
64
|
-
|
|
67
|
+
o.boxZoom !== !1 && (C(), e.preventDefault(), l.setPointerCapture(e.pointerId), x = {
|
|
65
68
|
mode: "select",
|
|
66
69
|
pointerId: e.pointerId,
|
|
67
70
|
target: l,
|
|
@@ -72,9 +75,9 @@ function a(a = {}) {
|
|
|
72
75
|
}, M(x));
|
|
73
76
|
}
|
|
74
77
|
}, F = (e) => {
|
|
75
|
-
x || e.button !== 0 ||
|
|
78
|
+
x || e.button !== 0 || o.axisInteractions === !1 || N(e, "x", u);
|
|
76
79
|
}, I = (e) => {
|
|
77
|
-
x || e.button !== 0 ||
|
|
80
|
+
x || e.button !== 0 || o.axisInteractions === !1 || N(e, "y", d);
|
|
78
81
|
}, L = (e) => {
|
|
79
82
|
if (!(!x || e.pointerId !== x.pointerId)) {
|
|
80
83
|
if (e.preventDefault(), x.mode === "pan") {
|
|
@@ -82,7 +85,7 @@ function a(a = {}) {
|
|
|
82
85
|
dx: t.width > 0 ? (x.lastX - e.clientX) / t.width : 0,
|
|
83
86
|
dy: t.height > 0 ? (e.clientY - x.lastY) / t.height : 0
|
|
84
87
|
}, x.axis);
|
|
85
|
-
n &&
|
|
88
|
+
n && s.pan(n), x.lastX = e.clientX, x.lastY = e.clientY;
|
|
86
89
|
return;
|
|
87
90
|
}
|
|
88
91
|
x.currentX = e.clientX, x.currentY = e.clientY, M(x);
|
|
@@ -90,20 +93,20 @@ function a(a = {}) {
|
|
|
90
93
|
}, R = (e) => {
|
|
91
94
|
if (!x || e.pointerId !== x.pointerId) return;
|
|
92
95
|
e.preventDefault();
|
|
93
|
-
let
|
|
94
|
-
if (x = null,
|
|
95
|
-
let
|
|
96
|
-
if (Math.hypot(
|
|
97
|
-
let
|
|
98
|
-
if (!
|
|
99
|
-
let
|
|
100
|
-
|
|
96
|
+
let n = x;
|
|
97
|
+
if (x = null, n.target.hasPointerCapture(e.pointerId) && n.target.releasePointerCapture(e.pointerId), E(), n.mode !== "select") return;
|
|
98
|
+
let r = e.clientX - n.startX, u = e.clientY - n.startY;
|
|
99
|
+
if (Math.hypot(r, u) < c) return;
|
|
100
|
+
let d = s.getViewport(), f = l.getBoundingClientRect(), p = i(n.startX, n.startY, f, d), m = i(e.clientX, e.clientY, f, d);
|
|
101
|
+
if (!p || !m) return;
|
|
102
|
+
let h = a(d, p, m, t(o.axis));
|
|
103
|
+
h.xMax > h.xMin && h.yMax > h.yMin && s.setViewport(h);
|
|
101
104
|
}, z = (e) => {
|
|
102
105
|
if (!x || e.pointerId !== x.pointerId) return;
|
|
103
106
|
let t = x;
|
|
104
107
|
x = null, t.target.hasPointerCapture(e.pointerId) && t.target.releasePointerCapture(e.pointerId), E();
|
|
105
108
|
}, B = (e, t) => {
|
|
106
|
-
if (
|
|
109
|
+
if (o.wheelZoom === !1) return;
|
|
107
110
|
C(), e.preventDefault();
|
|
108
111
|
let n = e.deltaY < 0 ? 1.1 : .9, r = l.getBoundingClientRect(), i = T({
|
|
109
112
|
factor: n,
|
|
@@ -111,24 +114,24 @@ function a(a = {}) {
|
|
|
111
114
|
cy: r.height > 0 ? 1 - (e.clientY - r.top) / r.height : .5,
|
|
112
115
|
axis: t
|
|
113
116
|
});
|
|
114
|
-
i &&
|
|
117
|
+
i && s.zoom(i);
|
|
115
118
|
}, V = (e) => {
|
|
116
|
-
B(e,
|
|
119
|
+
B(e, t(o.axis));
|
|
117
120
|
}, H = (e) => {
|
|
118
|
-
|
|
121
|
+
o.axisInteractions !== !1 && B(e, "x");
|
|
119
122
|
}, U = (e) => {
|
|
120
|
-
|
|
123
|
+
o.axisInteractions !== !1 && B(e, "y");
|
|
121
124
|
}, W = (e) => {
|
|
122
|
-
if (
|
|
125
|
+
if (o.doubleClickReset === !1) return;
|
|
123
126
|
e.preventDefault();
|
|
124
|
-
let t = S ??
|
|
125
|
-
|
|
127
|
+
let t = S ?? r(s.getViewport());
|
|
128
|
+
s.setViewport(t);
|
|
126
129
|
}, G = [
|
|
127
130
|
l,
|
|
128
131
|
u,
|
|
129
132
|
d
|
|
130
133
|
];
|
|
131
|
-
l.addEventListener("pointerdown", P), l.addEventListener("wheel", V, { passive: !1 }), l.addEventListener("dblclick", W),
|
|
134
|
+
l.addEventListener("pointerdown", P), l.addEventListener("wheel", V, { passive: !1 }), l.addEventListener("dblclick", W), o.axisInteractions !== !1 && (u.addEventListener("pointerdown", F), d.addEventListener("pointerdown", I), u.addEventListener("pointerenter", O), u.addEventListener("pointerleave", k), d.addEventListener("pointerenter", A), d.addEventListener("pointerleave", j), u.addEventListener("wheel", H, { passive: !1 }), d.addEventListener("wheel", U, { passive: !1 }), u.addEventListener("dblclick", W), d.addEventListener("dblclick", W));
|
|
132
135
|
for (let e of G) e.addEventListener("pointermove", L), e.addEventListener("pointerup", R), e.addEventListener("pointercancel", z);
|
|
133
136
|
return () => {
|
|
134
137
|
l.removeEventListener("pointerdown", P), l.removeEventListener("wheel", V), l.removeEventListener("dblclick", W), u.removeEventListener("pointerdown", F), d.removeEventListener("pointerdown", I), u.removeEventListener("pointerenter", O), u.removeEventListener("pointerleave", k), d.removeEventListener("pointerenter", A), d.removeEventListener("pointerleave", j), u.removeEventListener("wheel", H), d.removeEventListener("wheel", U), u.removeEventListener("dblclick", W), d.removeEventListener("dblclick", W);
|
|
@@ -138,6 +141,6 @@ function a(a = {}) {
|
|
|
138
141
|
} };
|
|
139
142
|
}
|
|
140
143
|
//#endregion
|
|
141
|
-
export {
|
|
144
|
+
export { o as interactionsPlugin };
|
|
142
145
|
|
|
143
146
|
//# sourceMappingURL=interactions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactions.js","names":[],"sources":["../../src/ui/Interactions.ts"],"sourcesContent":["import type { Viewport } from \"../core/types.js\";\nimport type { PanIntent, ViewportPolicy, ZoomAxis, ZoomIntent } from \"../interaction/types.js\";\nimport type { Chart, ChartPlugin } from \"./Chart.js\";\n\nexport interface InteractionsPluginOptions {\n readonly axis?: ZoomAxis;\n readonly viewportPolicy?: ViewportPolicy;\n readonly boxZoom?: boolean;\n readonly wheelZoom?: boolean;\n readonly axisInteractions?: boolean;\n readonly axisHover?: boolean;\n readonly axisHoverColor?: string;\n readonly axisHoverFilter?: string;\n readonly shiftDragPan?: boolean;\n readonly doubleClickReset?: boolean;\n readonly minDragDistancePx?: number;\n readonly selectionFill?: string;\n readonly selectionStroke?: string;\n}\n\nlet nextInteractionsPluginId = 1;\n\ntype InteractionTarget = HTMLCanvasElement | HTMLElement;\n\ntype DragState =\n | {\n readonly mode: \"pan\";\n readonly pointerId: number;\n readonly axis: ZoomAxis;\n readonly target: InteractionTarget;\n lastX: number;\n lastY: number;\n }\n | {\n readonly mode: \"select\";\n readonly pointerId: number;\n readonly target: HTMLCanvasElement;\n readonly startX: number;\n readonly startY: number;\n currentX: number;\n currentY: number;\n };\n\nfunction constrainPan(intent: PanIntent, axis: ZoomAxis): PanIntent {\n return {\n dx: axis === \"y\" ? 0 : intent.dx,\n dy: axis === \"x\" ? 0 : intent.dy,\n };\n}\n\nfunction normalizeViewport(v: Viewport): Viewport {\n return { xMin: v.xMin, xMax: v.xMax, yMin: v.yMin, yMax: v.yMax };\n}\n\nfunction clientToDataClamped(\n clientX: number,\n clientY: number,\n rect: DOMRect,\n viewport: Viewport,\n): [number, number] | null {\n if (rect.width <= 0 || rect.height <= 0) return null;\n\n const plotX = Math.max(0, Math.min(clientX - rect.left, rect.width));\n const plotY = Math.max(0, Math.min(clientY - rect.top, rect.height));\n return [\n viewport.xMin + (plotX / rect.width) * (viewport.xMax - viewport.xMin),\n viewport.yMax - (plotY / rect.height) * (viewport.yMax - viewport.yMin),\n ];\n}\n\nfunction applySelectionAxis(\n current: Viewport,\n a: [number, number],\n b: [number, number],\n axis: ZoomAxis,\n): Viewport {\n const xMin = Math.min(a[0], b[0]);\n const xMax = Math.max(a[0], b[0]);\n const yMin = Math.min(a[1], b[1]);\n const yMax = Math.max(a[1], b[1]);\n\n return {\n xMin: axis === \"y\" ? current.xMin : xMin,\n xMax: axis === \"y\" ? current.xMax : xMax,\n yMin: axis === \"x\" ? current.yMin : yMin,\n yMax: axis === \"x\" ? current.yMax : yMax,\n };\n}\n\nexport function interactionsPlugin(options: InteractionsPluginOptions = {}): ChartPlugin {\n return {\n install(chart: Chart) {\n const axis = options.axis ?? \"xy\";\n const minDragDistancePx = options.minDragDistancePx ?? 6;\n const canvas = chart.canvas;\n const xAxis = chart.xAxisElement;\n const yAxis = chart.yAxisElement;\n const selection = document.createElement(\"div\");\n const axisHoverClass = `blazeplot-axis-hover-${nextInteractionsPluginId++}`;\n const axisHoverStyle = document.createElement(\"style\");\n const originalXAxisPointerEvents = xAxis.style.pointerEvents;\n const originalYAxisPointerEvents = yAxis.style.pointerEvents;\n const originalXAxisCursor = xAxis.style.cursor;\n const originalYAxisCursor = yAxis.style.cursor;\n const originalXAxisFilter = xAxis.style.filter;\n const originalYAxisFilter = yAxis.style.filter;\n let drag: DragState | null = null;\n let resetViewport: Viewport | null = null;\n\n selection.className = \"blazeplot-selection\";\n selection.style.position = \"absolute\";\n selection.style.display = \"none\";\n selection.style.pointerEvents = \"none\";\n selection.style.zIndex = \"24\";\n selection.style.border = `1px solid ${options.selectionStroke ?? \"rgba(147, 197, 253, 0.95)\"}`;\n selection.style.background = options.selectionFill ?? \"rgba(59, 130, 246, 0.18)\";\n chart.plotElement.appendChild(selection);\n\n axisHoverStyle.textContent = `.${axisHoverClass} > div { color: ${options.axisHoverColor ?? \"#f8fafc\"} !important; }`;\n if (options.axisInteractions !== false && options.axisHover !== false) {\n chart.rootElement.appendChild(axisHoverStyle);\n }\n\n if (options.axisInteractions !== false) {\n xAxis.style.pointerEvents = \"auto\";\n yAxis.style.pointerEvents = \"auto\";\n xAxis.style.cursor = \"ew-resize\";\n yAxis.style.cursor = \"ns-resize\";\n }\n\n const captureResetViewport = (): void => {\n resetViewport ??= normalizeViewport(chart.getViewport());\n };\n\n const applyPanPolicy = (intent: PanIntent, panAxis: ZoomAxis): PanIntent | null => {\n const constrained = constrainPan(intent, panAxis);\n return options.viewportPolicy?.beforePan?.(chart.getCamera(), constrained) ?? constrained;\n };\n\n const applyZoomPolicy = (intent: ZoomIntent): ZoomIntent | null => {\n return options.viewportPolicy?.beforeZoom?.(chart.getCamera(), intent) ?? intent;\n };\n\n const hideSelection = (): void => {\n selection.style.display = \"none\";\n };\n\n const setAxisHovered = (target: HTMLElement, hovered: boolean): void => {\n if (options.axisHover === false) return;\n const filter = hovered ? options.axisHoverFilter ?? \"brightness(1.18)\" : null;\n target.classList.toggle(axisHoverClass, hovered);\n if (target === xAxis) {\n xAxis.style.filter = filter ?? originalXAxisFilter;\n } else if (target === yAxis) {\n yAxis.style.filter = filter ?? originalYAxisFilter;\n }\n };\n\n const onXAxisPointerEnter = (): void => setAxisHovered(xAxis, true);\n const onXAxisPointerLeave = (): void => setAxisHovered(xAxis, false);\n const onYAxisPointerEnter = (): void => setAxisHovered(yAxis, true);\n const onYAxisPointerLeave = (): void => setAxisHovered(yAxis, false);\n\n const updateSelection = (state: Extract<DragState, { mode: \"select\" }>): void => {\n const rect = canvas.getBoundingClientRect();\n const x0 = Math.max(0, Math.min(state.startX - rect.left, rect.width));\n const y0 = Math.max(0, Math.min(state.startY - rect.top, rect.height));\n const x1 = Math.max(0, Math.min(state.currentX - rect.left, rect.width));\n const y1 = Math.max(0, Math.min(state.currentY - rect.top, rect.height));\n const left = axis === \"y\" ? 0 : Math.min(x0, x1);\n const top = axis === \"x\" ? 0 : Math.min(y0, y1);\n const width = axis === \"y\" ? rect.width : Math.abs(x1 - x0);\n const height = axis === \"x\" ? rect.height : Math.abs(y1 - y0);\n\n selection.style.left = `${left}px`;\n selection.style.top = `${top}px`;\n selection.style.width = `${width}px`;\n selection.style.height = `${height}px`;\n selection.style.display = \"block\";\n };\n\n const beginPan = (event: PointerEvent, panAxis: ZoomAxis, target: InteractionTarget): void => {\n captureResetViewport();\n event.preventDefault();\n if (target !== canvas) setAxisHovered(target, true);\n target.setPointerCapture(event.pointerId);\n drag = {\n mode: \"pan\",\n pointerId: event.pointerId,\n axis: panAxis,\n target,\n lastX: event.clientX,\n lastY: event.clientY,\n };\n };\n\n const onCanvasPointerDown = (event: PointerEvent): void => {\n if (drag || event.button !== 0) return;\n\n if (event.shiftKey && options.shiftDragPan !== false) {\n beginPan(event, axis, canvas);\n return;\n }\n\n if (options.boxZoom === false) return;\n captureResetViewport();\n event.preventDefault();\n canvas.setPointerCapture(event.pointerId);\n drag = {\n mode: \"select\",\n pointerId: event.pointerId,\n target: canvas,\n startX: event.clientX,\n startY: event.clientY,\n currentX: event.clientX,\n currentY: event.clientY,\n };\n updateSelection(drag);\n };\n\n const onXAxisPointerDown = (event: PointerEvent): void => {\n if (drag || event.button !== 0 || options.axisInteractions === false) return;\n beginPan(event, \"x\", xAxis);\n };\n\n const onYAxisPointerDown = (event: PointerEvent): void => {\n if (drag || event.button !== 0 || options.axisInteractions === false) return;\n beginPan(event, \"y\", yAxis);\n };\n\n const onPointerMove = (event: PointerEvent): void => {\n if (!drag || event.pointerId !== drag.pointerId) return;\n event.preventDefault();\n\n if (drag.mode === \"pan\") {\n const rect = canvas.getBoundingClientRect();\n const dx = rect.width > 0 ? (drag.lastX - event.clientX) / rect.width : 0;\n const dy = rect.height > 0 ? (event.clientY - drag.lastY) / rect.height : 0;\n const intent = applyPanPolicy({ dx, dy }, drag.axis);\n if (intent) chart.pan(intent);\n drag.lastX = event.clientX;\n drag.lastY = event.clientY;\n return;\n }\n\n drag.currentX = event.clientX;\n drag.currentY = event.clientY;\n updateSelection(drag);\n };\n\n const onPointerUp = (event: PointerEvent): void => {\n if (!drag || event.pointerId !== drag.pointerId) return;\n event.preventDefault();\n\n const completed = drag;\n drag = null;\n if (completed.target.hasPointerCapture(event.pointerId)) completed.target.releasePointerCapture(event.pointerId);\n hideSelection();\n\n if (completed.mode !== \"select\") return;\n\n const dx = event.clientX - completed.startX;\n const dy = event.clientY - completed.startY;\n if (Math.hypot(dx, dy) < minDragDistancePx) return;\n\n const current = chart.getViewport();\n const rect = canvas.getBoundingClientRect();\n const start = clientToDataClamped(completed.startX, completed.startY, rect, current);\n const end = clientToDataClamped(event.clientX, event.clientY, rect, current);\n if (!start || !end) return;\n\n const next = applySelectionAxis(current, start, end, axis);\n if (next.xMax > next.xMin && next.yMax > next.yMin) chart.setViewport(next);\n };\n\n const onPointerCancel = (event: PointerEvent): void => {\n if (!drag || event.pointerId !== drag.pointerId) return;\n const completed = drag;\n drag = null;\n if (completed.target.hasPointerCapture(event.pointerId)) completed.target.releasePointerCapture(event.pointerId);\n hideSelection();\n };\n\n const wheelOnAxis = (event: WheelEvent, zoomAxis: ZoomAxis): void => {\n if (options.wheelZoom === false) return;\n captureResetViewport();\n event.preventDefault();\n const factor = event.deltaY < 0 ? 1.1 : 0.9;\n const rect = canvas.getBoundingClientRect();\n const cx = rect.width > 0 ? (event.clientX - rect.left) / rect.width : 0.5;\n const cy = rect.height > 0 ? 1 - (event.clientY - rect.top) / rect.height : 0.5;\n const intent = applyZoomPolicy({ factor, cx, cy, axis: zoomAxis });\n if (intent) chart.zoom(intent);\n };\n\n const onCanvasWheel = (event: WheelEvent): void => {\n wheelOnAxis(event, axis);\n };\n\n const onXAxisWheel = (event: WheelEvent): void => {\n if (options.axisInteractions === false) return;\n wheelOnAxis(event, \"x\");\n };\n\n const onYAxisWheel = (event: WheelEvent): void => {\n if (options.axisInteractions === false) return;\n wheelOnAxis(event, \"y\");\n };\n\n const onDoubleClick = (event: MouseEvent): void => {\n if (options.doubleClickReset === false) return;\n event.preventDefault();\n const target = resetViewport ?? normalizeViewport(chart.getViewport());\n chart.setViewport(target);\n };\n\n const pointerTargets = [canvas, xAxis, yAxis];\n canvas.addEventListener(\"pointerdown\", onCanvasPointerDown);\n canvas.addEventListener(\"wheel\", onCanvasWheel, { passive: false });\n canvas.addEventListener(\"dblclick\", onDoubleClick);\n\n if (options.axisInteractions !== false) {\n xAxis.addEventListener(\"pointerdown\", onXAxisPointerDown);\n yAxis.addEventListener(\"pointerdown\", onYAxisPointerDown);\n xAxis.addEventListener(\"pointerenter\", onXAxisPointerEnter);\n xAxis.addEventListener(\"pointerleave\", onXAxisPointerLeave);\n yAxis.addEventListener(\"pointerenter\", onYAxisPointerEnter);\n yAxis.addEventListener(\"pointerleave\", onYAxisPointerLeave);\n xAxis.addEventListener(\"wheel\", onXAxisWheel, { passive: false });\n yAxis.addEventListener(\"wheel\", onYAxisWheel, { passive: false });\n xAxis.addEventListener(\"dblclick\", onDoubleClick);\n yAxis.addEventListener(\"dblclick\", onDoubleClick);\n }\n\n for (const target of pointerTargets) {\n target.addEventListener(\"pointermove\", onPointerMove);\n target.addEventListener(\"pointerup\", onPointerUp);\n target.addEventListener(\"pointercancel\", onPointerCancel);\n }\n\n return () => {\n canvas.removeEventListener(\"pointerdown\", onCanvasPointerDown);\n canvas.removeEventListener(\"wheel\", onCanvasWheel);\n canvas.removeEventListener(\"dblclick\", onDoubleClick);\n xAxis.removeEventListener(\"pointerdown\", onXAxisPointerDown);\n yAxis.removeEventListener(\"pointerdown\", onYAxisPointerDown);\n xAxis.removeEventListener(\"pointerenter\", onXAxisPointerEnter);\n xAxis.removeEventListener(\"pointerleave\", onXAxisPointerLeave);\n yAxis.removeEventListener(\"pointerenter\", onYAxisPointerEnter);\n yAxis.removeEventListener(\"pointerleave\", onYAxisPointerLeave);\n xAxis.removeEventListener(\"wheel\", onXAxisWheel);\n yAxis.removeEventListener(\"wheel\", onYAxisWheel);\n xAxis.removeEventListener(\"dblclick\", onDoubleClick);\n yAxis.removeEventListener(\"dblclick\", onDoubleClick);\n for (const target of pointerTargets) {\n target.removeEventListener(\"pointermove\", onPointerMove);\n target.removeEventListener(\"pointerup\", onPointerUp);\n target.removeEventListener(\"pointercancel\", onPointerCancel);\n }\n xAxis.style.pointerEvents = originalXAxisPointerEvents;\n yAxis.style.pointerEvents = originalYAxisPointerEvents;\n xAxis.style.cursor = originalXAxisCursor;\n yAxis.style.cursor = originalYAxisCursor;\n xAxis.style.filter = originalXAxisFilter;\n yAxis.style.filter = originalYAxisFilter;\n xAxis.classList.remove(axisHoverClass);\n yAxis.classList.remove(axisHoverClass);\n axisHoverStyle.remove();\n selection.remove();\n };\n },\n };\n}\n"],"mappings":";AAoBA,IAAI,IAA2B;AAuB/B,SAAS,EAAa,GAAmB,GAA2B;CAClE,OAAO;EACL,IAAI,MAAS,MAAM,IAAI,EAAO;EAC9B,IAAI,MAAS,MAAM,IAAI,EAAO;CAChC;AACF;AAEA,SAAS,EAAkB,GAAuB;CAChD,OAAO;EAAE,MAAM,EAAE;EAAM,MAAM,EAAE;EAAM,MAAM,EAAE;EAAM,MAAM,EAAE;CAAK;AAClE;AAEA,SAAS,EACP,GACA,GACA,GACA,GACyB;CACzB,IAAI,EAAK,SAAS,KAAK,EAAK,UAAU,GAAG,OAAO;CAEhD,IAAM,IAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,IAAU,EAAK,MAAM,EAAK,KAAK,CAAC,GAC7D,IAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,IAAU,EAAK,KAAK,EAAK,MAAM,CAAC;CACnE,OAAO,CACL,EAAS,OAAQ,IAAQ,EAAK,SAAU,EAAS,OAAO,EAAS,OACjE,EAAS,OAAQ,IAAQ,EAAK,UAAW,EAAS,OAAO,EAAS,KACpE;AACF;AAEA,SAAS,EACP,GACA,GACA,GACA,GACU;CACV,IAAM,IAAO,KAAK,IAAI,EAAE,IAAI,EAAE,EAAE,GAC1B,IAAO,KAAK,IAAI,EAAE,IAAI,EAAE,EAAE,GAC1B,IAAO,KAAK,IAAI,EAAE,IAAI,EAAE,EAAE,GAC1B,IAAO,KAAK,IAAI,EAAE,IAAI,EAAE,EAAE;CAEhC,OAAO;EACL,MAAM,MAAS,MAAM,EAAQ,OAAO;EACpC,MAAM,MAAS,MAAM,EAAQ,OAAO;EACpC,MAAM,MAAS,MAAM,EAAQ,OA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Ae,CAAa,GACpD,EAAO,iBAAiB,aAAa,CAAW,GAChD,EAAO,iBAAiB,iBAAiB,CAAe;EAG1D,aAAa;GAaX,AAZA,EAAO,oBAAoB,eAAe,CAAmB,GAC7D,EAAO,oBAAoB,SAAS,CAAa,GACjD,EAAO,oBAAoB,YAAY,CAAa,GACpD,EAAM,oBAAoB,eAAe,CAAkB,GAC3D,EAAM,oBAAoB,eAAe,CAAkB,GAC3D,EAAM,oBAAoB,gBAAgB,CAAmB,GAC7D,EAAM,oBAAoB,gBAAgB,CAAmB,GAC7D,EAAM,oBAAoB,gBAAgB,CAAmB,GAC7D,EAAM,oBAAoB,gBAAgB,CAAmB,GAC7D,EAAM,oBAAoB,SAAS,CAAY,GAC/C,EAAM,oBAAoB,SAAS,CAAY,GAC/C,EAAM,oBAAoB,YAAY,CAAa,GACnD,EAAM,oBAAoB,YAAY,CAAa;GACnD,KAAK,IAAM,KAAU,GAGnB,AAFA,EAAO,oBAAoB,eAAe,CAAa,GACvD,EAAO,oBAAoB,aAAa,CAAW,GACnD,EAAO,oBAAoB,iBAAiB,CAAe;GAW7D,AATA,EAAM,MAAM,gBAAgB,GAC5B,EAAM,MAAM,gBAAgB,GAC5B,EAAM,MAAM,SAAS,GACrB,EAAM,MAAM,SAAS,GACrB,EAAM,MAAM,SAAS,GACrB,EAAM,MAAM,SAAS,GACrB,EAAM,UAAU,OAAO,CAAc,GACrC,EAAM,UAAU,OAAO,CAAc,GACrC,EAAe,OAAO,GACtB,EAAU,OAAO;EACnB;CACF,EACF;AACF"}
|
|
1
|
+
{"version":3,"file":"interactions.js","names":[],"sources":["../../src/ui/Interactions.ts"],"sourcesContent":["import type { Viewport } from \"../core/types.js\";\nimport type { PanIntent, ViewportPolicy, ZoomAxis, ZoomIntent } from \"../interaction/types.js\";\nimport type { Chart, ChartPlugin } from \"./Chart.js\";\n\nexport type InteractionAxisOption = ZoomAxis | (() => ZoomAxis);\n\nexport interface InteractionsPluginOptions {\n readonly axis?: InteractionAxisOption;\n readonly viewportPolicy?: ViewportPolicy;\n readonly boxZoom?: boolean;\n readonly wheelZoom?: boolean;\n readonly axisInteractions?: boolean;\n readonly axisHover?: boolean;\n readonly axisHoverColor?: string;\n readonly axisHoverFilter?: string;\n readonly shiftDragPan?: boolean;\n readonly doubleClickReset?: boolean;\n readonly minDragDistancePx?: number;\n readonly selectionFill?: string;\n readonly selectionStroke?: string;\n}\n\nlet nextInteractionsPluginId = 1;\n\ntype InteractionTarget = HTMLCanvasElement | HTMLElement;\n\ntype DragState =\n | {\n readonly mode: \"pan\";\n readonly pointerId: number;\n readonly axis: ZoomAxis;\n readonly target: InteractionTarget;\n lastX: number;\n lastY: number;\n }\n | {\n readonly mode: \"select\";\n readonly pointerId: number;\n readonly target: HTMLCanvasElement;\n readonly startX: number;\n readonly startY: number;\n currentX: number;\n currentY: number;\n };\n\nfunction resolveAxis(axis: InteractionAxisOption | undefined): ZoomAxis {\n return typeof axis === \"function\" ? axis() : axis ?? \"xy\";\n}\n\nfunction constrainPan(intent: PanIntent, axis: ZoomAxis): PanIntent {\n return {\n dx: axis === \"y\" ? 0 : intent.dx,\n dy: axis === \"x\" ? 0 : intent.dy,\n };\n}\n\nfunction normalizeViewport(v: Viewport): Viewport {\n return { xMin: v.xMin, xMax: v.xMax, yMin: v.yMin, yMax: v.yMax };\n}\n\nfunction clientToDataClamped(\n clientX: number,\n clientY: number,\n rect: DOMRect,\n viewport: Viewport,\n): [number, number] | null {\n if (rect.width <= 0 || rect.height <= 0) return null;\n\n const plotX = Math.max(0, Math.min(clientX - rect.left, rect.width));\n const plotY = Math.max(0, Math.min(clientY - rect.top, rect.height));\n return [\n viewport.xMin + (plotX / rect.width) * (viewport.xMax - viewport.xMin),\n viewport.yMax - (plotY / rect.height) * (viewport.yMax - viewport.yMin),\n ];\n}\n\nfunction applySelectionAxis(\n current: Viewport,\n a: [number, number],\n b: [number, number],\n axis: ZoomAxis,\n): Viewport {\n const xMin = Math.min(a[0], b[0]);\n const xMax = Math.max(a[0], b[0]);\n const yMin = Math.min(a[1], b[1]);\n const yMax = Math.max(a[1], b[1]);\n\n return {\n xMin: axis === \"y\" ? current.xMin : xMin,\n xMax: axis === \"y\" ? current.xMax : xMax,\n yMin: axis === \"x\" ? current.yMin : yMin,\n yMax: axis === \"x\" ? current.yMax : yMax,\n };\n}\n\nexport function interactionsPlugin(options: InteractionsPluginOptions = {}): ChartPlugin {\n return {\n install(chart: Chart) {\n const minDragDistancePx = options.minDragDistancePx ?? 6;\n const canvas = chart.canvas;\n const xAxis = chart.xAxisElement;\n const yAxis = chart.yAxisElement;\n const selection = document.createElement(\"div\");\n const axisHoverClass = `blazeplot-axis-hover-${nextInteractionsPluginId++}`;\n const axisHoverStyle = document.createElement(\"style\");\n const originalXAxisPointerEvents = xAxis.style.pointerEvents;\n const originalYAxisPointerEvents = yAxis.style.pointerEvents;\n const originalXAxisCursor = xAxis.style.cursor;\n const originalYAxisCursor = yAxis.style.cursor;\n const originalXAxisFilter = xAxis.style.filter;\n const originalYAxisFilter = yAxis.style.filter;\n let drag: DragState | null = null;\n let resetViewport: Viewport | null = null;\n\n selection.className = \"blazeplot-selection\";\n selection.style.position = \"absolute\";\n selection.style.display = \"none\";\n selection.style.pointerEvents = \"none\";\n selection.style.zIndex = \"24\";\n selection.style.border = `1px solid ${options.selectionStroke ?? \"rgba(147, 197, 253, 0.95)\"}`;\n selection.style.background = options.selectionFill ?? \"rgba(59, 130, 246, 0.18)\";\n chart.plotElement.appendChild(selection);\n\n axisHoverStyle.textContent = `.${axisHoverClass} > div { color: ${options.axisHoverColor ?? \"#f8fafc\"} !important; }`;\n if (options.axisInteractions !== false && options.axisHover !== false) {\n chart.rootElement.appendChild(axisHoverStyle);\n }\n\n if (options.axisInteractions !== false) {\n xAxis.style.pointerEvents = \"auto\";\n yAxis.style.pointerEvents = \"auto\";\n xAxis.style.cursor = \"ew-resize\";\n yAxis.style.cursor = \"ns-resize\";\n }\n\n const captureResetViewport = (): void => {\n resetViewport ??= normalizeViewport(chart.getViewport());\n };\n\n const applyPanPolicy = (intent: PanIntent, panAxis: ZoomAxis): PanIntent | null => {\n const constrained = constrainPan(intent, panAxis);\n return options.viewportPolicy?.beforePan?.(chart.getCamera(), constrained) ?? constrained;\n };\n\n const applyZoomPolicy = (intent: ZoomIntent): ZoomIntent | null => {\n return options.viewportPolicy?.beforeZoom?.(chart.getCamera(), intent) ?? intent;\n };\n\n const hideSelection = (): void => {\n selection.style.display = \"none\";\n };\n\n const setAxisHovered = (target: HTMLElement, hovered: boolean): void => {\n if (options.axisHover === false) return;\n const filter = hovered ? options.axisHoverFilter ?? \"brightness(1.18)\" : null;\n target.classList.toggle(axisHoverClass, hovered);\n if (target === xAxis) {\n xAxis.style.filter = filter ?? originalXAxisFilter;\n } else if (target === yAxis) {\n yAxis.style.filter = filter ?? originalYAxisFilter;\n }\n };\n\n const onXAxisPointerEnter = (): void => setAxisHovered(xAxis, true);\n const onXAxisPointerLeave = (): void => setAxisHovered(xAxis, false);\n const onYAxisPointerEnter = (): void => setAxisHovered(yAxis, true);\n const onYAxisPointerLeave = (): void => setAxisHovered(yAxis, false);\n\n const updateSelection = (state: Extract<DragState, { mode: \"select\" }>): void => {\n const rect = canvas.getBoundingClientRect();\n const x0 = Math.max(0, Math.min(state.startX - rect.left, rect.width));\n const y0 = Math.max(0, Math.min(state.startY - rect.top, rect.height));\n const x1 = Math.max(0, Math.min(state.currentX - rect.left, rect.width));\n const y1 = Math.max(0, Math.min(state.currentY - rect.top, rect.height));\n const selectionAxis = resolveAxis(options.axis);\n const left = selectionAxis === \"y\" ? 0 : Math.min(x0, x1);\n const top = selectionAxis === \"x\" ? 0 : Math.min(y0, y1);\n const width = selectionAxis === \"y\" ? rect.width : Math.abs(x1 - x0);\n const height = selectionAxis === \"x\" ? rect.height : Math.abs(y1 - y0);\n\n selection.style.left = `${left}px`;\n selection.style.top = `${top}px`;\n selection.style.width = `${width}px`;\n selection.style.height = `${height}px`;\n selection.style.display = \"block\";\n };\n\n const beginPan = (event: PointerEvent, panAxis: ZoomAxis, target: InteractionTarget): void => {\n captureResetViewport();\n event.preventDefault();\n if (target !== canvas) setAxisHovered(target, true);\n target.setPointerCapture(event.pointerId);\n drag = {\n mode: \"pan\",\n pointerId: event.pointerId,\n axis: panAxis,\n target,\n lastX: event.clientX,\n lastY: event.clientY,\n };\n };\n\n const onCanvasPointerDown = (event: PointerEvent): void => {\n if (drag || event.button !== 0) return;\n\n if (event.shiftKey && options.shiftDragPan !== false) {\n beginPan(event, resolveAxis(options.axis), canvas);\n return;\n }\n\n if (options.boxZoom === false) return;\n captureResetViewport();\n event.preventDefault();\n canvas.setPointerCapture(event.pointerId);\n drag = {\n mode: \"select\",\n pointerId: event.pointerId,\n target: canvas,\n startX: event.clientX,\n startY: event.clientY,\n currentX: event.clientX,\n currentY: event.clientY,\n };\n updateSelection(drag);\n };\n\n const onXAxisPointerDown = (event: PointerEvent): void => {\n if (drag || event.button !== 0 || options.axisInteractions === false) return;\n beginPan(event, \"x\", xAxis);\n };\n\n const onYAxisPointerDown = (event: PointerEvent): void => {\n if (drag || event.button !== 0 || options.axisInteractions === false) return;\n beginPan(event, \"y\", yAxis);\n };\n\n const onPointerMove = (event: PointerEvent): void => {\n if (!drag || event.pointerId !== drag.pointerId) return;\n event.preventDefault();\n\n if (drag.mode === \"pan\") {\n const rect = canvas.getBoundingClientRect();\n const dx = rect.width > 0 ? (drag.lastX - event.clientX) / rect.width : 0;\n const dy = rect.height > 0 ? (event.clientY - drag.lastY) / rect.height : 0;\n const intent = applyPanPolicy({ dx, dy }, drag.axis);\n if (intent) chart.pan(intent);\n drag.lastX = event.clientX;\n drag.lastY = event.clientY;\n return;\n }\n\n drag.currentX = event.clientX;\n drag.currentY = event.clientY;\n updateSelection(drag);\n };\n\n const onPointerUp = (event: PointerEvent): void => {\n if (!drag || event.pointerId !== drag.pointerId) return;\n event.preventDefault();\n\n const completed = drag;\n drag = null;\n if (completed.target.hasPointerCapture(event.pointerId)) completed.target.releasePointerCapture(event.pointerId);\n hideSelection();\n\n if (completed.mode !== \"select\") return;\n\n const dx = event.clientX - completed.startX;\n const dy = event.clientY - completed.startY;\n if (Math.hypot(dx, dy) < minDragDistancePx) return;\n\n const current = chart.getViewport();\n const rect = canvas.getBoundingClientRect();\n const start = clientToDataClamped(completed.startX, completed.startY, rect, current);\n const end = clientToDataClamped(event.clientX, event.clientY, rect, current);\n if (!start || !end) return;\n\n const next = applySelectionAxis(current, start, end, resolveAxis(options.axis));\n if (next.xMax > next.xMin && next.yMax > next.yMin) chart.setViewport(next);\n };\n\n const onPointerCancel = (event: PointerEvent): void => {\n if (!drag || event.pointerId !== drag.pointerId) return;\n const completed = drag;\n drag = null;\n if (completed.target.hasPointerCapture(event.pointerId)) completed.target.releasePointerCapture(event.pointerId);\n hideSelection();\n };\n\n const wheelOnAxis = (event: WheelEvent, zoomAxis: ZoomAxis): void => {\n if (options.wheelZoom === false) return;\n captureResetViewport();\n event.preventDefault();\n const factor = event.deltaY < 0 ? 1.1 : 0.9;\n const rect = canvas.getBoundingClientRect();\n const cx = rect.width > 0 ? (event.clientX - rect.left) / rect.width : 0.5;\n const cy = rect.height > 0 ? 1 - (event.clientY - rect.top) / rect.height : 0.5;\n const intent = applyZoomPolicy({ factor, cx, cy, axis: zoomAxis });\n if (intent) chart.zoom(intent);\n };\n\n const onCanvasWheel = (event: WheelEvent): void => {\n wheelOnAxis(event, resolveAxis(options.axis));\n };\n\n const onXAxisWheel = (event: WheelEvent): void => {\n if (options.axisInteractions === false) return;\n wheelOnAxis(event, \"x\");\n };\n\n const onYAxisWheel = (event: WheelEvent): void => {\n if (options.axisInteractions === false) return;\n wheelOnAxis(event, \"y\");\n };\n\n const onDoubleClick = (event: MouseEvent): void => {\n if (options.doubleClickReset === false) return;\n event.preventDefault();\n const target = resetViewport ?? normalizeViewport(chart.getViewport());\n chart.setViewport(target);\n };\n\n const pointerTargets = [canvas, xAxis, yAxis];\n canvas.addEventListener(\"pointerdown\", onCanvasPointerDown);\n canvas.addEventListener(\"wheel\", onCanvasWheel, { passive: false });\n canvas.addEventListener(\"dblclick\", onDoubleClick);\n\n if (options.axisInteractions !== false) {\n xAxis.addEventListener(\"pointerdown\", onXAxisPointerDown);\n yAxis.addEventListener(\"pointerdown\", onYAxisPointerDown);\n xAxis.addEventListener(\"pointerenter\", onXAxisPointerEnter);\n xAxis.addEventListener(\"pointerleave\", onXAxisPointerLeave);\n yAxis.addEventListener(\"pointerenter\", onYAxisPointerEnter);\n yAxis.addEventListener(\"pointerleave\", onYAxisPointerLeave);\n xAxis.addEventListener(\"wheel\", onXAxisWheel, { passive: false });\n yAxis.addEventListener(\"wheel\", onYAxisWheel, { passive: false });\n xAxis.addEventListener(\"dblclick\", onDoubleClick);\n yAxis.addEventListener(\"dblclick\", onDoubleClick);\n }\n\n for (const target of pointerTargets) {\n target.addEventListener(\"pointermove\", onPointerMove);\n target.addEventListener(\"pointerup\", onPointerUp);\n target.addEventListener(\"pointercancel\", onPointerCancel);\n }\n\n return () => {\n canvas.removeEventListener(\"pointerdown\", onCanvasPointerDown);\n canvas.removeEventListener(\"wheel\", onCanvasWheel);\n canvas.removeEventListener(\"dblclick\", onDoubleClick);\n xAxis.removeEventListener(\"pointerdown\", onXAxisPointerDown);\n yAxis.removeEventListener(\"pointerdown\", onYAxisPointerDown);\n xAxis.removeEventListener(\"pointerenter\", onXAxisPointerEnter);\n xAxis.removeEventListener(\"pointerleave\", onXAxisPointerLeave);\n yAxis.removeEventListener(\"pointerenter\", onYAxisPointerEnter);\n yAxis.removeEventListener(\"pointerleave\", onYAxisPointerLeave);\n xAxis.removeEventListener(\"wheel\", onXAxisWheel);\n yAxis.removeEventListener(\"wheel\", onYAxisWheel);\n xAxis.removeEventListener(\"dblclick\", onDoubleClick);\n yAxis.removeEventListener(\"dblclick\", onDoubleClick);\n for (const target of pointerTargets) {\n target.removeEventListener(\"pointermove\", onPointerMove);\n target.removeEventListener(\"pointerup\", onPointerUp);\n target.removeEventListener(\"pointercancel\", onPointerCancel);\n }\n xAxis.style.pointerEvents = originalXAxisPointerEvents;\n yAxis.style.pointerEvents = originalYAxisPointerEvents;\n xAxis.style.cursor = originalXAxisCursor;\n yAxis.style.cursor = originalYAxisCursor;\n xAxis.style.filter = originalXAxisFilter;\n yAxis.style.filter = originalYAxisFilter;\n xAxis.classList.remove(axisHoverClass);\n yAxis.classList.remove(axisHoverClass);\n axisHoverStyle.remove();\n selection.remove();\n };\n },\n };\n}\n"],"mappings":";AAsBA,IAAI,IAA2B;AAuB/B,SAAS,EAAY,GAAmD;CACtE,OAAO,OAAO,KAAS,aAAa,EAAK,IAAI,KAAQ;AACvD;AAEA,SAAS,EAAa,GAAmB,GAA2B;CAClE,OAAO;EACL,IAAI,MAAS,MAAM,IAAI,EAAO;EAC9B,IAAI,MAAS,MAAM,IAAI,EAAO;CAChC;AACF;AAEA,SAAS,EAAkB,GAAuB;CAChD,OAAO;EAAE,MAAM,EAAE;EAAM,MAAM,EAAE;EAAM,MAAM,EAAE;EAAM,MAAM,EAAE;CAAK;AAClE;AAEA,SAAS,EACP,GACA,GACA,GACA,GACyB;CACzB,IAAI,EAAK,SAAS,KAAK,EAAK,UAAU,GAAG,OAAO;CAEhD,IAAM,IAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,IAAU,EAAK,MAAM,EAAK,KAAK,CAAC,GAC7D,IAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,IAAU,EAAK,KAAK,EAAK,MAAM,CAAC;CACnE,OAAO,CACL,EAAS,OAAQ,IAAQ,EAAK,SAAU,EAAS,OAAO,EAAS,OACjE,EAAS,OAAQ,IAAQ,EAAK,UAAW,EAAS,OAAO,EAAS,KACpE;AACF;AAEA,SAAS,EACP,GACA,GACA,GACA,GACU;CACV,IAAM,IAAO,KAAK,IAAI,EAAE,IAAI,EAAE,EAAE,GAC1B,IAAO,KAAK,IAAI,EAAE,IAAI,EAAE,EAAE,GAC1B,IAAO,KAAK,IAAI,EAAE,IAAI,EAAE,EAA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27,11 +27,14 @@ function i(e = {}) {
|
|
|
27
27
|
let a = document.createElement("div");
|
|
28
28
|
a.className = e.className ?? "blazeplot-legend", a.style.position = "absolute", a.style.zIndex = "20", a.style.pointerEvents = "auto", a.style.padding = "8px 10px", a.style.border = n(e, i), a.style.background = e.backgroundColor ?? i.theme.legendBackgroundColor, a.style.color = e.textColor ?? i.theme.legendTextColor, a.style.font = e.font ?? i.theme.legendFont, a.style.whiteSpace = "pre", a.style.userSelect = "none", t(a, e.position ?? "top-right"), i.rootElement.appendChild(a);
|
|
29
29
|
let o = () => {
|
|
30
|
+
a.style.border = n(e, i), a.style.background = e.backgroundColor ?? i.theme.legendBackgroundColor, a.style.color = e.textColor ?? i.theme.legendTextColor, a.style.font = e.font ?? i.theme.legendFont;
|
|
31
|
+
}, s = () => {
|
|
32
|
+
o();
|
|
30
33
|
let t = i.getSeriesState();
|
|
31
34
|
e.render ? e.render(t, a, i) : r(t, a, i, e.toggleOnClick !== !1, e);
|
|
32
|
-
},
|
|
33
|
-
return
|
|
34
|
-
|
|
35
|
+
}, c = i.subscribe("serieschange", s), l = i.subscribe("themechange", s);
|
|
36
|
+
return s(), () => {
|
|
37
|
+
c(), l(), a.remove();
|
|
35
38
|
};
|
|
36
39
|
} };
|
|
37
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legend.js","names":[],"sources":["../../src/ui/Legend.ts"],"sourcesContent":["import type { Chart, ChartPlugin, ChartSeriesState } from \"./Chart.js\";\n\nexport interface LegendPluginOptions {\n readonly className?: string;\n readonly position?: \"top-left\" | \"top-right\" | \"bottom-left\" | \"bottom-right\";\n readonly toggleOnClick?: boolean;\n readonly backgroundColor?: string;\n readonly borderColor?: string;\n readonly textColor?: string;\n readonly mutedTextColor?: string;\n readonly font?: string;\n readonly render?: (state: readonly ChartSeriesState[], container: HTMLElement, chart: Chart) => void;\n}\n\nfunction rgba(color: readonly [number, number, number, number]): string {\n return `rgba(${Math.round(color[0] * 255)}, ${Math.round(color[1] * 255)}, ${Math.round(color[2] * 255)}, ${color[3]})`;\n}\n\nfunction applyPosition(el: HTMLElement, position: NonNullable<LegendPluginOptions[\"position\"]>): void {\n el.style.top = position.startsWith(\"top\") ? \"8px\" : \"auto\";\n el.style.bottom = position.startsWith(\"bottom\") ? \"8px\" : \"auto\";\n el.style.left = position.endsWith(\"left\") ? \"8px\" : \"auto\";\n el.style.right = position.endsWith(\"right\") ? \"8px\" : \"auto\";\n}\n\nfunction legendBorder(options: LegendPluginOptions, chart: Chart): string {\n const color = options.borderColor ?? chart.theme.legendBorderColor;\n return color === \"transparent\" ? \"0\" : `1px solid ${color}`;\n}\n\nfunction renderDefaultLegend(\n state: readonly ChartSeriesState[],\n container: HTMLElement,\n chart: Chart,\n toggleOnClick: boolean,\n options: LegendPluginOptions,\n): void {\n container.replaceChildren();\n\n for (const item of state) {\n const row = document.createElement(\"button\");\n row.type = \"button\";\n row.style.display = \"flex\";\n row.style.alignItems = \"center\";\n row.style.gap = \"6px\";\n row.style.border = \"0\";\n row.style.margin = \"0\";\n row.style.padding = \"0\";\n row.style.appearance = \"none\";\n row.style.background = \"transparent\";\n row.style.color = item.visible\n ? options.textColor ?? chart.theme.legendTextColor\n : options.mutedTextColor ?? chart.theme.legendMutedTextColor;\n row.style.font = \"inherit\";\n row.style.textAlign = \"left\";\n row.style.cursor = toggleOnClick ? \"pointer\" : \"default\";\n row.style.opacity = item.visible ? \"1\" : \"0.45\";\n\n const swatch = document.createElement(\"span\");\n swatch.textContent = \"\\u2588\";\n swatch.style.color = rgba(item.color);\n swatch.style.flex = \"0 0 auto\";\n\n const label = document.createElement(\"span\");\n label.textContent = item.name ?? item.id ?? `${item.mode} ${item.index + 1}`;\n\n row.append(swatch, label);\n if (toggleOnClick) {\n row.addEventListener(\"click\", () => {\n chart.setSeriesVisible(item.series, !item.visible);\n });\n }\n container.appendChild(row);\n }\n}\n\nexport function legendPlugin(options: LegendPluginOptions = {}): ChartPlugin {\n return {\n install(chart: Chart) {\n const container = document.createElement(\"div\");\n container.className = options.className ?? \"blazeplot-legend\";\n container.style.position = \"absolute\";\n container.style.zIndex = \"20\";\n container.style.pointerEvents = \"auto\";\n container.style.padding = \"8px 10px\";\n container.style.border = legendBorder(options, chart);\n container.style.background = options.backgroundColor ?? chart.theme.legendBackgroundColor;\n container.style.color = options.textColor ?? chart.theme.legendTextColor;\n container.style.font = options.font ?? chart.theme.legendFont;\n container.style.whiteSpace = \"pre\";\n container.style.userSelect = \"none\";\n applyPosition(container, options.position ?? \"top-right\");\n chart.rootElement.appendChild(container);\n\n const render = (): void => {\n const state = chart.getSeriesState();\n if (options.render) {\n options.render(state, container, chart);\n } else {\n renderDefaultLegend(state, container, chart, options.toggleOnClick !== false, options);\n }\n };\n\n const
|
|
1
|
+
{"version":3,"file":"legend.js","names":[],"sources":["../../src/ui/Legend.ts"],"sourcesContent":["import type { Chart, ChartPlugin, ChartSeriesState } from \"./Chart.js\";\n\nexport interface LegendPluginOptions {\n readonly className?: string;\n readonly position?: \"top-left\" | \"top-right\" | \"bottom-left\" | \"bottom-right\";\n readonly toggleOnClick?: boolean;\n readonly backgroundColor?: string;\n readonly borderColor?: string;\n readonly textColor?: string;\n readonly mutedTextColor?: string;\n readonly font?: string;\n readonly render?: (state: readonly ChartSeriesState[], container: HTMLElement, chart: Chart) => void;\n}\n\nfunction rgba(color: readonly [number, number, number, number]): string {\n return `rgba(${Math.round(color[0] * 255)}, ${Math.round(color[1] * 255)}, ${Math.round(color[2] * 255)}, ${color[3]})`;\n}\n\nfunction applyPosition(el: HTMLElement, position: NonNullable<LegendPluginOptions[\"position\"]>): void {\n el.style.top = position.startsWith(\"top\") ? \"8px\" : \"auto\";\n el.style.bottom = position.startsWith(\"bottom\") ? \"8px\" : \"auto\";\n el.style.left = position.endsWith(\"left\") ? \"8px\" : \"auto\";\n el.style.right = position.endsWith(\"right\") ? \"8px\" : \"auto\";\n}\n\nfunction legendBorder(options: LegendPluginOptions, chart: Chart): string {\n const color = options.borderColor ?? chart.theme.legendBorderColor;\n return color === \"transparent\" ? \"0\" : `1px solid ${color}`;\n}\n\nfunction renderDefaultLegend(\n state: readonly ChartSeriesState[],\n container: HTMLElement,\n chart: Chart,\n toggleOnClick: boolean,\n options: LegendPluginOptions,\n): void {\n container.replaceChildren();\n\n for (const item of state) {\n const row = document.createElement(\"button\");\n row.type = \"button\";\n row.style.display = \"flex\";\n row.style.alignItems = \"center\";\n row.style.gap = \"6px\";\n row.style.border = \"0\";\n row.style.margin = \"0\";\n row.style.padding = \"0\";\n row.style.appearance = \"none\";\n row.style.background = \"transparent\";\n row.style.color = item.visible\n ? options.textColor ?? chart.theme.legendTextColor\n : options.mutedTextColor ?? chart.theme.legendMutedTextColor;\n row.style.font = \"inherit\";\n row.style.textAlign = \"left\";\n row.style.cursor = toggleOnClick ? \"pointer\" : \"default\";\n row.style.opacity = item.visible ? \"1\" : \"0.45\";\n\n const swatch = document.createElement(\"span\");\n swatch.textContent = \"\\u2588\";\n swatch.style.color = rgba(item.color);\n swatch.style.flex = \"0 0 auto\";\n\n const label = document.createElement(\"span\");\n label.textContent = item.name ?? item.id ?? `${item.mode} ${item.index + 1}`;\n\n row.append(swatch, label);\n if (toggleOnClick) {\n row.addEventListener(\"click\", () => {\n chart.setSeriesVisible(item.series, !item.visible);\n });\n }\n container.appendChild(row);\n }\n}\n\nexport function legendPlugin(options: LegendPluginOptions = {}): ChartPlugin {\n return {\n install(chart: Chart) {\n const container = document.createElement(\"div\");\n container.className = options.className ?? \"blazeplot-legend\";\n container.style.position = \"absolute\";\n container.style.zIndex = \"20\";\n container.style.pointerEvents = \"auto\";\n container.style.padding = \"8px 10px\";\n container.style.border = legendBorder(options, chart);\n container.style.background = options.backgroundColor ?? chart.theme.legendBackgroundColor;\n container.style.color = options.textColor ?? chart.theme.legendTextColor;\n container.style.font = options.font ?? chart.theme.legendFont;\n container.style.whiteSpace = \"pre\";\n container.style.userSelect = \"none\";\n applyPosition(container, options.position ?? \"top-right\");\n chart.rootElement.appendChild(container);\n\n const applyTheme = (): void => {\n container.style.border = legendBorder(options, chart);\n container.style.background = options.backgroundColor ?? chart.theme.legendBackgroundColor;\n container.style.color = options.textColor ?? chart.theme.legendTextColor;\n container.style.font = options.font ?? chart.theme.legendFont;\n };\n\n const render = (): void => {\n applyTheme();\n const state = chart.getSeriesState();\n if (options.render) {\n options.render(state, container, chart);\n } else {\n renderDefaultLegend(state, container, chart, options.toggleOnClick !== false, options);\n }\n };\n\n const unsubscribeSeries = chart.subscribe(\"serieschange\", render);\n const unsubscribeTheme = chart.subscribe(\"themechange\", render);\n render();\n\n return () => {\n unsubscribeSeries();\n unsubscribeTheme();\n container.remove();\n };\n },\n };\n}\n"],"mappings":";AAcA,SAAS,EAAK,GAA0D;CACtE,OAAO,QAAQ,KAAK,MAAM,EAAM,KAAK,GAAG,EAAE,IAAI,KAAK,MAAM,EAAM,KAAK,GAAG,EAAE,IAAI,KAAK,MAAM,EAAM,KAAK,GAAG,EAAE,IAAI,EAAM,GAAG;AACvH;AAEA,SAAS,EAAc,GAAiB,GAA8D;CAIpG,AAHA,EAAG,MAAM,MAAM,EAAS,WAAW,KAAK,IAAI,QAAQ,QACpD,EAAG,MAAM,SAAS,EAAS,WAAW,QAAQ,IAAI,QAAQ,QAC1D,EAAG,MAAM,OAAO,EAAS,SAAS,MAAM,IAAI,QAAQ,QACpD,EAAG,MAAM,QAAQ,EAAS,SAAS,OAAO,IAAI,QAAQ;AACxD;AAEA,SAAS,EAAa,GAA8B,GAAsB;CACxE,IAAM,IAAQ,EAAQ,eAAe,EAAM,MAAM;CACjD,OAAO,MAAU,gBAAgB,MAAM,aAAa;AACtD;AAEA,SAAS,EACP,GACA,GACA,GACA,GACA,GACM;CACN,EAAU,gBAAgB;CAE1B,KAAK,IAAM,KAAQ,GAAO;EACxB,IAAM,IAAM,SAAS,cAAc,QAAQ;EAgB3C,AAfA,EAAI,OAAO,UACX,EAAI,MAAM,UAAU,QACpB,EAAI,MAAM,aAAa,U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AAM,YACnD,EAAU,MAAM,aAAa,OAC7B,EAAU,MAAM,aAAa,QAC7B,EAAc,GAAW,EAAQ,YAAY,WAAW,GACxD,EAAM,YAAY,YAAY,CAAS;EAEvC,IAAM,UAAyB;GAI7B,AAHA,EAAU,MAAM,SAAS,EAAa,GAAS,CAAK,GACpD,EAAU,MAAM,aAAa,EAAQ,mBAAmB,EAAM,MAAM,uBACpE,EAAU,MAAM,QAAQ,EAAQ,aAAa,EAAM,MAAM,iBACzD,EAAU,MAAM,OAAO,EAAQ,QAAQ,EAAM,MAAM;EACrD,GAEM,UAAqB;GACzB,EAAW;GACX,IAAM,IAAQ,EAAM,eAAe;GACnC,AAAI,EAAQ,SACV,EAAQ,OAAO,GAAO,GAAW,CAAK,IAEtC,EAAoB,GAAO,GAAW,GAAO,EAAQ,kBAAkB,IAAO,CAAO;EAEzF,GAEM,IAAoB,EAAM,UAAU,gBAAgB,CAAM,GAC1D,IAAmB,EAAM,UAAU,eAAe,CAAM;EAG9D,OAFA,EAAO,SAEM;GAGX,AAFA,EAAkB,GAClB,EAAiB,GACjB,EAAU,OAAO;EACnB;CACF,EACF;AACF"}
|
package/dist/plugins/tooltip.js
CHANGED
|
@@ -18,33 +18,48 @@ function r(r, i, a) {
|
|
|
18
18
|
}
|
|
19
19
|
i.innerHTML = s;
|
|
20
20
|
}
|
|
21
|
-
function i(e
|
|
21
|
+
function i(e, t, n) {
|
|
22
|
+
return Math.min(n, Math.max(t, e));
|
|
23
|
+
}
|
|
24
|
+
function a(e, t, n) {
|
|
25
|
+
let r = n.offsetX ?? 12, a = n.offsetY ?? 12, o = e.getBoundingClientRect(), s = e.ownerDocument, c = Math.max(1, globalThis.innerWidth || s.documentElement.clientWidth), l = Math.max(1, globalThis.innerHeight || s.documentElement.clientHeight), u = i(t.clientX + r, 4, Math.max(4, c - o.width - 4)), d = i(t.clientY + a, 4, Math.max(4, l - o.height - 4));
|
|
26
|
+
e.style.transform = `translate(${u}px, ${d}px)`;
|
|
27
|
+
}
|
|
28
|
+
function o(e = {}) {
|
|
22
29
|
return { install(t) {
|
|
23
30
|
let i = document.createElement("div");
|
|
24
|
-
i.className = e.className ?? "blazeplot-tooltip", i.style.position = "
|
|
25
|
-
let
|
|
26
|
-
|
|
27
|
-
let
|
|
28
|
-
if (
|
|
31
|
+
i.className = e.className ?? "blazeplot-tooltip", i.style.position = "fixed", i.style.left = "0", i.style.top = "0", i.style.zIndex = String(e.zIndex ?? 1e4), i.style.display = "none", i.style.pointerEvents = "none", i.style.background = e.backgroundColor ?? t.theme.tooltipBackgroundColor, i.style.color = e.textColor ?? t.theme.tooltipTextColor, i.style.font = e.font ?? t.theme.tooltipFont, i.style.padding = "8px 10px", i.style.whiteSpace = "pre", (t.rootElement.ownerDocument.body ?? t.rootElement).appendChild(i);
|
|
32
|
+
let o = document.createElement("div");
|
|
33
|
+
o.className = "blazeplot-tooltip-markers", o.style.position = "absolute", o.style.inset = "0", o.style.zIndex = "25", o.style.pointerEvents = "none", t.plotElement.appendChild(o);
|
|
34
|
+
let s = 0, c = () => {
|
|
35
|
+
if (e.lockWidth === !1) return;
|
|
36
|
+
let t = Math.ceil(i.getBoundingClientRect().width);
|
|
37
|
+
t <= s || (s = t, i.style.minWidth = `${s}px`);
|
|
38
|
+
}, l = () => {
|
|
39
|
+
s = 0, i.style.minWidth = "";
|
|
40
|
+
}, u = () => {
|
|
41
|
+
i.style.background = e.backgroundColor ?? t.theme.tooltipBackgroundColor, i.style.color = e.textColor ?? t.theme.tooltipTextColor, i.style.font = e.font ?? t.theme.tooltipFont;
|
|
42
|
+
}, d = (t) => {
|
|
43
|
+
if (o.replaceChildren(), !(e.highlight === !1 || !t)) for (let e of t.items) {
|
|
29
44
|
let t = document.createElement("div");
|
|
30
|
-
t.style.position = "absolute", t.style.left = `${e.plotX}px`, t.style.top = `${e.plotY}px`, t.style.width = "10px", t.style.height = "10px", t.style.border = "2px solid #f8fafc", t.style.borderRadius = "999px", t.style.background = n(e.series.style.color), t.style.boxShadow = "0 0 0
|
|
45
|
+
t.style.position = "absolute", t.style.left = `${e.plotX}px`, t.style.top = `${e.plotY}px`, t.style.width = "10px", t.style.height = "10px", t.style.border = "2px solid #f8fafc", t.style.borderRadius = "999px", t.style.background = n(e.series.style.color), t.style.boxShadow = "0 0 0 1px rgba(4, 8, 16, 0.85)", t.style.transform = "translate(-50%, -50%)", o.appendChild(t);
|
|
31
46
|
}
|
|
32
|
-
},
|
|
33
|
-
let
|
|
34
|
-
if (o
|
|
35
|
-
i.style.display = "none";
|
|
47
|
+
}, f = (n) => {
|
|
48
|
+
let o = n && (e.mode !== void 0 || e.maxDistancePx !== void 0) ? t.pick(n.clientX, n.clientY, e) : n;
|
|
49
|
+
if (d(o), !o || o.items.length === 0) {
|
|
50
|
+
i.style.display = "none", l();
|
|
36
51
|
return;
|
|
37
52
|
}
|
|
38
|
-
e.render ? e.render(
|
|
39
|
-
|
|
40
|
-
|
|
53
|
+
e.render ? e.render(o, i, t) : r(o, i, e.formatter), i.style.display = "block", c(), a(i, o, e);
|
|
54
|
+
}, p = t.subscribe("hover", f), m = t.subscribe("themechange", () => {
|
|
55
|
+
u(), f(t.getHoverState());
|
|
41
56
|
});
|
|
42
|
-
return () => {
|
|
43
|
-
|
|
57
|
+
return u(), () => {
|
|
58
|
+
p(), m(), o.remove(), i.remove();
|
|
44
59
|
};
|
|
45
60
|
} };
|
|
46
61
|
}
|
|
47
62
|
//#endregion
|
|
48
|
-
export {
|
|
63
|
+
export { o as tooltipPlugin };
|
|
49
64
|
|
|
50
65
|
//# sourceMappingURL=tooltip.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip.js","names":[],"sources":["../../src/ui/Tooltip.ts"],"sourcesContent":["import type { Chart, ChartHoverState, ChartPickItem, ChartPickMode, ChartPlugin } from \"./Chart.js\";\n\nexport interface TooltipPluginOptions {\n readonly className?: string;\n readonly mode?: ChartPickMode;\n readonly maxDistancePx?: number;\n readonly offsetX?: number;\n readonly offsetY?: number;\n readonly highlight?: boolean;\n readonly backgroundColor?: string;\n readonly textColor?: string;\n readonly font?: string;\n readonly formatter?: (item: ChartPickItem, state: ChartHoverState) => string;\n readonly render?: (state: ChartHoverState, container: HTMLElement, chart: Chart) => void;\n}\n\nfunction labelOf(item: ChartPickItem): string {\n return item.name ?? item.id ?? `${item.mode} ${item.seriesIndex + 1}`;\n}\n\nfunction formatNumber(value: number): string {\n if (!Number.isFinite(value)) return String(value);\n const abs = Math.abs(value);\n if (abs > 0 && (abs < 1e-3 || abs >= 1e6)) return value.toExponential(3);\n return Number(value.toPrecision(6)).toString();\n}\n\nfunction rgba(color: readonly [number, number, number, number]): string {\n return `rgba(${Math.round(color[0] * 255)}, ${Math.round(color[1] * 255)}, ${Math.round(color[2] * 255)}, ${color[3]})`;\n}\n\nfunction renderDefaultTooltip(\n state: ChartHoverState,\n container: HTMLElement,\n formatter: TooltipPluginOptions[\"formatter\"],\n): void {\n const pad = Math.max(1, ...state.items.map((item) => labelOf(item).length));\n let html = \"\";\n for (const item of state.items) {\n const value = formatter ? formatter(item, state) : `(${formatNumber(item.x)}, ${formatNumber(item.y)})`;\n const color = rgba(item.series.style.color);\n if (html) html += \"<br>\";\n html += `<span style=\"color:${color}\">\\u2588</span> ${labelOf(item).padEnd(pad)} ${value}`;\n }\n container.innerHTML = html;\n}\n\nexport function tooltipPlugin(options: TooltipPluginOptions = {}): ChartPlugin {\n return {\n install(chart: Chart) {\n const container = document.createElement(\"div\");\n container.className = options.className ?? \"blazeplot-tooltip\";\n container.style.position = \"absolute\";\n container.style.zIndex = \"30\";\n container.style.display = \"none\";\n container.style.pointerEvents = \"none\";\n container.style.background = options.backgroundColor ?? chart.theme.tooltipBackgroundColor;\n container.style.color = options.textColor ?? chart.theme.tooltipTextColor;\n container.style.font = options.font ?? chart.theme.tooltipFont;\n container.style.padding = \"8px 10px\";\n container.style.whiteSpace = \"pre\";\n chart.rootElement.appendChild(container);\n\n const markerLayer = document.createElement(\"div\");\n markerLayer.className = \"blazeplot-tooltip-markers\";\n markerLayer.style.position = \"absolute\";\n markerLayer.style.inset = \"0\";\n markerLayer.style.zIndex = \"25\";\n markerLayer.style.pointerEvents = \"none\";\n chart.plotElement.appendChild(markerLayer);\n\n const renderMarkers = (state: ChartHoverState | null): void => {\n markerLayer.replaceChildren();\n if (options.highlight === false || !state) return;\n\n for (const item of state.items) {\n const marker = document.createElement(\"div\");\n marker.style.position = \"absolute\";\n marker.style.left = `${item.plotX}px`;\n marker.style.top = `${item.plotY}px`;\n marker.style.width = \"10px\";\n marker.style.height = \"10px\";\n marker.style.border = \"2px solid #f8fafc\";\n marker.style.borderRadius = \"999px\";\n marker.style.background = rgba(item.series.style.color);\n marker.style.boxShadow = \"0 0 0 2px rgba(4, 8, 16, 0.85)\";\n marker.style.transform = \"translate(-50%, -50%)\";\n markerLayer.appendChild(marker);\n }\n };\n\n const render = (state: ChartHoverState | null): void => {\n const effectiveState = state && (options.mode !== undefined || options.maxDistancePx !== undefined)\n ? chart.pick(state.clientX, state.clientY, options)\n : state;\n\n renderMarkers(effectiveState);\n if (!effectiveState || effectiveState.items.length === 0) {\n container.style.display = \"none\";\n return;\n }\n\n if (options.render) {\n options.render(effectiveState, container, chart);\n } else {\n renderDefaultTooltip(effectiveState, container, options.formatter);\n }\n\n const rootRect = chart.rootElement.getBoundingClientRect();\n const x = effectiveState.clientX - rootRect.left + (options.offsetX ?? 12);\n const y = effectiveState.clientY - rootRect.top + (options.offsetY ?? 12);\n container.style.transform = `translate(${x}px, ${y}px)`;\n container.style.display = \"block\";\n };\n\n const unsubscribe = chart.subscribe(\"hover\", render);\n return () => {\n unsubscribe();\n markerLayer.remove();\n container.remove();\n };\n },\n };\n}\n"],"mappings":";AAgBA,SAAS,EAAQ,GAA6B;CAC5C,OAAO,EAAK,QAAQ,EAAK,MAAM,GAAG,EAAK,KAAK,GAAG,EAAK,cAAc;AACpE;AAEA,SAAS,EAAa,GAAuB;CAC3C,IAAI,CAAC,OAAO,SAAS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AU,EAAS,QAAQ,EAAQ,WAAW,KACjE,IAAI,EAAe,UAAU,EAAS,OAAO,EAAQ,WAAW;GAEtE,AADA,EAAU,MAAM,YAAY,aAAa,EAAE,MAAM,EAAE,MACnD,EAAU,MAAM,UAAU;EAC5B,CAEmD;EACnD,aAAa;GAGX,AAFA,EAAY,GACZ,EAAY,OAAO,GACnB,EAAU,OAAO;EACnB;CACF,EACF;AACF"}
|
|
1
|
+
{"version":3,"file":"tooltip.js","names":[],"sources":["../../src/ui/Tooltip.ts"],"sourcesContent":["import type { Chart, ChartHoverState, ChartPickItem, ChartPickMode, ChartPlugin } from \"./Chart.js\";\n\nexport interface TooltipPluginOptions {\n readonly className?: string;\n readonly mode?: ChartPickMode;\n readonly maxDistancePx?: number;\n readonly offsetX?: number;\n readonly offsetY?: number;\n readonly highlight?: boolean;\n readonly backgroundColor?: string;\n readonly textColor?: string;\n readonly font?: string;\n readonly zIndex?: number;\n readonly lockWidth?: boolean;\n readonly formatter?: (item: ChartPickItem, state: ChartHoverState) => string;\n readonly render?: (state: ChartHoverState, container: HTMLElement, chart: Chart) => void;\n}\n\nfunction labelOf(item: ChartPickItem): string {\n return item.name ?? item.id ?? `${item.mode} ${item.seriesIndex + 1}`;\n}\n\nfunction formatNumber(value: number): string {\n if (!Number.isFinite(value)) return String(value);\n const abs = Math.abs(value);\n if (abs > 0 && (abs < 1e-3 || abs >= 1e6)) return value.toExponential(3);\n return Number(value.toPrecision(6)).toString();\n}\n\nfunction rgba(color: readonly [number, number, number, number]): string {\n return `rgba(${Math.round(color[0] * 255)}, ${Math.round(color[1] * 255)}, ${Math.round(color[2] * 255)}, ${color[3]})`;\n}\n\nfunction renderDefaultTooltip(\n state: ChartHoverState,\n container: HTMLElement,\n formatter: TooltipPluginOptions[\"formatter\"],\n): void {\n const pad = Math.max(1, ...state.items.map((item) => labelOf(item).length));\n let html = \"\";\n for (const item of state.items) {\n const value = formatter ? formatter(item, state) : `(${formatNumber(item.x)}, ${formatNumber(item.y)})`;\n const color = rgba(item.series.style.color);\n if (html) html += \"<br>\";\n html += `<span style=\"color:${color}\">\\u2588</span> ${labelOf(item).padEnd(pad)} ${value}`;\n }\n container.innerHTML = html;\n}\n\nfunction clamp(value: number, min: number, max: number): number {\n return Math.min(max, Math.max(min, value));\n}\n\nfunction placeTooltip(\n container: HTMLElement,\n state: ChartHoverState,\n options: TooltipPluginOptions,\n): void {\n const offsetX = options.offsetX ?? 12;\n const offsetY = options.offsetY ?? 12;\n const tooltipRect = container.getBoundingClientRect();\n const margin = 4;\n const doc = container.ownerDocument;\n const viewportWidth = Math.max(1, globalThis.innerWidth || doc.documentElement.clientWidth);\n const viewportHeight = Math.max(1, globalThis.innerHeight || doc.documentElement.clientHeight);\n\n const viewportX = clamp(\n state.clientX + offsetX,\n margin,\n Math.max(margin, viewportWidth - tooltipRect.width - margin),\n );\n const viewportY = clamp(\n state.clientY + offsetY,\n margin,\n Math.max(margin, viewportHeight - tooltipRect.height - margin),\n );\n container.style.transform = `translate(${viewportX}px, ${viewportY}px)`;\n}\n\nexport function tooltipPlugin(options: TooltipPluginOptions = {}): ChartPlugin {\n return {\n install(chart: Chart) {\n const container = document.createElement(\"div\");\n container.className = options.className ?? \"blazeplot-tooltip\";\n container.style.position = \"fixed\";\n container.style.left = \"0\";\n container.style.top = \"0\";\n container.style.zIndex = String(options.zIndex ?? 10_000);\n container.style.display = \"none\";\n container.style.pointerEvents = \"none\";\n container.style.background = options.backgroundColor ?? chart.theme.tooltipBackgroundColor;\n container.style.color = options.textColor ?? chart.theme.tooltipTextColor;\n container.style.font = options.font ?? chart.theme.tooltipFont;\n container.style.padding = \"8px 10px\";\n container.style.whiteSpace = \"pre\";\n const tooltipParent = chart.rootElement.ownerDocument.body ?? chart.rootElement;\n tooltipParent.appendChild(container);\n\n const markerLayer = document.createElement(\"div\");\n markerLayer.className = \"blazeplot-tooltip-markers\";\n markerLayer.style.position = \"absolute\";\n markerLayer.style.inset = \"0\";\n markerLayer.style.zIndex = \"25\";\n markerLayer.style.pointerEvents = \"none\";\n chart.plotElement.appendChild(markerLayer);\n\n let lockedTooltipWidth = 0;\n\n const lockTooltipWidth = (): void => {\n if (options.lockWidth === false) return;\n const width = Math.ceil(container.getBoundingClientRect().width);\n if (width <= lockedTooltipWidth) return;\n lockedTooltipWidth = width;\n container.style.minWidth = `${lockedTooltipWidth}px`;\n };\n\n const resetTooltipWidth = (): void => {\n lockedTooltipWidth = 0;\n container.style.minWidth = \"\";\n };\n\n const applyTheme = (): void => {\n container.style.background = options.backgroundColor ?? chart.theme.tooltipBackgroundColor;\n container.style.color = options.textColor ?? chart.theme.tooltipTextColor;\n container.style.font = options.font ?? chart.theme.tooltipFont;\n };\n\n const renderMarkers = (state: ChartHoverState | null): void => {\n markerLayer.replaceChildren();\n if (options.highlight === false || !state) return;\n\n for (const item of state.items) {\n const marker = document.createElement(\"div\");\n marker.style.position = \"absolute\";\n marker.style.left = `${item.plotX}px`;\n marker.style.top = `${item.plotY}px`;\n marker.style.width = \"10px\";\n marker.style.height = \"10px\";\n marker.style.border = \"2px solid #f8fafc\";\n marker.style.borderRadius = \"999px\";\n marker.style.background = rgba(item.series.style.color);\n marker.style.boxShadow = \"0 0 0 1px rgba(4, 8, 16, 0.85)\";\n marker.style.transform = \"translate(-50%, -50%)\";\n markerLayer.appendChild(marker);\n }\n };\n\n const render = (state: ChartHoverState | null): void => {\n const effectiveState = state && (options.mode !== undefined || options.maxDistancePx !== undefined)\n ? chart.pick(state.clientX, state.clientY, options)\n : state;\n\n renderMarkers(effectiveState);\n if (!effectiveState || effectiveState.items.length === 0) {\n container.style.display = \"none\";\n resetTooltipWidth();\n return;\n }\n\n if (options.render) {\n options.render(effectiveState, container, chart);\n } else {\n renderDefaultTooltip(effectiveState, container, options.formatter);\n }\n\n container.style.display = \"block\";\n lockTooltipWidth();\n placeTooltip(container, effectiveState, options);\n };\n\n const unsubscribeHover = chart.subscribe(\"hover\", render);\n const unsubscribeTheme = chart.subscribe(\"themechange\", () => {\n applyTheme();\n render(chart.getHoverState());\n });\n applyTheme();\n return () => {\n unsubscribeHover();\n unsubscribeTheme();\n markerLayer.remove();\n container.remove();\n };\n },\n };\n}\n"],"mappings":";AAkBA,SAAS,EAAQ,GAA6B;CAC5C,OAAO,EAAK,QAAQ,EAAK,MAAM,GAAG,EAAK,KAAK,GAAG,EAAK,cAAc;AACpE;AAEA,SAAS,EAAa,GAAuB;CAC3C,IAAI,CAAC,OAAO,SAAS,CAAK,GAAG,OAAO,OAAO,CAAK;CAChD,IAAM,IAAM,KAAK,IAAI,CAAK;CAE1B,OADI,IAAM,MAAM,IAAM,QAAQ,KAAO,OAAa,EAAM,cAAc,CAAC,IAChE,OAAO,EAAM,YAAY,CAAC,CAAC,EAAE,SAAS;AAC/C;AAEA,SAAS,EAAK,GAA0D;CACtE,OAAO,QAAQ,KAAK,MAAM,EAAM,KAAK,GAAG,EAAE,IAAI,KAAK,MAAM,EAAM,KAAK,GAAG,EAAE,IAAI,KAAK,MAAM,EAAM,KAAK,GAAG,EAAE,IAAI,EAAM,GAAG;AACvH;AAEA,SAAS,EACP,GACA,GACA,GACM;CACN,IAAM,IAAM,KAAK,IAAI,GAAG,GAAG,EAAM,MAAM,KAAK,MAAS,EAAQ,CAAI,EAAE,MAAM,CAAC,GACtE,IAAO;CACX,KAAK,IAAM,KAAQ,EAAM,OAAO;EAC9B,IAAM,IAAQ,IAAY,EAAU,GAAM,CAAK,IAAI,IAAI,EAAa,EAAK,CAAC,EAAE,IAAI,EAAa,EAAK,CAAC,EAAE,IAC/F,IAAQ,EAAK,EAAK,OAAO,MAAM,KAAK;EAE1C,AADI,MAAM,KAAQ,SAClB,KAAQ,sBAAsB,EAAM,kBAAkB,EAAQ,CAAI,EAAE,OAAO,CAAG,EAAE,IAAI;CACtF;CACA,EAAU,YAAY;AACxB;AAEA,SAAS,EAAM,GAAe,GAAa,GAAqB;CAC9D,OAAO,KAAK,IAAI,GAAK,KAAK,IAAI,GAAK,CAAK,CAAC;AAC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U,QAC1B,EAAkB;IAClB;GACF;GAUA,AARI,EAAQ,SACV,EAAQ,OAAO,GAAgB,GAAW,CAAK,IAE/C,EAAqB,GAAgB,GAAW,EAAQ,SAAS,GAGnE,EAAU,MAAM,UAAU,SAC1B,EAAiB,GACjB,EAAa,GAAW,GAAgB,CAAO;EACjD,GAEM,IAAmB,EAAM,UAAU,SAAS,CAAM,GAClD,IAAmB,EAAM,UAAU,qBAAqB;GAE5D,AADA,EAAW,GACX,EAAO,EAAM,cAAc,CAAC;EAC9B,CAAC;EAED,OADA,EAAW,SACE;GAIX,AAHA,EAAiB,GACjB,EAAiB,GACjB,EAAY,OAAO,GACnB,EAAU,OAAO;EACnB;CACF,EACF;AACF"}
|
|
@@ -15,26 +15,32 @@ export declare class Renderer {
|
|
|
15
15
|
private readonly scaleUniform;
|
|
16
16
|
private readonly offsetUniform;
|
|
17
17
|
private readonly canvasSizeUniform;
|
|
18
|
+
private xOrigin;
|
|
18
19
|
constructor(backend: GpuBackend);
|
|
19
20
|
get supportsInstancedSegments(): boolean;
|
|
20
21
|
get supportsInstancedPoints(): boolean;
|
|
21
22
|
get supportsInstancedBars(): boolean;
|
|
22
23
|
clear(r: number, g: number, b: number, a: number): void;
|
|
23
24
|
createFloatBuffer(floatCount: number): GpuBuffer;
|
|
24
|
-
updateFloatBuffer(buffer: GpuBuffer, data: Float32Array): void;
|
|
25
|
+
updateFloatBuffer(buffer: GpuBuffer, data: Float32Array, floatCount?: number): void;
|
|
25
26
|
viewport(x: number, y: number, width: number, height: number): void;
|
|
27
|
+
setXOrigin(origin: number): void;
|
|
26
28
|
drawLines(positions: GpuBuffer, count: number, style: SeriesStyle, camera: Camera2D): void;
|
|
27
29
|
drawLineStrip(positions: GpuBuffer, count: number, style: SeriesStyle, camera: Camera2D): void;
|
|
30
|
+
drawClipLineStrip(positions: GpuBuffer, count: number, style: SeriesStyle): void;
|
|
31
|
+
drawClipLines(positions: GpuBuffer, count: number, style: SeriesStyle): void;
|
|
28
32
|
drawMinMaxSegments(positions: GpuBuffer, count: number, style: SeriesStyle, camera: Camera2D): void;
|
|
29
33
|
drawMinMaxSegmentsInstanced(instanceBuffer: GpuBuffer, instanceCount: number, style: SeriesStyle, camera: Camera2D): void;
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
drawPoints(positions: GpuBuffer, pointCount: number, style: SeriesStyle, camera: Camera2D, canvasWidth: number, canvasHeight: number): void;
|
|
35
|
+
private drawPointsInstanced;
|
|
36
|
+
private drawPointSprites;
|
|
32
37
|
drawAreaStrip(positions: GpuBuffer, count: number, style: SeriesStyle, camera: Camera2D): void;
|
|
33
38
|
drawBarsInstanced(instanceBuffer: GpuBuffer, barCount: number, style: SeriesStyle, camera: Camera2D): void;
|
|
34
39
|
drawBarRangesInstanced(instanceBuffer: GpuBuffer, barCount: number, style: SeriesStyle, camera: Camera2D): void;
|
|
35
40
|
drawBarTriangles(positions: GpuBuffer, vertexCount: number, style: SeriesStyle, camera: Camera2D): void;
|
|
36
41
|
private drawLinePrimitive;
|
|
37
42
|
private drawTrianglePrimitive;
|
|
43
|
+
private drawClipPrimitive;
|
|
38
44
|
private writeCameraUniforms;
|
|
39
45
|
dispose(): void;
|
|
40
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Renderer.d.ts","sourceRoot":"","sources":["../../src/render/Renderer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,KAAK,EAAiB,UAAU,EAAE,SAAS,EAAc,MAAM,YAAY,CAAC;AACnF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AASpD,qBAAa,QAAQ;
|
|
1
|
+
{"version":3,"file":"Renderer.d.ts","sourceRoot":"","sources":["../../src/render/Renderer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,KAAK,EAAiB,UAAU,E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,sBAAsB,CACpB,cAAc,EAAE,SAAS,EACzB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,QAAQ,GACf,IAAI;IAwBP,gBAAgB,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,GAAG,IAAI;IAIvG,OAAO,CAAC,iBAAiB;IAgBzB,OAAO,CAAC,qBAAqB;IAgB7B,OAAO,CAAC,iBAAiB;IAmBzB,OAAO,CAAC,mBAAmB;IAS3B,OAAO,IAAI,IAAI;CAGhB"}
|
package/dist/ui/AxisOverlay.d.ts
CHANGED
|
@@ -9,12 +9,13 @@ export type AxisOverlayConfig = ChartLayoutConfig;
|
|
|
9
9
|
export declare class AxisOverlay {
|
|
10
10
|
private readonly layout;
|
|
11
11
|
private readonly config;
|
|
12
|
-
private
|
|
12
|
+
private options;
|
|
13
13
|
private xPool;
|
|
14
14
|
private yPool;
|
|
15
15
|
private readonly xTicks;
|
|
16
16
|
private readonly yTicks;
|
|
17
17
|
constructor(layout: ChartLayoutElements, config: AxisOverlayConfig, options?: AxisOverlayOptions);
|
|
18
|
+
setOptions(options: AxisOverlayOptions): void;
|
|
18
19
|
update(camera: Camera2D, axis: AxisController): void;
|
|
19
20
|
dispose(): void;
|
|
20
21
|
private parentForAxis;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AxisOverlay.d.ts","sourceRoot":"","sources":["../../src/ui/AxisOverlay.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE/E,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CA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