ml-time-graph 1.9.1 → 1.11.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.
@@ -1,432 +0,0 @@
1
- import { D as DrawCommand, L as LineVariant, P as PointStyleType, a3 as DrawGroup, j as AggregatedPoint, d as TimeScale, e as LinearScale, l as DataPoint } from './scale-CQhADkWB.js';
2
-
3
- /** Output format type for the renderer (SVG string, Canvas, or nothing). */
4
- type RenderType = "svg" | "canvas" | "none";
5
-
6
- /*!
7
- * MLTimeGraph — Copyright (c) 2026 Michael Lechner
8
- * MIT with Attribution: free use incl. commercial requires visible credit to
9
- * "Michael Lechner". Commercial license (no attribution) on request. See LICENSE.
10
- */
11
-
12
- /** Renderer-Output */
13
- interface RenderOutput {
14
- type: RenderType;
15
- content: string;
16
- }
17
-
18
- /*!
19
- * MLTimeGraph — Copyright (c) 2026 Michael Lechner
20
- * MIT with Attribution: free use incl. commercial requires visible credit to
21
- * "Michael Lechner". Commercial license (no attribution) on request. See LICENSE.
22
- */
23
-
24
- /**
25
- * Abstract renderer — the chart logic never knows rendering details. It emits
26
- * `DrawCommand[]`, a renderer turns those into output.
27
- *
28
- * The shipped {@link SVGRenderer} produces a DOM-free SVG string (works in the
29
- * browser and on the server). For DOM-specific behaviour, extend SVGRenderer.
30
- */
31
- declare abstract class Renderer {
32
- abstract render(commands: DrawCommand[]): RenderOutput;
33
- }
34
-
35
- /*!
36
- * MLTimeGraph — Copyright (c) 2026 Michael Lechner
37
- * MIT with Attribution: free use incl. commercial requires visible credit to
38
- * "Michael Lechner". Commercial license (no attribution) on request. See LICENSE.
39
- */
40
- /**
41
- * Central defaults for the entire library.
42
- * Override individual values or mutate `theme` to restyle the chart globally.
43
- */
44
- declare const theme: {
45
- /**
46
- * Schriftstapel fuer jeden Text im Diagramm.
47
- *
48
- * Metrikkompatibel gewaehlt, nicht nach Aussehen: Liberation Sans hat
49
- * dieselben Vorschubbreiten wie Arial. Linux landet auf Liberation, Windows
50
- * und macOS auf Arial bzw. Helvetica -- die Beschriftungen brauchen ueberall
51
- * denselben Platz. DejaVu Sans waere deutlich breiter.
52
- */
53
- readonly fontFamily: "Liberation Sans, Arial, Helvetica, sans-serif";
54
- /** Default stroke color for series lines */
55
- readonly stroke: "#4285f4";
56
- /** Default line width in pixels */
57
- readonly strokeWidth: 2;
58
- /** Default point marker size (radius / half-width) */
59
- readonly pointSize: 4;
60
- /** Max data points before point markers are suppressed */
61
- readonly pointThreshold: 100;
62
- /** Default max time gap (ms) before the line breaks; 0 = off */
63
- readonly gapThreshold: 0;
64
- /** Default series type */
65
- readonly fill: "none";
66
- readonly hatch: null;
67
- /** Default band fill color */
68
- readonly bandFill: "#4285f4";
69
- /** Default band opacity (when countOpacity is disabled) */
70
- readonly bandOpacity: 0.6;
71
- /** Default avg line color for bands */
72
- readonly bandAvgLine: "#e53e3e";
73
- /** Default min color for minmaxavg series */
74
- readonly minColor: "#3b82f6";
75
- /** Default max color for minmaxavg series */
76
- readonly maxColor: "#ef4444";
77
- /** Default avg color for minmaxavg series */
78
- readonly avgColor: "#64748b";
79
- /** Area fill alpha suffix (hex) for zoned areas — default 20% opacity */
80
- readonly areaFillAlpha: "4285f433";
81
- /** Default axis baseline color */
82
- readonly axisColor: "#ccc";
83
- /** Default tick mark color */
84
- readonly tickColor: "#ddd";
85
- /** Default axis label text color */
86
- readonly textColor: "#777";
87
- /** Default axis text size (axis labels, tick labels) */
88
- readonly textSize: 11;
89
- /** Axis label (rotated title next to axis) fill color */
90
- readonly axisLabelColor: "#444";
91
- /** Axis label font size */
92
- readonly axisLabelSize: 12;
93
- /** Default grid line stroke */
94
- readonly gridStroke: "#e2e8f0";
95
- /** Default grid line stroke width */
96
- readonly gridStrokeWidth: 1;
97
- /** Default grid opacity */
98
- readonly gridOpacity: 1;
99
- /** Legend swatch stroke */
100
- readonly legendStroke: "#ccc";
101
- /** Legend text fill */
102
- readonly legendText: "#333";
103
- /** Legend font size */
104
- readonly legendFont: 11;
105
- /** Default annotation color */
106
- readonly annotationColor: "#334155";
107
- /** Default annotation line width */
108
- readonly annotationWidth: 1.5;
109
- /** Default annotation arrow head size */
110
- readonly annotationHead: 9;
111
- /** Default annotation point radius */
112
- readonly annotationRadius: 4;
113
- /** Default annotation text font size */
114
- readonly annotationFontSize: 11;
115
- /** Default threshold line color */
116
- readonly thresholdColor: "#666";
117
- /** Default threshold line style */
118
- readonly thresholdLine: "dashed";
119
- /** Default threshold fill opacity */
120
- readonly thresholdFillOpacity: 0.12;
121
- /** Default threshold label font size */
122
- readonly thresholdFontSize: 10;
123
- /** Default highlight fill color */
124
- readonly highlightColor: "#fbbf24";
125
- /** Default highlight box opacity */
126
- readonly highlightOpacity: 0.2;
127
- /** Default highlight label text color */
128
- readonly highlightLabelColor: "#92400e";
129
- /** Default marker color */
130
- readonly markerColor: "#f59e0b";
131
- /** Default marker point size (cross / circle radius) */
132
- readonly markerSize: 5;
133
- /** Gap region background fill */
134
- readonly gapFill: "#fff";
135
- /** Gap border stroke */
136
- readonly gapStroke: "#ccc";
137
- /** Gap border stroke width */
138
- readonly gapStrokeWidth: 1;
139
- /** Gap label text color */
140
- readonly gapFontColor: "#999";
141
- /** Gap label font size */
142
- readonly gapFontSize: 10;
143
- readonly gapFillOpacity: 0.15;
144
- /** Tooltip box background */
145
- readonly tooltipBg: "#fff";
146
- /** Tooltip border */
147
- readonly tooltipBorder: "#cbd5e1";
148
- /** Tooltip text color */
149
- readonly tooltipText: "#1e293b";
150
- /** Tooltip value label color */
151
- readonly tooltipValue: "#3b82f6";
152
- /** Tooltip crosshair stroke */
153
- readonly tooltipCrosshair: "#94a3b8";
154
- /** Tooltip snap radius in pixels */
155
- readonly tooltipSnapRadius: 20;
156
- /** Stats overlay line color */
157
- readonly statsLineColor: "#94a3b8";
158
- /** Stats label color */
159
- readonly statsLabelColor: "#64748b";
160
- /** Minimap overview line stroke */
161
- readonly minimapStroke: "#94a3b8";
162
- /** Minimap background */
163
- readonly minimapBg: "#f8f9fa";
164
- /** Minimap brush (viewport) fill */
165
- readonly minimapBrush: "#3b82f644";
166
- /** Default colour palette for enum categories and multi-series. */
167
- readonly palette: readonly ["#4285f4", "#ea4335", "#22c55e", "#fbbc05", "#9334ea", "#12b5e5", "#fb923c", "#6366f1"];
168
- };
169
-
170
- /*!
171
- * MLTimeGraph — Copyright (c) 2026 Michael Lechner
172
- * MIT with Attribution: free use incl. commercial requires visible credit to
173
- * "Michael Lechner". Commercial license (no attribution) on request. See LICENSE.
174
- */
175
-
176
- /** The Theme type — same shape as the immutable BUILTIN_DEFAULTS object. */
177
- type Theme = typeof theme;
178
- /**
179
- * Apply a partial override on top of the current global default theme.
180
- * Merged shallowly — nested objects (e.g. {@link Theme.palette}) are replaced
181
- * wholesale, not deep-merged.
182
- *
183
- * @example
184
- * setDefaultTheme({ stroke: '#0f172a', gridStroke: '#f1f5f9' });
185
- * new MLTimeGraph({ ... }); // picks up the new defaults
186
- */
187
- declare function setDefaultTheme(partial: Partial<Theme>): void;
188
- /**
189
- * Read the current global default theme (a snapshot — mutating the result
190
- * does NOT affect future reads).
191
- */
192
- declare function getDefaultTheme(): Readonly<Theme>;
193
- /**
194
- * Restore the global default theme to the library's built-in values
195
- * (`BUILTIN_DEFAULTS` from {@link ./defaults.ts}). Useful in test
196
- * `afterEach` hooks and when you want to undo a previous `setDefaultTheme`.
197
- */
198
- declare function resetDefaultTheme(): void;
199
-
200
- /*!
201
- * MLTimeGraph — Copyright (c) 2026 Michael Lechner
202
- * MIT with Attribution: free use incl. commercial requires visible credit to
203
- * "Michael Lechner". Commercial license (no attribution) on request. See LICENSE.
204
- */
205
-
206
- /** Single legend entry with series name and color swatch. */
207
- interface LegendItem {
208
- name: string;
209
- color: string;
210
- /**
211
- * The series' line variant, for a caller drawing its own legend: the swatch
212
- * has to show the same dashes as the curve it names, or it is wrong the moment
213
- * two series differ by anything but colour — a black-and-white print.
214
- * Undefined for a series with several lines (no single answer) or none.
215
- * Turn it into SVG attributes with `getLineStyle()`.
216
- */
217
- line?: LineVariant;
218
- /**
219
- * The marker shape — but only when markers are actually drawn. A series with
220
- * `markers.threshold` hides them above that many samples, and a symbol in the
221
- * legend that is missing from the chart states something untrue.
222
- * Draw it with `drawMarker()`.
223
- */
224
- marker?: Exclude<PointStyleType, "none">;
225
- }
226
- /** Layout direction for legend items. */
227
- type LegendOrientation = "vertical" | "horizontal";
228
- /** Configuration for legend rendering including items, position, and orientation. */
229
- interface LegendConfig {
230
- items: LegendItem[];
231
- /** Top-left pixel position. */
232
- x: number;
233
- y: number;
234
- /** Stack items vertically (default) or lay them in a row. */
235
- orientation?: LegendOrientation;
236
- }
237
- /** Estimated pixel size of the legend box (for layout reservation). */
238
- declare function measureLegend(items: LegendItem[], orientation?: LegendOrientation): {
239
- width: number;
240
- height: number;
241
- };
242
- /** Render a legend (swatch + label per item) as a single group of commands. */
243
- declare function renderLegend(config: LegendConfig): DrawGroup;
244
-
245
- /** Vertical marker on the chart: point circle, full-height line, or label at a specific time. */
246
- interface Marker {
247
- time: number;
248
- value?: number;
249
- label?: string;
250
- color?: string;
251
- pointStyle?: PointStyleType;
252
- lineStyle?: "full" | "to-value" | "to-top" | "none";
253
- seriesIndex?: number;
254
- }
255
-
256
- /*!
257
- * MLTimeGraph — Copyright (c) 2026 Michael Lechner
258
- * MIT with Attribution: free use incl. commercial requires visible credit to
259
- * "Michael Lechner". Commercial license (no attribution) on request. See LICENSE.
260
- */
261
- /** Layout configuration: dimensions, margins, and padding for the chart. */
262
- interface LayoutConfig {
263
- /** Total dimensions */
264
- width: number;
265
- height: number;
266
- /** Margins (in pixels) */
267
- margin: {
268
- top: number;
269
- right: number;
270
- bottom: number;
271
- left: number;
272
- };
273
- }
274
- /** Computed layout result with chart area dimensions and offsets. */
275
- interface LayoutResult {
276
- /** Total width */
277
- totalWidth: number;
278
- /** Total height */
279
- totalHeight: number;
280
- /** Chart content area width (excluding margins) */
281
- chartWidth: number;
282
- /** Chart content area height (excluding margins) */
283
- chartHeight: number;
284
- /** Pixel X offset of chart area */
285
- chartX: number;
286
- /** Pixel Y offset of chart area */
287
- chartY: number;
288
- /** Margins used */
289
- margin: LayoutConfig["margin"];
290
- }
291
- declare class Layout {
292
- readonly _config: LayoutConfig;
293
- constructor(config: LayoutConfig);
294
- /** Calculate layout dimensions */
295
- compute(): LayoutResult;
296
- /** Default layout for standard charts */
297
- static default(width?: number, height?: number): Layout;
298
- }
299
-
300
- /*!
301
- * MLTimeGraph — Copyright (c) 2026 Michael Lechner
302
- * MIT with Attribution: free use incl. commercial requires visible credit to
303
- * "Michael Lechner". Commercial license (no attribution) on request. See LICENSE.
304
- */
305
-
306
- /**
307
- * Flat style configuration for series rendering.
308
- * All fields are optional — defaults are applied internally via `resolveStyle()`.
309
- */
310
- interface SeriesStyle {
311
- /** Stroke color. */
312
- stroke?: string;
313
- /** Stroke width in pixels. */
314
- strokeWidth?: number;
315
- /** Enable Catmull-Rom smoothing. */
316
- smoothing?: boolean;
317
- /** Enable dashed line style. */
318
- dashed?: boolean;
319
- /** Fill colour (hex, rgba, or `url(#gradient-id)`). */
320
- fill?: string;
321
- /** Hatch pattern for fill (default: none). */
322
- hatch?: string;
323
- /** Data-point marker style. */
324
- pointStyle?: PointStyleType;
325
- /** Marker size (radius or half-width). */
326
- pointSize?: number;
327
- /** Marker outline colour. Default: same as the line's stroke (per-point). */
328
- pointStroke?: string;
329
- /** Marker fill colour. Default: same as the line's stroke. */
330
- pointFill?: string;
331
- /** Marker outline width. Default: 1.5. */
332
- pointStrokeWidth?: number;
333
- /** Shadow color. */
334
- shadowColor?: string;
335
- /** Shadow blur in pixels. */
336
- shadowBlur?: number;
337
- /** Shadow X offset. */
338
- shadowOffsetX?: number;
339
- /** Shadow Y offset. */
340
- shadowOffsetY?: number;
341
- /** SVG id prefix for all elements generated by this style. */
342
- id?: string;
343
- }
344
- interface RenderingContext {
345
- timeScale: TimeScale;
346
- valueScale: LinearScale;
347
- }
348
- /** Render segments as continuous lines (standard or smoothed). */
349
- declare function renderLine(segments: {
350
- data: DataPoint[];
351
- color?: string;
352
- }[], ctx: RenderingContext, style: SeriesStyle): DrawCommand[];
353
- /** Render segments as step-functions. */
354
- /**
355
- * Punktfolge einer Treppe: vor jeden Punkt kommt die Ecke auf seiner X- und
356
- * der vorigen Y-Hoehe. Steht hier und nicht nur in renderStep, weil
357
- * MLTimeGraph seine Pfade selbst zusammenbaut und `style.line.shape: "step"`
358
- * sonst wirkungslos bliebe -- so war es bis hierher.
359
- */
360
- declare function toStepPoints(pts: {
361
- x: number;
362
- y: number;
363
- }[]): {
364
- x: number;
365
- y: number;
366
- }[];
367
- /**
368
- * Dieselbe Treppe, aber im *Daten*raum: vor jeden Punkt kommt ein Punkt auf
369
- * seiner Zeit und dem vorigen Wert. Erst damit wird die Stufe zu Daten, die
370
- * jeder weitere Schritt -- Zonenteilung an einer Grenze, Flaeche unter der
371
- * Kurve -- ohne eigenes Wissen ueber Treppen richtig behandelt.
372
- *
373
- * In Pixeln (toStepPoints) war die Stufe dafuer zu spaet: die Flaeche wurde
374
- * aus den rohen Messwerten gebaut und lief als Rampe unter einer Treppe her,
375
- * und eine Zonengrenze schnitt den senkrechten Sprung an der interpolierten
376
- * Zeit statt am Zeitstempel des naechsten Wertes.
377
- */
378
- declare function toStepData(data: DataPoint[]): DataPoint[];
379
- declare function renderStep(segments: {
380
- data: DataPoint[];
381
- color?: string;
382
- }[], ctx: RenderingContext, style: SeriesStyle): DrawCommand[];
383
- /** Render segments as a filled area between two values (e.g. min/max band). */
384
- declare function renderArea(segments: {
385
- data: AggregatedPoint[];
386
- color?: string;
387
- }[], ctx: RenderingContext, style: SeriesStyle, yLow: (p: AggregatedPoint) => number, yHigh: (p: AggregatedPoint) => number): DrawCommand[];
388
- /**
389
- * Complex area renderer that splits a run by value boundaries (thresholds)
390
- * and renders the resulting zones as separate filled areas.
391
- */
392
- declare function renderZonedArea<T extends {
393
- time: number;
394
- }>(run: T[], ctx: RenderingContext, options: {
395
- boundaries: number[];
396
- yLow: (p: T) => number;
397
- yHigh: (p: T) => number;
398
- getValue: (p: T) => number;
399
- interpolate: (p1: T, p2: T, t: number) => T;
400
- getColor: (zoneIndex: number) => string | undefined;
401
- getHatch?: (zoneIndex: number) => string | undefined;
402
- }, style?: SeriesStyle): DrawCommand[];
403
- /**
404
- * Render a line series split by a threshold value, allowing different styles
405
- * for parts above and below that value.
406
- */
407
- declare function renderSplitLine(run: DataPoint[], threshold: number, ctx: RenderingContext, styles: {
408
- above?: SeriesStyle;
409
- below?: SeriesStyle;
410
- }): DrawCommand[];
411
- /** Render point markers for segments. */
412
- declare function renderMarkers(points: DataPoint[], ctx: RenderingContext, style: SeriesStyle, getColor: (p: DataPoint) => string): DrawCommand[];
413
- declare function drawMarker(// NOSONAR
414
- commands: DrawCommand[], id: string | undefined, shape: Exclude<PointStyleType, "none">, x: number, y: number, size: number, stroke: string, fill: string, sw: number): void;
415
-
416
- /*!
417
- * MLTimeGraph — Copyright (c) 2026 Michael Lechner
418
- * MIT with Attribution: free use incl. commercial requires visible credit to
419
- * "Michael Lechner". Commercial license (no attribution) on request. See LICENSE.
420
- */
421
- /**
422
- * Turn a free-form name into an ASCII slug usable as an `id`/CSS-class
423
- * suffix. Lowercased, non-alphanumeric runs collapsed to `-`, accents
424
- * stripped, trimmed, capped at 50 chars. Empty input → `'unnamed'`.
425
- *
426
- * slugify('Temperatur (°C)') → 'temperatur-c'
427
- * slugify('Signal A') → 'signal-a'
428
- * slugify(' ') → 'unnamed'
429
- */
430
- declare function slugify(s: string | undefined | null): string;
431
-
432
- export { type LegendOrientation as L, type Marker as M, Renderer as R, type Theme as T, type LegendItem as a, type LayoutResult as b, type RenderOutput as c, drawMarker as d, slugify as e, Layout as f, getDefaultTheme as g, type LayoutConfig as h, type LegendConfig as i, renderArea as j, renderLegend as k, renderLine as l, measureLegend as m, renderMarkers as n, renderSplitLine as o, renderStep as p, renderZonedArea as q, resetDefaultTheme as r, setDefaultTheme as s, toStepData as t, toStepPoints as u };