blazeplot 0.2.1 → 0.3.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 +11 -2
- package/dist/Chart-BW9JaHs6.js +2903 -0
- package/dist/Chart-BW9JaHs6.js.map +1 -0
- package/dist/OverlayUtils-Cw1o8UH-.js +35 -0
- package/dist/OverlayUtils-Cw1o8UH-.js.map +1 -0
- package/dist/core/SeriesStore.d.ts +9 -0
- package/dist/core/SeriesStore.d.ts.map +1 -1
- package/dist/core/UniformRingBuffer.d.ts +67 -0
- package/dist/core/UniformRingBuffer.d.ts.map +1 -0
- package/dist/core/index.d.ts +3 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/types.d.ts +13 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +153 -2185
- package/dist/index.js.map +1 -1
- package/dist/interaction/AxisController.d.ts +45 -3
- package/dist/interaction/AxisController.d.ts.map +1 -1
- package/dist/interaction/index.d.ts +1 -0
- package/dist/interaction/index.d.ts.map +1 -1
- package/dist/linked.d.ts +3 -0
- package/dist/linked.d.ts.map +1 -0
- package/dist/linked.js +64 -0
- package/dist/linked.js.map +1 -0
- package/dist/plugins/annotations.d.ts +3 -0
- package/dist/plugins/annotations.d.ts.map +1 -0
- package/dist/plugins/annotations.js +163 -0
- package/dist/plugins/annotations.js.map +1 -0
- package/dist/plugins/crosshair.d.ts +3 -0
- package/dist/plugins/crosshair.d.ts.map +1 -0
- package/dist/plugins/crosshair.js +192 -0
- package/dist/plugins/crosshair.js.map +1 -0
- package/dist/plugins/interactions.js +87 -65
- package/dist/plugins/interactions.js.map +1 -1
- package/dist/plugins/navigator.d.ts +3 -0
- package/dist/plugins/navigator.d.ts.map +1 -0
- package/dist/plugins/navigator.js +147 -0
- package/dist/plugins/navigator.js.map +1 -0
- package/dist/plugins/selection.d.ts +3 -0
- package/dist/plugins/selection.d.ts.map +1 -0
- package/dist/plugins/selection.js +144 -0
- package/dist/plugins/selection.js.map +1 -0
- package/dist/plugins/tooltip.js +29 -45
- package/dist/plugins/tooltip.js.map +1 -1
- package/dist/react.d.ts +14 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +30 -0
- package/dist/react.js.map +1 -0
- package/dist/render/ReglBackend.d.ts +1 -0
- package/dist/render/ReglBackend.d.ts.map +1 -1
- package/dist/render/Renderer.d.ts +1 -0
- package/dist/render/Renderer.d.ts.map +1 -1
- package/dist/render/types.d.ts +1 -0
- package/dist/render/types.d.ts.map +1 -1
- package/dist/ui/Annotations.d.ts +94 -0
- package/dist/ui/Annotations.d.ts.map +1 -0
- package/dist/ui/Chart.d.ts +83 -1
- package/dist/ui/Chart.d.ts.map +1 -1
- package/dist/ui/ChartLayout.d.ts +10 -0
- package/dist/ui/ChartLayout.d.ts.map +1 -1
- package/dist/ui/Crosshair.d.ts +60 -0
- package/dist/ui/Crosshair.d.ts.map +1 -0
- package/dist/ui/Interactions.d.ts.map +1 -1
- package/dist/ui/LinkedCharts.d.ts +23 -0
- package/dist/ui/LinkedCharts.d.ts.map +1 -0
- package/dist/ui/Navigator.d.ts +32 -0
- package/dist/ui/Navigator.d.ts.map +1 -0
- package/dist/ui/OverlayUtils.d.ts +17 -0
- package/dist/ui/OverlayUtils.d.ts.map +1 -0
- package/dist/ui/Selection.d.ts +64 -0
- package/dist/ui/Selection.d.ts.map +1 -0
- package/dist/ui/Tooltip.d.ts.map +1 -1
- package/dist/ui/theme.d.ts +12 -0
- package/dist/ui/theme.d.ts.map +1 -1
- package/package.json +35 -1
|
@@ -1,11 +1,53 @@
|
|
|
1
1
|
import { Camera2D } from './Camera2D.js';
|
|
2
|
+
export type AxisRenderTarget = "x" | "y";
|
|
3
|
+
export type BuiltInAxisScale = "linear" | "time" | "log" | "symlog" | "categorical";
|
|
4
|
+
export interface CustomAxisScale {
|
|
5
|
+
readonly type: "custom";
|
|
6
|
+
ticks?(min: number, max: number, maxTicks: number): readonly number[];
|
|
7
|
+
formatTick?(value: number, axis: AxisRenderTarget): string;
|
|
8
|
+
toScreen?(value: number): number;
|
|
9
|
+
fromScreen?(value: number): number;
|
|
10
|
+
}
|
|
11
|
+
export type AxisScale = BuiltInAxisScale | CustomAxisScale;
|
|
12
|
+
export type AxisTimeZone = "local" | "utc";
|
|
13
|
+
export type AxisTickFormatter = (value: number, axis: AxisRenderTarget) => string;
|
|
14
|
+
export type AxisTickFormat = string | AxisTickFormatter;
|
|
15
|
+
export interface AxisControllerAxisOptions {
|
|
16
|
+
readonly scale?: AxisScale;
|
|
17
|
+
readonly tickFormat?: AxisTickFormat;
|
|
18
|
+
readonly timezone?: AxisTimeZone;
|
|
19
|
+
readonly logBase?: number;
|
|
20
|
+
readonly symlogConstant?: number;
|
|
21
|
+
readonly categories?: readonly string[];
|
|
22
|
+
}
|
|
23
|
+
export interface AxisControllerOptions {
|
|
24
|
+
readonly x?: AxisControllerAxisOptions;
|
|
25
|
+
readonly y?: AxisControllerAxisOptions;
|
|
26
|
+
}
|
|
2
27
|
export declare class AxisController {
|
|
3
28
|
private readonly camera;
|
|
4
|
-
|
|
29
|
+
private options;
|
|
30
|
+
private lastXTimeInterval;
|
|
31
|
+
private lastYTimeInterval;
|
|
32
|
+
constructor(camera: Camera2D, options?: AxisControllerOptions);
|
|
33
|
+
setOptions(options: AxisControllerOptions): void;
|
|
5
34
|
getXTickValues(canvasWidth: number, maxTicks?: number, target?: number[]): number[];
|
|
6
35
|
getYTickValues(canvasHeight: number, maxTicks?: number, target?: number[]): number[];
|
|
7
|
-
formatValue(value: number): string;
|
|
8
|
-
private
|
|
36
|
+
formatValue(value: number, axis?: AxisRenderTarget): string;
|
|
37
|
+
private lastTimeInterval;
|
|
38
|
+
private getScaledTickValues;
|
|
39
|
+
private getLogTickValues;
|
|
40
|
+
private getSymlogTickValues;
|
|
41
|
+
private getCategoricalTickValues;
|
|
42
|
+
private formatLinearValue;
|
|
43
|
+
private getLinearTickValues;
|
|
44
|
+
private getTimeTickValues;
|
|
45
|
+
private chooseTimeInterval;
|
|
46
|
+
private floorTime;
|
|
47
|
+
private advanceTime;
|
|
48
|
+
private makeTime;
|
|
49
|
+
private formatTimeValue;
|
|
50
|
+
private formatTimePattern;
|
|
9
51
|
private niceStep;
|
|
10
52
|
private normalizeTick;
|
|
11
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AxisController.d.ts","sourceRoot":"","sources":["../../src/interaction/AxisController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,qBAAa,cAAc;
|
|
1
|
+
{"version":3,"file":"AxisController.d.ts","sourceRoot":"","sources":["../../src/interaction/AxisController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,MAAM,gBAAgB,GAAG,GAAG,GAAG,GAAG,CAAC;AACzC,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,aAAa,CAAC;AAEpF,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,KAAK,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;IACtE,UAAU,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,GAAG,MAAM,CAAC;IAC3D,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACjC,UAAU,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACpC;AAED,MAAM,MAAM,SAAS,GAAG,gBAAgB,GAAG,eAAe,CAAC;AAC3D,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,KAAK,CAAC;AAC3C,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,OAAO,CAAC,mBAAmB;IAwB3B,OAAO,CAAC,gBAAgB;IAexB,OAAO,CAAC,mBAAmB;IAS3B,OAAO,CAAC,wBAAwB;IAUhC,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,mBAAmB;IAmB3B,OAAO,CAAC,iBAAiB;IAoCzB,OAAO,CAAC,kBAAkB;IAW1B,OAAO,CAAC,SAAS;IA6BjB,OAAO,CAAC,WAAW;IA2BnB,OAAO,CAAC,QAAQ;IAMhB,OAAO,CAAC,eAAe;IAWvB,OAAO,CAAC,iBAAiB;IA+BzB,OAAO,CAAC,QAAQ;IAUhB,OAAO,CAAC,aAAa;CAKtB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { Camera2D } from './Camera2D.js';
|
|
2
2
|
export { AxisController } from './AxisController.js';
|
|
3
|
+
export type { AxisControllerAxisOptions, AxisControllerOptions, AxisRenderTarget, AxisScale, AxisTickFormat, AxisTickFormatter, AxisTimeZone, BuiltInAxisScale, CustomAxisScale } from './AxisController.js';
|
|
3
4
|
export type { PanIntent, ZoomAxis, ZoomIntent, ViewportPolicy } from './types.js';
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interaction/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interaction/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,YAAY,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,SAAS,EAAE,cAAc,EAAE,iBAAiB,EAAE,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC7M,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/linked.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linked.d.ts","sourceRoot":"","sources":["../src/linked.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC9E,YAAY,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/linked.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { t as e } from "./Chart-BW9JaHs6.js";
|
|
2
|
+
//#region src/ui/LinkedCharts.ts
|
|
3
|
+
function t(e, t) {
|
|
4
|
+
return typeof e == "number" ? `${e}px` : e ?? t;
|
|
5
|
+
}
|
|
6
|
+
function n(n, r) {
|
|
7
|
+
let i = Math.max(1, Math.floor(r.rows ?? r.panels.length)), a = Math.max(1, Math.floor(r.columns ?? Math.ceil(r.panels.length / i))), o = document.createElement("div"), s = [], c = [], l = !1, u = !1;
|
|
8
|
+
o.className = r.className ?? "blazeplot-linked-charts", o.style.display = "grid", o.style.width = "100%", o.style.height = "100%", o.style.minWidth = "0", o.style.minHeight = "0", o.style.gridTemplateRows = `repeat(${i}, minmax(0, 1fr))`, o.style.gridTemplateColumns = `repeat(${a}, minmax(0, 1fr))`, o.style.gap = t(r.spacing, "8px"), n.appendChild(o);
|
|
9
|
+
for (let t of r.panels) {
|
|
10
|
+
let n = document.createElement("div");
|
|
11
|
+
n.className = t.className ?? "blazeplot-linked-panel", n.style.position = "relative", n.style.minWidth = "0", n.style.minHeight = "0", o.appendChild(n), s.push(new e(n, t.options));
|
|
12
|
+
}
|
|
13
|
+
let d = (e, t) => {
|
|
14
|
+
l = !0;
|
|
15
|
+
try {
|
|
16
|
+
for (let n of s) n.setViewport({
|
|
17
|
+
xMin: e,
|
|
18
|
+
xMax: t
|
|
19
|
+
});
|
|
20
|
+
} finally {
|
|
21
|
+
l = !1;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
if (r.sharedX !== !1) for (let e of s) c.push(e.subscribe("viewportchange", (t) => {
|
|
25
|
+
if (!l) {
|
|
26
|
+
l = !0;
|
|
27
|
+
try {
|
|
28
|
+
for (let n of s) n !== e && n.setViewport({
|
|
29
|
+
xMin: t.viewport.xMin,
|
|
30
|
+
xMax: t.viewport.xMax
|
|
31
|
+
});
|
|
32
|
+
} finally {
|
|
33
|
+
l = !1;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}));
|
|
37
|
+
if (r.syncSelections) for (let e of s) c.push(e.subscribe("select", (t) => {
|
|
38
|
+
if (!u) {
|
|
39
|
+
u = !0;
|
|
40
|
+
try {
|
|
41
|
+
for (let n of s) n !== e && n.emitSelect(t.selection);
|
|
42
|
+
} finally {
|
|
43
|
+
u = !1;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}));
|
|
47
|
+
return {
|
|
48
|
+
root: o,
|
|
49
|
+
charts: s,
|
|
50
|
+
setXRange: d,
|
|
51
|
+
dispose() {
|
|
52
|
+
for (let e of c.splice(0)) e();
|
|
53
|
+
for (let e of s.splice(0)) e.dispose();
|
|
54
|
+
o.remove();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function r() {
|
|
59
|
+
return { install() {} };
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
export { n as createLinkedCharts, r as linkedChartsPlugin };
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=linked.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linked.js","names":[],"sources":["../src/ui/LinkedCharts.ts"],"sourcesContent":["import { Chart } from \"./Chart.js\";\nimport type { ChartOptions, ChartPlugin, ChartSelectEvent, ChartViewportChangeEvent } from \"./Chart.js\";\n\nexport interface LinkedChartPanelOptions {\n readonly options?: ChartOptions;\n readonly className?: string;\n}\n\nexport interface LinkedChartsOptions {\n readonly rows?: number;\n readonly columns?: number;\n readonly panels: readonly LinkedChartPanelOptions[];\n readonly sharedX?: boolean;\n readonly syncSelections?: boolean;\n readonly spacing?: number | string;\n readonly className?: string;\n}\n\nexport interface LinkedChartsHandle {\n readonly root: HTMLDivElement;\n readonly charts: readonly Chart[];\n setXRange(xMin: number, xMax: number): void;\n dispose(): void;\n}\n\nfunction cssSize(value: number | string | undefined, fallback: string): string {\n return typeof value === \"number\" ? `${value}px` : value ?? fallback;\n}\n\nexport function createLinkedCharts(target: HTMLElement, options: LinkedChartsOptions): LinkedChartsHandle {\n const rows = Math.max(1, Math.floor(options.rows ?? options.panels.length));\n const columns = Math.max(1, Math.floor(options.columns ?? Math.ceil(options.panels.length / rows)));\n const root = document.createElement(\"div\");\n const charts: Chart[] = [];\n const disposers: Array<() => void> = [];\n let syncingViewport = false;\n let syncingSelection = false;\n\n root.className = options.className ?? \"blazeplot-linked-charts\";\n root.style.display = \"grid\";\n root.style.width = \"100%\";\n root.style.height = \"100%\";\n root.style.minWidth = \"0\";\n root.style.minHeight = \"0\";\n root.style.gridTemplateRows = `repeat(${rows}, minmax(0, 1fr))`;\n root.style.gridTemplateColumns = `repeat(${columns}, minmax(0, 1fr))`;\n root.style.gap = cssSize(options.spacing, \"8px\");\n target.appendChild(root);\n\n for (const panel of options.panels) {\n const cell = document.createElement(\"div\");\n cell.className = panel.className ?? \"blazeplot-linked-panel\";\n cell.style.position = \"relative\";\n cell.style.minWidth = \"0\";\n cell.style.minHeight = \"0\";\n root.appendChild(cell);\n charts.push(new Chart(cell, panel.options));\n }\n\n const setXRange = (xMin: number, xMax: number): void => {\n syncingViewport = true;\n try {\n for (const chart of charts) chart.setViewport({ xMin, xMax });\n } finally {\n syncingViewport = false;\n }\n };\n\n if (options.sharedX !== false) {\n for (const chart of charts) {\n disposers.push(chart.subscribe(\"viewportchange\", (event: ChartViewportChangeEvent) => {\n if (syncingViewport) return;\n syncingViewport = true;\n try {\n for (const other of charts) {\n if (other !== chart) other.setViewport({ xMin: event.viewport.xMin, xMax: event.viewport.xMax });\n }\n } finally {\n syncingViewport = false;\n }\n }));\n }\n }\n\n if (options.syncSelections) {\n for (const chart of charts) {\n disposers.push(chart.subscribe(\"select\", (event: ChartSelectEvent) => {\n if (syncingSelection) return;\n syncingSelection = true;\n try {\n for (const other of charts) {\n if (other !== chart) other.emitSelect(event.selection);\n }\n } finally {\n syncingSelection = false;\n }\n }));\n }\n }\n\n return {\n root,\n charts,\n setXRange,\n dispose(): void {\n for (const dispose of disposers.splice(0)) dispose();\n for (const chart of charts.splice(0)) chart.dispose();\n root.remove();\n },\n };\n}\n\nexport function linkedChartsPlugin(): ChartPlugin {\n return {\n install() {\n // Marker plugin for codebases that share plugin arrays between single charts and linked layouts.\n },\n };\n}\n"],"mappings":";;AAyBA,SAAS,EAAQ,GAAoC,GAA0B;CAC7E,OAAO,OAAO,KAAU,WAAW,GAAG,EAAM,MAAM,KAAS;AAC7D;AAEA,SAAgB,EAAmB,GAAqB,GAAkD;CACxG,IAAM,IAAO,KAAK,IAAI,GAAG,KAAK,MAAM,EAAQ,QAAQ,EAAQ,OAAO,MAAM,CAAC,GACpE,IAAU,KAAK,IAAI,GAAG,KAAK,MAAM,EAAQ,WAAW,KAAK,KAAK,EAAQ,OAAO,SAAS,CAAI,CAAC,CAAC,GAC5F,IAAO,SAAS,cAAc,KAAK,GACnC,IAAkB,CAAC,GACnB,IAA+B,CAAC,GAClC,IAAkB,IAClB,IAAmB;CAWvB,AATA,EAAK,YAAY,EAAQ,aAAa,2BACtC,EAAK,MAAM,UAAU,QACrB,EAAK,MAAM,QAAQ,QACnB,EAAK,MAAM,SAAS,QACpB,EAAK,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W,EAAU,OAAO,CAAC,GAAG,EAAQ;GACnD,KAAK,IAAM,KAAS,EAAO,OAAO,CAAC,GAAG,EAAM,QAAQ;GACpD,EAAK,OAAO;EACd;CACF;AACF;AAEA,SAAgB,IAAkC;CAChD,OAAO,EACL,UAAU,CAEV,EACF;AACF"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { annotationsPlugin } from '../ui/Annotations.js';
|
|
2
|
+
export type { Annotation, AnnotationBase, AnnotationLabelOptions, AnnotationsPlugin, AnnotationsPluginOptions, BoxAnnotation, LabelAnnotation, PointAnnotation, XLineAnnotation, XRangeAnnotation, YLineAnnotation, YRangeAnnotation } from '../ui/Annotations.js';
|
|
3
|
+
//# sourceMappingURL=annotations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../src/plugins/annotations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,aAAa,EAAE,eAAe,EAAE,eAAe,EAAE,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
//#region src/ui/Annotations.ts
|
|
2
|
+
var e = "http://www.w3.org/2000/svg";
|
|
3
|
+
function t(t) {
|
|
4
|
+
return document.createElementNS(e, t);
|
|
5
|
+
}
|
|
6
|
+
function n(e) {
|
|
7
|
+
return e ? typeof e == "string" ? e : e.text : null;
|
|
8
|
+
}
|
|
9
|
+
function r(e) {
|
|
10
|
+
return typeof e == "string" ? { text: e } : e ?? { text: "" };
|
|
11
|
+
}
|
|
12
|
+
function i(e, t, n, r, i, a) {
|
|
13
|
+
let o = Math.max(0, Math.min(e, n)), s = Math.min(i, Math.max(e, n)), c = Math.max(0, Math.min(t, r)), l = Math.min(a, Math.max(t, r));
|
|
14
|
+
return s <= o || l <= c ? null : {
|
|
15
|
+
x: o,
|
|
16
|
+
y: c,
|
|
17
|
+
w: s - o,
|
|
18
|
+
h: l - c
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function a(e, t, n, r) {
|
|
22
|
+
return e >= 0 && e <= n && t >= 0 && t <= r;
|
|
23
|
+
}
|
|
24
|
+
function o(e = {}) {
|
|
25
|
+
let n = [...e.annotations ?? []], r = null, i = null, a = e.defaultColor ?? "rgba(255,255,255,0.85)", o = e.defaultFillColor ?? "rgba(255,255,255,0.12)", c = e.defaultFont ?? "12px system-ui, sans-serif", l = () => {
|
|
26
|
+
r && i && s(r, i, n, a, o, c);
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
install(n) {
|
|
30
|
+
r = n, i = t("svg"), i.classList.add(e.className ?? "blazeplot-annotations"), i.style.position = "absolute", i.style.inset = "0", i.style.width = "100%", i.style.height = "100%", i.style.pointerEvents = "none", i.style.overflow = "hidden", i.style.zIndex = String(e.zIndex ?? 12), n.plotElement.appendChild(i);
|
|
31
|
+
let a = n.subscribe("render", () => l());
|
|
32
|
+
return l(), () => {
|
|
33
|
+
a(), i?.remove(), i = null, r = null;
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
add(e) {
|
|
37
|
+
n = [...n, e], l();
|
|
38
|
+
},
|
|
39
|
+
remove(e) {
|
|
40
|
+
let t = n.filter((t) => t.id !== e), r = t.length !== n.length;
|
|
41
|
+
return r && (n = t, l()), r;
|
|
42
|
+
},
|
|
43
|
+
clear() {
|
|
44
|
+
n = [], l();
|
|
45
|
+
},
|
|
46
|
+
setAnnotations(e) {
|
|
47
|
+
n = [...e], l();
|
|
48
|
+
},
|
|
49
|
+
getAnnotations() {
|
|
50
|
+
return n;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function s(e, t, n, r, i, a) {
|
|
55
|
+
let o = Math.max(1, e.canvas.clientWidth), s = Math.max(1, e.canvas.clientHeight);
|
|
56
|
+
t.setAttribute("viewBox", `0 0 ${o} ${s}`), t.replaceChildren();
|
|
57
|
+
for (let l of n) l.visible !== !1 && c(e, t, l, o, s, r, i, a);
|
|
58
|
+
}
|
|
59
|
+
function c(e, n, r, o, s, c, m, h) {
|
|
60
|
+
let g = e.getViewport(r.yAxis ?? "left"), _ = (e) => (e - g.xMin) / (g.xMax - g.xMin) * o, v = (e) => (g.yMax - e) / (g.yMax - g.yMin) * s, y = t("g");
|
|
61
|
+
switch (r.className && y.classList.add(r.className), r.type) {
|
|
62
|
+
case "x-line": {
|
|
63
|
+
let e = _(r.x);
|
|
64
|
+
if (e < 0 || e > o) return;
|
|
65
|
+
let n = t("line");
|
|
66
|
+
n.setAttribute("x1", String(e)), n.setAttribute("x2", String(e)), n.setAttribute("y1", "0"), n.setAttribute("y2", String(s)), l(n, r.color ?? c, r.width, r.dash), y.appendChild(n), p(y, r.label, e + 4, 6, "start", c, h);
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case "y-line": {
|
|
70
|
+
let e = v(r.y);
|
|
71
|
+
if (e < 0 || e > s) return;
|
|
72
|
+
let n = t("line");
|
|
73
|
+
n.setAttribute("x1", "0"), n.setAttribute("x2", String(o)), n.setAttribute("y1", String(e)), n.setAttribute("y2", String(e)), l(n, r.color ?? c, r.width, r.dash), y.appendChild(n), p(y, r.label, o - 4, e - 4, "end", c, h);
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
case "x-range": {
|
|
77
|
+
let e = i(_(r.xMin), 0, _(r.xMax), s, o, s);
|
|
78
|
+
if (!e) return;
|
|
79
|
+
u(y, e, r.fillColor ?? m, r.borderColor, r.borderWidth), p(y, r.label, e.x + e.w * .5, 6, "middle", c, h);
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
case "y-range": {
|
|
83
|
+
let e = i(0, v(r.yMax), o, v(r.yMin), o, s);
|
|
84
|
+
if (!e) return;
|
|
85
|
+
u(y, e, r.fillColor ?? m, r.borderColor, r.borderWidth), p(y, r.label, o - 4, e.y + e.h * .5, "end", c, h);
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
case "box": {
|
|
89
|
+
let e = i(_(r.xMin), v(r.yMax), _(r.xMax), v(r.yMin), o, s);
|
|
90
|
+
if (!e) return;
|
|
91
|
+
u(y, e, r.fillColor ?? m, r.borderColor, r.borderWidth), p(y, r.label, e.x + e.w * .5, e.y + 6, "middle", c, h);
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case "point": {
|
|
95
|
+
let e = _(r.x), t = v(r.y), n = r.radius ?? 5;
|
|
96
|
+
if (!a(e, t, o, s)) return;
|
|
97
|
+
d(y, e, t, n, r), p(y, r.label, e + n + 4, t - n - 2, "start", c, h);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
case "label": {
|
|
101
|
+
let e = _(r.x), t = v(r.y);
|
|
102
|
+
if (!a(e, t, o, s)) return;
|
|
103
|
+
f(y, r, e, t, c, h);
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
n.appendChild(y);
|
|
108
|
+
}
|
|
109
|
+
function l(e, t, n = 1, r) {
|
|
110
|
+
e.setAttribute("stroke", t), e.setAttribute("stroke-width", String(n)), e.setAttribute("fill", "none"), r && e.setAttribute("stroke-dasharray", r);
|
|
111
|
+
}
|
|
112
|
+
function u(e, n, r, i, a = 0) {
|
|
113
|
+
let o = t("rect");
|
|
114
|
+
o.setAttribute("x", String(n.x)), o.setAttribute("y", String(n.y)), o.setAttribute("width", String(n.w)), o.setAttribute("height", String(n.h)), o.setAttribute("fill", r), i && (o.setAttribute("stroke", i), o.setAttribute("stroke-width", String(a || 1))), e.appendChild(o);
|
|
115
|
+
}
|
|
116
|
+
function d(e, n, r, i, a) {
|
|
117
|
+
let o = a.color ?? "rgba(255,255,255,0.95)", s = a.strokeColor ?? "rgba(0,0,0,0.35)", c = a.strokeWidth ?? 1;
|
|
118
|
+
if (a.shape === "diamond") {
|
|
119
|
+
let a = t("polygon");
|
|
120
|
+
a.setAttribute("points", `${n},${r - i} ${n + i},${r} ${n},${r + i} ${n - i},${r}`), a.setAttribute("fill", o), a.setAttribute("stroke", s), a.setAttribute("stroke-width", String(c)), e.appendChild(a);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (a.shape === "cross") {
|
|
124
|
+
for (let [a, s, u, d] of [[
|
|
125
|
+
n - i,
|
|
126
|
+
r,
|
|
127
|
+
n + i,
|
|
128
|
+
r
|
|
129
|
+
], [
|
|
130
|
+
n,
|
|
131
|
+
r - i,
|
|
132
|
+
n,
|
|
133
|
+
r + i
|
|
134
|
+
]]) {
|
|
135
|
+
let n = t("line");
|
|
136
|
+
n.setAttribute("x1", String(a)), n.setAttribute("y1", String(s)), n.setAttribute("x2", String(u)), n.setAttribute("y2", String(d)), l(n, o, c + 1), e.appendChild(n);
|
|
137
|
+
}
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
let u = t("circle");
|
|
141
|
+
u.setAttribute("cx", String(n)), u.setAttribute("cy", String(r)), u.setAttribute("r", String(i)), u.setAttribute("fill", o), u.setAttribute("stroke", s), u.setAttribute("stroke-width", String(c)), e.appendChild(u);
|
|
142
|
+
}
|
|
143
|
+
function f(e, n, r, i, a, o) {
|
|
144
|
+
let s = m(e, n.text, r, i, "start", n.color ?? a, n.font ?? o);
|
|
145
|
+
if (n.backgroundColor) {
|
|
146
|
+
let a = t("rect");
|
|
147
|
+
a.setAttribute("x", String(r - 4)), a.setAttribute("y", String(i - 14)), a.setAttribute("width", String(Math.max(16, n.text.length * 7 + 8))), a.setAttribute("height", "18"), a.setAttribute("rx", "3"), a.setAttribute("fill", n.backgroundColor), e.insertBefore(a, s);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function p(e, t, i, a, o, s, c) {
|
|
151
|
+
let l = n(t);
|
|
152
|
+
if (!l) return;
|
|
153
|
+
let u = r(t);
|
|
154
|
+
m(e, l, i + (u.offsetX ?? 0), a + (u.offsetY ?? 0), o, u.color ?? s, u.font ?? c);
|
|
155
|
+
}
|
|
156
|
+
function m(e, n, r, i, a, o, s) {
|
|
157
|
+
let c = t("text");
|
|
158
|
+
return c.textContent = n, c.setAttribute("x", String(r)), c.setAttribute("y", String(i)), c.setAttribute("fill", o), c.setAttribute("font", s), c.setAttribute("text-anchor", a), c.setAttribute("dominant-baseline", "hanging"), c.setAttribute("paint-order", "stroke"), c.setAttribute("stroke", "rgba(0,0,0,0.45)"), c.setAttribute("stroke-width", "3"), e.appendChild(c), c;
|
|
159
|
+
}
|
|
160
|
+
//#endregion
|
|
161
|
+
export { o as annotationsPlugin };
|
|
162
|
+
|
|
163
|
+
//# sourceMappingURL=annotations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotations.js","names":[],"sources":["../../src/ui/Annotations.ts"],"sourcesContent":["import type { Chart, ChartPlugin } from \"./Chart.js\";\nimport type { SeriesYAxis } from \"../core/types.js\";\n\nexport interface AnnotationLabelOptions {\n readonly text: string;\n readonly position?: \"start\" | \"center\" | \"end\" | \"top\" | \"bottom\" | \"left\" | \"right\";\n readonly color?: string;\n readonly font?: string;\n readonly offsetX?: number;\n readonly offsetY?: number;\n}\n\nexport interface AnnotationBase {\n readonly id?: string;\n readonly visible?: boolean;\n readonly yAxis?: SeriesYAxis;\n readonly className?: string;\n readonly label?: string | AnnotationLabelOptions;\n}\n\nexport interface XLineAnnotation extends AnnotationBase {\n readonly type: \"x-line\";\n readonly x: number;\n readonly color?: string;\n readonly width?: number;\n readonly dash?: string;\n}\n\nexport interface YLineAnnotation extends AnnotationBase {\n readonly type: \"y-line\";\n readonly y: number;\n readonly color?: string;\n readonly width?: number;\n readonly dash?: string;\n}\n\nexport interface XRangeAnnotation extends AnnotationBase {\n readonly type: \"x-range\";\n readonly xMin: number;\n readonly xMax: number;\n readonly fillColor?: string;\n readonly borderColor?: string;\n readonly borderWidth?: number;\n}\n\nexport interface YRangeAnnotation extends AnnotationBase {\n readonly type: \"y-range\";\n readonly yMin: number;\n readonly yMax: number;\n readonly fillColor?: string;\n readonly borderColor?: string;\n readonly borderWidth?: number;\n}\n\nexport interface BoxAnnotation extends AnnotationBase {\n readonly type: \"box\";\n readonly xMin: number;\n readonly xMax: number;\n readonly yMin: number;\n readonly yMax: number;\n readonly fillColor?: string;\n readonly borderColor?: string;\n readonly borderWidth?: number;\n}\n\nexport interface PointAnnotation extends AnnotationBase {\n readonly type: \"point\";\n readonly x: number;\n readonly y: number;\n readonly radius?: number;\n readonly color?: string;\n readonly strokeColor?: string;\n readonly strokeWidth?: number;\n readonly shape?: \"circle\" | \"diamond\" | \"cross\";\n}\n\nexport interface LabelAnnotation extends AnnotationBase {\n readonly type: \"label\";\n readonly x: number;\n readonly y: number;\n readonly text: string;\n readonly color?: string;\n readonly font?: string;\n readonly backgroundColor?: string;\n}\n\nexport type Annotation =\n | XLineAnnotation\n | YLineAnnotation\n | XRangeAnnotation\n | YRangeAnnotation\n | BoxAnnotation\n | PointAnnotation\n | LabelAnnotation;\n\nexport interface AnnotationsPluginOptions {\n readonly annotations?: readonly Annotation[];\n readonly className?: string;\n readonly defaultColor?: string;\n readonly defaultFillColor?: string;\n readonly defaultFont?: string;\n readonly zIndex?: number;\n}\n\nexport interface AnnotationsPlugin extends ChartPlugin {\n add(annotation: Annotation): void;\n remove(id: string): boolean;\n clear(): void;\n setAnnotations(annotations: readonly Annotation[]): void;\n getAnnotations(): readonly Annotation[];\n}\n\nconst SVG_NS = \"http://www.w3.org/2000/svg\";\n\nfunction svg<K extends keyof SVGElementTagNameMap>(tag: K): SVGElementTagNameMap[K] {\n return document.createElementNS(SVG_NS, tag);\n}\n\nfunction labelText(label: string | AnnotationLabelOptions | undefined): string | null {\n if (!label) return null;\n return typeof label === \"string\" ? label : label.text;\n}\n\nfunction labelOptions(label: string | AnnotationLabelOptions | undefined): AnnotationLabelOptions {\n return typeof label === \"string\" ? { text: label } : label ?? { text: \"\" };\n}\n\nfunction clampRect(x0: number, y0: number, x1: number, y1: number, width: number, height: number): { x: number; y: number; w: number; h: number } | null {\n const left = Math.max(0, Math.min(x0, x1));\n const right = Math.min(width, Math.max(x0, x1));\n const top = Math.max(0, Math.min(y0, y1));\n const bottom = Math.min(height, Math.max(y0, y1));\n if (right <= left || bottom <= top) return null;\n return { x: left, y: top, w: right - left, h: bottom - top };\n}\n\nfunction isInsidePlot(x: number, y: number, width: number, height: number): boolean {\n return x >= 0 && x <= width && y >= 0 && y <= height;\n}\n\nexport function annotationsPlugin(options: AnnotationsPluginOptions = {}): AnnotationsPlugin {\n let annotations = [...(options.annotations ?? [])];\n let chartRef: Chart | null = null;\n let overlay: SVGSVGElement | null = null;\n const color = options.defaultColor ?? \"rgba(255,255,255,0.85)\";\n const fillColor = options.defaultFillColor ?? \"rgba(255,255,255,0.12)\";\n const font = options.defaultFont ?? \"12px system-ui, sans-serif\";\n\n const requestRender = (): void => {\n if (chartRef && overlay) render(chartRef, overlay, annotations, color, fillColor, font);\n };\n\n return {\n install(chart: Chart) {\n chartRef = chart;\n overlay = svg(\"svg\");\n overlay.classList.add(options.className ?? \"blazeplot-annotations\");\n overlay.style.position = \"absolute\";\n overlay.style.inset = \"0\";\n overlay.style.width = \"100%\";\n overlay.style.height = \"100%\";\n overlay.style.pointerEvents = \"none\";\n overlay.style.overflow = \"hidden\";\n overlay.style.zIndex = String(options.zIndex ?? 12);\n chart.plotElement.appendChild(overlay);\n const unsubscribeRender = chart.subscribe(\"render\", () => requestRender());\n requestRender();\n return () => {\n unsubscribeRender();\n overlay?.remove();\n overlay = null;\n chartRef = null;\n };\n },\n add(annotation: Annotation): void {\n annotations = [...annotations, annotation];\n requestRender();\n },\n remove(id: string): boolean {\n const next = annotations.filter((annotation) => annotation.id !== id);\n const changed = next.length !== annotations.length;\n if (changed) {\n annotations = next;\n requestRender();\n }\n return changed;\n },\n clear(): void {\n annotations = [];\n requestRender();\n },\n setAnnotations(next: readonly Annotation[]): void {\n annotations = [...next];\n requestRender();\n },\n getAnnotations(): readonly Annotation[] {\n return annotations;\n },\n };\n}\n\nfunction render(\n chart: Chart,\n overlay: SVGSVGElement,\n annotations: readonly Annotation[],\n defaultColor: string,\n defaultFillColor: string,\n defaultFont: string,\n): void {\n const width = Math.max(1, chart.canvas.clientWidth);\n const height = Math.max(1, chart.canvas.clientHeight);\n overlay.setAttribute(\"viewBox\", `0 0 ${width} ${height}`);\n overlay.replaceChildren();\n\n for (const annotation of annotations) {\n if (annotation.visible === false) continue;\n drawAnnotation(chart, overlay, annotation, width, height, defaultColor, defaultFillColor, defaultFont);\n }\n}\n\nfunction drawAnnotation(\n chart: Chart,\n overlay: SVGSVGElement,\n annotation: Annotation,\n width: number,\n height: number,\n defaultColor: string,\n defaultFillColor: string,\n defaultFont: string,\n): void {\n const viewport = chart.getViewport(annotation.yAxis ?? \"left\");\n const xToPx = (x: number): number => ((x - viewport.xMin) / (viewport.xMax - viewport.xMin)) * width;\n const yToPx = (y: number): number => ((viewport.yMax - y) / (viewport.yMax - viewport.yMin)) * height;\n const group = svg(\"g\");\n if (annotation.className) group.classList.add(annotation.className);\n\n switch (annotation.type) {\n case \"x-line\": {\n const x = xToPx(annotation.x);\n if (x < 0 || x > width) return;\n const line = svg(\"line\");\n line.setAttribute(\"x1\", String(x));\n line.setAttribute(\"x2\", String(x));\n line.setAttribute(\"y1\", \"0\");\n line.setAttribute(\"y2\", String(height));\n styleStroke(line, annotation.color ?? defaultColor, annotation.width, annotation.dash);\n group.appendChild(line);\n appendLabel(group, annotation.label, x + 4, 6, \"start\", defaultColor, defaultFont);\n break;\n }\n case \"y-line\": {\n const y = yToPx(annotation.y);\n if (y < 0 || y > height) return;\n const line = svg(\"line\");\n line.setAttribute(\"x1\", \"0\");\n line.setAttribute(\"x2\", String(width));\n line.setAttribute(\"y1\", String(y));\n line.setAttribute(\"y2\", String(y));\n styleStroke(line, annotation.color ?? defaultColor, annotation.width, annotation.dash);\n group.appendChild(line);\n appendLabel(group, annotation.label, width - 4, y - 4, \"end\", defaultColor, defaultFont);\n break;\n }\n case \"x-range\": {\n const rect = clampRect(xToPx(annotation.xMin), 0, xToPx(annotation.xMax), height, width, height);\n if (!rect) return;\n appendRect(group, rect, annotation.fillColor ?? defaultFillColor, annotation.borderColor, annotation.borderWidth);\n appendLabel(group, annotation.label, rect.x + rect.w * 0.5, 6, \"middle\", defaultColor, defaultFont);\n break;\n }\n case \"y-range\": {\n const rect = clampRect(0, yToPx(annotation.yMax), width, yToPx(annotation.yMin), width, height);\n if (!rect) return;\n appendRect(group, rect, annotation.fillColor ?? defaultFillColor, annotation.borderColor, annotation.borderWidth);\n appendLabel(group, annotation.label, width - 4, rect.y + rect.h * 0.5, \"end\", defaultColor, defaultFont);\n break;\n }\n case \"box\": {\n const rect = clampRect(xToPx(annotation.xMin), yToPx(annotation.yMax), xToPx(annotation.xMax), yToPx(annotation.yMin), width, height);\n if (!rect) return;\n appendRect(group, rect, annotation.fillColor ?? defaultFillColor, annotation.borderColor, annotation.borderWidth);\n appendLabel(group, annotation.label, rect.x + rect.w * 0.5, rect.y + 6, \"middle\", defaultColor, defaultFont);\n break;\n }\n case \"point\": {\n const x = xToPx(annotation.x);\n const y = yToPx(annotation.y);\n const radius = annotation.radius ?? 5;\n if (!isInsidePlot(x, y, width, height)) return;\n appendMarker(group, x, y, radius, annotation);\n appendLabel(group, annotation.label, x + radius + 4, y - radius - 2, \"start\", defaultColor, defaultFont);\n break;\n }\n case \"label\": {\n const x = xToPx(annotation.x);\n const y = yToPx(annotation.y);\n if (!isInsidePlot(x, y, width, height)) return;\n appendStandaloneLabel(group, annotation, x, y, defaultColor, defaultFont);\n break;\n }\n }\n\n overlay.appendChild(group);\n}\n\nfunction styleStroke(el: SVGElement, color: string, width: number = 1, dash?: string): void {\n el.setAttribute(\"stroke\", color);\n el.setAttribute(\"stroke-width\", String(width));\n el.setAttribute(\"fill\", \"none\");\n if (dash) el.setAttribute(\"stroke-dasharray\", dash);\n}\n\nfunction appendRect(group: SVGGElement, rect: { x: number; y: number; w: number; h: number }, fill: string, stroke?: string, strokeWidth: number = 0): void {\n const el = svg(\"rect\");\n el.setAttribute(\"x\", String(rect.x));\n el.setAttribute(\"y\", String(rect.y));\n el.setAttribute(\"width\", String(rect.w));\n el.setAttribute(\"height\", String(rect.h));\n el.setAttribute(\"fill\", fill);\n if (stroke) {\n el.setAttribute(\"stroke\", stroke);\n el.setAttribute(\"stroke-width\", String(strokeWidth || 1));\n }\n group.appendChild(el);\n}\n\nfunction appendMarker(group: SVGGElement, x: number, y: number, radius: number, annotation: PointAnnotation): void {\n const fill = annotation.color ?? \"rgba(255,255,255,0.95)\";\n const stroke = annotation.strokeColor ?? \"rgba(0,0,0,0.35)\";\n const strokeWidth = annotation.strokeWidth ?? 1;\n if (annotation.shape === \"diamond\") {\n const polygon = svg(\"polygon\");\n polygon.setAttribute(\"points\", `${x},${y - radius} ${x + radius},${y} ${x},${y + radius} ${x - radius},${y}`);\n polygon.setAttribute(\"fill\", fill);\n polygon.setAttribute(\"stroke\", stroke);\n polygon.setAttribute(\"stroke-width\", String(strokeWidth));\n group.appendChild(polygon);\n return;\n }\n\n if (annotation.shape === \"cross\") {\n for (const [x1, y1, x2, y2] of [[x - radius, y, x + radius, y], [x, y - radius, x, y + radius]] as const) {\n const line = svg(\"line\");\n line.setAttribute(\"x1\", String(x1));\n line.setAttribute(\"y1\", String(y1));\n line.setAttribute(\"x2\", String(x2));\n line.setAttribute(\"y2\", String(y2));\n styleStroke(line, fill, strokeWidth + 1);\n group.appendChild(line);\n }\n return;\n }\n\n const circle = svg(\"circle\");\n circle.setAttribute(\"cx\", String(x));\n circle.setAttribute(\"cy\", String(y));\n circle.setAttribute(\"r\", String(radius));\n circle.setAttribute(\"fill\", fill);\n circle.setAttribute(\"stroke\", stroke);\n circle.setAttribute(\"stroke-width\", String(strokeWidth));\n group.appendChild(circle);\n}\n\nfunction appendStandaloneLabel(group: SVGGElement, annotation: LabelAnnotation, x: number, y: number, defaultColor: string, defaultFont: string): void {\n const text = appendText(group, annotation.text, x, y, \"start\", annotation.color ?? defaultColor, annotation.font ?? defaultFont);\n if (annotation.backgroundColor) {\n const rect = svg(\"rect\");\n rect.setAttribute(\"x\", String(x - 4));\n rect.setAttribute(\"y\", String(y - 14));\n rect.setAttribute(\"width\", String(Math.max(16, annotation.text.length * 7 + 8)));\n rect.setAttribute(\"height\", \"18\");\n rect.setAttribute(\"rx\", \"3\");\n rect.setAttribute(\"fill\", annotation.backgroundColor);\n group.insertBefore(rect, text);\n }\n}\n\nfunction appendLabel(group: SVGGElement, label: string | AnnotationLabelOptions | undefined, x: number, y: number, anchor: \"start\" | \"middle\" | \"end\", defaultColor: string, defaultFont: string): void {\n const textValue = labelText(label);\n if (!textValue) return;\n const opts = labelOptions(label);\n appendText(group, textValue, x + (opts.offsetX ?? 0), y + (opts.offsetY ?? 0), anchor, opts.color ?? defaultColor, opts.font ?? defaultFont);\n}\n\nfunction appendText(group: SVGGElement, textValue: string, x: number, y: number, anchor: \"start\" | \"middle\" | \"end\", color: string, font: string): SVGTextElement {\n const text = svg(\"text\");\n text.textContent = textValue;\n text.setAttribute(\"x\", String(x));\n text.setAttribute(\"y\", String(y));\n text.setAttribute(\"fill\", color);\n text.setAttribute(\"font\", font);\n text.setAttribute(\"text-anchor\", anchor);\n text.setAttribute(\"dominant-baseline\", \"hanging\");\n text.setAttribute(\"paint-order\", \"stroke\");\n text.setAttribute(\"stroke\", \"rgba(0,0,0,0.45)\");\n text.setAttribute(\"stroke-width\", \"3\");\n group.appendChild(text);\n return text;\n}\n"],"mappings":";AAgHA,IAAM,IAAS;AAEf,SAAS,EAA0C,GAAiC;CAClF,OAAO,SAAS,gBAAgB,GAAQ,CAAG;AAC7C;AAEA,SAAS,EAAU,GAAmE;CAEpF,OADK,IACE,OAAO,KAAU,WAAW,IAAQ,EAAM,OAD9B;AAErB;AAEA,SA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D,GAAW,GAAW,GAAoC,GAAsB,GAA2B;CACtM,IAAM,IAAY,EAAU,CAAK;CACjC,IAAI,CAAC,GAAW;CAChB,IAAM,IAAO,EAAa,CAAK;CAC/B,EAAW,GAAO,GAAW,KAAK,EAAK,WAAW,IAAI,KAAK,EAAK,WAAW,IAAI,GAAQ,EAAK,SAAS,GAAc,EAAK,QAAQ,CAAW;AAC7I;AAEA,SAAS,EAAW,GAAoB,GAAmB,GAAW,GAAW,GAAoC,GAAe,GAA8B;CAChK,IAAM,IAAO,EAAI,MAAM;CAYvB,OAXA,EAAK,cAAc,GACnB,EAAK,aAAa,KAAK,OAAO,CAAC,CAAC,GAChC,EAAK,aAAa,KAAK,OAAO,CAAC,CAAC,GAChC,EAAK,aAAa,QAAQ,CAAK,GAC/B,EAAK,aAAa,QAAQ,CAAI,GAC9B,EAAK,aAAa,eAAe,CAAM,GACvC,EAAK,aAAa,qBAAqB,SAAS,GAChD,EAAK,aAAa,eAAe,QAAQ,GACzC,EAAK,aAAa,UAAU,kBAAkB,GAC9C,EAAK,aAAa,gBAAgB,GAAG,GACrC,EAAM,YAAY,CAAI,GACf;AACT"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { crosshairPlugin } from '../ui/Crosshair.js';
|
|
2
|
+
export type { CrosshairAxis, CrosshairEventType, CrosshairMode, CrosshairPlugin, CrosshairPluginOptions, CrosshairPosition, CrosshairSnapMode, RulerMeasurement } from '../ui/Crosshair.js';
|
|
3
|
+
//# sourceMappingURL=crosshair.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crosshair.d.ts","sourceRoot":"","sources":["../../src/plugins/crosshair.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,aAAa,EAAE,eAAe,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { a as e, i as t, n, t as r } from "../OverlayUtils-Cw1o8UH-.js";
|
|
2
|
+
//#region src/ui/Crosshair.ts
|
|
3
|
+
var i = /* @__PURE__ */ new Map();
|
|
4
|
+
function a(e, t, n) {
|
|
5
|
+
let r = {
|
|
6
|
+
xMin: t,
|
|
7
|
+
xMax: n,
|
|
8
|
+
yMin: -Infinity,
|
|
9
|
+
yMax: Infinity
|
|
10
|
+
}, i = 0;
|
|
11
|
+
for (let t of e.getSeriesState()) {
|
|
12
|
+
if (!t.visible) continue;
|
|
13
|
+
let e = t.series.visibleIndexRange(r);
|
|
14
|
+
i += Math.max(0, e.end - e.start);
|
|
15
|
+
}
|
|
16
|
+
return i;
|
|
17
|
+
}
|
|
18
|
+
function o(e, t) {
|
|
19
|
+
return !t || t === "none" ? !0 : t === "ctrl" ? e.ctrlKey : t === "shift" ? e.shiftKey : t === "alt" ? e.altKey : e.metaKey;
|
|
20
|
+
}
|
|
21
|
+
function s(e, t, n, r) {
|
|
22
|
+
let i = e.pick(t, n, {
|
|
23
|
+
mode: r,
|
|
24
|
+
group: "none"
|
|
25
|
+
})?.items[0];
|
|
26
|
+
return i ? {
|
|
27
|
+
dataX: i.x,
|
|
28
|
+
dataY: i.y,
|
|
29
|
+
plotX: i.plotX,
|
|
30
|
+
plotY: i.plotY,
|
|
31
|
+
items: [i]
|
|
32
|
+
} : null;
|
|
33
|
+
}
|
|
34
|
+
function c(e, t, n, r, i) {
|
|
35
|
+
let a = e.canvas.getBoundingClientRect();
|
|
36
|
+
if (a.width <= 0 || a.height <= 0) return null;
|
|
37
|
+
let o = i === "nearest-point" ? "nearest-point" : "nearest-x";
|
|
38
|
+
if (i !== "none") {
|
|
39
|
+
let r = s(e, t, n, o);
|
|
40
|
+
if (r) return r;
|
|
41
|
+
}
|
|
42
|
+
let c = e.clientToData(t, n, r);
|
|
43
|
+
if (!c) return null;
|
|
44
|
+
let [l, u] = e.dataToPlot(c[0], c[1], r);
|
|
45
|
+
return {
|
|
46
|
+
dataX: c[0],
|
|
47
|
+
dataY: c[1],
|
|
48
|
+
plotX: l,
|
|
49
|
+
plotY: u,
|
|
50
|
+
items: []
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function l(e, t, n) {
|
|
54
|
+
let r = e.canvas.getBoundingClientRect();
|
|
55
|
+
if (r.width <= 0 || r.height <= 0) return null;
|
|
56
|
+
let i = e.getViewport(n), a = i.yMin + (i.yMax - i.yMin) * .5, [o, c] = e.dataToPlot(t, a, n);
|
|
57
|
+
return s(e, r.left + o, r.top + c, "nearest-x") || {
|
|
58
|
+
dataX: t,
|
|
59
|
+
dataY: a,
|
|
60
|
+
plotX: o,
|
|
61
|
+
plotY: c,
|
|
62
|
+
items: []
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function u(e, n, r, i, a) {
|
|
66
|
+
if (e.items.length === 0) {
|
|
67
|
+
n.textContent = `x ${r(e.dataX)} y ${i(e.dataY)}`;
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
t(n, e.items, e, a, (e) => `(${r(e.x)}, ${i(e.y)})`);
|
|
71
|
+
}
|
|
72
|
+
function d(t = {}) {
|
|
73
|
+
let s = t.axis ?? "xy", d = t.yAxis ?? "left", f = t.snap ?? "none", p = t.mode ?? "crosshair", m = t.rulerModifier ?? "none", h = null, g = null, _ = null, v = null, y = null, b = null, x = null, S = null, C = null, w = t.formatX ?? r, T = t.formatY ?? r, E = null, D = null, O = /* @__PURE__ */ new Set(), k = /* @__PURE__ */ new Set(), A = /* @__PURE__ */ new Set(), j = /* @__PURE__ */ new Set(), M = (e) => {
|
|
74
|
+
g && (g.style.display = e ? "block" : "none");
|
|
75
|
+
}, N = (e) => {
|
|
76
|
+
E = e, t.onMove?.(e);
|
|
77
|
+
for (let t of O) t(e);
|
|
78
|
+
}, P = (e) => {
|
|
79
|
+
t.onMeasureStart?.(e);
|
|
80
|
+
for (let t of k) t(e);
|
|
81
|
+
}, F = (e) => {
|
|
82
|
+
D = e, t.onMeasureChange?.(e);
|
|
83
|
+
for (let t of A) t(e);
|
|
84
|
+
}, I = (e) => {
|
|
85
|
+
D = e, t.onMeasureEnd?.(e), t.onMeasure?.(e);
|
|
86
|
+
for (let t of j) t(e);
|
|
87
|
+
}, L = (e) => {
|
|
88
|
+
let t = h;
|
|
89
|
+
!t || !b || n(b, e.plotX, e.plotY, t.canvas.clientWidth, t.canvas.clientHeight, {
|
|
90
|
+
offsetX: 12,
|
|
91
|
+
offsetY: 12
|
|
92
|
+
});
|
|
93
|
+
}, R = (n) => {
|
|
94
|
+
if (!y || (y.replaceChildren(), t.highlight === !1 || !n)) return;
|
|
95
|
+
let r = Math.max(2, t.markerSize ?? 10), i = Math.max(0, t.markerStrokeWidth ?? 2);
|
|
96
|
+
for (let a of n.items) {
|
|
97
|
+
let n = document.createElement("div");
|
|
98
|
+
n.style.position = "absolute", n.style.left = `${a.plotX}px`, n.style.top = `${a.plotY}px`, n.style.width = `${r}px`, n.style.height = `${r}px`, n.style.border = `${i}px solid ${t.markerStrokeColor ?? "#f8fafc"}`, n.style.borderRadius = "999px", n.style.background = e(a.series.style.color), n.style.boxShadow = "0 0 0 1px rgba(4, 8, 16, 0.85)", n.style.transform = "translate(-50%, -50%)", y.appendChild(n);
|
|
99
|
+
}
|
|
100
|
+
}, z = (e) => {
|
|
101
|
+
if (R(e), !e || !g || !_ || !v || !b) {
|
|
102
|
+
M(!1);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
M(!0), _.style.display = s === "y" ? "none" : "block", v.style.display = s === "x" ? "none" : "block", _.style.left = `${e.plotX}px`, v.style.top = `${e.plotY}px`, t.label === !1 ? b.style.display = "none" : (b.style.display = "block", t.render ? t.render(e, b, h) : u(e, b, w, T, t.formatter), L(e));
|
|
106
|
+
}, B = (e, t, n) => {
|
|
107
|
+
let r = t.dataX - e.dataX, i = t.dataY - e.dataY;
|
|
108
|
+
return {
|
|
109
|
+
start: e,
|
|
110
|
+
end: t,
|
|
111
|
+
deltaX: r,
|
|
112
|
+
deltaY: i,
|
|
113
|
+
slope: r === 0 ? Infinity : i / r,
|
|
114
|
+
sampleCount: a(n, Math.min(e.dataX, t.dataX), Math.max(e.dataX, t.dataX))
|
|
115
|
+
};
|
|
116
|
+
}, V = (e) => {
|
|
117
|
+
let t = h;
|
|
118
|
+
!t || !x || !S || !C || !e || (x.style.display = "block", S.setAttribute("x1", String(C.plotX)), S.setAttribute("y1", String(C.plotY)), S.setAttribute("x2", String(e.plotX)), S.setAttribute("y2", String(e.plotY)), F(B(C, e, t)));
|
|
119
|
+
}, H = (e) => {
|
|
120
|
+
if (!(!t.group || !W)) for (let n of i.get(t.group) ?? []) n !== W && n.showShared(e.dataX, W);
|
|
121
|
+
}, U = () => {
|
|
122
|
+
if (!(!t.group || !W)) for (let e of i.get(t.group) ?? []) e !== W && e.hideShared(W);
|
|
123
|
+
}, W = {
|
|
124
|
+
showShared(e, t) {
|
|
125
|
+
if (t === W || !h) return;
|
|
126
|
+
let n = l(h, e, d);
|
|
127
|
+
z(n), N(n);
|
|
128
|
+
},
|
|
129
|
+
hideShared(e) {
|
|
130
|
+
e !== W && (z(null), N(null));
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
return {
|
|
134
|
+
install(e) {
|
|
135
|
+
h = e;
|
|
136
|
+
let n = t.color ?? "rgba(148, 163, 184, 0.55)", r = `${t.width ?? 1}px`, a = t.dash;
|
|
137
|
+
if (g = document.createElement("div"), g.className = "blazeplot-crosshair", g.style.position = "absolute", g.style.inset = "0", g.style.display = "none", g.style.pointerEvents = "none", g.style.zIndex = String(t.zIndex ?? 1e4), _ = document.createElement("div"), _.style.position = "absolute", _.style.top = "0", _.style.bottom = "0", _.style.zIndex = "1", _.style.borderLeft = `${r} solid ${n}`, a && (_.style.borderLeftStyle = "dashed"), v = document.createElement("div"), v.style.position = "absolute", v.style.left = "0", v.style.right = "0", v.style.zIndex = "1", v.style.borderTop = `${r} solid ${n}`, a && (v.style.borderTopStyle = "dashed"), y = document.createElement("div"), y.className = "blazeplot-crosshair-markers", y.style.position = "absolute", y.style.inset = "0", y.style.zIndex = "2", y.style.pointerEvents = "none", b = document.createElement("div"), b.style.position = "absolute", b.style.zIndex = "3", b.style.padding = "4px 6px", b.style.borderRadius = "3px", b.style.background = t.labelBackground ?? e.theme.tooltipBackgroundColor, b.style.color = t.labelColor ?? e.theme.tooltipTextColor, b.style.font = t.labelFont ?? e.theme.tooltipFont, b.style.whiteSpace = "nowrap", x = document.createElementNS("http://www.w3.org/2000/svg", "svg"), x.style.position = "absolute", x.style.inset = "0", x.style.width = "100%", x.style.height = "100%", x.style.display = "none", x.style.overflow = "hidden", x.style.zIndex = "1", S = document.createElementNS("http://www.w3.org/2000/svg", "line"), S.setAttribute("stroke", n), S.setAttribute("stroke-width", String(t.width ?? 1)), a && S.setAttribute("stroke-dasharray", a), x.appendChild(S), g.appendChild(_), g.appendChild(v), g.appendChild(x), g.appendChild(y), g.appendChild(b), e.plotElement.appendChild(g), t.group) {
|
|
138
|
+
let e = i.get(t.group) ?? /* @__PURE__ */ new Set();
|
|
139
|
+
e.add(W), i.set(t.group, e);
|
|
140
|
+
}
|
|
141
|
+
let s = (t) => {
|
|
142
|
+
let n = c(e, t.clientX, t.clientY, d, f);
|
|
143
|
+
z(n), N(n), n && H(n), p === "ruler" && V(n);
|
|
144
|
+
}, l = () => {
|
|
145
|
+
C || z(null), N(null), U();
|
|
146
|
+
}, u = (t) => {
|
|
147
|
+
p !== "ruler" || t.button !== 0 || !o(t, m) || (C = c(e, t.clientX, t.clientY, d, f), C && (P(C), t.preventDefault(), t.stopImmediatePropagation()));
|
|
148
|
+
}, w = (t) => {
|
|
149
|
+
if (p !== "ruler" || !C) return;
|
|
150
|
+
t.stopImmediatePropagation();
|
|
151
|
+
let n = c(e, t.clientX, t.clientY, d, f);
|
|
152
|
+
n && (I(B(C, n, e)), C = null);
|
|
153
|
+
};
|
|
154
|
+
return e.canvas.addEventListener("pointermove", s), e.canvas.addEventListener("pointerleave", l), e.canvas.addEventListener("pointerdown", u, { capture: !0 }), e.canvas.addEventListener("pointerup", w, { capture: !0 }), () => {
|
|
155
|
+
if (e.canvas.removeEventListener("pointermove", s), e.canvas.removeEventListener("pointerleave", l), e.canvas.removeEventListener("pointerdown", u, { capture: !0 }), e.canvas.removeEventListener("pointerup", w, { capture: !0 }), t.group) {
|
|
156
|
+
let e = i.get(t.group);
|
|
157
|
+
e?.delete(W), e?.size === 0 && i.delete(t.group);
|
|
158
|
+
}
|
|
159
|
+
g?.remove(), g = null, _ = null, v = null, y = null, b = null, x = null, S = null, C = null, h = null;
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
getPosition() {
|
|
163
|
+
return E;
|
|
164
|
+
},
|
|
165
|
+
getMeasurement() {
|
|
166
|
+
return D;
|
|
167
|
+
},
|
|
168
|
+
clearMeasurement() {
|
|
169
|
+
D = null, C = null, x && (x.style.display = "none");
|
|
170
|
+
},
|
|
171
|
+
subscribe(e, t) {
|
|
172
|
+
if (e === "move") {
|
|
173
|
+
let e = t;
|
|
174
|
+
return O.add(e), () => O.delete(e);
|
|
175
|
+
}
|
|
176
|
+
if (e === "measurestart") {
|
|
177
|
+
let e = t;
|
|
178
|
+
return k.add(e), () => k.delete(e);
|
|
179
|
+
}
|
|
180
|
+
if (e === "measurechange") {
|
|
181
|
+
let e = t;
|
|
182
|
+
return A.add(e), () => A.delete(e);
|
|
183
|
+
}
|
|
184
|
+
let n = t;
|
|
185
|
+
return j.add(n), () => j.delete(n);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
//#endregion
|
|
190
|
+
export { d as crosshairPlugin };
|
|
191
|
+
|
|
192
|
+
//# sourceMappingURL=crosshair.js.map
|