ml-time-graph 1.15.0 → 1.16.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 CHANGED
@@ -19,6 +19,37 @@ release notes, and every change is in `git log` in full.
19
19
 
20
20
  ---
21
21
 
22
+ ## [1.16.0] - 2026-10-07
23
+
24
+ ### Added
25
+ - **`theme` per chart** (TS and Go JSON options) — this chart's colours over the global defaults,
26
+ without `setDefaultTheme`.
27
+ - **`legendItems()`: `seriesId` and `width`** — the key for `hidden`/`pointsAt` (the existing `id`
28
+ is its CSS slug) and the drawn line width, so `resolveDash(line, width)` matches the curve.
29
+ - **`zeigerImSvg(svg, clientX, clientY)`** — pointer to SVG coordinates at any scaling; used by
30
+ the built-in tooltip.
31
+ - **`includeThresholds` on a y axis** (TS and Go) — the automatic domain also covers the
32
+ thresholds drawn on that axis; `line: 'none'` ones do not count, an explicit `domain` wins.
33
+
34
+ ### Changed
35
+ - **`Theme` has ordinary field types** (`string`, `number`) instead of literal types —
36
+ `setDefaultTheme({ textColor: '#94a3b8' })` needs no cast.
37
+
38
+ ### Fixed
39
+ - **The built-in tooltip (`attachTooltip`, `tooltip: { show: true }`) showed the wrong value on
40
+ step lines.** It searched the nearest sample by itself; it now goes through `pointsAt` — a step
41
+ line holds its value, enum series show their state. Samples carry `held`, `label` and the full
42
+ `point`; `points` passes options on; the header shows the cursor's time.
43
+ - **Fill region between series on different y axes** — the other series' edge was mapped with
44
+ this series' scale and missed its line; each edge now uses the scale of its own line.
45
+ - **Fill region to a step series** ramped into each jump instead of following the vertical;
46
+ the area now takes both values at the jump.
47
+ - **`legend: { position: 'below' }` covered the x-axis title** — both sat at the bottom edge;
48
+ the title now sits above the legend.
49
+ - **A grid line covered a threshold line at the same height** (in PDF completely) — the grid is
50
+ drawn after the series, thresholds before. The grid now leaves out lines under drawn thresholds.
51
+ - **Go wrote a tick at zero as `-0`** when the domain was padded below zero; now `0`, as in TS.
52
+
22
53
  ## [1.15.0] - 2026-10-07
23
54
 
24
55
  ### Added
package/USAGE.md CHANGED
@@ -480,6 +480,42 @@ widest stroke plus a little is a good rule of thumb. An explicit `domain` is lef
480
480
  alone, and padding that does not fit the chart height is ignored rather than
481
481
  producing an inverted scale.
482
482
 
483
+ ### Thresholds in view — `includeThresholds`
484
+
485
+ The automatic domain follows the readings only. A limit at 10 °C next to readings of 2..7 °C
486
+ lies outside the chart and is clipped away — exactly the line the chart should show.
487
+ `includeThresholds` widens the domain to the thresholds drawn on that axis:
488
+
489
+ ```ts
490
+ axes: { left: { includeThresholds: true, padding: 8 } }
491
+ thresholds: [
492
+ { name: 'max', value: 10 }, // counts
493
+ { name: 'min', value: 0, line: 'solid' }, // counts
494
+ { name: 'ref', value: 20, line: 'none' }, // label/band only -- does not count
495
+ ]
496
+ ```
497
+
498
+ Only thresholds with `axisIndex` of that axis count, and only those that draw a line.
499
+ `padding` applies on top. An explicit `domain` is left alone. Off by default.
500
+
501
+ ### Colours per chart — `theme`
502
+
503
+ `theme` in the options sets this chart's colours and sizes over the global defaults — a dark
504
+ chart next to a light one, or a light redraw for printing, without touching global state:
505
+
506
+ ```ts
507
+ const dark = { textColor: '#94a3b8', axisColor: '#475569', gridStroke: '#334155', legendText: '#cbd5e1' };
508
+ new MLTimeGraph({ ...options, theme: isDark ? dark : undefined });
509
+ ```
510
+
511
+ `setDefaultTheme(partial)` still changes the default for every chart (avoid it in a server
512
+ rendering several requests at once). The field names are the same as in the Go port's JSON
513
+ options; fields only the browser knows (`tooltip*`, `minimap*`) are ignored there.
514
+
515
+ To turn a pointer event into the SVG pixels that `pointsAt`, `invertTime` and `plotRect` speak,
516
+ use `zeigerImSvg(svg, e.clientX, e.clientY)` — correct at any scaling, `viewBox` or CSS
517
+ transform.
518
+
483
519
  ### Margins that fit — `autoMargin`
