ml-time-graph 1.0.0 → 1.0.5

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/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { e as LegendOrientation, f as Renderer, M as Marker, d as LegendItem, b as LayoutResult, R as RenderOutput, t as theme } from './layout-Sc5UkC0r.js';
2
- import { V as LineVariant, h as AnySeries, ab as Threshold, Q as Highlight, J as Gap, O as GapsConfig, e as Annotation, f as AnnotationBandConfig, p as DrawCommand, ae as TimeScale, W as LinearScale, P as HatchVariant, H as FillSpec, a as AggregatedSeries, l as DataPoint, ag as TimeSeries } from './scale-Cbr0KpPz.js';
3
- export { A as AggregatedPoint, b as AggregationConfig, c as AggregationMode, g as AnnotationBandItem, m as DataPointRef, E as EnumMap, F as FillBound, y as FillDirectionType, z as FillRegion, G as FillSide, I as FillStyle, K as GapConfig, L as GapLabel, M as GapRegion, N as GapStyle, S as LineDashStyle, U as LineStyle, Y as MarkerStyle, $ as PointStyleType, a3 as SensorType, a4 as SeriesOverlay, a5 as SeriesOverlayKind, a6 as SeriesStyle, a7 as SeriesType, a8 as ShadowStyle, ac as ThresholdLabelConfig, ad as ThresholdLabelPosition } from './scale-Cbr0KpPz.js';
4
- export { L as LimitStatsPoint, M as MktPoint, S as StatsAggregatedPoint, a as StdDevPoint } from './aggregated_subtypes-DZNZyFTX.js';
1
+ import { e as LegendOrientation, f as Renderer, M as Marker, d as LegendItem, b as LayoutResult, R as RenderOutput, t as theme } from './layout-BOYtrsZa.js';
2
+ import { U as LineVariant, g as AnySeries, aa as Threshold, P as Highlight, I as Gap, N as GapsConfig, d as Annotation, e as AnnotationBandConfig, o as DrawCommand, ad as TimeScale, V as LinearScale, O as HatchVariant, f as AnnotationBandItem, _ as PointStyleType, ac as ThresholdLabelPosition, a5 as SeriesStyle, G as FillSpec, af as TimeSeries, A as AggregatedPoint, a as AggregatedSeries, k as DataPoint } from './scale-BRE_QhbZ.js';
3
+ export { b as AggregationConfig, c as AggregationMode, l as DataPointRef, E as EnumMap, F as FillBound, x as FillDirectionType, y as FillRegion, z as FillSide, H as FillStyle, J as GapConfig, K as GapLabel, L as GapRegion, M as GapStyle, R as LineDashStyle, T as LineStyle, X as MarkerStyle, a2 as SensorType, a3 as SeriesOverlay, a4 as SeriesOverlayKind, a6 as SeriesType, a7 as ShadowStyle, ab as ThresholdLabelConfig } from './scale-BRE_QhbZ.js';
5
4
 
6
5
  /*!
7
6
  * MLTimeGraph — Copyright (c) 2026 Michael Lechner
@@ -46,6 +45,8 @@ interface AxisLabelsStyle {
46
45
  }
47
46
  /** Configuration for one Y-axis (left or right). */
