ml-time-graph 1.10.0 → 1.12.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/CHANGELOG.md +65 -0
- package/README.de.md +33 -3
- package/README.md +31 -2
- package/SKILLS.md +111 -0
- package/dist/analyze/index.d.ts +72 -1
- package/dist/analyze/index.js +2 -2
- package/dist/index.d.ts +7 -288
- package/dist/index.js +9 -9
- package/dist/interaction/index.d.ts +1 -1
- package/dist/internals.d.ts +58 -7
- package/dist/internals.js +12 -12
- package/dist/{marker_renderer-D6rDW2Pe.d.ts → marker_renderer-D5TfGx8R.d.ts} +349 -2
- package/dist/{scale-B3MhoTu1.d.ts → scale-BStQU_t-.d.ts} +53 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -19,6 +19,71 @@ release notes, and every change is in `git log` in full.
|
|
|
19
19
|
|
|
20
20
|
---
|
|
21
21
|
|
|
22
|
+
## [1.12.0] - 2026-10-06
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
- **Gap labels can turn upright when they do not fit.** `gaps.style.label.rotate: 'auto'` rotates
|
|
26
|
+
a gap's label to -90° only when the text is wider than the gap, measured with the same advance
|
|
27
|
+
table the rest of the layout uses — before 1.10.0 there was no way to know. A short outage
|
|
28
|
+
labelled "Sensor Offline" used to spill out on both sides and over the data next to it. An
|
|
29
|
+
explicit angle still wins, and a label placed in the margin (`'above'` / `'below'`) stays flat,
|
|
30
|
+
because nothing is in its way there.
|
|
31
|
+
- **`divergenceExcursions()` in `ml-time-analyze`** — the periods in which several probes that
|
|
32
|
+
should agree did not, **and which one ran away**. Two probes in a fridge more than 2 °C apart
|
|
33
|
+
means something is wrong; *Unten is 4.5 °C warmer* sends someone to the right probe, *the
|
|
34
|
+
difference was 4.5 °C* does not. `minDurationMs` ignores a single noisy sample, and a timestamp
|
|
35
|
+
with fewer than two readings ends an episode the way a gap does. The pieces existed
|
|
36
|
+
(`spatialDelta` + `computeLimitExcursions`); what every caller wrote by hand was the wiring —
|
|
37
|
+
and lost the probe attribution doing it.
|
|
38
|
+
- **Highlights take `rotate: 'auto'` too.** Same rule as a gap label, and the same reason: a
|
|
39
|
+
four-hour episode labelled "Unten +4.5 °C" used to spill out over the data beside it. The shared
|
|
40
|
+
range renderer could already do it; highlights simply did not pass it through.
|
|
41
|
+
- **A strip that says when readings were missing.** `gaps.style.band` draws a bar on the plot's
|
|
42
|
+
baseline for every gap — one per gap, because the data between two gaps is not missing. It needs
|
|
43
|
+
no extra margin, unlike an annotation band, and it is the answer for gaps drawn as `'empty'`,
|
|
44
|
+
where the picture otherwise shows nothing but a break in the line. `height`, `fill`, `opacity`
|
|
45
|
+
and an `offset` into the bottom margin are yours to set.
|
|
46
|
+
|
|
47
|
+
- **Every legend entry is its own group — so you can click one.** Each entry now renders as
|
|
48
|
+
`<g class="legend-item legend-item--<id>" id="legend-<id>">`, carrying the *same* stable key as
|
|
49
|
+
the series it names (`#series-<id>`). `legend.itemClass` adds a class of your own to every entry,
|
|
50
|
+
and `legendItems()` returns the key as `id`. One handler on the chart is enough to toggle a
|
|
51
|
+
series: `#legend-pump` → `#series-pump`. Until now a clickable legend meant drawing the legend
|
|
52
|
+
yourself — with a second idea of what a swatch looks like. **The SVG gains a wrapper `<g>` per
|
|
53
|
+
entry**; CSS that targets `.chart-legend rect` still matches, but anything relying on entries
|
|
54
|
+
being direct children does not.
|
|
55
|
+
|
|
56
|
+
### Fixed
|
|
57
|
+
- **Go: a chart-wide `gaps.style.display` was ignored.** Only a region's own `style.display` was
|
|
58
|
+
read, so `display: 'empty'` set for the whole chart fell back to the default and drew a filled
|
|
59
|
+
area with two dashed edges — "draw nothing" drew something. TypeScript merged the chart-wide
|
|
60
|
+
style all along. No reference chart used the chart-wide field, which is why nobody saw it.
|
|
61
|
+
|
|
62
|
+
## [1.11.0] - 2026-10-05
|
|
63
|
+
|
|
64
|
+
### Added
|
|
65
|
+
- **`CommandBuilder` now covers every draw command**, in both libraries, and is reachable:
|
|
66
|
+
`ml-time-graph/internals` exports it, Go has `renderer.NewCommandBuilder()`. It sets the `type`
|
|
67
|
+
field for you, chains, nests groups — and skips a group whose body stays empty, which every
|
|
68
|
+
renderer used to guard by hand. Until 1.11.0 the TypeScript class had exactly one method
|
|
69
|
+
(`addLine`) and no entry point named it, so nobody could use it; the Go port had none at all.
|
|
70
|
+
`renderLegend` is built with it in both ports, so it runs on every reference chart.
|
|
71
|
+
- **A panel behind the legend.** `legend.box` draws a background and a border under the entries —
|
|
72
|
+
`box: {}` is enough and takes the defaults (white, a grey hairline, 6 px padding, 85 % opaque).
|
|
73
|
+
It is meant for `inside-left` / `inside-right`, where the legend sits over the data and a dense
|
|
74
|
+
curve or a filled area makes it hard to read. `stroke: 'none'` keeps the background without a
|
|
75
|
+
border. Nothing is drawn without `box`, so every existing chart looks as it did.
|
|
76
|
+
|
|
77
|
+
### Fixed
|
|
78
|
+
- **A labelled threshold no longer deletes the axis number at its height unless the two can
|
|
79
|
+
actually meet.** The axis dropped every tick label within 8 px of a labelled threshold, looking
|
|
80
|
+
only at the height and never at where the threshold's label sits. With the default position
|
|
81
|
+
(`'right'`, inside the plot) a humidity chart lost exactly its `100` at the left axis while
|
|
82
|
+
the label "saturation" stood at the far right. A tick label now gives way only to a threshold
|
|
83
|
+
label in the gutter of the same side: `'outside-left'` for a left axis, `'outside-right'` for a
|
|
84
|
+
right one. Expect axis numbers to reappear in charts with labelled thresholds — ten of the
|
|
85
|
+
reference templates gained one to three each, nothing else moved. Both ports, same rule.
|
|
86
|
+
|
|
22
87
|
## [1.10.0] - 2026-10-05
|
|
23
88
|
|
|
24
89
|
### 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
|
-
|
|
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
|
|
@@ -171,7 +201,7 @@ deshalb gibt es **ein** Changelog für beide: [CHANGELOG.md](https://gitlab.com/
|
|
|
171
201
|
Es liegt auch dem Paket bei — die Historie genau der Version, die du installiert hast, liegt
|
|
172
202
|
damit neben dem Code.
|
|
173
203
|
|
|
174
|
-
### Warum schon 1.
|
|
204
|
+
### Warum schon 1.X, und warum so viele Minor-Versionen?
|
|
175
205
|
|
|
176
206
|
Weil die Bibliothek täglich im Einsatz ist, und der Einsatz findet, was ein sauberer Entwurf
|
|
177
207
|
nicht findet.
|
|
@@ -219,7 +249,7 @@ go get gitlab.com/mlc0911/mlctimegraphpdf
|
|
|
219
249
|
mtg-pdf -in chart.json -out chart.pdf
|
|
220
250
|
```
|
|
221
251
|
|
|
222
|
-
Noch jung: Version 0.
|
|
252
|
+
Noch jung: Version 0.X.0, nicht 1.0, und ein, zwei Fähigkeiten hinter dieser Bibliothek. Was man
|
|
223
253
|
vorher wissen sollte — eine Füllung auf einem *Pfad*, also die Fläche unter einer Linie oder
|
|
224
254
|
einer Treppe, kommt derzeit deckend und ohne Schraffur heraus, weil nur Rechtecke beides
|
|
225
255
|
durchreichen. Linien, Marker, Text, Strichmuster, Kurvengeometrie und rechteckige Füllungen sind
|
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
|
-
|
|
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
|
|
@@ -170,7 +199,7 @@ changelog for both: [CHANGELOG.md](https://gitlab.com/mlc0911/mlctimegraph/-/blo
|
|
|
170
199
|
It ships with this package too, so the history of the exact version you installed is right
|
|
171
200
|
next to the code.
|
|
172
201
|
|
|
173
|
-
### Why already at 1.
|
|
202
|
+
### Why already at 1.X, and why so many minor releases?
|
|
174
203
|
|
|
175
204
|
Because the library is in daily professional use, and use finds what a clean design does not.
|
|
176
205
|
|
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
|
|
|
@@ -295,6 +317,95 @@ labels are drawn later still and stay on top either way.
|
|
|
295
317
|
is *meant* to cover it, or when a faint raster behind the data is enough. One setting governs the
|
|
296
318
|
whole grid; `axes.x` wins over `axes.left`, same as for the style.
|
|
297
319
|
|
|
320
|
+
### Building draw commands — `CommandBuilder`
|
|
321
|
+
```ts
|
|
322
|
+
import { CommandBuilder } from 'ml-time-graph/internals';
|
|
323
|
+
|
|
324
|
+
const b = new CommandBuilder();
|
|
325
|
+
b.rect({ x: 0, y: 0, w: 10, h: 10, fill: '#eee' })
|
|
326
|
+
.text({ content: 'Label', x: 14, y: 9 })
|
|
327
|
+
.group({ cssClass: 'marks' }, (g) => g.circle({ cx: 5, cy: 5, r: 2 }));
|
|
328
|
+
const group = b.toGroup({ cssClass: 'my-layer' });
|
|
329
|
+
```
|
|
330
|
+
For anyone producing draw commands — a custom layer, an annotation of your own, a renderer that
|
|
331
|
+
feeds the same `SVGRenderer`. It sets `type` for you, chains, and nests.
|
|
332
|
+
|
|
333
|
+
Two rules worth knowing. `group` draws **nothing** when its body adds nothing, so you cannot leave
|
|
334
|
+
an empty `<g>` behind; `toGroup` always returns a group, because a function that promises one must
|
|
335
|
+
deliver one. And `commands` hands out a copy — what you do with it afterwards cannot reach back
|
|
336
|
+
into the chart.
|
|
337
|
+
|
|
338
|
+
In Go it is `renderer.NewCommandBuilder()` with the same methods.
|
|
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
|
+
|
|
392
|
+
### A panel behind the legend — `legend.box`
|
|
393
|
+
```ts
|
|
394
|
+
legend: { show: true, position: 'inside-right', box: {} }
|
|
395
|
+
```
|
|
396
|
+
A legend inside the plot sits **over** the data, and over a dense curve or a filled area it can be
|
|
397
|
+
unreadable. `box` puts a quiet panel under it. Like the grid, it is drawn only when you ask:
|
|
398
|
+
`box: {}` takes the defaults — white, a grey hairline, 6 px padding, 85 % opaque, so the data still
|
|
399
|
+
shows through faintly. `fill`, `stroke`, `strokeWidth`, `padding` and `opacity` override them, and
|
|
400
|
+
`stroke: 'none'` keeps the background without a border.
|
|
401
|
+
|
|
402
|
+
The panel takes the place where the entries would otherwise end, rather than pushing them around:
|
|
403
|
+
turning it on does not move the legend out over the plot edge. With an outside legend the padding
|
|
404
|
+
is reserved as real space, so the border never reaches into the plot.
|
|
405
|
+
|
|
406
|
+
There are no rounded corners — the draw-command model has no corner radius, and adding one would
|
|
407
|
+
mean changing SVG, Go and the PDF renderer for a rounding.
|
|
408
|
+
|
|
298
409
|
### Legend Placement
|
|
299
410
|
`inside-left` / `inside-right` draw over the plot, `outside-left` / `outside-right` beside it,
|
|
300
411
|
`above` / `below` as a horizontal strip that wraps into as many rows as the entries need — the
|
package/dist/analyze/index.d.ts
CHANGED
|
@@ -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 };
|
package/dist/analyze/index.js
CHANGED
|
@@ -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{
|
|
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};
|