484
520
 
485
521
  The chart draws into fixed margins. When they are too narrow, labels are cut, and a cut number
@@ -884,9 +920,10 @@ const { x, y } = chart.project(time, value, axis); // data → pixel
884
920
 
885
921
  ### Tooltips — `attachTooltip` (built-in)
886
922
 
887
- One line wires a DOM tooltip that snaps to the nearest sample per series, draws a
888
- "pick" ring on each matched point, and **flips across the cursor to stay inside
889
- the chart** (right/below in the left/top half, left/above past 50%):
923
+ One line wires a DOM tooltip that shows, per series, the value its line shows at the
924
+ cursor — found by [`pointsAt`](#points-under-the-pointer--pointsat-your-own-tooltip), so a
925
+ step line holds its value — draws a "pick" ring on each matched point, and **flips across
926
+ the cursor to stay inside the chart** (right/below in the left/top half, left/above past 50%):
890
927
 
891
928
  ```ts
892
929
  import { mount, attachTooltip } from 'ml-time-graph';
@@ -903,10 +940,14 @@ detach(); // removes the listeners + pick markers
903
940
 
904
941
  `attachTooltip(target, chart, options?)` returns a cleanup function. The `target`
905
942
  must already contain the rendered `<svg>` (mount / render first). Each hover
906
- yields one `TooltipSample` per series — `{ seriesIndex, series, time, value, x, y }`.
907
-
908
- Options: `format` (HTML; default = time header + `name: value` rows),
909
- `snapRadius` (px, default ∞), `className` (default `mlc-tooltip`), and
943
+ yields one `TooltipSample` per series — `{ seriesIndex, series, time, value, x, y, held?,
944
+ label?, point }` (`point` is the full `pointsAt` hit) — and the cursor's time:
945
+ `format(samples, { time })`.
946
+
947
+ Options: `format` (HTML; default = the cursor's time as header + `name: value` rows, the
948
+ value as the axis writes it, a held value with its measuring time), `snapRadius` (px,
949
+ default ∞), `points` (passed on to `pointsAt`: `mode`, `modes`, `maxAgeMs`, `overlays`,
950
+ `hidden`), `className` (default `mlc-tooltip`), and
910
951
  `showPicks` / `pickRadius` / `picksClassName` for the markers. Style the box via
911
952
  the `.mlc-tooltip` CSS class — **don't set `transform`**; placement (incl. the
912
953
  flip) is computed in JS.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { M as MLTimeGraphOptions, L as LegendItem, R as Renderer, a as LayoutResult, b as Margin, A as AxesConfig, X as XAxisConfig, Y as YAxisConfig, c as LegendOptions, d as LegendPosition, e as LegendOrientation, f as Marker, g as RenderOutput } from './marker_renderer-C5rNViFi.js';
2
- export { h as AxisLabelsStyle, i as AxisStyle, G as GridLineStyle, j as GridStyle, T as TextMetrics, k as Theme, l as TickConfig, m as drawMarker, n as estimateMetrics, o as getDefaultTheme, p as liberationMetrics, r as resetDefaultTheme, s as setDefaultTheme, q as slugify } from './marker_renderer-C5rNViFi.js';
3
- import { d as AnySeries, h as Annotation, a as DrawCommand, T as TimeScale, L as LinearScale, f as Gap, g as GapsConfig, e as Threshold, H as Highlight, i as AnnotationBandConfig, k as SeriesStyle, b as LineVariant, S as SmoothingType, F as FillSpec, l as TimeSeries, m as LineDashStyle, n as ThresholdFill, j as HatchVariant, o as ThresholdLabelPosition, P as PointStyleType, M as MarkerLineStyle, R as RangeLabelPosition, p as AnnotationPointShape, q as LabelAnchor, r as AnnotationBandItem, s as TextBaseline, t as AggregatedPoint, u as AggregatedSeries, D as DataPoint } from './scale-CDPJGYpZ.js';
4
- export { v as AggregatedShowAs, w as AggregationConfig, x as AggregationMode, y as AnnotationKind, z as AxisOrientation, A as AxisPosition, B as DataPointRef, E as EnumMap, C as FillBound, I as FillRegion, J as FillSide, K as FillStyle, N as GapConfig, O as GapLabel, Q as GapRegion, U as GapStyle, G as GridLayer, V as LineShape, W as LineStyle, X as MarkerStyle, Y as MovingAverageType, Z as SVGLineStyle, _ as SensorType, $ as SeriesOverlay, a0 as SeriesOverlayKind, a1 as SeriesType, a2 as ShadowStyle, a3 as SolidDashStyle, a4 as ThresholdLabelConfig, a5 as getLineStyle, a6 as resolveDash } from './scale-CDPJGYpZ.js';
1
+ import { M as MLTimeGraphOptions, L as LegendItem, R as Renderer, a as LayoutResult, b as Margin, A as AxesConfig, X as XAxisConfig, Y as YAxisConfig, c as LegendOptions, d as LegendPosition, e as LegendOrientation, f as Marker, g as RenderOutput } from './marker_renderer-CN1N04nS.js';
2
+ export { h as AxisLabelsStyle, i as AxisStyle, G as GridLineStyle, j as GridStyle, T as TextMetrics, k as Theme, l as TickConfig, m as drawMarker, n as estimateMetrics, o as getDefaultTheme, p as liberationMetrics, r as resetDefaultTheme, s as setDefaultTheme, q as slugify } from './marker_renderer-CN1N04nS.js';
3
+ import { e as AnySeries, i as Annotation, a as DrawCommand, T as TimeScale, L as LinearScale, g as Gap, h as GapsConfig, f as Threshold, H as Highlight, j as AnnotationBandConfig, l as SeriesStyle, c as LineVariant, S as SmoothingType, F as FillSpec, m as TimeSeries, b as LineDashStyle, n as ThresholdFill, k as HatchVariant, o as ThresholdLabelPosition, P as PointStyleType, M as MarkerLineStyle, R as RangeLabelPosition, p as AnnotationPointShape, q as LabelAnchor, r as AnnotationBandItem, s as TextBaseline, t as AggregatedPoint, u as AggregatedSeries, D as DataPoint } from './scale-kRRbXFik.js';
4
+ export { v as AggregatedShowAs, w as AggregationConfig, x as AggregationMode, y as AnnotationKind, z as AxisOrientation, A as AxisPosition, B as DataPointRef, E as EnumMap, C as FillBound, I as FillRegion, J as FillSide, K as FillStyle, N as GapConfig, O as GapLabel, Q as GapRegion, U as GapStyle, G as GridLayer, V as LineShape, W as LineStyle, X as MarkerStyle, Y as MovingAverageType, Z as SVGLineStyle, _ as SensorType, $ as SeriesOverlay, a0 as SeriesOverlayKind, a1 as SeriesType, a2 as ShadowStyle, a3 as SolidDashStyle, a4 as ThresholdLabelConfig, a5 as getLineStyle, a6 as resolveDash } from './scale-kRRbXFik.js';
5
5
 
6
6
  /*!
7
7
  * MLTimeGraph — Copyright (c) 2026 Michael Lechner
@@ -106,6 +106,8 @@ declare class MLTimeGraph {
106
106
  * misst, und die Zusage "dasselbe JSON, dasselbe Bild" faellt.
107
107
  */
108
108
  private readonly _textMetrics;
109
+ /** Das eigene Schema dieses Diagramms (Option `theme`), ueber dem globalen. */
110
+ private readonly _theme?;
109
111
  /** Was die Overlays beim letzten renderCommands berechnet haben, je Reihe. */
110
112
  private readonly _overlayWerte;
111
113
  /** Serien auf die Zeichenflaeche beschneiden (Vorgabe: ja) — siehe options.ts. */
@@ -165,8 +167,12 @@ declare class MLTimeGraph {
165
167
  private _layoutMitLegende;
166
168
  /**
167
169
  * Compute the chart's renderer-agnostic draw commands.
170
+ *
171
+ * Mit dem eigenen Schema (Option `theme`), falls gesetzt -- wie alle
172
+ * oeffentlichen Wege, die Schemawerte lesen (legendItems, layout, pointsAt).
168
173
  */
169
174
  renderCommands(): DrawCommand[];
175
+ private _zeichne;
170
176
  /** Build the draw commands for a single series based on its type. */
171
177
  /**
172
178
  * Wie die Linie einer skalaren Reihe gezeichnet wird: ihr Grund-Eintrag,
@@ -180,6 +186,7 @@ declare class MLTimeGraph {
180
186
  private _renderSeries;
181
187
  private _interpolateValue;
182
188
  legendItems(): LegendItem[];
189
+ private _legendeneintraege;
183
190
  /**
184
191
  * Die Farbe einer Reihe ohne eigene Angabe.
185
192
  *
@@ -234,6 +241,7 @@ declare class MLTimeGraph {
234
241
  * area there is nothing. Same rules in the Go port (`PointsAt`).
235
242
  */
236
243
  pointsAt(x: number, y: number, options?: PointsAtOptions): PointAt[];
244
+ private _punkteAm;
237
245
  invertTime(x: number): number;
238
246
  invertValue(y: number, axisIndex?: number): number;
239
247
  project(time: number, value: number, axisIndex?: number): {
@@ -276,20 +284,29 @@ declare function autoMargin(options: MLTimeGraphOptions, opts?: AutoMarginOption
276
284
  * "Michael Lechner". Commercial license (no attribution) on request. See LICENSE.
277
285
  */
278
286
 
279
- /** A single sample at the cursor's X position — one per series. */
287
+ /**
288
+ * A single sample at the cursor — one per series, found by `chart.pointsAt`:
289
+ * the value the drawn line shows there (a step line holds its last value).
290
+ */
280
291
  interface TooltipSample {
281
292
  /** Index of the series in the chart's `series[]`. */
282
293
  seriesIndex: number;
283
294
  /** The series itself (for `.name`, `.style.line.color`, etc.). */
284
295
  series: AnySeries;
285
- /** Timestamp of the closest sample to the cursor (ms). */
296
+ /** Time of the MEASUREMENT (ms) — for a held value, when it was measured. */
286
297
  time: number;
287
298
  /** Numeric value of the sample. For aggregated series this is the `avg`. */
288
299
  value: number;
289
- /** Pixel X of the sample in the rendered SVG. */
300
+ /** Pixel X of the sample in the rendered SVG (on the line). */
290
301
  x: number;
291
302
  /** Pixel Y of the sample in the rendered SVG. */
292
303
  y: number;
304
+ /** The value was measured before the cursor and is carried forward. */
305
+ held?: boolean;
306
+ /** The value as the axis writes it (enum state, axis `format`). */
307
+ label?: string;
308
+ /** Everything `pointsAt` knows about the hit (colour, overlay, bucket …). */
309
+ point: PointAt;
293
310
  }
294
311
  /** Configuration for the DOM-attached tooltip helper. */
295
312
  interface TooltipOptions {
@@ -301,13 +318,20 @@ interface TooltipOptions {
301
318
  * `innerHTML`. If not given, a sensible default is used (time header
302
319
  * + one row per series with `name: value`).
303
320
  */
304
- format?: (samples: TooltipSample[]) => string;
321
+ format?: (samples: TooltipSample[], cursor: {
322
+ time: number;
323
+ }) => string;
305
324
  /**
306
- * Maximum cursor-to-sample distance in pixels for a sample to count.
307
- * Default: `Infinity` (always snap to the nearest sample of each
308
- * series, regardless of distance).
325
+ * Maximum cursor-to-sample distance in pixels for a sample to count
326
+ * (mode `'nearest'`). Default: `Infinity` (always the nearest sample of
327
+ * each series, regardless of distance).
309
328
  */
310
329
  snapRadius?: number;
330
+ /**
331
+ * Passed on to `chart.pointsAt`: `mode`, `modes`, `maxAgeMs`, `overlays`,
332
+ * `hidden`. A step line holds its value by default.
333
+ */
334
+ points?: Omit<PointsAtOptions, "radius">;
311
335
  /** CSS class for the tooltip `<div>`. Default: `'mlc-tooltip'`. */
312
336
  className?: string;
313
337
  /**
@@ -322,10 +346,15 @@ interface TooltipOptions {
322
346
  }
323
347
  /**
324
348
  * Attach an interactive tooltip to a rendered chart. Listens to mousemove
325
- * on the chart's `<svg>` element, snaps each series to its nearest sample
326
- * at the cursor's X position, and renders the result via the `format`
349
+ * on the chart's `<svg>` element, asks `chart.pointsAt` for the value each
350
+ * series' line shows at the cursor, and renders the result via the `format`
327
351
  * callback into a positioned `<div>`.
328
352
  *
353
+ * Until 1.15.0 this helper searched the nearest sample in time by itself --
354
+ * on a step line that is the wrong value (a door open from minute 10 to 40
355
+ * read "closed" at minute 38). Now it goes through `pointsAt`, the same rules
356
+ * as any own tooltip.
357
+ *
329
358
  * Returns a cleanup function that removes the listeners and the tooltip
330
359
  * element. Idempotent — calling cleanup twice is a no-op.
331
360
  *
@@ -393,6 +422,55 @@ interface MountOptions extends MLTimeGraphOptions {
393
422
  */
394
423
  declare function mount(target: HTMLElement | string, options?: MountOptions): MLTimeGraph;
395
424
 
425
+ /*!
426
+ * MLTimeGraph — Copyright (c) 2026 Michael Lechner
427
+ * MIT with Attribution: free use incl. commercial requires visible credit to
428
+ * "Michael Lechner". Commercial license (no attribution) on request. See LICENSE.
429
+ */
430
+ /** Das Noetigste eines SVG-Elements -- ein echtes `SVGSVGElement` passt. */
431
+ interface SvgFuerZeiger {
432
+ getScreenCTM?(): {
433
+ a: number;
434
+ b: number;
435
+ c: number;
436
+ d: number;
437
+ e: number;
438
+ f: number;
439
+ inverse(): {
440
+ a: number;
441
+ b: number;
442
+ c: number;
443
+ d: number;
444
+ e: number;
445
+ f: number;
446
+ };
447
+ } | null;
448
+ getBoundingClientRect(): {
449
+ left: number;
450
+ top: number;
451
+ width: number;
452
+ height: number;
453
+ };
454
+ viewBox?: {
455
+ baseVal: {
456
+ x: number;
457
+ y: number;
458
+ width: number;
459
+ height: number;
460
+ } | null;
461
+ };
462
+ }
463
+ /**
464
+ * The pointer position in the SVG's own coordinates -- the pixels that
465
+ * `pointsAt`, `invertTime` and `plotRect` speak. Correct at any scaling,
466
+ * `viewBox` and CSS transform (via `getScreenCTM()`); without a screen
467
+ * matrix (not laid out yet) it falls back to `viewBox` and the element's box.
468
+ */
469
+ declare function zeigerImSvg(svg: SvgFuerZeiger, clientX: number, clientY: number): {
470
+ x: number;
471
+ y: number;
472
+ };
473
+
396
474
  /*!
397
475
  * MLTimeGraph — Copyright (c) 2026 Michael Lechner
398
476
  * MIT with Attribution: free use incl. commercial requires visible credit to
@@ -1014,6 +1092,6 @@ declare function mergeOptions(...layers: (OptionsLayer | undefined)[]): MLTimeGr
1014
1092
  * Monate spaeter eine Datei aus einem Stapel von Berichten in der Hand haelt,
1015
1093
  * kann sonst nicht feststellen, welcher Stand sie gezeichnet hat.
1016
1094
  */
1017
- declare const VERSION = "1.15.0";
1095
+ declare const VERSION = "1.16.0";
1018
1096
 
1019
- export { AggregatedPoint, AggregatedSeries, Annotation, AnnotationBandBuilder, AnnotationBandConfig, AnnotationBandItem, AnnotationBandItemBuilder, AnnotationBuilder, AnnotationPointShape, AnySeries, type AutoMarginOptions, AxesConfig, DataPoint, DrawCommand, type FieldAccessor, type FillBetweenThresholdsInput, FillSpec, Gap, GapsConfig, GraphBuilder, HatchVariant, Highlight, HighlightBuilder, LabelAnchor, LegendItem, LegendOptions, LegendOrientation, LegendPosition, type LimitStatsPoint, LineDashStyle, LineVariant, MLTimeGraph, MLTimeGraphOptions, Margin, Marker, MarkerBuilder, MarkerLineStyle, type MktPoint, type OptionsLayer, type PointAt, PointStyleType, type PointsAtOptions, RangeLabelPosition, SVGRenderer, SeriesStyle, SmoothingType, type StatsAggregatedPoint, type StdDevPoint, TextBaseline, Threshold, ThresholdBuilder, ThresholdFill, ThresholdLabelPosition, type TimeInput, TimeSeries, TimeSeriesBuilder, type ToDataPointsSpec, type TooltipOptions, type TooltipSample, VERSION, XAxisConfig, YAxisConfig, attachTooltip, autoMargin, fillBetweenThresholds, mergeOptions, mount, parseAggregated, parseDataPoint, parseSeries, toDataPoints, toSeries };
1097
+ export { AggregatedPoint, AggregatedSeries, Annotation, AnnotationBandBuilder, AnnotationBandConfig, AnnotationBandItem, AnnotationBandItemBuilder, AnnotationBuilder, AnnotationPointShape, AnySeries, type AutoMarginOptions, AxesConfig, DataPoint, DrawCommand, type FieldAccessor, type FillBetweenThresholdsInput, FillSpec, Gap, GapsConfig, GraphBuilder, HatchVariant, Highlight, HighlightBuilder, LabelAnchor, LegendItem, LegendOptions, LegendOrientation, LegendPosition, type LimitStatsPoint, LineDashStyle, LineVariant, MLTimeGraph, MLTimeGraphOptions, Margin, Marker, MarkerBuilder, MarkerLineStyle, type MktPoint, type OptionsLayer, type PointAt, PointStyleType, type PointsAtOptions, RangeLabelPosition, SVGRenderer, SeriesStyle, SmoothingType, type StatsAggregatedPoint, type StdDevPoint, TextBaseline, Threshold, ThresholdBuilder, ThresholdFill, ThresholdLabelPosition, type TimeInput, TimeSeries, TimeSeriesBuilder, type ToDataPointsSpec, type TooltipOptions, type TooltipSample, VERSION, XAxisConfig, YAxisConfig, attachTooltip, autoMargin, fillBetweenThresholds, mergeOptions, mount, parseAggregated, parseDataPoint, parseSeries, toDataPoints, toSeries, zeigerImSvg };