ml-time-graph 1.11.0 → 1.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -19,6 +19,55 @@ release notes, and every change is in `git log` in full.
19
19
 
20
20
  ---
21
21
 
22
+ ## [1.12.1] - 2026-10-06
23
+
24
+ ### Fixed
25
+ - **`SKILLS.md` still called the built-in legend non-interactive.** The entry under *Traps* told
26
+ you that toggling a series meant `legend.position: 'separate'` and drawing the legend yourself —
27
+ true until 1.12.0, and wrong in the very release that changed it. The file ships inside the
28
+ package and is the first thing a coding assistant reads, so a stale trap there points every
29
+ reader at a detour that no longer exists. No code changed.
30
+
31
+ ## [1.12.0] - 2026-10-06
32
+
33
+ ### Added
34
+ - **Gap labels can turn upright when they do not fit.** `gaps.style.label.rotate: 'auto'` rotates
35
+ a gap's label to -90° only when the text is wider than the gap, measured with the same advance
36
+ table the rest of the layout uses — before 1.10.0 there was no way to know. A short outage
37
+ labelled "Sensor Offline" used to spill out on both sides and over the data next to it. An
38
+ explicit angle still wins, and a label placed in the margin (`'above'` / `'below'`) stays flat,
39
+ because nothing is in its way there.
40
+ - **`divergenceExcursions()` in `ml-time-analyze`** — the periods in which several probes that
41
+ should agree did not, **and which one ran away**. Two probes in a fridge more than 2 °C apart
42
+ means something is wrong; *Unten is 4.5 °C warmer* sends someone to the right probe, *the
43
+ difference was 4.5 °C* does not. `minDurationMs` ignores a single noisy sample, and a timestamp
44
+ with fewer than two readings ends an episode the way a gap does. The pieces existed
45
+ (`spatialDelta` + `computeLimitExcursions`); what every caller wrote by hand was the wiring —
46
+ and lost the probe attribution doing it.
47
+ - **Highlights take `rotate: 'auto'` too.** Same rule as a gap label, and the same reason: a
48
+ four-hour episode labelled "Unten +4.5 °C" used to spill out over the data beside it. The shared
49
+ range renderer could already do it; highlights simply did not pass it through.
50
+ - **A strip that says when readings were missing.** `gaps.style.band` draws a bar on the plot's
51
+ baseline for every gap — one per gap, because the data between two gaps is not missing. It needs
52
+ no extra margin, unlike an annotation band, and it is the answer for gaps drawn as `'empty'`,
53
+ where the picture otherwise shows nothing but a break in the line. `height`, `fill`, `opacity`
54
+ and an `offset` into the bottom margin are yours to set.
55
+
56
+ - **Every legend entry is its own group — so you can click one.** Each entry now renders as
57
+ `<g class="legend-item legend-item--<id>" id="legend-<id>">`, carrying the *same* stable key as
58
+ the series it names (`#series-<id>`). `legend.itemClass` adds a class of your own to every entry,
59
+ and `legendItems()` returns the key as `id`. One handler on the chart is enough to toggle a
60
+ series: `#legend-pump` → `#series-pump`. Until now a clickable legend meant drawing the legend
61
+ yourself — with a second idea of what a swatch looks like. **The SVG gains a wrapper `<g>` per
62
+ entry**; CSS that targets `.chart-legend rect` still matches, but anything relying on entries
63
+ being direct children does not.
64
+
65
+ ### Fixed
66
+ - **Go: a chart-wide `gaps.style.display` was ignored.** Only a region's own `style.display` was
67
+ read, so `display: 'empty'` set for the whole chart fell back to the default and drew a filled
68
+ area with two dashed edges — "draw nothing" drew something. TypeScript merged the chart-wide
69
+ style all along. No reference chart used the chart-wide field, which is why nobody saw it.
70
+
22
71
  ## [1.11.0] - 2026-10-05
23
72
 
24
73
  ### Added
package/README.de.md CHANGED
@@ -12,6 +12,10 @@ Browser und im Backend.
12
12
 
13
13
  > Voll typisiert · i18n-aware · DOM-freier SVG-Renderer (Browser & serverseitig) · keine Laufzeit-Abhängigkeiten · ESM-only
14
14
 
