hydraloop-diagram-react 0.0.0-stage → 1.0.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/readme.md ADDED
@@ -0,0 +1,125 @@
1
+ # hydraloop-diagram-react
2
+
3
+ > React flow diagram of a [Hydraloop](https://www.hydraloop.com) H600, and the model that works out what the device is doing from its signals
4
+
5
+ [![The flow diagram while train A receives greywater, T3 circulates through UV-C and the distribution pump supplies the toilets](https://raw.githubusercontent.com/gr2m/hydraloop/main/packages/diagram-react/assets/receiving-greywater.svg)](https://hydraloop-diagram.gr2m.dev/)
6
+
7
+ Try it with any state in the playground: https://hydraloop-diagram.gr2m.dev/
8
+
9
+ The diagram shows the inlet and bypass, both treatment trains (T1 and T2 of A and B), UV-C, the T3 storage, the T4 backup and the outlets. Pipes are colored and animated while a routine, valve, pump or sensor signal shows water moving through them. Hover a valve, pump, sensor or tank for its raw value.
10
+
11
+ The model (`stateAt`) derives that state from tank levels, IO signals, HDM routines and firmware behaviors, as loaded from the internal HDM API with [`hydraloop-internal`](../internal/readme.md). See the [H600 dashboard](../../apps/h600.gr2m.dev/README.md) for how the H600 was found to work.
12
+
13
+ > [!WARNING]
14
+ > The model is derived from the data of one H600 (firmware 9.24), not documented by Hydraloop. Its results may change as the inference improves.
15
+
16
+ ## Install
17
+
18
+ ```
19
+ npm install hydraloop-diagram-react
20
+ ```
21
+
22
+ React 19 or newer is a peer dependency. The components have no hooks or browser-only code, so they also render as React Server Components.
23
+
24
+ ## Usage
25
+
26
+ ```tsx
27
+ import {
28
+ DiagramLegend,
29
+ FlowDiagram,
30
+ FlowSummary,
31
+ stateAt,
32
+ type Dataset,
33
+ } from "hydraloop-diagram-react";
34
+ import "hydraloop-diagram-react/styles.css";
35
+
36
+ export function H600({ dataset, t }: { dataset: Dataset; t: number }) {
37
+ const state = stateAt(dataset, t);
38
+ return (
39
+ <figure>
40
+ <FlowDiagram state={state} device={dataset.device} />
41
+ <FlowSummary state={state} />
42
+ <figcaption>
43
+ <DiagramLegend />
44
+ </figcaption>
45
+ </figure>
46
+ );
47
+ }
48
+ ```
49
+
50
+ ### Components
51
+
52
+ - `<FlowDiagram state device />`: the diagram as an `<svg>` that fills the width of its container. `state` is a `DeviceState` from `stateAt()`, `device` is `dataset.device`, used for the outlets that are connected.
53
+ - `<FlowSummary state />`: the flows the diagram animates, as a sentence, e.g. "Water moving: Greywater → train A · T3 → toilets".
54
+ - `<DiagramLegend />`: the colors of the pipes.
55
+ - `activeFlows(state)`: the flows of `<FlowSummary>` as an array of strings.
56
+
57
+ Times in the tooltips use the runtime's locale and time zone. As they can differ between server and browser, their `<title>` elements have `suppressHydrationWarning`.
58
+
59
+ ### Model
60
+
61
+ `hydraloop-diagram-react/model` exports the model without React, e.g. for a server or a CLI. The package root exports it, too.
62
+
63
+ - `stateAt(dataset, t)`: the `DeviceState` at time `t` (milliseconds since epoch): tank levels and trends, IO values, the phase of each train and how it was determined, T3, T4, the supply of the outlets, and `room`.
64
+ - `roomAt(dataset, t)`: how many liters of greywater the H600 can take before they are bypassed to the sewer.
65
+ - `routineAt(dataset, side, t)`, `fillingTrain(dataset, t)`, `isScheduledRestart(dataset, interval)`, `ventedLevels(dataset, side)`, `onIntervals(points, from, until)`, `stepAt(points, t)`, `valueAt(points, t)`
66
+ - `IO`: the names of the IO signals with known roles. `sideIo(name, side)` adds the `_b` suffix of train B.
67
+ - `caption(captions, name)`, `humanize(text)`, `capacityNote(level)`: labels
68
+ - Types: `Dataset`, `DeviceState`, `DeviceInfo`, `TankLevel`, `TrainState`, `Room`, …
69
+
70
+ ### Dataset
71
+
72
+ `Dataset` holds the data of a time range. All times are milliseconds since epoch, and all series are sorted by time:
73
+
74
+ | Field | Content |
75
+ | ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
76
+ | `device` | Name, type and online state, and which outlets are connected |
77
+ | `from`, `until` | The range |
78
+ | `tanks` | Levels in liters of `t1a`, `t2a`, `t1b`, `t2b` and `t3` (`local.graph.getData()`, converted with `local.graph.getDeviceLevels()`) |
79
+ | `tankMax` | The scale of each tank in liters |
80
+ | `io` | Points per IO name, one per change, including the last one before `from` (`local.graph.getIo()`) |
81
+ | `manual` | Whether an IO was switched manually, same shape as `io` (optional) |
82
+ | `routines` | Routine changes per side, including the last one before `from` (`local.graph.getRoutineData()`) |
83
+ | `behaviors` | Firmware behaviors that overlap the range (`behavior` of `local.graph.getIo()`) |
84
+ | `outages` | Outages, to tell the scheduled restart from a full H600 (`local.connectivity.getOutageSummaries()`, optional) |
85
+ | `ventedBefore` | T2 at the last venting of each train before `from` (optional) |
86
+ | `captions` | IO captions from `local.graph.getGraphConfig()` |
87
+ | `demo`, `fetchedAt`, `warnings`, … | Not used by the model |
88
+
89
+ The [H600 dashboard](../../apps/h600.gr2m.dev/README.md) builds it in [`lib/hdm.ts`](../../apps/h600.gr2m.dev/lib/hdm.ts) and keeps it up to date from the device socket in [`lib/live.ts`](../../apps/h600.gr2m.dev/lib/live.ts).
90
+
91
+ ## Styles
92
+
93
+ Import `hydraloop-diagram-react/styles.css` once. All class names, custom properties and keyframes are prefixed with `hl-`, so they don't collide with the page's styles.
94
+
95
+ The colors are custom properties on `:root` without specificity, so the page can override them, e.g. to use its own theme:
96
+
97
+ ```css
98
+ :root {
99
+ --hl-bg: var(--background);
100
+ --hl-fg: var(--foreground);
101
+ --hl-grey: #b26a00; /* greywater */
102
+ --hl-clean: #16893f; /* treated water */
103
+ }
104
+ ```
105
+
106
+ | Property | Used for |
107
+ | ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
108
+ | `--hl-bg` | Background of tanks, valves and pumps, and the gaps where pipes cross. Must match the page's background |
109
+ | `--hl-fg`, `--hl-muted`, `--hl-subtle` | Text, outlines and unknown states |
110
+ | `--hl-border` | Hatching of tanks without level data |
111
+ | `--hl-border-strong` | Tank outlines, and pipes with unknown state |
112
+ | `--hl-focus` | Focused valves, pumps and tanks |
113
+ | `--hl-grey`, `--hl-clean`, `--hl-mains`, `--hl-waste`, `--hl-air`, `--hl-uv` | The kinds of water, air and UV-C |
114
+ | `--hl-pipe-idle`, `--hl-pipe-open` | Pipes without water moving, closed and open |
115
+ | `--hl-font-family` | The diagram's text. Inherits the font if unset |
116
+
117
+ The dark colors apply with `prefers-color-scheme: dark`, unless `<html data-theme="light">`, and with `<html data-theme="dark">`. Animations stop with `prefers-reduced-motion: reduce`.
118
+
119
+ ## Development
120
+
121
+ The playground at https://hydraloop-diagram.gr2m.dev/ renders the diagram for any state, from the source in [`apps/hydraloop-diagram.gr2m.dev`](../../apps/hydraloop-diagram.gr2m.dev/README.md). The image above is its "Receiving greywater" preset, rendered with `npm run readme-svg` in that folder.
122
+
123
+ ## License
124
+
125
+ [ISC](license)
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.