ml-time-graph 1.5.1 → 1.7.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/GRAPH_JSON_STRUCTURE.md +668 -0
- package/QUICKSTART_GRAPH_BUILDER.de.md +217 -0
- package/QUICKSTART_GRAPH_BUILDER.md +244 -0
- package/USAGE.md +62 -1
- package/dist/analyze/index.d.ts +1 -0
- package/dist/analyze/index.js +2 -2
- package/dist/index.d.ts +80 -6
- package/dist/index.js +25 -25
- package/dist/interaction/index.d.ts +1 -1
- package/dist/internals.d.ts +4 -4
- package/dist/internals.js +18 -18
- package/dist/{scale-ByGpczxS.d.ts → scale-D6NtEaUB.d.ts} +28 -7
- package/dist/{series_renderer-BxGvCHMY.d.ts → series_renderer-DQXKJttA.d.ts} +2 -2
- package/package.json +4 -2
- package/API_DESIGN.md +0 -1211
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# Quickstart: `GraphBuilder` (Deutsch)
|
|
2
|
+
|
|
3
|
+
`GraphBuilder` ist der imperative, objektorientierte Weg, mit MLTimeGraph ein
|
|
4
|
+
Diagramm aufzubauen. Statt einen großen Options-Objekt-Baum in einem Rutsch
|
|
5
|
+
zusammenzustellen, erzeugst du einen Builder und fügst die Konfiguration
|
|
6
|
+
Schritt für Schritt hinzu — jede `set*()` / `add*()`-Methode gibt `this`
|
|
7
|
+
zurück, sodass sich alles natürlich ketten lässt. Es funktioniert im Browser
|
|
8
|
+
**und** auf Node (SSR, Reportgenerierung, Datei-Output), weil das Rendern nur
|
|
9
|
+
einen SVG-String erzeugt.
|
|
10
|
+
|
|
11
|
+
Die vollständige Feld-zu-Feld-Referenz der Options, die `toOptions()`
|
|
12
|
+
liefert, findest du in [GRAPH_JSON_STRUCTURE.md](GRAPH_JSON_STRUCTURE.md) (englisch).
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pnpm add ml-time-graph # oder: npm i / yarn add
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Benötigt Node >= 18. Der Build ist ESM-only.
|
|
21
|
+
|
|
22
|
+
## Import
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { GraphBuilder } from "ml-time-graph";
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Alle unterstützenden Typen (`Threshold`, `Annotation`, `Marker`, …) werden als
|
|
29
|
+
Typen aus demselben Einstiegspunkt exportiert.
|
|
30
|
+
|
|
31
|
+
## Minimales Diagramm
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
const g = new GraphBuilder(800, 400);
|
|
35
|
+
|
|
36
|
+
// Zeiten sind Epoche-Millisekunden (Zahl) – niemals `Date`-Objekte.
|
|
37
|
+
g.addSeries({
|
|
38
|
+
name: "Temperatur",
|
|
39
|
+
data: [
|
|
40
|
+
{ time: Date.parse("2026-01-15T08:00:00Z"), value: 20.5 }, // 1768464000000
|
|
41
|
+
{ time: Date.parse("2026-01-15T09:00:00Z"), value: 24.1 }, // 1768467600000
|
|
42
|
+
{ time: Date.parse("2026-01-15T10:00:00Z"), value: 31.8 }, // 1768471200000
|
|
43
|
+
],
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// In ein DOM-Element …
|
|
47
|
+
g.mount("#chart");
|
|
48
|
+
|
|
49
|
+
// … oder als SVG-String (SSR / Datei / innerHTML)
|
|
50
|
+
const svg = g.getSvg();
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Breite `0` übergeben (oder weglassen) und `mount()` aufrufen, um die Pixelweite
|
|
54
|
+
automatisch aus der `clientWidth` des Ziels zu ermitteln.
|
|
55
|
+
|
|
56
|
+
## Kettung (Chaining)
|
|
57
|
+
|
|
58
|
+
Jeder Setter und Adder gibt den Builder zurück, sodass ein komplettes Diagramm
|
|
59
|
+
in einer einzigen Aussage steht:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
new GraphBuilder(900, 420)
|
|
63
|
+
.setLocale("de-DE")
|
|
64
|
+
.addSeries({ name: "Sensor 1", data })
|
|
65
|
+
.addThreshold({ name: "Limit", value: 35, color: "#dc2626" })
|
|
66
|
+
.addHighlight({ startTime: t1, endTime: t2, color: "#fef2f2" }) // Epoche-ms-Zahlen
|
|
67
|
+
.setXAxis({ label: "Zeit" })
|
|
68
|
+
.setLeftAxis({ label: "Temperatur (°C)" })
|
|
69
|
+
.setLegend(true, "inside-right")
|
|
70
|
+
.mount("#chart");
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Setter
|
|
74
|
+
|
|
75
|
+
| Methode | Wirkung |
|
|
76
|
+
| --- | --- |
|
|
77
|
+
| `setWidth(w)` / `setHeight(h)` / `setSize(w, h)` | Pixelwerte für die Größe. |
|
|
78
|
+
| `setMargin(margin)` oder `setMargin(top, right, bottom, left)` | Rand pro Seite in Pixeln. |
|
|
79
|
+
| `setLocale(locale)` | z. B. `"de-DE"` für Datum-/Zahlenformatierung. |
|
|
80
|
+
| `setAxes({ x?, left?, right? })` | Ersetzt den gesamten Achsenblock. |
|
|
81
|
+
| `setXAxis(cfg)` | Patcht nur die X-Achse (Spread-Merge). |
|
|
82
|
+
| `setLeftAxis(cfg)` | Patcht nur die linke Y-Achse, rechts bleibt unangetastet. |
|
|
83
|
+
| `setRightAxis(cfg)` | Patcht nur die rechte Y-Achse. |
|
|
84
|
+
| `setYAxis(index, cfg)` | Patcht eine beliebige Y-Achse per Index (Array wächst automatisch). |
|
|
85
|
+
| `setLegend(opts)` oder `setLegend(show, position?, orientation?)` | Legende zeigen / platzieren / ausrichten. Positionen: `"inside-right"`, `"inside-left"`, `"outside-right"`, `"outside-left"`, `"separate"`. |
|
|
86
|
+
| `setGaps(gapArrayOrConfig)` | Datengap-Handling — legacy `Gap[]` oder `{ regions?, autoDetect?, minGapMs?, style? }`. |
|
|
87
|
+
| `setTooltip({ show?, format?, snapRadius?, … })` | Tooltip; wirkt nur zusammen mit `mount()` (in reinem `getSvg()`-Output gibt es nichts zum Überfahren). Standard bei Aufruf: `show: true`. |
|
|
88
|
+
|
|
89
|
+
Achsen-Beispiele:
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
g.setXAxis({ label: "Zeit", format: (d) => d.toLocaleTimeString("de-DE") });
|
|
93
|
+
|
|
94
|
+
g.setLeftAxis({ label: "Temperatur (°C)", grid: { major: { color: "#e5e7eb" } } });
|
|
95
|
+
|
|
96
|
+
// Zwei Serien auf unterschiedlichen Skalen:
|
|
97
|
+
g.addSeries({ name: "Temp", data: tempData, yAxisIndex: 0 });
|
|
98
|
+
g.addSeries({ name: "Fluss", data: flowData, yAxisIndex: 1 });
|
|
99
|
+
g.setLeftAxis({ label: "°C" });
|
|
100
|
+
g.setRightAxis({ label: "L/h" });
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Adder
|
|
104
|
+
|
|
105
|
+
Jeder Adder hängt ein Element an seine interne Liste an; die `*All` / Plural-
|
|
106
|
+
Varianten hängen Arrays an. Alle geben `this` zurück.
|
|
107
|
+
|
|
108
|
+
| Methode | Fügt hinzu |
|
|
109
|
+
| --- | --- |
|
|
110
|
+
| `addSeries(s)` / `addSeriesAll(s[])` | Eine Zeitserie (`AnySeries`: rohe `DataPoint[]` oder aggregiert min/max/avg). |
|
|
111
|
+
| `addThreshold(t)` / `addThresholds(t[])` | Eine Schwelle: Linie, optionale Füllzone, optionales Label. |
|
|
112
|
+
| `addAnnotation(a)` / `addAnnotations(a[])` | Freiform-Overlay — eine der Varianten `line`, `arrow`, `rect`, `point`, `label` (diskriminiert über das Feld `type`). |
|
|
113
|
+
| `addHighlight(h)` | Ein hinterlegter Zeitraum, gezeichnet hinter den Daten. |
|
|
114
|
+
| `addMarker(m)` | Eine vertikale Markierung zu einem Zeitstempel, optional Wertpunkt + Label. |
|
|
115
|
+
| `addAnnotationBand(band)` | Ein horizontaler Streifen unter dem Diagramm mit farbigen Zeitfenstern und Labels. |
|
|
116
|
+
|
|
117
|
+
Beispiele:
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
// Schwellwert: `fill` ist eine Zeichenkette ("above" | "below" | "none") und
|
|
121
|
+
// `line` ist eine Zeichenkette ("solid" | "dashed" | "dotted" | "none");
|
|
122
|
+
// die Deckkraft ist ein separates Feld.
|
|
123
|
+
g.addThreshold({
|
|
124
|
+
name: "Max",
|
|
125
|
+
value: 35,
|
|
126
|
+
color: "#dc2626",
|
|
127
|
+
fill: "above",
|
|
128
|
+
fillOpacity: 0.1,
|
|
129
|
+
line: "dashed",
|
|
130
|
+
label: { position: "right" }, // oder direkt `label: "Max"` / `label: false`
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// Hervorgehobener Zeitraum (Störungs-Fenster). `startTime`/`endTime` sind Epoche-ms-Zahlen:
|
|
134
|
+
g.addHighlight({
|
|
135
|
+
startTime: Date.parse("2026-01-15T09:10:00Z"), // 1768468200000
|
|
136
|
+
endTime: Date.parse("2026-01-15T09:40:00Z"), // 1768470000000
|
|
137
|
+
color: "#fee2e2",
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// Ein Pfeil zwischen zwei Datenpunkten (Koordinaten: Epoche-ms + Wert).
|
|
141
|
+
// `title` ist Metadaten für Toggle-Panels / Legenden – im Diagramm NICHT gezeichnet:
|
|
142
|
+
g.addAnnotation({
|
|
143
|
+
id: "pfeil-sprung",
|
|
144
|
+
title: "Sprung bei Stoerung", // optional, nicht gerendert
|
|
145
|
+
type: "arrow",
|
|
146
|
+
from: { time: 1768469100000, value: 28.5 },
|
|
147
|
+
to: { time: 1768469160000, value: 41.3 },
|
|
148
|
+
color: "#b91c1c",
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// Sichtbarer Text im Diagramm ist ein eigener `label`-Annotation-Typ:
|
|
152
|
+
g.addAnnotation({
|
|
153
|
+
type: "label",
|
|
154
|
+
at: { time: 1768469160000, value: 41.3 },
|
|
155
|
+
text: "Sprung bei Stoerung",
|
|
156
|
+
anchor: "start",
|
|
157
|
+
dx: 8,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// Ein Marker (Epoche-ms):
|
|
161
|
+
g.addMarker({
|
|
162
|
+
time: Date.parse("2026-01-15T09:25:00Z"), // 1768469100000
|
|
163
|
+
value: 41.3,
|
|
164
|
+
label: "Spitze",
|
|
165
|
+
color: "#b91c1c",
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// Annotationsband unter dem Diagramm. Das Band hat ein `name` (kein title);
|
|
169
|
+
// seine Items verwenden `startTime`/`endTime` und eine CSS-Farb-angabe `fill`:
|
|
170
|
+
g.addAnnotationBand({
|
|
171
|
+
name: "Betriebszustand",
|
|
172
|
+
height: 28,
|
|
173
|
+
items: [
|
|
174
|
+
{ startTime: Date.parse("2026-01-15T08:00:00Z"), endTime: Date.parse("2026-01-15T09:20:00Z"), fill: "#dcfce7", label: "Normal" },
|
|
175
|
+
{ startTime: Date.parse("2026-01-15T09:20:00Z"), endTime: Date.parse("2026-01-15T10:30:00Z"), fill: "#fee2e2", label: "Anlage gestoppt" },
|
|
176
|
+
],
|
|
177
|
+
});
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Teilweise Neudefinition eines Charts
|
|
181
|
+
|
|
182
|
+
`clear()` entfernt eine Kategorie (oder alles, ohne Argument), wodurch sich
|
|
183
|
+
Abschnitte einfach neu aufbauen lassen — z. B. den Datensatz tauschen, aber
|
|
184
|
+
Schwellen und Annotationen behalten:
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
g.clear("series"); // nur Serien entfernen
|
|
188
|
+
g.addSeries({ name: "Temperatur", data });
|
|
189
|
+
|
|
190
|
+
// oder ganz von vorn beginnen:
|
|
191
|
+
g.clear(); // entfernt series, thresholds, annotations, highlights, markers, bands
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Abschluss-Methoden (Terminal methods)
|
|
195
|
+
|
|
196
|
+
Diese geben den Builder **nicht** zurück. Sie kommen ans Ende der Kette.
|
|
197
|
+
|
|
198
|
+
| Methode | Rückgabe | Typische Anwendung |
|
|
199
|
+
| --- | --- | --- |
|
|
200
|
+
| `toOptions()` | `MLTimeGraphOptions` | Die vollständige, serialisierbare Konfiguration — an anderen Orten verwenden, persistieren oder mit einem anderen Chart diffen. Per Adder gesetzte Felder überschreiben gleichnamige Felder aus dem Konstruktionspfad. |
|
|
201
|
+
| `build()` | `MLTimeGraph` | Eine frische Chart-Instanz pro Aufruf, für erweiterte Nutzung: `project()`, `invertTime()`, `setData()`, manuelle `attachTooltip(...)`-Aufrufe, kustomes Rendern. |
|
|
202
|
+
| `getSvg()` | `string` | Komplette `<svg …>`-Markup. In die Datei schreiben (`fs.writeFileSync("chart.svg", svg)`), als HTTP-Antwort übermitteln oder per `el.innerHTML = g.getSvg()` setzen. Wiederholte Aufrufe rendern neu mit dem aktuellen Builder-Zustand. |
|
|
203
|
+
| `mount(target)` | `MLTimeGraph` | Rendern in ein DOM-Element (Element oder Selektor-String wie `"#chart"`). Ermittelt die Breite automatisch, schreibt responsives SVG und hängt das Tooltip an, falls eines konfiguriert wurde. Wirft, wenn das Ziel nicht gefunden wird. |
|
|
204
|
+
|
|
205
|
+
### SSR / Reportgenerierung (Node)
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
import { GraphBuilder } from "ml-time-graph";
|
|
209
|
+
import { writeFileSync } from "node:fs";
|
|
210
|
+
|
|
211
|
+
const svg = new GraphBuilder(1200, 600)
|
|
212
|
+
.addSeries({ name: "CPU", data })
|
|
213
|
+
.setAxes({ left: { label: "%", ticks: { count: 5 } } })
|
|
214
|
+
.getSvg();
|
|
215
|
+
|
|
216
|
+
writeFileSync("report-chart.svg", svg);
|
|
217
|
+
```
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
# Quickstart: `GraphBuilder`
|
|
2
|
+
|
|
3
|
+
`GraphBuilder` is the imperative, object-oriented way to author a chart with
|
|
4
|
+
MLTimeGraph. Instead of assembling one big options object up front, you create
|
|
5
|
+
a builder and add config step by step — every `set*()` / `add*()` method
|
|
6
|
+
returns `this`, so calls chain naturally. It works in the browser **and** on
|
|
7
|
+
Node (SSR, report generation, file output) because rendering just produces an
|
|
8
|
+
SVG string.
|
|
9
|
+
|
|
10
|
+
For the full field-by-field reference of the options that `toOptions()`
|
|
11
|
+
produces, see [GRAPH_JSON_STRUCTURE.md](GRAPH_JSON_STRUCTURE.md).
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add ml-time-graph # or: npm i / yarn add
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Requires Node >= 18. The build is ESM-only.
|
|
20
|
+
|
|
21
|
+
## Import
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { GraphBuilder } from "ml-time-graph";
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
All supporting types (`Threshold`, `Annotation`, `Marker`, ...) are exported
|
|
28
|
+
as types from the same entry point.
|
|
29
|
+
|
|
30
|
+
## Minimal chart
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
const g = new GraphBuilder(800, 400);
|
|
34
|
+
|
|
35
|
+
// Times are epoch milliseconds (number) — never `Date` objects.
|
|
36
|
+
g.addSeries({
|
|
37
|
+
name: "Temperatur",
|
|
38
|
+
data: [
|
|
39
|
+
{ time: Date.parse("2026-01-15T08:00:00Z"), value: 20.5 }, // 1768464000000
|
|
40
|
+
{ time: Date.parse("2026-01-15T09:00:00Z"), value: 24.1 }, // 1768467600000
|
|
41
|
+
{ time: Date.parse("2026-01-15T10:00:00Z"), value: 31.8 }, // 1768471200000
|
|
42
|
+
],
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Into a DOM element …
|
|
46
|
+
g.mount("#chart");
|
|
47
|
+
|
|
48
|
+
// … or as an SVG string (SSR / file / innerHTML)
|
|
49
|
+
const svg = g.getSvg();
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Pass width `0` (or omit it) and call `mount()` to auto-detect the pixel width
|
|
53
|
+
from the target's `clientWidth`.
|
|
54
|
+
|
|
55
|
+
## Chaining
|
|
56
|
+
|
|
57
|
+
Every setter and adder returns the builder, so a complete chart can be one
|
|
58
|
+
statement:
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
new GraphBuilder(900, 420)
|
|
62
|
+
.setLocale("de-DE")
|
|
63
|
+
.addSeries({ name: "Sensor 1", data })
|
|
64
|
+
.addThreshold({ name: "Limit", value: 35, color: "#dc2626" })
|
|
65
|
+
.addHighlight({ startTime: t1, endTime: t2, color: "#fef2f2" }) // epoch ms numbers
|
|
66
|
+
.setXAxis({ label: "Zeit" })
|
|
67
|
+
.setLeftAxis({ label: "Temperatur (°C)" })
|
|
68
|
+
.setLegend(true, "inside-right")
|
|
69
|
+
.mount("#chart");
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Setters
|
|
73
|
+
|
|
74
|
+
| Method | Effect |
|
|
75
|
+
| --- | --- |
|
|
76
|
+
| `setWidth(w)` / `setHeight(h)` / `setSize(w, h)` | Pixel dimensions. |
|
|
77
|
+
| `setMargin(margin)` or `setMargin(top, right, bottom, left)` | Per-side pixel margins. |
|
|
78
|
+
| `setLocale(locale)` | e.g. `"de-DE"` for date/number formatting. |
|
|
79
|
+
| `setAxes({ x?, left?, right? })` | Replace the entire axes block. |
|
|
80
|
+
| `setXAxis(cfg)` | Patch only the X-axis (spread merge). |
|
|
81
|
+
| `setLeftAxis(cfg)` | Patch the left Y-axis only; leaves the right one untouched. |
|
|
82
|
+
| `setRightAxis(cfg)` | Patch the right Y-axis only. |
|
|
83
|
+
| `setYAxis(index, cfg)` | Patch any Y-axis by index (array auto-expands). |
|
|
84
|
+
| `setLegend(opts)` or `setLegend(show, position?, orientation?)` | Show / place / orient the legend. Positions: `"inside-right"`, `"inside-left"`, `"outside-right"`, `"outside-left"`, `"separate"`. |
|
|
85
|
+
| `setGaps(gapArrayOrConfig)` | Data-gap handling — legacy `Gap[]` or `{ regions?, autoDetect?, minGapMs?, style? }`. |
|
|
86
|
+
| `setTooltip({ show?, format?, snapRadius?, ... })` | Tooltip; only takes effect with `mount()` (there is nothing to hover over in pure `getSvg()` output). Defaults to `show: true` when called. |
|
|
87
|
+
|
|
88
|
+
Axes examples:
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
g.setXAxis({ label: "Zeit", format: (d) => d.toLocaleTimeString("de-DE") });
|
|
92
|
+
|
|
93
|
+
g.setLeftAxis({ label: "Temperatur (°C)", grid: { major: { color: "#e5e7eb" } } });
|
|
94
|
+
|
|
95
|
+
// Two series on different scales:
|
|
96
|
+
g.addSeries({ name: "Temp", data: tempData, yAxisIndex: 0 });
|
|
97
|
+
g.addSeries({ name: "Fluss", data: flowData, yAxisIndex: 1 });
|
|
98
|
+
g.setLeftAxis({ label: "°C" });
|
|
99
|
+
g.setRightAxis({ label: "L/h" });
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Adders
|
|
103
|
+
|
|
104
|
+
Each adder appends one item to its internal list; the `*All` / plural variants
|
|
105
|
+
append arrays. All return `this`.
|
|
106
|
+
|
|
107
|
+
| Method | Adds |
|
|
108
|
+
| --- | --- |
|
|
109
|
+
| `addSeries(s)` / `addSeriesAll(s[])` | A time series (`AnySeries`: raw `DataPoint[]` or aggregated min/max/avg). |
|
|
110
|
+
| `addThreshold(t)` / `addThresholds(t[])` | A threshold: line, optional fill zone, optional label. |
|
|
111
|
+
| `addAnnotation(a)` / `addAnnotations(a[])` | Free-form overlay — one of the variants `line`, `arrow`, `rect`, `point`, `label` (discriminated on the `type` field). |
|
|
112
|
+
| `addHighlight(h)` | A highlighted time range drawn behind the data. |
|
|
113
|
+
| `addMarker(m)` | A vertical pin at a timestamp, optional value dot + label. |
|
|
114
|
+
| `addAnnotationBand(band)` | A horizontal strip below the chart showing colored time ranges with items/labels. |
|
|
115
|
+
|
|
116
|
+
Examples:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
// Threshold: `fill` is a string ("above" | "below" | "none") and `line` is
|
|
120
|
+
// a string ("solid" | "dashed" | "dotted" | "none"); opacity is a separate field.
|
|
121
|
+
g.addThreshold({
|
|
122
|
+
name: "Max",
|
|
123
|
+
value: 35,
|
|
124
|
+
color: "#dc2626",
|
|
125
|
+
fill: "above",
|
|
126
|
+
fillOpacity: 0.1,
|
|
127
|
+
line: "dashed",
|
|
128
|
+
label: { position: "right" }, // or just `label: "Max"` / `label: false`
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// Highlighted region (incident window). `startTime`/`endTime` are epoch ms numbers:
|
|
132
|
+
g.addHighlight({
|
|
133
|
+
startTime: Date.parse("2026-01-15T09:10:00Z"), // 1768468200000
|
|
134
|
+
endTime: Date.parse("2026-01-15T09:40:00Z"), // 1768470000000
|
|
135
|
+
color: "#fee2e2",
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// An arrow between two data points (coordinates are epoch ms + value numbers).
|
|
139
|
+
// `title` is metadata for toggle panels / legends — not drawn in the chart:
|
|
140
|
+
g.addAnnotation({
|
|
141
|
+
id: "arrow-spike",
|
|
142
|
+
title: "Sprung bei Stoerung", // optional, not rendered
|
|
143
|
+
type: "arrow",
|
|
144
|
+
from: { time: 1768469100000, value: 28.5 },
|
|
145
|
+
to: { time: 1768469160000, value: 41.3 },
|
|
146
|
+
color: "#b91c1c",
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// Visible text on the chart is a separate `label` annotation:
|
|
150
|
+
g.addAnnotation({
|
|
151
|
+
type: "label",
|
|
152
|
+
at: { time: 1768469160000, value: 41.3 },
|
|
153
|
+
text: "Sprung bei Stoerung",
|
|
154
|
+
anchor: "start",
|
|
155
|
+
dx: 8,
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// A marker pin (epoch ms):
|
|
159
|
+
g.addMarker({
|
|
160
|
+
time: Date.parse("2026-01-15T09:25:00Z"), // 1768469100000
|
|
161
|
+
value: 41.3,
|
|
162
|
+
label: "Spitze",
|
|
163
|
+
color: "#b91c1c",
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// Annotation band below the chart. The band has a `name` (not title);
|
|
167
|
+
// its items use `startTime`/`endTime` and a CSS-color `fill`:
|
|
168
|
+
g.addAnnotationBand({
|
|
169
|
+
name: "Betriebszustand",
|
|
170
|
+
height: 28,
|
|
171
|
+
items: [
|
|
172
|
+
{ startTime: Date.parse("2026-01-15T08:00:00Z"), endTime: Date.parse("2026-01-15T09:20:00Z"), fill: "#dcfce7", label: "Normal" },
|
|
173
|
+
{ startTime: Date.parse("2026-01-15T09:20:00Z"), endTime: Date.parse("2026-01-15T10:30:00Z"), fill: "#fee2e2", label: "Anlage gestoppt" },
|
|
174
|
+
],
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Rebuilding parts of a chart
|
|
179
|
+
|
|
180
|
+
`clear()` wipes one category (or everything when called with no argument),
|
|
181
|
+
which makes it easy to rebuild sections — e.g. swap the dataset while keeping
|
|
182
|
+
thresholds and annotations:
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
g.clear("series"); // remove only series
|
|
186
|
+
g.addSeries({ name: "Temperatur", data });
|
|
187
|
+
|
|
188
|
+
// or start completely over:
|
|
189
|
+
g.clear(); // removes series, thresholds, annotations, highlights, markers, bands
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Terminal methods
|
|
193
|
+
|
|
194
|
+
These **do not** return the builder. Call them last.
|
|
195
|
+
|
|
196
|
+
| Method | Returns | Typical use |
|
|
197
|
+
| --- | --- | --- |
|
|
198
|
+
| `toOptions()` | `MLTimeGraphOptions` | The complete, serializable config — pass it to other code, persist it, or diff against another chart. Fields added via adders win over same-named fields set through the constructor path. |
|
|
199
|
+
| `build()` | `MLTimeGraph` | A fresh chart instance each call, for advanced use: `project()`, `invertTime()`, `setData()`, manual `attachTooltip(...)` calls, custom rendering. |
|
|
200
|
+
| `getSvg()` | `string` | Full `<svg …>` markup. Write to a file (`fs.writeFileSync("chart.svg", svg)`), send as an HTTP response body, or set via `el.innerHTML = g.getSvg()`. Repeated calls re-render with the current builder state. |
|
|
201
|
+
| `mount(target)` | `MLTimeGraph` | Render into a DOM element (element or selector string like `"#chart"`). Auto-detects width when not set, writes responsive SVG, and attaches the tooltip if one was configured. Throws if the target is not found. |
|
|
202
|
+
|
|
203
|
+
### SSR / report generation (Node)
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
import { GraphBuilder } from "ml-time-graph";
|
|
207
|
+
import { writeFileSync } from "node:fs";
|
|
208
|
+
|
|
209
|
+
const svg = new GraphBuilder(1200, 600)
|
|
210
|
+
.addSeries({ name: "CPU", data })
|
|
211
|
+
.setAxes({ left: { label: "%", ticks: { count: 5 } } })
|
|
212
|
+
.getSvg();
|
|
213
|
+
|
|
214
|
+
writeFileSync("report-chart.svg", svg);
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Browser
|
|
218
|
+
|
|
219
|
+
```ts
|
|
220
|
+
g.mount("#chart"); // renders + tooltip (if set)
|
|
221
|
+
|
|
222
|
+
// … or grab the instance for further interaction:
|
|
223
|
+
const chart = g.build();
|
|
224
|
+
const x = chart.project(time).x; // data → pixel mapping
|
|
225
|
+
const t = chart.invertTime(x); // pixel → time
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Relationship to the other entry points
|
|
229
|
+
|
|
230
|
+
- **`mount(target, options)`** — one-shot: build from a single options object
|
|
231
|
+
and install it. Simplest API for dashboards.
|
|
232
|
+
- **`new MLTimeGraph(options)`** — instance-level construction without any
|
|
233
|
+
DOM coupling (project/invert/setData, custom renderers).
|
|
234
|
+
- **`GraphBuilder`** — step-by-step config accumulation with clean terminal
|
|
235
|
+
methods; the best fit when the chart is assembled programmatically or the
|
|
236
|
+
output is a file / SSR payload.
|
|
237
|
+
- The companion builders (`TimeSeriesBuilder`, `ThresholdBuilder`, …) are
|
|
238
|
+
exported from the same entry point and work on individual items — use them
|
|
239
|
+
with or without `GraphBuilder`.
|
|
240
|
+
|
|
241
|
+
For the complete, field-by-field structure of what `toOptions()` produces, see
|
|
242
|
+
[GRAPH_JSON_STRUCTURE.md](GRAPH_JSON_STRUCTURE.md). For general usage topics
|
|
243
|
+
(MKT lines, overlays, aggregation) see [USAGE.md](USAGE.md); for design-level
|
|
244
|
+
details see [USAGE.md](USAGE.md).
|
package/USAGE.md
CHANGED
|
@@ -58,6 +58,46 @@ the browser and server-side. For DOM-specific behaviour, extend
|
|
|
58
58
|
A `series` entry is either a **raw** time series (`DataPoint[]` = `{ time, value }`)
|
|
59
59
|
or an **aggregated** series (`AggregatedPoint[]` = `{ time, min, max, avg, count }`).
|
|
60
60
|
|
|
61
|
+
### Your data is shaped differently — `toDataPoints`
|
|
62
|
+
|
|
63
|
+
`{ time, value }` is what the chart reads everywhere: scales, run splitting, zone
|
|
64
|
+
cuts, the tooltip, the Go port. It stays strict on purpose. The give is at the
|
|
65
|
+
boundary — one conversion, instead of a `.map()` in every caller:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import { toDataPoints, toSeries } from 'ml-time-graph';
|
|
69
|
+
|
|
70
|
+
// Tuples
|
|
71
|
+
toDataPoints([[1758434400000, 2.1], [1758438000000, 3.4]]);
|
|
72
|
+
|
|
73
|
+
// Other field names, Unix seconds
|
|
74
|
+
toDataPoints(rows, { time: 'ts', value: 'val', timeUnit: 's' });
|
|
75
|
+
|
|
76
|
+
// ISO strings or Date objects — recognised on their own
|
|
77
|
+
toDataPoints(rows, { time: 'recorded_at', value: 'reading' });
|
|
78
|
+
|
|
79
|
+
// Anything else: read it yourself
|
|
80
|
+
toDataPoints(rows, { time: (r) => r.meta.at, value: (r) => r.payload.power.kw });
|
|
81
|
+
|
|
82
|
+
// Series name and conversion in one line
|
|
83
|
+
series: [toSeries('Load', rows, { time: 'ts', value: 'val', timeUnit: 's' })];
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Details worth knowing:
|
|
87
|
+
|
|
88
|
+
- **Numbers are milliseconds** unless you say otherwise. No guessing by default —
|
|
89
|
+
`timeUnit: 's'` for Unix seconds, `'auto'` to detect them. `'auto'` leaves a
|
|
90
|
+
relative time base (0, 1000, 2000 …) alone, so it cannot silently shift it.
|
|
91
|
+
- **A missing reading becomes a gap**, not a zero: `null`, `undefined`, `NaN` and
|
|
92
|
+
`''` all break the line. Drawing a missing measurement as 0 would claim a value
|
|
93
|
+
the sensor never reported.
|
|
94
|
+
- **Numeric strings are converted** (`'21.5'` → `21.5`) — the usual CSV and JSON
|
|
95
|
+
case. A non-numeric string throws and names the row, instead of quietly
|
|
96
|
+
producing an empty chart.
|
|
97
|
+
- **Sorted by time** by default; pass `sort: false` if you sorted already.
|
|
98
|
+
|
|
99
|
+
See `demos/adapters.html` — the same chart from four input shapes.
|
|
100
|
+
|
|
61
101
|
Visual styling lives in a nested `style` block — `line`, `fill`, `markers`, `shadow`,
|
|
62
102
|
`gap`. Any combination is allowed: set `line` for a line, add `fill` for an area
|
|
63
103
|
underneath, add `markers` for points, set `style.line: false` for points only.
|
|
@@ -74,12 +114,16 @@ underneath, add `markers` for points, set `style.line: false` for points only.
|
|
|
74
114
|
}
|
|
75
115
|
|
|
76
116
|
// Step + smoothed overlay (multi-line array — same data, both rendered)
|
|
117
|
+
// Each entry keeps its own shape: the first is the staircase, the second a
|
|
118
|
+
// smoothed line through the readings. An entry without a `shape` of its own is
|
|
119
|
+
// a straight line — it does NOT inherit the first one's. The first entry is
|
|
120
|
+
// the series' shape: fill, zone colours and markers follow it.
|
|
77
121
|
{
|
|
78
122
|
name: 'CPU',
|
|
79
123
|
data,
|
|
80
124
|
style: { line: [
|
|
81
125
|
{ color: '#999', width: 1, shape: 'step' },
|
|
82
|
-
{ color: '#3b82f6', width: 2, smoothing: true },
|
|
126
|
+
{ color: '#3b82f6', width: 2, smoothing: true, opacity: 0.8 },
|
|
83
127
|
] },
|
|
84
128
|
}
|
|
85
129
|
|
|
@@ -176,6 +220,23 @@ style: { fill: fillBetweenThresholds({
|
|
|
176
220
|
|
|
177
221
|
A `FillBound` is `'series' | 'chartTop' | 'chartBottom' | { threshold: name } | { value: n }`.
|
|
178
222
|
|
|
223
|
+
A fill follows the shape of its line. With `shape: 'step'` the area is a
|
|
224
|
+
staircase too — it never claims a value between two readings, which is the whole
|
|
225
|
+
point of a step for state-like quantities (runtime, stage, operating mode):
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
style: {
|
|
229
|
+
line: { color: '#1d4ed8', width: 2, shape: 'step' },
|
|
230
|
+
fill: { color: '#1d4ed822', hatch: 'classic-diagonal' },
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
A threshold bound cuts the vertical jump at the reading's timestamp, so the part
|
|
235
|
+
above a limit is a rectangle, not a triangle. Steps are never smoothed: a
|
|
236
|
+
`smoothing: true` next to `shape: 'step'` is ignored for both line and fill.
|
|
237
|
+
(Before 1.7.0 the area ran as a ramp underneath the staircase — see
|
|
238
|
+
`demos/steps.html`.)
|
|
239
|
+
|
|
179
240
|
For *classified* (mutually-exclusive) zone bands, give a region both a `side`
|
|
180
241
|
and an `outer` bound — the region renders only in X-spans where the line's
|
|
181
242
|
value is between the fixed inner bound and `outer`:
|
package/dist/analyze/index.d.ts
CHANGED
|
@@ -119,6 +119,7 @@ declare class SeriesProcessor {
|
|
|
119
119
|
static splitByBoundaries<T>(run: T[], boundaries: number[], getValue: (p: T) => number, interpolate: (p1: T, p2: T, t: number) => T): {
|
|
120
120
|
data: T[];
|
|
121
121
|
zoneIndex: number;
|
|
122
|
+
zoneLow: number;
|
|
122
123
|
}[];
|
|
123
124
|
/**
|
|
124
125
|
* Splits a contiguous run into two groups: those below and those at/above a threshold.
|
package/dist/analyze/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var E=class{static interpolateDataPoint(n,i,t){return {time:n.time+Math.round(t*(i.time-n.time)),value:(n.value??0)+t*((i.value??0)-(n.value??0))}}static interpolateAggregatedPoint(n,i,t){let a=(e,l)=>e!==null&&l!==null?e+t*(l-e):null;return {time:n.time+t*(i.time-n.time),min:a(n.min,i.min),max:a(n.max,i.max),avg:a(n.avg,i.avg),count:Math.round(n.count+t*(i.count-n.count))}}static getRuns(n,i,t=0){let a=[...n].sort((r,m)=>r.time-m.time),e=[],l=[],u=null;for(let r of a){let m=i(r),o=t>0&&u&&r.time-u.time>t;(m||o)&&l.length&&(e.push(l),l=[]),m||l.push(r),u=r;}return l.length&&e.push(l),e}static splitByBoundaries(n,i,t,a){if(n.length===0)return [];if(i.length===0)return [{data:n,zoneIndex:0,zoneLow:Number.NEGATIVE_INFINITY}];let e=[...i].sort((o,s)=>o-s),l=[],u=o=>o<=0?Number.NEGATIVE_INFINITY:e[o-1],r=o=>{let s=0;for(let f=0;f<e.length&&o>=e[f];f++)s=f+1;return s},m=[n[0]];for(let o=1;o<n.length;o++){let s=n[o-1],f=n[o],g=t(s),d=t(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=a(s,f,x);m.push(h);let c=r((b+v)/2);l.push({data:m,zoneIndex:c,zoneLow:u(c)}),m=[h],b=v;}(p.length===0||p[p.length-1]!==d)&&m.push(f);}if(m.length>1){let o=t(m[0]),s=t(m[m.length-1]),f=r((o+s)/2);l.push({data:m,zoneIndex:f,zoneLow:u(f)});}return l}static splitByThreshold(n,i,t,a){let e=this.splitByBoundaries(n,[i],t,a),l={above:[],below:[]};for(let u of e)u.zoneIndex===0?l.below.push(u.data):l.above.push(u.data);return l}},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 y(n,i,t,a=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:t?0:null,minutesBelowLow:t?0:null,count:0};let l=1/0,u=-1/0,r=0;for(let h of e)h<l&&(l=h),h>u&&(u=h),r+=h;let m=r/e.length,o=t?0:null,s=t?0:null;if(t)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>t.limitHigh&&(o+=w),c.value<t.limitLow&&(s+=w);}}let f=0,g=0,d=(t?.activationEnergy??83144)/D;for(let h of e){f+=Math.pow(h-m,2);let c=h+N;g+=Math.exp(-d/c);}let p=f/e.length,b=Math.sqrt(p),v=null,x=null;if(e.length>=a){let h=g/e.length,c=d/-Math.log(h);v=Number((c-N).toFixed(2)),x=Number((v-m).toFixed(2));}return {time:n,min:Number(l.toFixed(2)),max:Number(u.toFixed(2)),avg:Number(m.toFixed(2)),mkt:v,deltaMkt:x,stdDev:Number(b.toFixed(2)),minutesAboveHigh:o!==null?Number(o.toFixed(1)):null,minutesBelowLow:s!==null?Number(s.toFixed(1)):null,count:e.length}}function L(n,i="hourly",t,a,e=1){if(!n.length)return [];let l=i==="hourly"?36e5:i==="daily"?864e5:t??3600*1e3,u=[...n].sort((s,f)=>s.time-f.time),r=[],m=u[0].time,o=[];for(let s of u){for(;s.time-m>=l;)r.push(y(m,o,a,e)),m+=l,o=[];o.push(s);}return r.push(y(m,o,a,e)),r}function S(n,i){let t=1/0,a=-1/0,e=0;for(let u of i)u<t&&(t=u),u>a&&(a=u),e+=u;let l=e/i.length;return {time:n,min:t,max:a,avg:l,count:i.length}}function z(n,i=6e4){if(n.length<2)return [];let t=[...n].sort((e,l)=>e.time-l.time),a=[];for(let e=1;e<t.length;e++)t[e].time-t[e-1].time>i&&a.push({startTime:t[e-1].time,endTime:t[e].time});return a}function B(n){let i=[],t=0,a=0,e=0,l=0;for(let u of n)u.count>0&&(e++,u.minutesAboveHigh&&(t+=u.minutesAboveHigh),u.stdDev&&u.stdDev>a&&(a=u.stdDev),u.deltaMkt&&u.deltaMkt>2&&l++);return e===0?[]:(t>120&&i.push({type:"critical",message:`Kritische Gesamtbelastung: Das Produkt war im gesamten Zeitraum insgesamt ${Math.round(t)} Minuten zu warm.`,metric:"Total Excursion Time"}),l>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"}),a>4&&i.push({type:"warning",message:`High instability measured. Maximum standard deviation was ${a}\xB0C. The cooling system controls imprecisely.`,metric:"Standard Deviation Peak"}),i)}function P(n,i){if(n.length<=i)return n;let t=[],a=Math.ceil(n.length/i);t.push(n[0]);for(let e=1;e<n.length;e+=a)t.push(n[Math.min(e,n.length-1)]);return t}function _(n,i="hourly",t){let a={limitLow:t.low,limitHigh:t.high,activationEnergy:t.activationEnergy};return L(n,i,t.interval,a,t.minCountForMkt??1)}var C=class{static compute(n){let i=n.map(r=>r.value).filter(r=>r!==null).sort((r,m)=>r-m);if(i.length===0)return {min:NaN,max:NaN,avg:NaN,mean:NaN,median:NaN,stdDev:NaN,count:0};let t=i.length,a=i.reduce((r,m)=>r+m,0)/t,e=t%2===1?i[Math.floor(t/2)]:(i[t/2-1]+i[t/2])/2,l=i.reduce((r,m)=>r+Math.pow(m-a,2),0)/t,u=Math.sqrt(l);return {min:i[0],max:i[t-1],avg:a,mean:a,median:e,stdDev:u,count:t}}static computeInRange(n,i,t){let a=n.filter(e=>e.time>=i&&e.time<=t);return this.compute(a)}};function q(n,i){let t=typeof n=="number"?n:n.mean,a=typeof n=="number"?i??NaN:n.stdDev;return !Number.isFinite(t)||!Number.isFinite(a)||t===0?null:Math.abs(a/t)*100}var G=83144;function F(n,i=83144){let t=i/8.314,a=0,e=0;for(let u of n)u!==null&&(a+=Math.exp(-t/(u+273.15)),e++);if(e===0)return null;let l=a/e;return t/-Math.log(l)-273.15}function R(n,i,t=83144){let a=new Array(n.length),e=0;for(let l=0;l<n.length;l++){let u=n[l].time,r=u-i;for(;e<l&&n[e].time<r;)e++;let m=n.slice(e,l+1).map(s=>s.value),o=F(m,t);a[l]={time:u,value:o,synthetic:true};}return a}function I(n){let i=0,t=0;for(let l of n)l!==null&&(i+=l,t++);if(t===0)return null;let a=i/t,e=0;for(let l of n){if(l===null)continue;let u=l-a;e+=u*u;}return Math.sqrt(e/t)}function k(n){let i=0,t=0;for(let l of n)l!==null&&(i+=l,t++);if(t<2)return null;let a=i/t,e=0;for(let l of n){if(l===null)continue;let u=l-a;e+=u*u;}return Math.sqrt(e/(t-1))}function V(n,i,t=false){let a=new Array(n.length),e=0,l=t?k:I;for(let u=0;u<n.length;u++){let r=n[u].time,m=r-i;for(;e<u&&n[e].time<m;)e++;let o=n.slice(e,u+1).map(f=>f.value),s=l(o);a[u]={time:r,value:s,synthetic:true};}return a}function K(n,i){let{high:t,low:a}=i,e={msAboveHigh:0,msBelowLow:0,globalMax:null,globalMin:null,excursions:[]},l=null;for(let u=0;u<n.length;u++){let r=n[u];if(r.value===null){l&&(e.excursions.push(l),l=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 m=t!==void 0&&r.value>t,o=a!==void 0&&r.value<a,s=m?"above":o?"below":null,f=n[u-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){l&&(e.excursions.push(l),l=null);continue}l&&l.side===s?(l.endTime=r.time,l.durationMs=l.endTime-l.startTime,(s==="above"&&r.value>l.extremum||s==="below"&&r.value<l.extremum)&&(l.extremum=r.value)):(l&&e.excursions.push(l),l={startTime:r.time,endTime:r.time,side:s,extremum:r.value,durationMs:0});}return l&&e.excursions.push(l),e}function O(n){if(n.length===0)return [];let i=new Map;for(let a of n)for(let e of a.data){if(e.value===null)continue;let l=i.get(e.time);l||(l=[],i.set(e.time,l)),l.push({name:a.name,value:e.value});}let t=[];for(let a of [...i.keys()].sort((e,l)=>e-l)){let e=i.get(a);if(e.length===0){t.push({time:a,min:null,max:null,delta:null,minSensor:null,maxSensor:null});continue}let l=e[0],u=e[0];for(let r=1;r<e.length;r++)e[r].value<l.value&&(l=e[r]),e[r].value>u.value&&(u=e[r]);t.push({time:a,min:l.value,max:u.value,delta:e.length<2?null:u.value-l.value,minSensor:l.name,maxSensor:u.name});}return t}function U(n){let i=[];for(let e of n){let l=0,u=0,r=1/0,m=-1/0;for(let o of e.data)o.value!==null&&(l+=o.value,u++,o.value<r&&(r=o.value),o.value>m&&(m=o.value));u!==0&&i.push({name:e.name,mean:l/u,min:r,max:m,count:u});}if(i.length===0)return {sensors:[],hottest:null,coldest:null,meanDelta:null};let t=i[0],a=i[0];for(let e=1;e<i.length;e++)i[e].mean>t.mean&&(t=i[e]),i[e].mean<a.mean&&(a=i[e]);return {sensors:i,hottest:t,coldest:a,meanDelta:t.mean-a.mean}}function T(n){let i=0,t=0,a=0,e=0,l=0;for(let o of n)o.value!==null&&(i++,t+=o.time,a+=o.value,e+=o.time*o.value,l+=o.time*o.time);if(i<2)return null;let u=i*l-t*t;if(u===0)return null;let r=(i*e-t*a)/u,m=(a-r*t)/i;return {slope:r,intercept:m,n:i}}function A(n,i){if(n.length===0)return null;let t=n[n.length-1].time,a=t-i,e=n.filter(l=>l.time>=a&&l.time<=t);return T(e)}function Y(n,i){let t=[],a=0;for(let e=0;e<n.length;e++){let l=n[e].time,u=l-i;for(;a<n.length&&n[a].time<u;)a++;let r=T(n.slice(a,e+1));t.push({time:l,fit:r});}return t}function W(n,i,t={}){let a=t.lookbackMs??9e5,e=t.side??"either";if(n.length===0)return null;let l=n[n.length-1];if(l.value===null)return null;let u=A(n,a);if(!u||u.slope===0)return null;let r=u.slope>0&&l.value<i,m=u.slope<0&&l.value>i;if(e==="above"&&!r||e==="below"&&!m||e==="either"&&!r&&!m)return null;let o=(i-u.intercept)/u.slope,s=o-l.time;return s<=0?null:{msUntil:s,eta:o,fit:u,currentValue:l.value}}function Z(n,i={}){let t=i.refTempCelsius??121.11,a=i.zValueKelvin??10,e=0;for(let l=0;l<n.length-1;l++){let u=n[l],r=n[l+1];if(u.value===null||r.value===null)continue;let m=(r.time-u.time)/6e4;if(m<=0)continue;let o=Math.pow(10,(u.value-t)/a),s=Math.pow(10,(r.value-t)/a);e+=(o+s)/2*m;}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 S=class{static interpolateDataPoint(n,i,t){return {time:n.time+Math.round(t*
|
|
|
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{G as DEFAULT_ACTIVATION_ENERGY,H as PRODUCT_PROFILES,E as SeriesProcessor,C as StatsAggregator,L as aggregateBySlot,_ as aggregateWithStats,B as analyzeLongTermTrends,K as computeLimitExcursions,S as createAggr,A as currentTrend,z as detectGaps,P as downsample,Z as f0Sterilization,U as hotColdSpots,T as linearFit,F as mkt,W as predictTimeToThreshold,R as rollingMkt,V as rollingStdDev,Y as rollingTrend,k as sampleStdDev,O as spatialDelta,I as stdDev,q as varianceCoefficient};
|