ml-time-graph 1.7.1 → 1.8.3

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.
@@ -117,7 +117,7 @@ Varianten hängen Arrays an. Alle geben `this` zurück.
117
117
  Beispiele:
118
118
 
119
119
  ```ts
120
- // Schwellwert: `fill` ist eine Zeichenkette ("above" | "below" | "none") und
120
+ // Schwellenwert: `fill` ist eine Zeichenkette ("above" | "below" | "none") und
121
121
  // `line` ist eine Zeichenkette ("solid" | "dashed" | "dotted" | "none");
122
122
  // die Deckkraft ist ein separates Feld.
123
123
  g.addThreshold({
package/README.de.md CHANGED
@@ -2,13 +2,18 @@
2
2
 
3
3
  *[English](https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/packages/ml-time-graph/README.md) · Deutsch*
4
4
 
5
- **TypeScript-Library für die grafische Darstellung von Messwerten** — Zeitreihen
6
- schnell und unkompliziert aufbereiten, mit Fokus auf Reporting und Incident-Analyse.
5
+ **TypeScript-Library für die Darstellung beliebiger Zeitreihen** — Telemetrie, Sensoren,
6
+ Systemmetriken, Logs, Finanzdaten, Labor- oder Prozessmesswerte. Ihre auffälligste Fähigkeit
7
+ ist die **erklärende Beschriftung**: freie Annotationen in Datenkoordinaten (Pfeile, Labels,
8
+ Sprechblasen), Zeitbereichs-Markierungen, Status- und Phasenbänder und Schwellenwert-Zonen
9
+ machen aus einer rohen Kurve einen Nachweis. Dazu eine bestimmende Eigenschaft der Architektur:
10
+ Sie erzeugt SVG als reinen String, ohne das DOM je anzufassen — derselbe Aufruf läuft im
11
+ Browser und im Backend.
7
12
 
8
13
  > Voll typisiert · i18n-aware · DOM-freier SVG-Renderer (Browser & serverseitig) · keine Laufzeit-Abhängigkeiten · ESM-only
9
14
 
10
15
  > 🤖 **Sie arbeiten mit einem KI-Assistenten?** Geben Sie ihm
11
- > **[SKILLS.md](SKILLS.md)** — die Datei wird mitgeliefert und liegt nach
16
+ > **[SKILLS.md](https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/packages/ml-time-graph/SKILLS.md)** — die Datei wird mitgeliefert und liegt nach
12
17
  > `npm install` unter `node_modules/ml-time-graph/SKILLS.md`. Eine Seite: der
13
18
  > kürzeste Weg zum Diagramm, die vier Einstiegspunkte, die üblichen Aufgaben und
14
19
  > ein Abschnitt **Traps** für die Stellen, an denen ein Modell danebengreift
@@ -72,20 +77,64 @@ mount('#chart', {
72
77
  });
73
78
  ```
74
79
 