48
47
  interface YAxisConfig {
48
+ /** Position is 'left' or 'right' to determine placement side. Defaults to 'left'. */
49
+ position?: "left" | "right";
49
50
  /** Rotated label drawn next to the axis. */
50
51
  label?: string;
51
52
  /** Override the value domain. `'auto'` lets the chart compute it from data. */
@@ -86,6 +87,8 @@ interface AxesConfig {
86
87
  x?: XAxisConfig;
87
88
  left?: YAxisConfig;
88
89
  right?: YAxisConfig;
90
+ /** Y specifies an arbitrary number of vertical axes, each mapped by its slice index. */
91
+ y?: YAxisConfig[];
89
92
  }
90
93
 
91
94
  /*!
@@ -298,14 +301,16 @@ interface TooltipOptions {
298
301
  * position: absolute;
299
302
  * pointer-events: none;
300
303
  * padding: 6px 10px;
301
- * background: rgba(15, 23, 42, 0.92);
302
- * color: #fff;
304
+ * background: rgba(254, 243, 199, 0.92); / * sticky-note yellow * /
305
+ * color: #1e293b;
306
+ * border: 1px solid rgba(217, 119, 6, 0.35);
303
307
  * border-radius: 4px;
304
308
  * font-size: 12px;
305
309
  * transform: translate(8px, 8px);
310
+ * box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
306
311
  * }
307
- * .mlc-tooltip__time { opacity: 0.7; margin-bottom: 4px; }
308
- * .mlc-tooltip__name { opacity: 0.8; }
312
+ * .mlc-tooltip__time { opacity: 0.7; margin-bottom: 4px; font-weight: 600; }
313
+ * .mlc-tooltip__name { opacity: 0.85; }
309
314
  * ```
310
315
  */
311
316
  declare function attachTooltip(target: HTMLElement, chart: MLTimeGraph, options?: TooltipOptions): () => void;
@@ -353,6 +358,298 @@ interface MountOptions extends MLTimeGraphOptions {
353
358
  */
354
359
  declare function mount(target: HTMLElement | string, options?: MountOptions): MLTimeGraph;
355
360
 
361
+ /*!
362
+ * MLTimeGraph — Copyright (c) 2026 Michael Lechner
363
+ * MIT with Attribution: free use incl. commercial requires visible credit to
364
+ * "Michael Lechner". Commercial license (no attribution) on request. See LICENSE.
365
+ */
366
+
367
+ /**
368
+ * Imperative builder for MLTimeGraph. Accumulate config via `setX` /
369
+ * `addX` methods, then materialise via `getSvg()` / `mount()` / `build()`.
370
+ */
371
+ declare class GraphBuilder {
372
+ private _opts;
373
+ private _series;
374
+ private _thresholds;
375
+ private _annotations;
376
+ private _highlights;
377
+ private _markers;
378
+ private _bands;
379
+ private _tooltip?;
380
+ /**
381
+ * @param width Chart width in px. Pass `0` or omit to auto-detect from the
382
+ * target's `clientWidth` in {@link mount}.
383
+ * @param height Chart height in px.
384
+ */
385
+ constructor(width?: number, height?: number);
386
+ /** Set the chart's pixel width. */
387
+ setWidth(width: number): this;
388
+ /** Set the chart's pixel height. */
389
+ setHeight(height: number): this;
390
+ /** Override the chart's pixel dimensions. */
391
+ setSize(width: number, height: number): this;
392
+ /**
393
+ * Override per-side pixel margins.
394
+ * Can be passed as a full `Margin` object or four number arguments: `top, right, bottom, left`.
395
+ */
396
+ setMargin(margin: Margin): this;
397
+ setMargin(top: number, right: number, bottom: number, left: number): this;
398
+ /** Locale for date/number formatting (e.g. 'de-DE'). */
399
+ setLocale(locale: string): this;
400
+ /** Set the entire axes block (x / left / right). Replaces previous. */
401
+ setAxes(axes: AxesConfig): this;
402
+ /** Patch just the X-axis config; leaves left/right untouched. */
403
+ setXAxis(config: XAxisConfig): this;
404
+ /** Patch just the left Y-axis. */
405
+ setLeftAxis(config: YAxisConfig): this;
406
+ /** Patch just the right Y-axis (`yAxisIndex: 1` series). */
407
+ setRightAxis(config: YAxisConfig): this;
408
+ /** Patch a specific Y-axis configuration by index. */
409
+ setYAxis(index: number, config: YAxisConfig): this;
410
+ /**
411
+ * Show / position / orient the integrated legend.
412
+ * Can be passed as a full `LegendOptions` object or three arguments: `show, position, orientation`.
413
+ */
414
+ setLegend(legend: LegendOptions): this;
415
+ setLegend(show: boolean, position?: LegendPosition, orientation?: LegendOrientation): this;
416
+ /**
417
+ * Configure data-gap handling. Accepts either the legacy `Gap[]` or the
418
+ * new `GapsConfig` (`{ regions?, autoDetect?, minGapMs?, style? }`).
419
+ */
420
+ setGaps(gaps: Gap[] | GapsConfig): this;
421
+ /**
422
+ * Tooltip config. Only takes effect when {@link mount} is used — pure
423
+ * `getSvg()` output has nothing to hover over. Default `show: true`
424
+ * when called; pass an explicit `show: false` to keep the chart but
425
+ * skip the listener.
426
+ */
427
+ setTooltip(tooltip: TooltipOptions & {
428
+ show?: boolean;
429
+ }): this;
430
+ /** Append one series. */
431
+ addSeries(series: AnySeries): this;
432
+ /** Append multiple series at once. */
433
+ addSeriesAll(series: AnySeries[]): this;
434
+ /** Append one threshold (line + optional fill + label). */
435
+ addThreshold(threshold: Threshold): this;
436
+ /** Append multiple thresholds at once. */
437
+ addThresholds(thresholds: Threshold[]): this;
438
+ /** Append one annotation (line / arrow / rect / point / label). */
439
+ addAnnotation(annotation: Annotation): this;
440
+ /** Append multiple annotations at once. */
441
+ addAnnotations(annotations: Annotation[]): this;
442
+ /** Append one highlight (coloured time range behind the data). */
443
+ addHighlight(highlight: Highlight): this;
444
+ /** Append one marker (vertical pin at a timestamp). */
445
+ addMarker(marker: Marker): this;
446
+ /** Append one annotation band (horizontal strip below the chart). */
447
+ addAnnotationBand(band: AnnotationBandConfig): this;
448
+ /** Wipe a category of added items. Useful for re-building part of a chart. */
449
+ clear(category?: "series" | "thresholds" | "annotations" | "highlights" | "markers" | "bands"): this;
450
+ /** Compose the final MLTimeGraphOptions from current state. */
451
+ toOptions(): MLTimeGraphOptions;
452
+ /** Build the chart instance. Each call returns a fresh MLTimeGraph. */
453
+ build(): MLTimeGraph;
454
+ /**
455
+ * Render the chart and return the full `<svg ...>` string. Suitable for
456
+ * SSR (`fs.writeFileSync(...)`, response body) or for stamping into a
457
+ * DOM element via `el.innerHTML = builder.getSvg()`.
458
+ */
459
+ getSvg(): string;
460
+ /**
461
+ * Build the chart AND inject the SVG into a DOM element. Mirrors what
462
+ * `mount(target, options)` does for the imperative case. Returns the
463
+ * MLTimeGraph instance so the caller can do further work (tooltips,
464
+ * setData, etc.).
465
+ */
466
+ mount(target: HTMLElement | string): MLTimeGraph;
467
+ }
468
+ /**
469
+ * TimeSeriesBuilder simplifies constructing raw TimeSeries datasets.
470
+ */
471
+ declare class TimeSeriesBuilder {
472
+ private _series;
473
+ constructor(name: string);
474
+ /** Appends a value-point to the series. */
475
+ addPoint(time: number, value: number | null): this;
476
+ /** Appends an array of data points directly to the series. */
477
+ addPoints(points: Array<{
478
+ time: number;
479
+ value: number | null;
480
+ }>): this;
481
+ /** Appends parallel arrays of timestamps and values to the series. */
482
+ addFloats(times: number[], values: Array<number | null>): this;
483
+ /** Appends a null point (signaling gaps/offline state). */
484
+ addNullPoint(time: number): this;
485
+ /** Assigns the visual styles configuration. */
486
+ setStyle(style: SeriesStyle): this;
487
+ /** Shortcut to apply custom stroke styling (color, width, dash style). */
488
+ setLineStyle(color: string, width: number, style?: LineVariant): this;
489
+ /** Configures spline interpolation (smoothing) on the series path. */
490
+ setSmoothing(smooth: boolean): this;
491
+ /** Assigns the area fill specification. */
492
+ setFill(fill: FillSpec): this;
493
+ /** Sets a custom identifier for the series path. */
494
+ setID(id: string): this;
495
+ /** Sets named thresholds to split and color the line segment. */
496
+ setColorByThresholds(thresholdNames: string[]): this;
497
+ /** Compiles and returns the TimeSeries object. */
498
+ build(): TimeSeries;
499
+ }
500
+ /**
501
+ * ThresholdBuilder simplifies constructing value boundaries.
502
+ */
503
+ declare class ThresholdBuilder {
504
+ private _threshold;
505
+ constructor(name: string, value: number);
506
+ /** Sets the threshold boundary color. */
507
+ setColor(color: string): this;
508
+ /** Configures the line type (solid, dashed, dotted, none). */
509
+ setLine(style: "solid" | "dashed" | "dotted" | "none"): this;
510
+ /** Configures half-plane fills (above, below, none) and opacity. */
511
+ setFill(fillType: "above" | "below" | "none", opacity: number): this;
512
+ /** Configures a hatch pattern style for the fill. */
513
+ setFillHatch(hatch: HatchVariant): this;
514
+ /** Configures the labels parameters. */
515
+ setLabel(text: string, position?: ThresholdLabelPosition): this;
516
+ /** Configures a unique ID for referencing the threshold. */
517
+ setID(id: string): this;
518
+ /** Compiles and returns the Threshold object. */
519
+ build(): Threshold;
520
+ }
521
+ /**
522
+ * MarkerBuilder simplifies constructing vertical pins/markers.
523
+ */
524
+ declare class MarkerBuilder {
525
+ private _marker;
526
+ constructor(time: number);
527
+ /** Sets the marker value (for point markers). */
528
+ setValue(v: number): this;
529
+ /** Sets the text label. */
530
+ setLabel(lbl: string): this;
531
+ /** Sets the marker color. */
532
+ setColor(color: string): this;
533
+ /** Sets the shape of the point marker (circle, square, cross, star, arrow, none). */
534
+ setPointStyle(style: PointStyleType): this;
535
+ /** Sets the type of vertical projection line (full, to-value, to-top, none). */
536
+ setLineStyle(style: "full" | "to-value" | "to-top" | "none"): this;
537
+ /** Targets a specific series by index for interpolation. */
538
+ setSeriesIndex(idx: number): this;
539
+ /** Compiles and returns the Marker object. */
540
+ build(): Marker;
541
+ }
542
+ /**
543
+ * HighlightBuilder simplifies constructing highlighted time bands.
544
+ */
545
+ declare class HighlightBuilder {
546
+ private _highlight;
547
+ constructor(startTime: number, endTime: number);
548
+ /** Sets the text label. */
549
+ setLabel(lbl: string): this;
550
+ /** Sets the background color. */
551
+ setColor(color: string): this;
552
+ /** Sets the opacity. */
553
+ setOpacity(opacity: number): this;
554
+ /** Sets the label alignment (top, center, bottom, above, below). */
555
+ setLabelPosition(pos: "top" | "center" | "bottom" | "above" | "below"): this;
556
+ /** Sets the text rotation in degrees. */
557
+ setRotate(rotate: number): this;
558
+ /** Compiles and returns the Highlight object. */
559
+ build(): Highlight;
560
+ }
561
+ /**
562
+ * AnnotationBuilder simplifies constructing free-form annotations.
563
+ */
564
+ declare class AnnotationBuilder {
565
+ private _ann;
566
+ constructor(typ: "line" | "arrow" | "rect" | "point" | "label");
567
+ /** Sets a unique identifier. */
568
+ setID(id: string): this;
569
+ /** Sets the title (used for legend / toggles, not drawn). */
570
+ setTitle(title: string): this;
571
+ /** Sets the start point coordinate reference. */
572
+ setFrom(time: number, value: number, axis?: number): this;
573
+ /** Sets the end point coordinate reference. */
574
+ setTo(time: number, value: number, axis?: number): this;
575
+ /** Sets the coordinate reference position (for point/label). */
576
+ setAt(time: number, value: number, axis?: number): this;
577
+ /** Sets the primary stroke/text color. */
578
+ setColor(color: string): this;
579
+ /** Sets the stroke width. */
580
+ setWidth(w: number): this;
581
+ /** Sets the dash pattern ("dashed" | "dotted"). */
582
+ setDash(dash: "dashed" | "dotted"): this;
583
+ /** Sets the arrowhead size (arrow only). */
584
+ setHeadSize(size: number): this;
585
+ /** Sets the fill color. */
586
+ setFill(fill: string): this;
587
+ /** Sets the hatch pattern variant. */
588
+ setHatch(hatch: HatchVariant): this;
589
+ /** Sets the stroke color. */
590
+ setStroke(stroke: string): this;
591
+ /** Sets the opacity. */
592
+ setOpacity(opacity: number): this;
593
+ /** Sets the point radius (point only). */
594
+ setRadius(radius: number): this;
595
+ /** Sets the point shape (point only). */
596
+ setShape(shape: "circle" | "square" | "cross"): this;
597
+ /** Sets the label text (label only). */
598
+ setText(text: string): this;
599
+ /** Sets the text anchor (label only). */
600
+ setAnchor(anchor: "start" | "middle" | "end"): this;
601
+ /** Sets the horizontal offset (label only). */
602
+ setDx(dx: number): this;
603
+ /** Sets the vertical offset (label only). */
604
+ setDy(dy: number): this;
605
+ /** Sets the label rotation in degrees (label only). */
606
+ setRotate(rotate: number): this;
607
+ /** Compiles and returns the Annotation object. */
608
+ build(): Annotation;
609
+ }
610
+ /**
611
+ * AnnotationBandBuilder simplifies constructing annotation bands below the chart.
612
+ */
613
+ declare class AnnotationBandBuilder {
614
+ private _band;
615
+ constructor(name: string);
616
+ /** Sets the band height in pixels. */
617
+ setHeight(h: number): this;
618
+ /** Sets the vertical spacing between bands. */
619
+ setSpacing(s: number): this;
620
+ /** Sets a default hatch pattern variant for all items in the band. */
621
+ setHatch(hatch: HatchVariant): this;
622
+ /** Sets whether to draw a time axis under the band. */
623
+ setShowAxis(show: boolean): this;
624
+ /** Sets whether the band is listed in the chart legend. */
625
+ setShowInLegend(show: boolean): this;
626
+ /** Sets the background color of the band. */
627
+ setBackground(bg: string): this;
628
+ /** Adds an event range/item to the band. */
629
+ addItem(item: AnnotationBandItem): this;
630
+ /** Compiles and returns the AnnotationBandConfig object. */
631
+ build(): AnnotationBandConfig;
632
+ }
633
+ /**
634
+ * AnnotationBandItemBuilder simplifies constructing annotation band event ranges.
635
+ */
636
+ declare class AnnotationBandItemBuilder {
637
+ private _item;
638
+ constructor(startTime: number, endTime: number);
639
+ /** Sets the fill color. */
640
+ setFill(fill: string): this;
641
+ /** Sets the hatch pattern variant. */
642
+ setHatch(hatch: HatchVariant): this;
643
+ /** Sets the border stroke color. */
644
+ setStroke(stroke: string): this;
645
+ /** Sets the border stroke width. */
646
+ setStrokeWidth(w: number): this;
647
+ /** Sets the text label and optional label formatting fields. */
648
+ setLabel(lbl: string, fontSize?: number, fill?: string, baseline?: 'top' | 'middle' | 'bottom'): this;
649
+ /** Compiles and returns the AnnotationBandItem object. */
650
+ build(): AnnotationBandItem;
651
+ }
652
+
356
653
  /*!
357
654
  * MLTimeGraph — Copyright (c) 2026 Michael Lechner
358
655
  * MIT with Attribution: free use incl. commercial requires visible credit to
@@ -395,6 +692,46 @@ declare class SVGRenderer extends Renderer {
395
692
  _esc(s: string): string;
396
693
  }
397
694
 
695
+ /*!
696
+ * MLTimeGraph — Copyright (c) 2026 Michael Lechner
697
+ * MIT with Attribution: free use incl. commercial requires visible credit to
698
+ * "Michael Lechner". Commercial license (no attribution) on request. See LICENSE.
699
+ */
700
+
701
+ /** Slot carrying a rolling Mean Kinetic Temperature value (USP <1079.2>). */
702
+ interface MktPoint extends AggregatedPoint {
703
+ /** Mean kinetic temperature for this slot. `null` = gap. */
704
+ mkt: number | null;
705
+ /** Delta vs the previous slot's MKT (optional). */
706
+ deltaMkt?: number | null;
707
+ }
708
+ /** Slot carrying the standard deviation of the samples in the window. */
709
+ interface StdDevPoint extends AggregatedPoint {
710
+ /** Standard deviation of the samples in this slot. `null` = gap. */
711
+ stdDev: number | null;
712
+ }
713
+ /**
714
+ * Slot carrying minutes-above-/below-limit statistics. At least one of
715
+ * `minutesAboveHigh` or `minutesBelowLow` must be set.
716
+ */
717
+ interface LimitStatsPoint extends AggregatedPoint {
718
+ /** Minutes above the upper limit in this slot. */
719
+ minutesAboveHigh?: number | null;
720
+ /** Minutes below the lower limit in this slot. */
721
+ minutesBelowLow?: number | null;
722
+ }
723
+ /**
724
+ * The "full-stats" aggregated slot — combines all three specialised
725
+ * subtypes via intersection. This is what `aggregateBySlot(data, mode,
726
+ * thresholds)` returns when thresholds are provided: per-slot MKT (USP
727
+ * <1079.2>), standard deviation, and out-of-bounds minute counters.
728
+ *
729
+ * Prefer this typed alias over plain `AggregatedPoint` whenever you
730
+ * downstream-consume `aggregateBySlot`'s output and want guaranteed access
731
+ * to the stat fields.
732
+ */
733
+ type StatsAggregatedPoint = MktPoint & StdDevPoint & LimitStatsPoint;
734
+
398
735
  /*!
399
736
  * MLTimeGraph — Copyright (c) 2026 Michael Lechner
400
737
  * MIT with Attribution: free use incl. commercial requires visible credit to
@@ -478,4 +815,4 @@ declare function getDefaultTheme(): Readonly<Theme>;
478
815
  */
479
816
  declare function resetDefaultTheme(): void;
480
817
 
481
- export { AggregatedSeries, Annotation, AnnotationBandConfig, AnySeries, type AxesConfig, type AxisLabelsStyle, type AxisStyle, DataPoint, type FillBetweenThresholdsInput, FillSpec, Gap, GapsConfig, type GridLineStyle, type GridStyle, HatchVariant, Highlight, type LegendOptions, type LegendPosition, MLTimeGraph, type MLTimeGraphOptions, type Margin, Marker, SVGRenderer, type Theme, Threshold, type TickConfig, TimeSeries, type TooltipOptions, type TooltipSample, type XAxisConfig, type YAxisConfig, attachTooltip, fillBetweenThresholds, getDefaultTheme, mount, parseAggregated, parseDataPoint, parseSeries, resetDefaultTheme, setDefaultTheme };
818
+ export { AggregatedPoint, AggregatedSeries, Annotation, AnnotationBandBuilder, AnnotationBandConfig, AnnotationBandItem, AnnotationBandItemBuilder, AnnotationBuilder, AnySeries, type AxesConfig, type AxisLabelsStyle, type AxisStyle, DataPoint, type FillBetweenThresholdsInput, FillSpec, Gap, GapsConfig, GraphBuilder, type GridLineStyle, type GridStyle, HatchVariant, Highlight, HighlightBuilder, type LegendOptions, type LegendPosition, type LimitStatsPoint, MLTimeGraph, type MLTimeGraphOptions, type Margin, Marker, MarkerBuilder, type MktPoint, PointStyleType, SVGRenderer, SeriesStyle, type StatsAggregatedPoint, type StdDevPoint, type Theme, Threshold, ThresholdBuilder, ThresholdLabelPosition, type TickConfig, TimeSeries, TimeSeriesBuilder, type TooltipOptions, type TooltipSample, type XAxisConfig, type YAxisConfig, attachTooltip, fillBetweenThresholds, getDefaultTheme, mount, parseAggregated, parseDataPoint, parseSeries, resetDefaultTheme, setDefaultTheme };