15
+ > ▶️ **[Ausprobieren: interaktive Demos auf mlcgo.eu](https://mlcgo.eu/books/mlctimegraph/demo/)** —
16
+ > sechzehn Seiten, jede Karte mit Code- und Werte-Reiter, nichts zu installieren. Dieselben Seiten
17
+ > stecken im [Handbuch](https://mlcgo.eu/books/mlctimegraph/).
18
+
15
19
  > 🤖 **Sie arbeiten mit einem KI-Assistenten?** Geben Sie ihm
16
20
  > **[SKILLS.md](https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/packages/ml-time-graph/SKILLS.md)** — die Datei wird mitgeliefert und liegt nach
17
21
  > `npm install` unter `node_modules/ml-time-graph/SKILLS.md`. Eine Seite: der
@@ -132,7 +136,7 @@ Incident-Reports, ein Sensorstrom mit Statistik-Overlays (±2σ-Band +
132
136
  *unterhalb* des Diagramms markieren — dort verdecken sie nichts, und man
133
137
  liest in einer Zeile ab, **wann** etwas galt. Alles dieselbe Library. **Die Galerie läuft
134
138
  online: [mlcgo.eu/books/mlctimegraph/demo](https://mlcgo.eu/books/mlctimegraph/demo/)** —
135
- fünfzehn Seiten zum Anfassen, jede Karte mit Code- und Werte-Reiter, nichts zu installieren.
139
+ sechzehn Seiten zum Anfassen, jede Karte mit Code- und Werte-Reiter, nichts zu installieren.
136
140
  Lokal geht es mit `pnpm dev`; die Bilder oben entstehen mit
137
141
  `node scripts/make-examples.mjs`.
138
142
 
@@ -154,6 +158,32 @@ Sowohl die TypeScript- als auch die Go-Bibliothek:
154
158
 
155
159
  ---
156
160
 
161
+ ## 🔭 Ausblick: kleinere SVGs
162
+
163
+ Ein Diagramm trägt mehr Bytes mit sich, als es müsste. Gemessen an allen 41
164
+ Vergleichsdiagrammen (234 KB): **36 % der Ausgabe sind Darstellungsattribute** — `stroke` an
165
+ 1282 Elementen, `stroke-width` an 1256, `fill` an 973, jedes an jedem Kind wiederholt.
166
+
167
+ SVG vererbt die meisten davon. Einmal an der `<g>` statt an jedem Kind, und dieselben Bilder
168
+ werden **15,9 % kleiner — 37,2 KB**.
169
+
170
+ Zwei Dinge, die naheliegen und nicht stimmen:
171
+
172
+ - **Es ist keine CSS-Sache.** Kein `<style>`-Block, keine Klassenregeln, kein Präfix. Ein
173
+ `<style>`-Block spräche etwa dieselbe Ersparnis, brächte aber drei Probleme mit: zwei Diagramme
174
+ auf einer Seite gerieten sich über dieselben Regeln in die Quere, unsere Regeln konkurrierten
175
+ mit dem Stilblatt des Aufrufers (heute schlägt jede seiner Regeln ein Darstellungsattribut),
176
+ und erst dadurch bräuchten ids und Klassen einen Namensraum. Reine Vererbung hat nichts davon.
177
+ - **Es sind keine 23 %.** Alles hochzuziehen ergäbe das, änderte aber das Bild: 579
178
+ `<text>`-Elemente stehen in Gruppen mit Linien, und ein `stroke` an der Gruppe gäbe den
179
+ Achsenbeschriftungen eine Kontur — Text ist gefüllt, nicht umrandet. Ein Attribut darf nur
180
+ hoch, wenn jedes Kind ohne dieses Attribut davon wirklich unberührt bleibt. Diese Regel lässt
181
+ 15,9 % übrig.
182
+
183
+ Es greift in die Ausgabe jedes Diagramms ein, ist also nichts für eine Patch-Fassung.
184
+
185
+ ---
186
+
157
187
  ## 🐞 Fehler gefunden?
158
188
 
159
189
  Issues liegen unter
package/README.md CHANGED
@@ -12,6 +12,10 @@ backend.
12
12
 
13
13
  > Fully typed · i18n-aware · DOM-free SVG output (browser & server) · zero runtime dependencies · ESM-only
14
14
 
15
+ > ▶️ **[Try it: interactive demos on mlcgo.eu](https://mlcgo.eu/books/mlctimegraph/demo/)** — sixteen
16
+ > pages, every card with a Code and a Values tab, nothing to install. The same pages are embedded
17
+ > in the [handbook](https://mlcgo.eu/books/mlctimegraph/).
18
+
15
19
  > 🤖 **Working with an AI coding assistant?** Point it at
16
20
  > **[SKILLS.md](https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/packages/ml-time-graph/SKILLS.md)** — it ships inside the package, so after
17
21
  > `npm install` it sits at `node_modules/ml-time-graph/SKILLS.md`. One page:
@@ -132,7 +136,7 @@ incident-style reports, a sensor stream with statistic overlays (±2σ band +
132
136
  the chart — where they cover nothing and you read in one line **when**
133
137
  something applied. All rendered with the same library. **The gallery runs
134
138
  online: [mlcgo.eu/books/mlctimegraph/demo](https://mlcgo.eu/books/mlctimegraph/demo/)** —
135
- fifteen pages to play with, every card with a Code and a Values tab, nothing to install.
139
+ sixteen pages to play with, every card with a Code and a Values tab, nothing to install.
136
140
  Locally it is `pnpm dev`; the images above come from
137
141
  `node scripts/make-examples.mjs`.
138
142
 
@@ -154,6 +158,31 @@ Both the TypeScript and Go libraries:
154
158
 
155
159
  ---
156
160
 
161
+ ## 🔭 Outlook: smaller SVGs
162
+
163
+ A chart's SVG carries more bytes than it needs to. Measured across all 41 reference charts
164
+ (234 KB): **36 % of the output is presentation attributes** — `stroke` on 1282 elements,
165
+ `stroke-width` on 1256, `fill` on 973, and so on, each one repeated on every child.
166
+
167
+ SVG inherits most of them. Written once on the `<g>` instead of on every child, the same
168
+ pictures come out **15.9 % smaller — 37.2 KB**.
169
+
170
+ Two things that sound right and are not:
171
+
172
+ - **It is not a CSS feature.** No `<style>` block, no class rules, no prefix. A `<style>` block
173
+ would save about as much and bring three problems with it: two charts on one page would fight
174
+ over the same rules, our rules would start competing with the caller's stylesheet (today every
175
+ caller rule wins over a presentation attribute), and only then would ids and classes need
176
+ namespacing. Plain inheritance has none of that.
177
+ - **It is not 23 %.** Lifting everything would be, but it would change the picture: 579 `<text>`
178
+ elements sit in groups with lines, and moving `stroke` up would give axis labels an outline —
179
+ text is filled, not stroked. An attribute may only move up when every child without it is
180
+ genuinely unaffected. That rule is what leaves 15.9 %.
181
+
182
+ It touches the output of every chart, so it is not a patch release.
183
+
184
+ ---
185
+
157
186
  ## 🐞 Found a bug?
158
187
 
159
188
  Issues live at
package/SKILLS.md CHANGED
@@ -173,6 +173,28 @@ draw all five types identically — the Go port did not draw any of them before
173
173
  | `empty` | nothing — the line breaks, that is all |
174
174
  | `bridge_line` | a dotted line between the readings around the gap (per series only) |
175
175
 
176
+ Two things make a gap readable, and both are off unless you ask:
177
+
178
+ ```ts
179
+ gaps: {
180
+ style: {
181
+ label: { rotate: 'auto' }, // turn it upright when it does not fit
182
+ band: { height: 6, fill: '#dc2626', opacity: 0.8 }, // a strip on the baseline
183
+ },
184
+ regions: [...],
185
+ }
186
+ ```
187
+
188
+ `rotate: 'auto'` turns a label to -90° **only when it is wider than its gap** — measured with the
189
+ same advance table the rest of the layout uses. *Sensor Offline* is about 72 px; a two-hour gap on
190
+ a 600 px chart is 50. Flat, it spills out over the data next to it. A label placed in the margin
191
+ (`baseline: 'above' | 'below'`) stays flat: nothing is in its way there.
192
+
193
+ `band` draws a strip on the plot's baseline, **one per gap** — the data between two gaps is not
194
+ missing. It is the answer for `display: 'empty'`, where the picture otherwise shows nothing but a
195
+ break in the line, and it needs no extra margin (an annotation band does). `offset` pushes it into
196
+ the bottom margin if you have room there.
197
+
176
198
  A **label** is separate from all of this and comes from `gaps.regions[].label` — a region knows
177
199
  which gap it describes, a series style would have to give all of them the same text:
178
200
 
@@ -315,6 +337,58 @@ into the chart.
315
337
 
316
338
  In Go it is `renderer.NewCommandBuilder()` with the same methods.
317
339
 
340
+ ### Two probes that should agree — `divergenceExcursions`
341
+ ```ts
342
+ import { divergenceExcursions } from 'ml-time-graph/analyze';
343
+
344
+ const episodes = divergenceExcursions(
345
+ [{ name: 'Oben', data: oben }, { name: 'Unten', data: unten }],
346
+ { maxDelta: 2, minDurationMs: 30 * 60_000 },
347
+ );
348
+ // → [{ startTime, endTime, durationMs, peakDelta, peakTime, maxSensor, minSensor }]
349
+ ```
350
+ Two sensors measuring the same thing: while they agree, all is well. Beyond `maxDelta` something
351
+ is wrong — one is icing up, one sits in the draught, one has drifted. **`maxSensor` is the half
352
+ you can act on**: *Unten is 4.5 °C warmer* sends someone to the right probe, *the difference was
353
+ 4.5 °C* does not.
354
+
355
+ `minDurationMs` drops episodes shorter than that — a single sample over the limit is noise, not an
356
+ incident. A timestamp with fewer than two readings has no difference and ends an episode, the way
357
+ a gap does. Sensors are matched by timestamp without interpolation, so bring them to the same
358
+ cadence first.
359
+
360
+ Draw the result as highlights, with `rotate: 'auto'` so a long label in a short episode turns
361
+ upright instead of spilling over the data:
362
+
363
+ ```ts
364
+ highlights: episodes.map((e) => ({
365
+ startTime: e.startTime, endTime: e.endTime,
366
+ label: `${e.maxSensor} +${e.peakDelta.toFixed(1)} °C`,
367
+ labelPosition: 'top', rotate: 'auto',
368
+ }))
369
+ ```
370
+
371
+ ### A legend you can click — `legend.itemClass`
372
+ ```ts
373
+ legend: { show: true, itemClass: 'clickmetotoggle' }
374
+ ```
375
+ Every entry is its own group: `<g class="legend-item legend-item--<id>" id="legend-<id>">`, and
376
+ `<id>` is the **same key the series group carries** (`#series-<id>`, from `series.id` or the name).
377
+ `itemClass` adds your own class to every entry.
378
+
379
+ That is the whole feature — the library brings nothing to click *with*, it brings something to
380
+ click *on*:
381
+
382
+ ```js
383
+ container.addEventListener('click', (e) => {
384
+ const item = e.target.closest('.clickmetotoggle');
385
+ if (!item) return;
386
+ container.querySelector('#' + item.id.replace('legend-', 'series-'))
387
+ .classList.toggle('hidden'); // .hidden { display: none }
388
+ });
389
+ ```
390
+ `chart.legendItems()` returns the same key as `id`, for anyone still rendering their own legend.
391
+
318
392
  ### A panel behind the legend — `legend.box`
319
393
  ```ts
320
394
  legend: { show: true, position: 'inside-right', box: {} }
@@ -447,8 +521,12 @@ scratch image.
447
521
  - **`resolveDash()` vs `getLineStyle()`:** `dashed` and `dotted` predate the scalable dash table and keep fixed SVG patterns (`"4,4"` and `"2,4"`) in the renderer for backwards compatibility. `getLineStyle()` returns the scalable table (`"6, 4"` for width 2). Anyone rendering custom legend swatches must call `resolveDash(variant, width)` so the swatch matches what is actually drawn.
448
522
  - **Markers do not inherit `line.width`:** `style.markers` carries its own pen — `strokeWidth`, `stroke`, `fill`. That is usually what you want (a 10 px line with 10 px marker outlines is a blob), but it means a marker stays hairline-thin when the line gets thick, and nothing tells you. Set `markers.strokeWidth` explicitly whenever `line.width` leaves the default.
449
523
  - **Marker suppression at threshold:** `style.markers.threshold` (and default `theme.pointThreshold = 100`) hides point markers when series sample count exceeds it to prevent visual crowding. Crucially, `chart.legendItems()` also omits the `marker` property when points are suppressed, because a symbol in the legend missing from the curve states something untrue.
450
- - **Built-in legend is static SVG:** Built-in legends (`inside-right`, `above`, `below`, …) are
451
- non-interactive SVG elements. For interactive series toggling or HTML layout below the chart, use `legend: { position: 'separate' }` and render HTML buttons from `chart.legendItems()` using `drawMarker()` and `SVGRenderer` or `resolveDash()`.
524
+ - **A built-in legend carries no behaviour, but it is reachable.** Until 1.12.0 this entry said a
525
+ built-in legend was "non-interactive" and that toggling meant `position: 'separate'` and drawing
526
+ it yourself. That is no longer true: every entry is its own group with the same stable key as its
527
+ series (`#legend-<id>` → `#series-<id>`), and `legend.itemClass` adds your own hook. The library
528
+ still ships no click handler — you write one, and one on the chart is enough. `'separate'` remains
529
+ the way when the legend belongs in HTML, or needs to do more than toggle.
452
530
  - **An annotation's `dash` takes a variant, not a pattern:** the type is `'dashed' | 'dotted'`. A raw SVG pattern like `'5,5'` is not rejected — it draws a solid line, in both libraries.
453
531
  - **One option is still accepted and does nothing:** `series.sensorType` is in the types and the parser reads it, but no renderer acts on it — in either library. Setting it to `'enum'` does not label the axis; that is `series.enumMap`, which 1.10.0 wired up. Until 1.10.0 this list also held `ticks.minor`, `grid.minor` and `enumMap` itself: three fields the types promised and both renderers swallowed. Nothing warns you; the picture just stays as it was.
454
532
  - **CSS classes are not namespaced:** the chart uses plain names like `.series` and `.time-axis`. Inline the SVG into a page whose stylesheet has a `.series` rule and that rule applies to the chart. Scope your own selectors, and suspect the host page when an embedded chart looks wrong but the standalone file does not.
@@ -482,6 +482,77 @@ interface HotColdSpotsResult {
482
482
  */
483
483
  declare function hotColdSpots(sensors: NamedSeries[]): HotColdSpotsResult;
484
484
 
485
+ /*!
486
+ * MLTimeGraph — Copyright (c) 2026 Michael Lechner
487
+ * MIT with Attribution: free use incl. commercial requires visible credit to
488
+ * "Michael Lechner". Commercial license (no attribution) on request. See LICENSE.
489
+ */
490
+
491
+ interface DivergenceOptions {
492
+ /**
493
+ * Ab welcher Differenz die Fuehler als uneinig gelten.
494
+ *
495
+ * Gemeint ist der Abstand zwischen dem hoechsten und dem niedrigsten
496
+ * Messwert zum selben Zeitpunkt -- bei zwei Fuehlern also schlicht ihr
497
+ * Unterschied. Streng groesser: genau `maxDelta` ist noch in Ordnung.
498
+ */
499
+ maxDelta: number;
500
+ /**
501
+ * Episoden, die kuerzer dauern, werden uebergangen (in ms, Vorgabe 0).
502
+ *
503
+ * Ein einzelner Messwert ueber der Grenze ist Rauschen, kein Vorfall. Ohne
504
+ * diese Schwelle meldet ein zappelnder Fuehler Dutzende Episoden von je
505
+ * einer Abtastperiode, und die Meldung, die zaehlt, geht darin unter.
506
+ */
507
+ minDurationMs?: number;
508
+ }
509
+ interface DivergenceEpisode {
510
+ /** Erster Zeitpunkt, an dem die Grenze ueberschritten war. */
511
+ startTime: number;
512
+ /** Letzter Zeitpunkt, an dem sie es noch war. */
513
+ endTime: number;
514
+ /** Dauer in ms -- `endTime - startTime`. */
515
+ durationMs: number;
516
+ /** Groesste erreichte Differenz. */
517
+ peakDelta: number;
518
+ /** Wann sie erreicht wurde. */
519
+ peakTime: number;
520
+ /**
521
+ * Die beiden Fuehler im Augenblick der groessten Differenz.
522
+ *
523
+ * Das ist der handlungsrelevante Teil: "Unten ist 4,8 Grad waermer als Oben"
524
+ * schickt jemanden an den richtigen Fuehler, "die Differenz betrug 4,8 Grad"
525
+ * nicht.
526
+ */
527
+ maxSensor: string | null;
528
+ minSensor: string | null;
529
+ }
530
+ /**
531
+ * Die Zeitraeume, in denen mehrere Fuehler um mehr als `maxDelta`
532
+ * auseinanderliefen.
533
+ *
534
+ * Die Fuehler werden ueber den Zeitstempel zusammengefuehrt, ohne
535
+ * Interpolation -- wie in {@link spatialDelta}, und mit derselben Pflicht des
536
+ * Aufrufers, sie auf denselben Takt zu bringen. Ein Zeitpunkt mit weniger als
537
+ * zwei gueltigen Messwerten hat keine Differenz; er beendet eine laufende
538
+ * Episode, wie es eine Luecke tut.
539
+ *
540
+ * Die Grenzen folgen {@link computeLimitExcursions}: `startTime` ist der erste
541
+ * Messzeitpunkt ueber der Grenze, `endTime` der letzte -- nicht der erste
542
+ * darunter. Eine Episode aus einem einzigen Messwert dauert damit 0 ms, und
543
+ * genau die faengt `minDurationMs` ab.
544
+ *
545
+ * @example
546
+ * // Kuehlschrank mit zwei Fuehlern: mehr als 2 Grad Unterschied und
547
+ * // laenger als eine halbe Stunde ist ein Abtauproblem.
548
+ * const episoden = divergenceExcursions(
549
+ * [{ name: "Oben", data: oben }, { name: "Unten", data: unten }],
550
+ * { maxDelta: 2, minDurationMs: 30 * 60_000 },
551
+ * );
552
+ * // → [{ startTime, endTime, peakDelta: 4.8, maxSensor: "Unten", … }]
553
+ */
554
+ declare function divergenceExcursions(sensors: NamedSeries[], opts: DivergenceOptions): DivergenceEpisode[];
555
+
485
556
  /*!
486
557
  * MLTimeGraph — Copyright (c) 2026 Michael Lechner
487
558
  * MIT with Attribution: free use incl. commercial requires visible credit to
@@ -587,4 +658,4 @@ interface F0Opts {
587
658
  */
588
659
  declare function f0Sterilization(data: DataPoint[], opts?: F0Opts): number;
589
660
 
590
- export { type AggregatedPoint, type AggregationConfig, type AggregationMode, type AggregationThresholds, type ComputeLimitsOpts, DEFAULT_ACTIVATION_ENERGY, type DataPoint, type F0Opts, type HotColdSpotsResult, type LimitExcursion, type LimitStats, type LimitStatsPoint, type LongTermInsight, type MktPoint, type NamedSeries, PRODUCT_PROFILES, type PredictOpts, type PredictResult, type ProductConfig, type ProductType, type SensorStat, SeriesProcessor, type SpatialPoint, type StatsAggregatedPoint, StatsAggregator, type StatsResult, type StdDevPoint, type TrendFit, type TrendPoint, aggregateBySlot, aggregateWithStats, analyzeLongTermTrends, computeLimitExcursions, createAggr, currentTrend, detectGaps, downsample, f0Sterilization, hotColdSpots, linearFit, mkt, predictTimeToThreshold, rollingEma, rollingMean, rollingMkt, rollingStdDev, rollingTrend, sampleStdDev, spatialDelta, stdDev, varianceCoefficient };
661
+ export { type AggregatedPoint, type AggregationConfig, type AggregationMode, type AggregationThresholds, type ComputeLimitsOpts, DEFAULT_ACTIVATION_ENERGY, type DataPoint, type DivergenceEpisode, type DivergenceOptions, type F0Opts, type HotColdSpotsResult, type LimitExcursion, type LimitStats, type LimitStatsPoint, type LongTermInsight, type MktPoint, type NamedSeries, PRODUCT_PROFILES, type PredictOpts, type PredictResult, type ProductConfig, type ProductType, type SensorStat, SeriesProcessor, type SpatialPoint, type StatsAggregatedPoint, StatsAggregator, type StatsResult, type StdDevPoint, type TrendFit, type TrendPoint, aggregateBySlot, aggregateWithStats, analyzeLongTermTrends, computeLimitExcursions, createAggr, currentTrend, detectGaps, divergenceExcursions, downsample, f0Sterilization, hotColdSpots, linearFit, mkt, predictTimeToThreshold, rollingEma, rollingMean, rollingMkt, rollingStdDev, rollingTrend, sampleStdDev, spatialDelta, stdDev, varianceCoefficient };
@@ -1,4 +1,4 @@
1
- var k=class{static interpolateDataPoint(n,i,l){return {time:n.time+Math.round(l*(i.time-n.time)),value:(n.value??0)+l*((i.value??0)-(n.value??0)),synthetic:true}}static interpolateAggregatedPoint(n,i,l){let u=(e,t)=>e!==null&&t!==null?e+l*(t-e):null;return {time:n.time+l*(i.time-n.time),min:u(n.min,i.min),max:u(n.max,i.max),avg:u(n.avg,i.avg),count:Math.round(n.count+l*(i.count-n.count))}}static getRuns(n,i,l=0){let u=[...n].sort((r,o)=>r.time-o.time),e=[],t=[],a=null;for(let r of u){let o=i(r),m=l>0&&a&&r.time-a.time>l;(o||m)&&t.length&&(e.push(t),t=[]),o||t.push(r),a=r;}return t.length&&e.push(t),e}static splitByBoundaries(n,i,l,u){if(n.length===0)return [];if(i.length===0)return [{data:n,zoneIndex:0,zoneLow:Number.NEGATIVE_INFINITY}];let e=[...i].sort((m,s)=>m-s),t=[],a=m=>m<=0?Number.NEGATIVE_INFINITY:e[m-1],r=m=>{let s=0;for(let f=0;f<e.length&&m>=e[f];f++)s=f+1;return s},o=[n[0]];for(let m=1;m<n.length;m++){let s=n[m-1],f=n[m],g=l(s),d=l(f),p;d>g?p=e.filter(v=>v>g&&v<=d):d<g?p=e.filter(v=>v>=d&&v<g).reverse():p=[];let b=g;for(let v of p){let x=(v-g)/(d-g),h=u(s,f,x);o.push(h);let c=r((b+v)/2);t.push({data:o,zoneIndex:c,zoneLow:a(c)}),o=[h],b=v;}(p.length===0||p[p.length-1]!==d)&&o.push(f);}if(o.length>1||n.length===1){let m=l(o[0]),s=l(o[o.length-1]),f=r((m+s)/2);t.push({data:o,zoneIndex:f,zoneLow:a(f)});}return t}static splitByThreshold(n,i,l,u){let e=this.splitByBoundaries(n,[i],l,u),t={above:[],below:[]};for(let a of e)a.zoneIndex===0?t.below.push(a.data):t.above.push(a.data);return t}},H={pharma_cold:{limitLow:2,limitHigh:8,activationEnergy:83144},pharma_ambient:{limitLow:15,limitHigh:25,activationEnergy:83144},blood:{limitLow:2,limitHigh:6,activationEnergy:83144},food_chilled:{limitLow:0,limitHigh:4},frozen:{limitLow:-40,limitHigh:-18}},D=8.314462618,y=273.15;function N(n,i,l,u=1){let e=i.filter(h=>h.value!==null&&h.value!==void 0&&!Number.isNaN(h.value)).map(h=>h.value);if(!e.length)return {time:n,min:null,max:null,avg:null,mkt:null,deltaMkt:null,stdDev:null,minutesAboveHigh:l?0:null,minutesBelowLow:l?0:null,count:0};let t=1/0,a=-1/0,r=0;for(let h of e)h<t&&(t=h),h>a&&(a=h),r+=h;let o=r/e.length,m=l?0:null,s=l?0:null;if(l)for(let h=0;h<i.length;h++){let c=i[h];if(c.value!==null&&c.value!==void 0){let M=i[h+1],w=(M?M.time-c.time:0)/(1e3*60);c.value>l.limitHigh&&(m+=w),c.value<l.limitLow&&(s+=w);}}let f=0,g=0,d=(l?.activationEnergy??83144)/D;for(let h of e){f+=Math.pow(h-o,2);let c=h+y;g+=Math.exp(-d/c);}let p=f/e.length,b=Math.sqrt(p),v=null,x=null;if(e.length>=u){let h=g/e.length,c=d/-Math.log(h);v=Number((c-y).toFixed(2)),x=Number((v-o).toFixed(2));}return {time:n,min:Number(t.toFixed(2)),max:Number(a.toFixed(2)),avg:Number(o.toFixed(2)),mkt:v,deltaMkt:x,stdDev:Number(b.toFixed(2)),minutesAboveHigh:m!==null?Number(m.toFixed(1)):null,minutesBelowLow:s!==null?Number(s.toFixed(1)):null,count:e.length}}function A(n,i="hourly",l,u,e=1){if(!n.length)return [];let t=i==="hourly"?36e5:i==="daily"?864e5:l??3600*1e3,a=[...n].sort((s,f)=>s.time-f.time),r=[],o=a[0].time,m=[];for(let s of a){for(;s.time-o>=t;)r.push(N(o,m,u,e)),o+=t,m=[];m.push(s);}return r.push(N(o,m,u,e)),r}function S(n,i){let l=1/0,u=-1/0,e=0;for(let a of i)a<l&&(l=a),a>u&&(u=a),e+=a;let t=e/i.length;return {time:n,min:l,max:u,avg:t,count:i.length}}function z(n,i=6e4){if(n.length<2)return [];let l=[...n].sort((e,t)=>e.time-t.time),u=[];for(let e=1;e<l.length;e++)l[e].time-l[e-1].time>i&&u.push({startTime:l[e-1].time,endTime:l[e].time});return u}function B(n){let i=[],l=0,u=0,e=0,t=0;for(let a of n)a.count>0&&(e++,a.minutesAboveHigh&&(l+=a.minutesAboveHigh),a.stdDev&&a.stdDev>u&&(u=a.stdDev),a.deltaMkt&&a.deltaMkt>2&&t++);return e===0?[]:(l>120&&i.push({type:"critical",message:`Kritische Gesamtbelastung: Das Produkt war im gesamten Zeitraum insgesamt ${Math.round(l)} Minuten zu warm.`,metric:"Total Excursion Time"}),t>e*.15&&i.push({type:"warning",message:"Frequent thermal shocks detected. The kinetic temperature deviates strongly from the average (possible regular door openings).",metric:"Delta MKT Instability"}),u>4&&i.push({type:"warning",message:`High instability measured. Maximum standard deviation was ${u}\xB0C. The cooling system controls imprecisely.`,metric:"Standard Deviation Peak"}),i)}function _(n,i){if(n.length<=i)return n;let l=[],u=Math.ceil(n.length/i);l.push(n[0]);for(let e=1;e<n.length;e+=u)l.push(n[Math.min(e,n.length-1)]);return l}function C(n,i="hourly",l){let u={limitLow:l.low,limitHigh:l.high,activationEnergy:l.activationEnergy};return A(n,i,l.interval,u,l.minCountForMkt??1)}var P=class{static compute(n){let i=n.map(r=>r.value).filter(r=>r!==null).sort((r,o)=>r-o);if(i.length===0)return {min:NaN,max:NaN,avg:NaN,mean:NaN,median:NaN,stdDev:NaN,count:0};let l=i.length,u=i.reduce((r,o)=>r+o,0)/l,e=l%2===1?i[Math.floor(l/2)]:(i[l/2-1]+i[l/2])/2,t=i.reduce((r,o)=>r+Math.pow(o-u,2),0)/l,a=Math.sqrt(t);return {min:i[0],max:i[l-1],avg:u,mean:u,median:e,stdDev:a,count:l}}static computeInRange(n,i,l){let u=n.filter(e=>e.time>=i&&e.time<=l);return this.compute(u)}};function q(n,i){let l=typeof n=="number"?n:n.mean,u=typeof n=="number"?i??NaN:n.stdDev;return !Number.isFinite(l)||!Number.isFinite(u)||l===0?null:Math.abs(u/l)*100}var G=83144;function L(n,i=83144){let l=i/8.314,u=0,e=0;for(let a of n)a!==null&&(u+=Math.exp(-l/(a+273.15)),e++);if(e===0)return null;let t=u/e;return l/-Math.log(t)-273.15}function R(n,i,l=83144){let u=new Array(n.length),e=0;for(let t=0;t<n.length;t++){let a=n[t].time,r=a-i;for(;e<t&&n[e].time<r;)e++;let o=n.slice(e,t+1).map(s=>s.value),m=L(o,l);u[t]={time:a,value:m,synthetic:true};}return u}function E(n){let i=0,l=0;for(let t of n)t!==null&&(i+=t,l++);if(l===0)return null;let u=i/l,e=0;for(let t of n){if(t===null)continue;let a=t-u;e+=a*a;}return Math.sqrt(e/l)}function F(n){let i=0,l=0;for(let t of n)t!==null&&(i+=t,l++);if(l<2)return null;let u=i/l,e=0;for(let t of n){if(t===null)continue;let a=t-u;e+=a*a;}return Math.sqrt(e/(l-1))}function V(n,i,l=false){let u=new Array(n.length),e=0,t=l?F:E;for(let a=0;a<n.length;a++){let r=n[a].time,o=r-i;for(;e<a&&n[e].time<o;)e++;let m=n.slice(e,a+1).map(f=>f.value),s=t(m);u[a]={time:r,value:s,synthetic:true};}return u}function K(n,i){let l=new Array(n.length),u=0;for(let e=0;e<n.length;e++){let t=n[e].time,a=t-i;for(;u<e&&n[u].time<a;)u++;let r=0,o=0;for(let m=u;m<=e;m++){let s=n[m].value;s!==null&&(r+=s,o++);}l[e]={time:t,value:o===0?null:r/o,synthetic:true};}return l}function O(n,i){let l=new Array(n.length),u=null,e=0;for(let t=0;t<n.length;t++){let a=n[t].time,r=n[t].value;if(r===null){l[t]={time:a,value:u,synthetic:true};continue}if(u===null||i<=0)u=r;else {let o=1-Math.exp(-(a-e)/i);u=r*o+u*(1-o);}e=a,l[t]={time:a,value:u,synthetic:true};}return l}function U(n,i){let{high:l,low:u}=i,e={msAboveHigh:0,msBelowLow:0,globalMax:null,globalMin:null,excursions:[]},t=null;for(let a=0;a<n.length;a++){let r=n[a];if(r.value===null){t&&(e.excursions.push(t),t=null);continue}(e.globalMax===null||r.value>e.globalMax)&&(e.globalMax=r.value),(e.globalMin===null||r.value<e.globalMin)&&(e.globalMin=r.value);let o=l!==void 0&&r.value>l,m=u!==void 0&&r.value<u,s=o?"above":m?"below":null,f=n[a-1];if(f&&f.value!==null&&s!==null){let g=r.time-f.time;s==="above"?e.msAboveHigh+=g:e.msBelowLow+=g;}if(s===null){t&&(e.excursions.push(t),t=null);continue}t&&t.side===s?(t.endTime=r.time,t.durationMs=t.endTime-t.startTime,(s==="above"&&r.value>t.extremum||s==="below"&&r.value<t.extremum)&&(t.extremum=r.value)):(t&&e.excursions.push(t),t={startTime:r.time,endTime:r.time,side:s,extremum:r.value,durationMs:0});}return t&&e.excursions.push(t),e}function Y(n){if(n.length===0)return [];let i=new Map;for(let u of n)for(let e of u.data){if(e.value===null)continue;let t=i.get(e.time);t||(t=[],i.set(e.time,t)),t.push({name:u.name,value:e.value});}let l=[];for(let u of [...i.keys()].sort((e,t)=>e-t)){let e=i.get(u);if(e.length===0){l.push({time:u,min:null,max:null,delta:null,minSensor:null,maxSensor:null});continue}let t=e[0],a=e[0];for(let r=1;r<e.length;r++)e[r].value<t.value&&(t=e[r]),e[r].value>a.value&&(a=e[r]);l.push({time:u,min:t.value,max:a.value,delta:e.length<2?null:a.value-t.value,minSensor:t.name,maxSensor:a.name});}return l}function $(n){let i=[];for(let e of n){let t=0,a=0,r=1/0,o=-1/0;for(let m of e.data)m.value!==null&&(t+=m.value,a++,m.value<r&&(r=m.value),m.value>o&&(o=m.value));a!==0&&i.push({name:e.name,mean:t/a,min:r,max:o,count:a});}if(i.length===0)return {sensors:[],hottest:null,coldest:null,meanDelta:null};let l=i[0],u=i[0];for(let e=1;e<i.length;e++)i[e].mean>l.mean&&(l=i[e]),i[e].mean<u.mean&&(u=i[e]);return {sensors:i,hottest:l,coldest:u,meanDelta:l.mean-u.mean}}function T(n){let i=0,l=0,u=0,e=0,t=0;for(let m of n)m.value!==null&&(i++,l+=m.time,u+=m.value,e+=m.time*m.value,t+=m.time*m.time);if(i<2)return null;let a=i*t-l*l;if(a===0)return null;let r=(i*e-l*u)/a,o=(u-r*l)/i;return {slope:r,intercept:o,n:i}}function I(n,i){if(n.length===0)return null;let l=n[n.length-1].time,u=l-i,e=n.filter(t=>t.time>=u&&t.time<=l);return T(e)}function W(n,i){let l=[],u=0;for(let e=0;e<n.length;e++){let t=n[e].time,a=t-i;for(;u<n.length&&n[u].time<a;)u++;let r=T(n.slice(u,e+1));l.push({time:t,fit:r});}return l}function Z(n,i,l={}){let u=l.lookbackMs??9e5,e=l.side??"either";if(n.length===0)return null;let t=n[n.length-1];if(t.value===null)return null;let a=I(n,u);if(!a||a.slope===0)return null;let r=a.slope>0&&t.value<i,o=a.slope<0&&t.value>i;if(e==="above"&&!r||e==="below"&&!o||e==="either"&&!r&&!o)return null;let m=(i-a.intercept)/a.slope,s=m-t.time;return s<=0?null:{msUntil:s,eta:m,fit:a,currentValue:t.value}}function j(n,i={}){let l=i.refTempCelsius??121.11,u=i.zValueKelvin??10,e=0;for(let t=0;t<n.length-1;t++){let a=n[t],r=n[t+1];if(a.value===null||r.value===null)continue;let o=(r.time-a.time)/6e4;if(o<=0)continue;let m=Math.pow(10,(a.value-l)/u),s=Math.pow(10,(r.value-l)/u);e+=(m+s)/2*o;}return e}/*!
1
+ var I=class{static interpolateDataPoint(n,i,l){return {time:n.time+Math.round(l*(i.time-n.time)),value:(n.value??0)+l*((i.value??0)-(n.value??0)),synthetic:true}}static interpolateAggregatedPoint(n,i,l){let u=(e,t)=>e!==null&&t!==null?e+l*(t-e):null;return {time:n.time+l*(i.time-n.time),min:u(n.min,i.min),max:u(n.max,i.max),avg:u(n.avg,i.avg),count:Math.round(n.count+l*(i.count-n.count))}}static getRuns(n,i,l=0){let u=[...n].sort((r,o)=>r.time-o.time),e=[],t=[],a=null;for(let r of u){let o=i(r),m=l>0&&a&&r.time-a.time>l;(o||m)&&t.length&&(e.push(t),t=[]),o||t.push(r),a=r;}return t.length&&e.push(t),e}static splitByBoundaries(n,i,l,u){if(n.length===0)return [];if(i.length===0)return [{data:n,zoneIndex:0,zoneLow:Number.NEGATIVE_INFINITY}];let e=[...i].sort((m,s)=>m-s),t=[],a=m=>m<=0?Number.NEGATIVE_INFINITY:e[m-1],r=m=>{let s=0;for(let f=0;f<e.length&&m>=e[f];f++)s=f+1;return s},o=[n[0]];for(let m=1;m<n.length;m++){let s=n[m-1],f=n[m],g=l(s),d=l(f),p;d>g?p=e.filter(v=>v>g&&v<=d):d<g?p=e.filter(v=>v>=d&&v<g).reverse():p=[];let x=g;for(let v of p){let b=(v-g)/(d-g),h=u(s,f,b);o.push(h);let c=r((x+v)/2);t.push({data:o,zoneIndex:c,zoneLow:a(c)}),o=[h],x=v;}(p.length===0||p[p.length-1]!==d)&&o.push(f);}if(o.length>1||n.length===1){let m=l(o[0]),s=l(o[o.length-1]),f=r((m+s)/2);t.push({data:o,zoneIndex:f,zoneLow:a(f)});}return t}static splitByThreshold(n,i,l,u){let e=this.splitByBoundaries(n,[i],l,u),t={above:[],below:[]};for(let a of e)a.zoneIndex===0?t.below.push(a.data):t.above.push(a.data);return t}},H={pharma_cold:{limitLow:2,limitHigh:8,activationEnergy:83144},pharma_ambient:{limitLow:15,limitHigh:25,activationEnergy:83144},blood:{limitLow:2,limitHigh:6,activationEnergy:83144},food_chilled:{limitLow:0,limitHigh:4},frozen:{limitLow:-40,limitHigh:-18}},D=8.314462618,N=273.15;function T(n,i,l,u=1){let e=i.filter(h=>h.value!==null&&h.value!==void 0&&!Number.isNaN(h.value)).map(h=>h.value);if(!e.length)return {time:n,min:null,max:null,avg:null,mkt:null,deltaMkt:null,stdDev:null,minutesAboveHigh:l?0:null,minutesBelowLow:l?0:null,count:0};let t=1/0,a=-1/0,r=0;for(let h of e)h<t&&(t=h),h>a&&(a=h),r+=h;let o=r/e.length,m=l?0:null,s=l?0:null;if(l)for(let h=0;h<i.length;h++){let c=i[h];if(c.value!==null&&c.value!==void 0){let M=i[h+1],w=(M?M.time-c.time:0)/(1e3*60);c.value>l.limitHigh&&(m+=w),c.value<l.limitLow&&(s+=w);}}let f=0,g=0,d=(l?.activationEnergy??83144)/D;for(let h of e){f+=Math.pow(h-o,2);let c=h+N;g+=Math.exp(-d/c);}let p=f/e.length,x=Math.sqrt(p),v=null,b=null;if(e.length>=u){let h=g/e.length,c=d/-Math.log(h);v=Number((c-N).toFixed(2)),b=Number((v-o).toFixed(2));}return {time:n,min:Number(t.toFixed(2)),max:Number(a.toFixed(2)),avg:Number(o.toFixed(2)),mkt:v,deltaMkt:b,stdDev:Number(x.toFixed(2)),minutesAboveHigh:m!==null?Number(m.toFixed(1)):null,minutesBelowLow:s!==null?Number(s.toFixed(1)):null,count:e.length}}function S(n,i="hourly",l,u,e=1){if(!n.length)return [];let t=i==="hourly"?36e5:i==="daily"?864e5:l??3600*1e3,a=[...n].sort((s,f)=>s.time-f.time),r=[],o=a[0].time,m=[];for(let s of a){for(;s.time-o>=t;)r.push(T(o,m,u,e)),o+=t,m=[];m.push(s);}return r.push(T(o,m,u,e)),r}function z(n,i){let l=1/0,u=-1/0,e=0;for(let a of i)a<l&&(l=a),a>u&&(u=a),e+=a;let t=e/i.length;return {time:n,min:l,max:u,avg:t,count:i.length}}function B(n,i=6e4){if(n.length<2)return [];let l=[...n].sort((e,t)=>e.time-t.time),u=[];for(let e=1;e<l.length;e++)l[e].time-l[e-1].time>i&&u.push({startTime:l[e-1].time,endTime:l[e].time});return u}function _(n){let i=[],l=0,u=0,e=0,t=0;for(let a of n)a.count>0&&(e++,a.minutesAboveHigh&&(l+=a.minutesAboveHigh),a.stdDev&&a.stdDev>u&&(u=a.stdDev),a.deltaMkt&&a.deltaMkt>2&&t++);return e===0?[]:(l>120&&i.push({type:"critical",message:`Kritische Gesamtbelastung: Das Produkt war im gesamten Zeitraum insgesamt ${Math.round(l)} Minuten zu warm.`,metric:"Total Excursion Time"}),t>e*.15&&i.push({type:"warning",message:"Frequent thermal shocks detected. The kinetic temperature deviates strongly from the average (possible regular door openings).",metric:"Delta MKT Instability"}),u>4&&i.push({type:"warning",message:`High instability measured. Maximum standard deviation was ${u}\xB0C. The cooling system controls imprecisely.`,metric:"Standard Deviation Peak"}),i)}function C(n,i){if(n.length<=i)return n;let l=[],u=Math.ceil(n.length/i);l.push(n[0]);for(let e=1;e<n.length;e+=u)l.push(n[Math.min(e,n.length-1)]);return l}function P(n,i="hourly",l){let u={limitLow:l.low,limitHigh:l.high,activationEnergy:l.activationEnergy};return S(n,i,l.interval,u,l.minCountForMkt??1)}var q=class{static compute(n){let i=n.map(r=>r.value).filter(r=>r!==null).sort((r,o)=>r-o);if(i.length===0)return {min:NaN,max:NaN,avg:NaN,mean:NaN,median:NaN,stdDev:NaN,count:0};let l=i.length,u=i.reduce((r,o)=>r+o,0)/l,e=l%2===1?i[Math.floor(l/2)]:(i[l/2-1]+i[l/2])/2,t=i.reduce((r,o)=>r+Math.pow(o-u,2),0)/l,a=Math.sqrt(t);return {min:i[0],max:i[l-1],avg:u,mean:u,median:e,stdDev:a,count:l}}static computeInRange(n,i,l){let u=n.filter(e=>e.time>=i&&e.time<=l);return this.compute(u)}};function G(n,i){let l=typeof n=="number"?n:n.mean,u=typeof n=="number"?i??NaN:n.stdDev;return !Number.isFinite(l)||!Number.isFinite(u)||l===0?null:Math.abs(u/l)*100}var R=83144;function k(n,i=83144){let l=i/8.314,u=0,e=0;for(let a of n)a!==null&&(u+=Math.exp(-l/(a+273.15)),e++);if(e===0)return null;let t=u/e;return l/-Math.log(t)-273.15}function V(n,i,l=83144){let u=new Array(n.length),e=0;for(let t=0;t<n.length;t++){let a=n[t].time,r=a-i;for(;e<t&&n[e].time<r;)e++;let o=n.slice(e,t+1).map(s=>s.value),m=k(o,l);u[t]={time:a,value:m,synthetic:true};}return u}function A(n){let i=0,l=0;for(let t of n)t!==null&&(i+=t,l++);if(l===0)return null;let u=i/l,e=0;for(let t of n){if(t===null)continue;let a=t-u;e+=a*a;}return Math.sqrt(e/l)}function E(n){let i=0,l=0;for(let t of n)t!==null&&(i+=t,l++);if(l<2)return null;let u=i/l,e=0;for(let t of n){if(t===null)continue;let a=t-u;e+=a*a;}return Math.sqrt(e/(l-1))}function K(n,i,l=false){let u=new Array(n.length),e=0,t=l?E:A;for(let a=0;a<n.length;a++){let r=n[a].time,o=r-i;for(;e<a&&n[e].time<o;)e++;let m=n.slice(e,a+1).map(f=>f.value),s=t(m);u[a]={time:r,value:s,synthetic:true};}return u}function O(n,i){let l=new Array(n.length),u=0;for(let e=0;e<n.length;e++){let t=n[e].time,a=t-i;for(;u<e&&n[u].time<a;)u++;let r=0,o=0;for(let m=u;m<=e;m++){let s=n[m].value;s!==null&&(r+=s,o++);}l[e]={time:t,value:o===0?null:r/o,synthetic:true};}return l}function U(n,i){let l=new Array(n.length),u=null,e=0;for(let t=0;t<n.length;t++){let a=n[t].time,r=n[t].value;if(r===null){l[t]={time:a,value:u,synthetic:true};continue}if(u===null||i<=0)u=r;else {let o=1-Math.exp(-(a-e)/i);u=r*o+u*(1-o);}e=a,l[t]={time:a,value:u,synthetic:true};}return l}function Y(n,i){let{high:l,low:u}=i,e={msAboveHigh:0,msBelowLow:0,globalMax:null,globalMin:null,excursions:[]},t=null;for(let a=0;a<n.length;a++){let r=n[a];if(r.value===null){t&&(e.excursions.push(t),t=null);continue}(e.globalMax===null||r.value>e.globalMax)&&(e.globalMax=r.value),(e.globalMin===null||r.value<e.globalMin)&&(e.globalMin=r.value);let o=l!==void 0&&r.value>l,m=u!==void 0&&r.value<u,s=o?"above":m?"below":null,f=n[a-1];if(f&&f.value!==null&&s!==null){let g=r.time-f.time;s==="above"?e.msAboveHigh+=g:e.msBelowLow+=g;}if(s===null){t&&(e.excursions.push(t),t=null);continue}t&&t.side===s?(t.endTime=r.time,t.durationMs=t.endTime-t.startTime,(s==="above"&&r.value>t.extremum||s==="below"&&r.value<t.extremum)&&(t.extremum=r.value)):(t&&e.excursions.push(t),t={startTime:r.time,endTime:r.time,side:s,extremum:r.value,durationMs:0});}return t&&e.excursions.push(t),e}function L(n){if(n.length===0)return [];let i=new Map;for(let u of n)for(let e of u.data){if(e.value===null)continue;let t=i.get(e.time);t||(t=[],i.set(e.time,t)),t.push({name:u.name,value:e.value});}let l=[];for(let u of [...i.keys()].sort((e,t)=>e-t)){let e=i.get(u);if(e.length===0){l.push({time:u,min:null,max:null,delta:null,minSensor:null,maxSensor:null});continue}let t=e[0],a=e[0];for(let r=1;r<e.length;r++)e[r].value<t.value&&(t=e[r]),e[r].value>a.value&&(a=e[r]);l.push({time:u,min:t.value,max:a.value,delta:e.length<2?null:a.value-t.value,minSensor:t.name,maxSensor:a.name});}return l}function $(n){let i=[];for(let e of n){let t=0,a=0,r=1/0,o=-1/0;for(let m of e.data)m.value!==null&&(t+=m.value,a++,m.value<r&&(r=m.value),m.value>o&&(o=m.value));a!==0&&i.push({name:e.name,mean:t/a,min:r,max:o,count:a});}if(i.length===0)return {sensors:[],hottest:null,coldest:null,meanDelta:null};let l=i[0],u=i[0];for(let e=1;e<i.length;e++)i[e].mean>l.mean&&(l=i[e]),i[e].mean<u.mean&&(u=i[e]);return {sensors:i,hottest:l,coldest:u,meanDelta:l.mean-u.mean}}function W(n,i){let{maxDelta:l,minDurationMs:u=0}=i,e=[],t=null,a=()=>{t&&t.durationMs>=u&&e.push(t),t=null;};for(let r of L(n)){if(r.delta===null||r.delta<=l){a();continue}t?(t.endTime=r.time,t.durationMs=t.endTime-t.startTime,r.delta>t.peakDelta&&(t.peakDelta=r.delta,t.peakTime=r.time,t.maxSensor=r.maxSensor,t.minSensor=r.minSensor)):t={startTime:r.time,endTime:r.time,durationMs:0,peakDelta:r.delta,peakTime:r.time,maxSensor:r.maxSensor,minSensor:r.minSensor};}return a(),e}function y(n){let i=0,l=0,u=0,e=0,t=0;for(let m of n)m.value!==null&&(i++,l+=m.time,u+=m.value,e+=m.time*m.value,t+=m.time*m.time);if(i<2)return null;let a=i*t-l*l;if(a===0)return null;let r=(i*e-l*u)/a,o=(u-r*l)/i;return {slope:r,intercept:o,n:i}}function F(n,i){if(n.length===0)return null;let l=n[n.length-1].time,u=l-i,e=n.filter(t=>t.time>=u&&t.time<=l);return y(e)}function Z(n,i){let l=[],u=0;for(let e=0;e<n.length;e++){let t=n[e].time,a=t-i;for(;u<n.length&&n[u].time<a;)u++;let r=y(n.slice(u,e+1));l.push({time:t,fit:r});}return l}function j(n,i,l={}){let u=l.lookbackMs??9e5,e=l.side??"either";if(n.length===0)return null;let t=n[n.length-1];if(t.value===null)return null;let a=F(n,u);if(!a||a.slope===0)return null;let r=a.slope>0&&t.value<i,o=a.slope<0&&t.value>i;if(e==="above"&&!r||e==="below"&&!o||e==="either"&&!r&&!o)return null;let m=(i-a.intercept)/a.slope,s=m-t.time;return s<=0?null:{msUntil:s,eta:m,fit:a,currentValue:t.value}}function J(n,i={}){let l=i.refTempCelsius??121.11,u=i.zValueKelvin??10,e=0;for(let t=0;t<n.length-1;t++){let a=n[t],r=n[t+1];if(a.value===null||r.value===null)continue;let o=(r.time-a.time)/6e4;if(o<=0)continue;let m=Math.pow(10,(a.value-l)/u),s=Math.pow(10,(r.value-l)/u);e+=(m+s)/2*o;}return e}/*!
2
2
  * MLTimeGraph — Copyright (c) 2026 Michael Lechner
3
3
  * MIT with Attribution: free use incl. commercial requires visible credit to
4
4
  * "Michael Lechner". Commercial license (no attribution) on request. See LICENSE.
@@ -12,4 +12,4 @@ var k=class{static interpolateDataPoint(n,i,l){return {time:n.time+Math.round(l*
12
12
  * MLTimeGraph — Copyright (c) 2026 Michael Lechner
13
13
  * MIT with Attribution: free use incl. commercial requires visible credit to
14
14
  * "Michael Lechner". Commercial license (no attribution) on request. See LICENSE.
15
- */export{G as DEFAULT_ACTIVATION_ENERGY,H as PRODUCT_PROFILES,k as SeriesProcessor,P as StatsAggregator,A as aggregateBySlot,C as aggregateWithStats,B as analyzeLongTermTrends,U as computeLimitExcursions,S as createAggr,I as currentTrend,z as detectGaps,_ as downsample,j as f0Sterilization,$ as hotColdSpots,T as linearFit,L as mkt,Z as predictTimeToThreshold,O as rollingEma,K as rollingMean,R as rollingMkt,V as rollingStdDev,W as rollingTrend,F as sampleStdDev,Y as spatialDelta,E as stdDev,q as varianceCoefficient};
15
+ */export{R as DEFAULT_ACTIVATION_ENERGY,H as PRODUCT_PROFILES,I as SeriesProcessor,q as StatsAggregator,S as aggregateBySlot,P as aggregateWithStats,_ as analyzeLongTermTrends,Y as computeLimitExcursions,z as createAggr,F as currentTrend,B as detectGaps,W as divergenceExcursions,C as downsample,J as f0Sterilization,$ as hotColdSpots,y as linearFit,k as mkt,j as predictTimeToThreshold,U as rollingEma,O as rollingMean,V as rollingMkt,K as rollingStdDev,Z as rollingTrend,E as sampleStdDev,L as spatialDelta,A as stdDev,G as varianceCoefficient};
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { M as MLTimeGraphOptions, L as LegendItem, R as Renderer, a as LayoutResult, b as Margin, A as AxesConfig, X as XAxisConfig, Y as YAxisConfig, c as LegendOptions, d as LegendPosition, e as LegendOrientation, f as Marker, g as RenderOutput } from './marker_renderer-CiccLy7h.js';
2
- export { h as AxisLabelsStyle, i as AxisStyle, G as GridLineStyle, j as GridStyle, T as TextMetrics, k as Theme, l as TickConfig, m as drawMarker, n as estimateMetrics, o as getDefaultTheme, p as liberationMetrics, r as resetDefaultTheme, s as setDefaultTheme, q as slugify } from './marker_renderer-CiccLy7h.js';
3
- import { d as AnySeries, h as Annotation, a as DrawCommand, T as TimeScale, L as LinearScale, f as Gap, g as GapsConfig, e as Threshold, H as Highlight, i as AnnotationBandConfig, k as SeriesStyle, b as LineVariant, S as SmoothingType, F as FillSpec, l as TimeSeries, m as LineDashStyle, n as ThresholdFill, j as HatchVariant, o as ThresholdLabelPosition, P as PointStyleType, M as MarkerLineStyle, R as RangeLabelPosition, p as AnnotationPointShape, q as LabelAnchor, r as AnnotationBandItem, s as TextBaseline, t as AggregatedPoint, u as AggregatedSeries, D as DataPoint } from './scale-DQ-IdB6t.js';
4
- export { v as AggregatedShowAs, w as AggregationConfig, x as AggregationMode, y as AnnotationKind, z as AxisOrientation, A as AxisPosition, B as DataPointRef, E as EnumMap, C as FillBound, I as FillRegion, J as FillSide, K as FillStyle, N as GapConfig, O as GapLabel, Q as GapRegion, U as GapStyle, G as GridLayer, V as LineShape, W as LineStyle, X as MarkerStyle, Y as MovingAverageType, Z as SVGLineStyle, _ as SensorType, $ as SeriesOverlay, a0 as SeriesOverlayKind, a1 as SeriesType, a2 as ShadowStyle, a3 as SolidDashStyle, a4 as ThresholdLabelConfig, a5 as getLineStyle, a6 as resolveDash } from './scale-DQ-IdB6t.js';
1
+ import { M as MLTimeGraphOptions, L as LegendItem, R as Renderer, a as LayoutResult, b as Margin, A as AxesConfig, X as XAxisConfig, Y as YAxisConfig, c as LegendOptions, d as LegendPosition, e as LegendOrientation, f as Marker, g as RenderOutput } from './marker_renderer-D5TfGx8R.js';
2
+ export { h as AxisLabelsStyle, i as AxisStyle, G as GridLineStyle, j as GridStyle, T as TextMetrics, k as Theme, l as TickConfig, m as drawMarker, n as estimateMetrics, o as getDefaultTheme, p as liberationMetrics, r as resetDefaultTheme, s as setDefaultTheme, q as slugify } from './marker_renderer-D5TfGx8R.js';
3
+ import { d as AnySeries, h as Annotation, a as DrawCommand, T as TimeScale, L as LinearScale, f as Gap, g as GapsConfig, e as Threshold, H as Highlight, i as AnnotationBandConfig, k as SeriesStyle, b as LineVariant, S as SmoothingType, F as FillSpec, l as TimeSeries, m as LineDashStyle, n as ThresholdFill, j as HatchVariant, o as ThresholdLabelPosition, P as PointStyleType, M as MarkerLineStyle, R as RangeLabelPosition, p as AnnotationPointShape, q as LabelAnchor, r as AnnotationBandItem, s as TextBaseline, t as AggregatedPoint, u as AggregatedSeries, D as DataPoint } from './scale-BStQU_t-.js';
4
+ export { v as AggregatedShowAs, w as AggregationConfig, x as AggregationMode, y as AnnotationKind, z as AxisOrientation, A as AxisPosition, B as DataPointRef, E as EnumMap, C as FillBound, I as FillRegion, J as FillSide, K as FillStyle, N as GapConfig, O as GapLabel, Q as GapRegion, U as GapStyle, G as GridLayer, V as LineShape, W as LineStyle, X as MarkerStyle, Y as MovingAverageType, Z as SVGLineStyle, _ as SensorType, $ as SeriesOverlay, a0 as SeriesOverlayKind, a1 as SeriesType, a2 as ShadowStyle, a3 as SolidDashStyle, a4 as ThresholdLabelConfig, a5 as getLineStyle, a6 as resolveDash } from './scale-BStQU_t-.js';
5
5
 
6
6
  /*!
7
7
  * MLTimeGraph — Copyright (c) 2026 Michael Lechner
@@ -28,6 +28,7 @@ declare class MLTimeGraph {
28
28
  private readonly _thresholds;
29
29
  private readonly _highlights;
30
30
  private readonly _gaps;
31
+ private readonly _gapsBand?;
31
32
  private readonly _gapsAutoDetect;
32
33
  private readonly _gapsMinGapMs;
33
34
  private _annotations;
@@ -861,6 +862,6 @@ declare function mergeOptions(...layers: (OptionsLayer | undefined)[]): MLTimeGr
861
862
  * Monate spaeter eine Datei aus einem Stapel von Berichten in der Hand haelt,
862
863
  * kann sonst nicht feststellen, welcher Stand sie gezeichnet hat.
863
864
  */
864
- declare const VERSION = "1.11.0";
865
+ declare const VERSION = "1.12.1";
865
866
 
866
867
  export { AggregatedPoint, AggregatedSeries, Annotation, AnnotationBandBuilder, AnnotationBandConfig, AnnotationBandItem, AnnotationBandItemBuilder, AnnotationBuilder, AnnotationPointShape, AnySeries, AxesConfig, DataPoint, DrawCommand, type FieldAccessor, type FillBetweenThresholdsInput, FillSpec, Gap, GapsConfig, GraphBuilder, HatchVariant, Highlight, HighlightBuilder, LabelAnchor, LegendItem, LegendOptions, LegendOrientation, LegendPosition, type LimitStatsPoint, LineDashStyle, LineVariant, MLTimeGraph, MLTimeGraphOptions, Margin, Marker, MarkerBuilder, MarkerLineStyle, type MktPoint, type OptionsLayer, PointStyleType, RangeLabelPosition, SVGRenderer, SeriesStyle, SmoothingType, type StatsAggregatedPoint, type StdDevPoint, TextBaseline, Threshold, ThresholdBuilder, ThresholdFill, ThresholdLabelPosition, type TimeInput, TimeSeries, TimeSeriesBuilder, type ToDataPointsSpec, type TooltipOptions, type TooltipSample, VERSION, XAxisConfig, YAxisConfig, attachTooltip, fillBetweenThresholds, mergeOptions, mount, parseAggregated, parseDataPoint, parseSeries, toDataPoints, toSeries };