80
+ **Die Daten sehen anders aus?** Dann müssen sie nicht umgebaut werden. `toSeries` nimmt
81
+ Tupel, eine REST-Antwort in Unix-Sekunden, einen CSV-Export aus Zeichenketten oder ein
82
+ verschachteltes Dokument und macht daraus, was das Diagramm erwartet:
83
+
84
+ ```ts
85
+ import { toSeries } from 'ml-time-graph';
86
+
87
+ // [[1700000000000, 18.2], …] → time/value
88
+ toSeries('Temperatur', tupel)
89
+
90
+ // [{ ts: 1700000000, val: '18.2' }, …] → eigene Feldnamen, Sekunden, Zeichenketten
91
+ toSeries('Temperatur', zeilen, { time: 'ts', value: 'val', timeUnit: 's' })
92
+ ```
93
+
94
+ Fehlende Messwerte (`null`, `undefined`, `NaN`, `''`) werden zu Lücken; eine Zeichenkette,
95
+ die keine Zahl ist, wirft und nennt die Zeilennummer. Zum Ausprobieren: **[Input Adapters](https://mlcgo.eu/books/mlctimegraph/demo/adapters.html)**
96
+ — vier Eingabeformen, ein Diagramm.
97
+
98
+ ### Der wiederkehrende Teil in eine eigene Ebene
99
+
100
+ Sobald mehrere Berichte entstehen, wiederholt sich ein Teil der Beschreibung: Maße, Achsen,
101
+ Legende, Farben. In jede Datei kopiert heißt das, ihn irgendwann an zwölf Stellen zu ändern
102
+ und an einer zu vergessen. `mergeOptions` legt ihn stattdessen darüber:
103
+
104
+ ```ts
105
+ import { mergeOptions, MLTimeGraph } from 'ml-time-graph';
106
+
107
+ new MLTimeGraph(mergeOptions(hausTheme, messwerte)); // die spätere Ebene gewinnt
108
+ ```
109
+
110
+ Die Regel ist ein Satz: **Objekte verschmelzen, alles andere wird ersetzt** — auch Arrays,
111
+ damit ein Theme mit einem einzigen Linienstil nicht aus einer Kurve zwei macht. Nicht zu
112
+ verwechseln mit `{ ...hausTheme, ...messwerte }`: Der Spread ist **flach**, ein `axes` im
113
+ zweiten Objekt ersetzt damit das komplette `axes` des ersten, samt Gitter und Ticks.
114
+
115
+ Serverseitig gilt dieselbe Regel — `graph-cli -with haus-theme.json`, beliebig oft
116
+ gestapelt. Ausführlich im Handbuch, [Kapitel 5](https://mlcgo.eu/books/mlctimegraph/de/05/).
117
+
75
118
  📖 **Nutzung & API → [USAGE.md](https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/packages/ml-time-graph/USAGE.md)** *(englisch)*
76
119
 
77
120
  ## Galerie
78
121
 
79
122
  <p align="center">
80
- <a href="https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/packages/ml-time-graph/ex1.svg"><img src="https://gitlab.com/mlc0911/mlctimegraph/-/raw/main/packages/ml-time-graph/ex1.svg" alt="Linie mit Zonen-Färbung und Threshold-Fills" width="300"></a>
81
- <a href="https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/packages/ml-time-graph/ex2.svg"><img src="https://gitlab.com/mlc0911/mlctimegraph/-/raw/main/packages/ml-time-graph/ex2.svg" alt="Multi-Zonen-Hatch-Fills" width="300"></a>
123
+ <a href="https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/packages/ml-time-graph/ex1.svg"><img src="https://gitlab.com/mlc0911/mlctimegraph/-/raw/main/packages/ml-time-graph/ex1.svg" alt="Linie nach Schwellenwert-Zonen eingefärbt, mit Datenlücken" width="300"></a>
124
+ <a href="https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/packages/ml-time-graph/ex2.svg"><img src="https://gitlab.com/mlc0911/mlctimegraph/-/raw/main/packages/ml-time-graph/ex2.svg" alt="Min/Max/Avg-Band mit schraffierten Flächen" width="300"></a>
82
125
  <a href="https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/packages/ml-time-graph/ex3.svg"><img src="https://gitlab.com/mlc0911/mlctimegraph/-/raw/main/packages/ml-time-graph/ex3.svg" alt="stdDevBand + movingMkt-Overlays auf einem Sensorstrom" width="300"></a>
126
+ <a href="https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/packages/ml-time-graph/ex4.svg"><img src="https://gitlab.com/mlc0911/mlctimegraph/-/raw/main/packages/ml-time-graph/ex4.svg" alt="Annotationsbänder markieren Betriebszustände unter dem Diagramm" width="300"></a>
83
127
  </p>
84
128
 
85
- Typische Sensor-Darstellung (links), Multi-Zonen-Schraffuren für
86
- Incident-Reports (Mitte), Sensorstrom mit Statistik-Overlays (rechts:
87
- ±2σ-Band + 12-h-MKT) — alles dieselbe Library, alle in der
88
- Demo-Galerie zu sehen (`pnpm dev`).
129
+ Typische Sensor-Darstellung, Min/Max/Avg mit Schraffuren für
130
+ Incident-Reports, ein Sensorstrom mit Statistik-Overlays (±2σ-Band +
131
+ 12-h-MKT) und Annotationsbänder, die Betriebszustände und Ereignisse
132
+ *unterhalb* des Diagramms markieren — dort verdecken sie nichts, und man
133
+ liest in einer Zeile ab, **wann** etwas galt. Alles dieselbe Library. **Die Galerie läuft
134
+ 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.
136
+ Lokal geht es mit `pnpm dev`; die Bilder oben entstehen mit
137
+ `node scripts/make-examples.mjs`.
89
138
 
90
139
  ---
91
140
 
@@ -93,6 +142,10 @@ Demo-Galerie zu sehen (`pnpm dev`).
93
142
 
94
143
  Benötigst du serverseitiges Rendering der exakt gleichen Charts? Es gibt einen 1:1 Go-Port dieser Engine unter **[gitlab.com/mlc0911/mlctimegraph/go-time-graph](https://gitlab.com/mlc0911/mlctimegraph/-/tree/main/go-time-graph)**.
95
144
 
145
+ **Einstieg:** [BUILDER.md](https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/go-time-graph/docs/BUILDER.md)
146
+ beginnt mit einem vollständigen Quickstart — ein lauffähiges `main.go`, das eine Reihe
147
+ aufbaut, Schwellenwerte setzt und die SVG-Datei schreibt.
148
+
96
149
  Sowohl die TypeScript- als auch die Go-Bibliothek:
97
150
  - Verarbeiten das **exakt gleiche JSON-Konfigurationsschema**.
98
151
  - Generieren **identische SVG-Strukturen und Layoutberechnungen**.
@@ -101,10 +154,53 @@ Sowohl die TypeScript- als auch die Go-Bibliothek:
101
154
 
102
155
  ---
103
156
 
157
+ ## 🐞 Fehler gefunden?
158
+
159
+ Issues liegen unter
160
+ [gitlab.com/mlc0911/mlctimegraph/-/issues](https://gitlab.com/mlc0911/mlctimegraph/-/issues).
161
+ Die Vorlagen fragen nach deinen Chart-Optionen — damit wird aus einer Meldung in
162
+ Minuten ein fehlschlagender Test. Einzelheiten in
163
+ [CONTRIBUTING.md](https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/CONTRIBUTING.md).
164
+
165
+ ---
166
+
104
167
  ## 📜 Versionsverlauf
105
168
 
106
169
  Beide Bibliotheken werden im Gleichschritt unter einer Versionsnummer veröffentlicht —
107
170
  deshalb gibt es **ein** Changelog für beide: [CHANGELOG.md](https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/CHANGELOG.md).
171
+ Es liegt auch dem Paket bei — die Historie genau der Version, die du installiert hast, liegt
172
+ damit neben dem Code.
173
+
174
+ ### Warum schon 1.8, und warum so viele Minor-Versionen?
175
+
176
+ Weil die Bibliothek täglich im Einsatz ist, und der Einsatz findet, was ein sauberer Entwurf
177
+ nicht findet.
178
+
179
+ Das meiste sind **Randfälle in echten Daten**. Gebaut wurde die Engine für eine Reihe von
180
+ Messwerten; an kommt eine Reihe mit zwei Werten auf demselben Zeitstempel, ein leerer Slot,
181
+ ein einzelner Wert zwischen zwei Ausfällen, eine Stunde, in der sich gar nichts geändert hat.
182
+ Nichts davon war falsch entworfen — es war schlicht nicht bedacht. Jeder dieser Fälle hat
183
+ heute eine eigene Testvorlage: `edge_marker_duplicate_time`, `edge_gaps_autodetect`,
184
+ `edge_minmaxavg_single_point`, `edge_constant_value` und zehn weitere.
185
+
186
+ Einiges sieht man **erst in der Menge**. Der Go-Port zeichnet dieselben Diagramme auf dem
187
+ Server; was er kostet, merkt niemand, bevor zehntausend Berichte durchlaufen. So gemessen und
188
+ behoben: Ein Diagramm mit 25 000 Punkten ging von 68 ms auf 13 ms und von 921 KB auf 403 KB —
189
+ weil der SVG-String Segment für Segment zusammengesetzt wurde und jede Koordinate sechzehn
190
+ Stellen trug, die kein Bildschirm auflöst.
191
+
192
+ Und einiges sind **Fragen**. „Wieso geht das nicht?" ist meistens keine fehlende Fähigkeit,
193
+ sondern ein Satz in der Dokumentation, den man auf zwei Arten lesen kann. Die werden am selben
194
+ Tag korrigiert, und in der Regel kommt ein Test dazu — damit die Lesart festgehalten ist und
195
+ nicht erinnert werden muss.
196
+
197
+ Was sich *nicht* ändert, ist die Schnittstelle. Sie ist seit 1.0 additiv — keine Option
198
+ entfernt, keine Signatur geändert. Wo ein Bild falsch war, wurde es korrigiert, und diese
199
+ Korrekturen stehen im Changelog unter **Changed**, nie versteckt unter Fixed.
200
+
201
+ Dafür sind die Tests da: **574 in TypeScript, 74 in Go und 36 gemeinsame Vorlagen**, die beide
202
+ Bibliotheken auf byte-gleiche Ausgabe festnageln. Sie sind nicht dazu da zu beweisen, dass das
203
+ Neue funktioniert. Sie sind dazu da, dass das Neue das Alte nicht stillschweigend verändert.
108
204
 
109
205
  ---
110
206
 
@@ -166,12 +262,30 @@ werden und die nachträgliche Auswertung entscheidend ist.
166
262
  - ❌ **Volle Interaktivität** — Zoom/Pan ja, aber in Grenzen
167
263
  - ❌ GPU-Performance-Optimierungen o. Ä.
168
264
 
265
+ „Keine Performance-Bibliothek" heißt: kein GPU-Pfad, kein virtualisiertes Canvas. Es heißt
266
+ nicht, dass die Sache langsam wäre. Gemessen, damit niemand raten muss: Eine **Linie mit
267
+ 25 000 Punkten steht in rund 20 ms** in Chromium — Diagramm samt fertigem SVG-String, 900×400 —
268
+ und die Datei ist 403 KB groß. Es skaliert linear: 5 000 Punkte ≈ 4 ms, 50 000 ≈ 36 ms.
269
+ Gemessen auf einem Xeon E5-2650 v2 mit 2,6 GHz, einer Server-CPU von 2013; ein heutiger
270
+ Arbeitsplatzrechner ist schneller. Der Go-Port braucht für dieselben 25 000 Punkte rund 13 ms.
271
+
272
+ Koordinaten werden mit drei Nachkommastellen geschrieben. Das ist weit jenseits dessen, was
273
+ ein Bildschirm oder ein Drucker auflöst — 0,001 px sind bei 300 dpi drei Tausendstel eines
274
+ Punktes — und es ist der Grund für die kleinen Dateien: ungekürzt brauchte dasselbe Diagramm
275
+ 921 KB.
276
+
169
277
  ## Ausblick / in Überlegung
170
278
 
171
- - Möglichkeiten der „Live"-Darstellung
172
- - Einfache Anbindung von Backends (woher kommen meine Daten?)
173
279
  - svelte wrapper
174
280
 
281
+ Zwei Punkte von hier sind erledigt und stehen jetzt woanders:
282
+
283
+ - **Woher kommen meine Daten?** → `toSeries` / `toDataPoints`, siehe oben beim Quickstart.
284
+ - **„Live"-Darstellung** → `setData()` auf einer bestehenden Instanz, neu zeichnen, fertig.
285
+ Kein zweites Diagramm, kein Neuaufbau. Vorgeführt in der Demo
286
+ [Interaction](https://mlcgo.eu/books/mlctimegraph/demo/interaction.html), Karte
287
+ `interaction-3`.
288
+
175
289
  ## Demos & Entwicklung
176
290
 
177
291
  ```bash
@@ -198,8 +312,3 @@ Copyright-Hinweis im Quellcode erhalten bleibt.
198
312
 
199
313
  **Ohne Nennung:** Unternehmen, die die Attribution nicht zeigen möchten, können eine
200
314
  **kommerzielle Lizenz auf Anfrage** erhalten, die diese Pflicht aufhebt — Kontakt: ‹mlcgo.eu@michael-lechner.de›.
201
-
202
- ---
203
-
204
- <sub>Das Projekt diente ursprünglich als Test für Crush-Development mit Ollama +
205
- neuem LLM — bestanden 😉, brauchte aber doch einige Nacharbeit.</sub>
package/README.md CHANGED
@@ -2,13 +2,18 @@
2
2
 
3
3
  *English · [Deutsch](https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/packages/ml-time-graph/README.de.md)*
4
4
 
5
- **A TypeScript library for visualizing measurement data** — turn time series into
6
- clear, readable charts quickly, with a focus on reporting and incident analysis.
5
+ **A TypeScript library for visualizing any time-series data** — telemetry, physical sensors,
6
+ system metrics, logs, finance, laboratory or process measurements. Its standout capability is
7
+ rich **contextual annotation**: free-form annotations in data coordinates (arrows, labels,
8
+ callout rects), time-range highlights, status and phase bands, and threshold zones turn a raw
9
+ curve into an explanatory record. And one defining architectural property: it produces SVG as a
10
+ plain string without ever touching the DOM — the identical call runs in a browser and in a
11
+ backend.
7
12
 
8
13
  > Fully typed · i18n-aware · DOM-free SVG output (browser & server) · zero runtime dependencies · ESM-only
9
14
 
10
15
  > 🤖 **Working with an AI coding assistant?** Point it at
11
- > **[SKILLS.md](SKILLS.md)** — it ships inside the package, so after
16
+ > **[SKILLS.md](https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/packages/ml-time-graph/SKILLS.md)** — it ships inside the package, so after
12
17
  > `npm install` it sits at `node_modules/ml-time-graph/SKILLS.md`. One page:
13
18
  > the shortest path to a chart, the four entry points, the recipes, and a
14
19
  > **Traps** section for the places a model guesses wrong (timestamps are epoch
@@ -72,20 +77,64 @@ mount('#chart', {
72
77
  });
73
78
  ```
74
79
 
80
+ **Your data looks different?** Then it does not have to be rebuilt. `toSeries` takes tuples,
81
+ a REST payload in Unix seconds, a CSV export of strings or a nested document, and turns it
82
+ into what the chart expects:
83
+
84
+ ```ts
85
+ import { toSeries } from 'ml-time-graph';
86
+
87
+ // [[1700000000000, 18.2], …] → time/value
88
+ toSeries('Temperature', tuples)
89
+
90
+ // [{ ts: 1700000000, val: '18.2' }, …] → your field names, seconds, strings
91
+ toSeries('Temperature', rows, { time: 'ts', value: 'val', timeUnit: 's' })
92
+ ```
93
+
94
+ Missing readings (`null`, `undefined`, `NaN`, `''`) become gaps; a string that is not a number
95
+ throws and names the row. Try it: **[Input Adapters](https://mlcgo.eu/books/mlctimegraph/demo/adapters.html)** — four
96
+ input shapes, one chart.
97
+
98
+ ### The repeating part as a layer of its own
99
+
100
+ As soon as there are several reports, part of the description repeats: dimensions, axes,
101
+ legend, colours. Copied into every file, that means changing it in twelve places one day and
102
+ forgetting one. `mergeOptions` puts it underneath instead:
103
+
104
+ ```ts
105
+ import { mergeOptions, MLTimeGraph } from 'ml-time-graph';
106
+
107
+ new MLTimeGraph(mergeOptions(houseTheme, readings)); // the later layer wins
108
+ ```
109
+
110
+ The rule is one sentence: **objects merge, everything else is replaced** — arrays included, so
111
+ a theme carrying a single line style does not turn one curve into two. Not to be confused with
112
+ `{ ...houseTheme, ...readings }`: the spread is **shallow**, so an `axes` in the second object
113
+ replaces the first one's `axes` entirely, grid and ticks and all.
114
+
115
+ The same rule server-side — `graph-cli -with house-theme.json`, stacked as often as you like.
116
+ In full in the handbook, [chapter 5](https://mlcgo.eu/books/mlctimegraph/en/05/).
117
+
75
118
  📖 **Usage & API → [USAGE.md](https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/packages/ml-time-graph/USAGE.md)**
76
119
 
77
120
  ## Gallery
78
121
 
79
122
  <p align="center">
80
- <a href="https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/packages/ml-time-graph/ex1.svg"><img src="https://gitlab.com/mlc0911/mlctimegraph/-/raw/main/packages/ml-time-graph/ex1.svg" alt="Line chart with zoned colouring + threshold fills" width="300"></a>
81
- <a href="https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/packages/ml-time-graph/ex2.svg"><img src="https://gitlab.com/mlc0911/mlctimegraph/-/raw/main/packages/ml-time-graph/ex2.svg" alt="Hatched multi-zone threshold fills" width="300"></a>
82
- <a href="https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/packages/ml-time-graph/ex3.svg"><img src="https://gitlab.com/mlc0911/mlctimegraph/-/raw/main/packages/ml-time-graph/ex3.svg" alt="stdDevBand + movingMkt-Overlays on a sensor stream" width="300"></a>
123
+ <a href="https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/packages/ml-time-graph/ex1.svg"><img src="https://gitlab.com/mlc0911/mlctimegraph/-/raw/main/packages/ml-time-graph/ex1.svg" alt="Line coloured by threshold zones, with gaps" width="300"></a>
124
+ <a href="https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/packages/ml-time-graph/ex2.svg"><img src="https://gitlab.com/mlc0911/mlctimegraph/-/raw/main/packages/ml-time-graph/ex2.svg" alt="Min/max/avg band with hatched fills" width="300"></a>
125
+ <a href="https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/packages/ml-time-graph/ex3.svg"><img src="https://gitlab.com/mlc0911/mlctimegraph/-/raw/main/packages/ml-time-graph/ex3.svg" alt="stdDevBand + movingMkt overlays on a sensor stream" width="300"></a>
126
+ <a href="https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/packages/ml-time-graph/ex4.svg"><img src="https://gitlab.com/mlc0911/mlctimegraph/-/raw/main/packages/ml-time-graph/ex4.svg" alt="Annotation bands marking operating states below the chart" width="300"></a>
83
127
  </p>
84
128
 
85
- A typical sensor visualisation (left), multi-zone hatched fills for
86
- incident-style reports (center), and a sensor stream with statistic
87
- overlays (right: ±2σ band + 12 h MKT) — all rendered with the same
88
- library, all live in the demo gallery (`pnpm dev`).
129
+ A typical sensor visualisation, min/max/avg with hatched fills for
130
+ incident-style reports, a sensor stream with statistic overlays (±2σ band +
131
+ 12 h MKT), and annotation bands marking operating states and events *below*
132
+ the chart — where they cover nothing and you read in one line **when**
133
+ something applied. All rendered with the same library. **The gallery runs
134
+ 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.
136
+ Locally it is `pnpm dev`; the images above come from
137
+ `node scripts/make-examples.mjs`.
89
138
 
90
139
  ---
91
140
 
@@ -93,6 +142,10 @@ library, all live in the demo gallery (`pnpm dev`).
93
142
 
94
143
  Need server-side rendering of the exact same charts? There is a 1:1 Go port of this engine available at **[gitlab.com/mlc0911/mlctimegraph/go-time-graph](https://gitlab.com/mlc0911/mlctimegraph/-/tree/main/go-time-graph)**.
95
144
 
145
+ **Where to start:** [BUILDER.md](https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/go-time-graph/docs/BUILDER.md)
146
+ opens with a complete quickstart — a runnable `main.go` that builds a series, sets thresholds
147
+ and writes the SVG file.
148
+
96
149
  Both the TypeScript and Go libraries:
97
150
  - Process the **exact same JSON configuration schema**.
98
151
  - Support **multiple stacked Y-axes** on both left and right sides (with configurable pixel `offset` and automatic step offsets).
@@ -101,10 +154,50 @@ Both the TypeScript and Go libraries:
101
154
 
102
155
  ---
103
156
 
157
+ ## 🐞 Found a bug?
158
+
159
+ Issues live at
160
+ [gitlab.com/mlc0911/mlctimegraph/-/issues](https://gitlab.com/mlc0911/mlctimegraph/-/issues).
161
+ The templates ask for your chart options — with them a report becomes a failing
162
+ test in minutes. [CONTRIBUTING.md](https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/CONTRIBUTING.md) has the details.
163
+
164
+ ---
165
+
104
166
  ## 📜 Release history
105
167
 
106
168
  Both libraries are released in lockstep on one version number, so there is **one**
107
169
  changelog for both: [CHANGELOG.md](https://gitlab.com/mlc0911/mlctimegraph/-/blob/main/CHANGELOG.md).
170
+ It ships with this package too, so the history of the exact version you installed is right
171
+ next to the code.
172
+
173
+ ### Why already at 1.8, and why so many minor releases?
174
+
175
+ Because the library is in daily professional use, and use finds what a clean design does not.
176
+
177
+ Most of it is **edge cases in real data**. The engine was built for a series of readings; what
178
+ arrives is a series with two readings on the same timestamp, a slot that is empty, a single
179
+ value between two outages, an hour in which nothing changed at all. None of that was wrong in
180
+ the design — it simply had not been thought of. Every one of those now has a test template of
181
+ its own: `edge_marker_duplicate_time`, `edge_gaps_autodetect`, `edge_minmaxavg_single_point`,
182
+ `edge_constant_value` and ten more.
183
+
184
+ Some of it is **things you only see at scale**. The Go port renders the same charts
185
+ server-side; nobody notices what it costs until ten thousand reports go through it. Measured
186
+ and fixed that way: a 25,000-point chart went from 68 ms to 13 ms and from 921 KB to 403 KB,
187
+ because the SVG string was being concatenated one segment at a time and every coordinate
188
+ carried sixteen digits of precision no screen resolves.
189
+
190
+ And some of it is **questions**. "Why doesn't this work?" is usually not a missing feature but
191
+ a sentence in the documentation that could be read two ways. Those get fixed the same day, and
192
+ usually a test comes with them so the reading is pinned rather than remembered.
193
+
194
+ What does *not* change is the interface. It has been additive since 1.0 — no option removed,
195
+ no signature altered. Where a picture was wrong it was corrected, and those corrections are in
196
+ the changelog under **Changed**, never buried under Fixed.
197
+
198
+ That is what the tests are for: **574 in TypeScript, 74 in Go, and 36 shared templates** that
199
+ hold both libraries to byte-identical output. They are not there to prove the new thing works.
200
+ They are there so that the new thing does not quietly change the old one.
108
201
 
109
202
  ---
110
203
 
@@ -165,12 +258,29 @@ after-the-fact evaluation is what matters.
165
258
  - ❌ **Full interactivity** — zoom/pan yes, but within limits
166
259
  - ❌ GPU performance optimizations and the like
167
260
 
261
+ "Not a performance library" means there is no GPU path and no virtualized canvas — it does not
262
+ mean the thing is slow. Measured, so nobody has to guess: a **25,000-point line renders in
263
+ about 20 ms** in Chromium (chart plus the finished SVG string, 900×400) and the file comes to
264
+ 403 KB. It scales linearly — 5,000 points ≈ 4 ms, 50,000 ≈ 36 ms. That is on a Xeon E5-2650 v2
265
+ at 2.6 GHz, a server CPU from 2013; a current desktop does it faster. The Go port does the
266
+ same 25,000 points in about 13 ms.
267
+
268
+ Coordinates are written with three decimals. That is far beyond what any screen or printer
269
+ resolves — 0.001 px is three thousandths of a point at 300 dpi — and it is what keeps the
270
+ files small: written in full, that same chart took 921 KB.
271
+
168
272
  ## Outlook / under consideration
169
273
 
170
- - "Live" rendering options
171
- - Simple backend integration (where does my data come from?)
172
274
  - Svelte wrapper
173
275
 
276
+ Two items that used to sit here are done, and live elsewhere now:
277
+
278
+ - **Where does my data come from?** → `toSeries` / `toDataPoints`, see the Quickstart above.
279
+ - **"Live" rendering** → `setData()` on an existing instance, then re-render. No second chart,
280
+ no rebuild. Shown in the
281
+ [Interaction](https://mlcgo.eu/books/mlctimegraph/demo/interaction.html) demo, card
282
+ `interaction-3`.
283
+
174
284
  ## Demos & development
175
285
 
176
286
  ```bash
@@ -197,8 +307,3 @@ and the copyright notice is retained in the source.
197
307
 
198
308
  **Without attribution:** organizations that prefer not to display the attribution can
199
309
  obtain a **commercial license on request** that waives it — contact: ‹mlcgo.eu@michael-lechner.de›.
200
-
201
- ---
202
-
203
- <sub>Originally a test of Crush development with Ollama + a new LLM — passed 😉, but it
204
- did need some rework.</sub>
package/SKILLS.md CHANGED
@@ -26,6 +26,38 @@ mount('#chart', {
26
26
  });
27
27
  ```
28
28
 
29
+ ### The data does not look like that
30
+
31
+ `{ time, value }` is what the chart wants, not what you have. Convert instead of rebuilding —
32
+ tuples, a REST payload in Unix seconds, a CSV export of strings, a nested document:
33
+
34
+ ```ts
35
+ import { toSeries } from 'ml-time-graph';
36
+
37
+ toSeries('Temperature', tuples) // [[1704067200000, 21.5], …]
38
+ toSeries('Temperature', rows, { time: 'ts', value: 'val', timeUnit: 's' })
39
+ ```
40
+
41
+ Missing readings (`null`, `undefined`, `NaN`, `''`) become gaps. A string that is not a number
42
+ throws and names the row — silently dropping it would turn a broken export into a plausible
43
+ chart.
44
+
45
+ ### The same options in every chart
46
+
47
+ Dimensions, axes, legend, colours repeat across reports. Put them underneath instead of copying
48
+ them:
49
+
50
+ ```ts
51
+ import { mergeOptions, MLTimeGraph } from 'ml-time-graph';
52
+
53
+ new MLTimeGraph(mergeOptions(houseTheme, readings)); // the later layer wins
54
+ ```
55
+
56
+ Objects merge, everything else is replaced — arrays included, so a theme carrying one line
57
+ style does not turn one curve into two. `{ ...a, ...b }` is **not** the same: the spread is
58
+ shallow and an `axes` in `b` drops `a`'s grid and ticks. Server-side the same rule is
59
+ `graph-cli -with theme.json`, stackable.
60
+
29
61
  ## When to Use What
30
62
 
31
63
  - `mount(target, options)`: The declarative browser shortcut when a DOM element or selector exists — measures container width, renders SVG, and injects markup in one call.
@@ -36,7 +68,7 @@ mount('#chart', {
36
68
 
37
69
  ## Package Entry Points
38
70
 
39
- - `ml-time-graph`: Core chart rendering API — `mount`, `MLTimeGraph`, `SVGRenderer`, `GraphBuilder`, `attachTooltip`, types, and legend helpers (`resolveDash`, `drawMarker`).
71
+ - `ml-time-graph`: Core chart rendering API — `mount`, `MLTimeGraph`, `SVGRenderer`, `GraphBuilder`, `attachTooltip`, input adapters (`toSeries`, `toDataPoints`), options layering (`mergeOptions`), types, and legend helpers (`resolveDash`, `getLineStyle`, `drawMarker`).
40
72
  - `ml-time-graph/analyze`: Pure-math statistics companion — `aggregateBySlot`, `downsample` (LTTB), `detectGaps`, `rollingMkt`, `rollingStdDev`, `computeLimitExcursions`, `StatsAggregator`.
41
73
  - `ml-time-graph/interaction`: Headless interaction primitives — `Zoom`, `Minimap`, and coordinate-based interaction state management.
42
74
  - `ml-time-graph/internals`: Low-level building blocks for custom renderers — `DrawCommand` model, base `Renderer`, layout engine, scales, and axis renderers.
@@ -98,6 +130,8 @@ mount('#chart', {
98
130
  { type: 'arrow', from: { time: t1, value: 20 }, to: { time: t2, value: 35 }, color: '#ef4444' },
99
131
  { type: 'label', at: { time: t2, value: 35 }, text: 'Pressure Spike', dy: -10 },
100
132
  { type: 'rect', from: { time: t1, value: 15 }, to: { time: t2, value: 25 }, fill: '#10b98122' },
133
+ { type: 'line', from: { time: t1, value: 30 }, to: { time: t3, value: 30 }, dash: 'dashed' },
134
+ { type: 'point', at: { time: t2, value: 35 }, shape: 'circle' },
101
135
  ],
102
136
  // Horizontal status/phase bands below the plot (sharing the time axis):
103
137
  annotationBands: [
@@ -113,8 +147,43 @@ mount('#chart', {
113
147
  });
114
148
  ```
115
149
 
150
+ **The five annotation types and what each one takes:**
151
+
152
+ | `type` | Coordinates | Own fields |
153
+ | :--- | :--- | :--- |
154
+ | `line` | `from`, `to` | `color`, `width`, `dash` |
155
+ | `arrow` | `from`, `to` | `color`, `width`, `headSize` — the head sits on `to` |
156
+ | `rect` | `from`, `to` | `fill`, `hatch`, `stroke`, `opacity` |
157
+ | `point` | `at` | `shape` (`circle` \| `square` \| `cross`), `color`, `radius` |
158
+ | `label` | `at` | `text`, `dx`, `dy`, `anchor`, `rotate`, `color` |
159
+
160
+ A coordinate is `{ time, value, axis? }` — `axis` picks the y-scale (0 = left). An
161
+ annotation with an `id` is wrapped in `<g class="annotation annotation--{slug}">` and can
162
+ be targeted from CSS or toggled; without one its shapes are emitted bare. Both libraries
163
+ draw all five types identically — the Go port did not draw any of them before 1.8.0.
164
+
116
165
  ### Data Gaps
117
- `value: null` marks missing data and breaks the line. Connect with a bridge or render gap spans:
166
+ `value: null` marks missing data and breaks the *line*. What is drawn over the span is
167
+ `display`, and the four values mean the same per series and chart-wide:
168
+
169
+ | `display` | draws |
170
+ | --- | --- |
171
+ | `filled` | the area in the fill colour, no edges |
172
+ | `dashed_border` | the area **plus** two vertical dashed lines at its borders (default) |
173
+ | `empty` | nothing — the line breaks, that is all |
174
+ | `bridge_line` | a dotted line between the readings around the gap (per series only) |
175
+
176
+ A **label** is separate from all of this and comes from `gaps.regions[].label` — a region knows
177
+ which gap it describes, a series style would have to give all of them the same text:
178
+
179
+ ```ts
180
+ gaps: {
181
+ style: { display: 'filled', fill: '#6b7280', opacity: 0.15, label: { baseline: 'middle' } },
182
+ regions: [{ startTime: 1704070800000, endTime: 1704074400000, label: 'Sensor offline' }],
183
+ }
184
+ ```
185
+
186
+ Connect with a bridge or render gap spans:
118
187
  ```ts
119
188
  series: [{
120
189
  name: 'Sensor',
@@ -140,12 +209,19 @@ markers: [
140
209
  ```
141
210
 
142
211
  ### Axes & Margins
143
- The layout engine cannot measure rendered text. Always allocate sufficient margins for labels:
212
+ The layout engine cannot measure rendered text. Always allocate sufficient margins for labels.
213
+ And because the computed domain ends exactly on the smallest and largest reading, a thick line
214
+ or a marker at the extreme loses half of itself to the clip — `padding` adds room **in pixels**
215
+ (the cause is in pixels: `line.width`, `markers.size`), without giving up the automatic domain:
144
216
  ```ts
145
217
  margin: { top: 20, right: 80, bottom: 40, left: 60 },
146
218
  axes: {
147
219
  x: { label: 'Time', format: (d: Date) => d.toISOString().slice(11, 16) },
148
- left: { label: 'Temperature (°C)', format: (v: number) => `${v.toFixed(1)} °C` },
220
+ left: {
221
+ label: 'Temperature (°C)',
222
+ format: (v: number) => `${v.toFixed(1)} °C`,
223
+ padding: 8, // or { top: 24, bottom: 4 }
224
+ },
149
225
  right: { label: 'Humidity (%)', format: (v: number) => `${v.toFixed(0)} %` },
150
226
  }
151
227
  ```
@@ -174,11 +250,88 @@ const { content } = new SVGRenderer().render(chart.renderCommands());
174
250
  fs.writeFileSync('chart.svg', content);
175
251
  ```
176
252
 
253
+ ### Styling the SVG from CSS
254
+ Every group the renderer emits carries a class, and the Go port emits the same ones:
255
+
256
+ `value-axis left` / `value-axis right`, `time-axis`, `axis-labels`, `chart-grid`,
257
+ `chart-legend`, `series series--<slug>`, `thresholds` / `threshold threshold--<slug>`,
258
+ `threshold-labels` / `threshold-label threshold-label--<slug>`, `markers`, `gaps`,
259
+ `highlights`, `annotation-band`, `annotation-band-axis`.
260
+
261
+ On the `<path>` elements inside a series: `series-line` and `series-fill`.
262
+
263
+ The `<slug>` is `config.id ?? slugify(config.name)` — an explicit `id` verbatim, a name
264
+ lowercased with non-alphanumeric runs collapsed to `-`. Export `slugify` to build the
265
+ selector for a name you hold at runtime:
266
+ ```ts
267
+ import { slugify } from 'ml-time-graph';
268
+ svgRoot.querySelector(`.series--${slugify(series.name)}`)?.classList.toggle('is-hidden');
269
+ ```
270
+ The group also carries the same string as an `id` (`#series-temperatur`). Elements
271
+ *inside* a series group use a different, stable key instead: `s-<crc32 of the name>`
272
+ (`-line-<n>`, `-fill-r<region>-<piece>`).
273
+
274
+ **Prefer the classes.** An `id` is unique per *document*, not per chart: two charts on one
275
+ page produce the same key, and `getElementById` returns the first one. Scope through the
276
+ container instead — `#chart-2 .series--temperature .series-line`.
277
+
278
+ Full table and the provenance comment (`<!-- MLTimeGraph x.y.z -->`, the first child of
279
+ every `<svg>`): [USAGE.md — CSS classes in the SVG](USAGE.md#css-classes-in-the-svg).
280
+
281
+ ### Aggregated Series (`showAs`)
282
+ Points of the shape `{ time, min, max, avg, count }` — one slot per bucket, as
283
+ `aggregateBySlot()` produces:
284
+
285
+ - `showAs: 'minmaxavg'` — three lines (min / max / avg) plus optional `fillToMax` /
286
+ `fillToMin` envelopes. **Geometrically identical to three ordinary series**; what it adds
287
+ is one legend entry instead of three, one series key for all three paths, and
288
+ `avgDashed` on by default (`tests/series/minmaxavg_drei_serien.test.ts` proves the
289
+ equality). Use three plain series when they should behave as three.
290
+ - `showAs: 'band'` — one filled rectangle per slot, min→max. No three-series equivalent.
291
+
292
+ The envelope fills are reachable from plain series too: a fill bound takes
293
+ `{ series: '<id or name>' }`, which spans the area between two curves. The referenced
294
+ curve is interpolated onto this series' timestamps, and the area **breaks where that
295
+ curve has a gap** — same rule as a line.
296
+ Its `avgLine` and `countOpacity` options are TypeScript-only so far.
297
+
298
+ ### Statistic Overlays
299
+ `series.overlays` computes from the series' own data at render time:
300
+ `movingAverage` (`type: 'simple' | 'exponential'`), `movingMkt` (USP <1079.2>),
301
+ `stdDevBand`, `limits`. **Both libraries render all of them** — the Go port since 1.8.0.
302
+
303
+ Every window is in **milliseconds**, including the exponential one
304
+ (`alpha = 1 - exp(-Δt / window)`, not the count-based `2/(N+1)`).
305
+
306
+ The same numbers are available without drawing anything — `rollingMean`, `rollingEma`,
307
+ `rollingStdDev`, `rollingMkt` from `ml-time-graph/analyze`, `analyze.RollingMean` … from
308
+ `pkg/analyze` in Go. An overlay is a convenience, not a second implementation; passing the
309
+ pre-computed series as an ordinary one gives the identical picture, which
310
+ `tests/series/overlay_extern.test.ts` proves rather than claims.
311
+
312
+ ### Time Zone
313
+ `locale` decides *how* a time is written, `timeZone` **which** time:
314
+
315
+ ```ts
316
+ new MLTimeGraph({ locale: 'de-DE', timeZone: 'Europe/Berlin', series });
317
+ ```
318
+
319
+ Unset means the machine's zone — fine on one machine, a trap across two: a browser sits in
320
+ the reader's zone, a server in UTC, and the same JSON then labels the same reading with
321
+ different times. Set it whenever a chart is produced in one place and read in another. Only
322
+ the labels move; tick positions are epoch arithmetic. Same option in Go
323
+ (`Options.TimeZone`, JSON `timeZone`), which embeds the zone database so it works in a
324
+ scratch image.
325
+
177
326
  ## Traps (Read Before Coding)
178
327
 
179
328
  - **Timestamps are numbers, not Date objects:** `time` is always milliseconds since Unix epoch (`number`). Passing a `Date` object fails typechecking or evaluates to `NaN`.
180
329
  - **Labels are not measured (fixed margins):** The renderer has no DOM and cannot compute text bounding boxes. Margins default to `{ top: 20, right: 20, bottom: 40, left: 60 }`. If you add a right Y-axis or formatted units (e.g. `120.5 °C`), `right: 20` will clip the labels against the SVG edge. A clipped number is a wrong number, not an incomplete one (`120` clipped to `20`). Always set `margin.right` explicitly (e.g. 70–90 px) when using right axes.
181
330
  - **`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.
331
+ - **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.
182
332
  - **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.
183
333
  - **Built-in legend is static SVG:** Built-in legends (`inside-right`, etc.) are 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()`.
334
+ - **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.
335
+ - **Some options are accepted and do nothing:** `axes.<axis>.ticks.minor`, `axes.<axis>.grid.minor`, `fill.hatchColor` / `fill.hatchWidth`, `series.enumMap` and `series.sensorType` are in the types but no renderer reads them — in either library. Nothing warns you; the picture just stays as it was.
336
+ - **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.
184
337
  - **Hatch lines adapt to fill colour:** Hatch patterns inherit the opaque colour of the area they belong to (`opaqueColor(fill)`), while the backdrop stays translucent. An earlier default drew fixed blue lines (`#4D88FF`), which falsely signaled an extra state on incident charts where colour is semantic.