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/dist/flow-diagram.d.ts +11 -0
- package/dist/flow-diagram.js +513 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/model.d.ts +320 -0
- package/dist/model.js +662 -0
- package/dist/styles.css +586 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +1 -0
- package/license +15 -0
- package/package.json +45 -4
- package/readme.md +125 -0
- package/README.md +0 -3
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type DeviceInfo, type DeviceState } from "./model.js";
|
|
2
|
+
export declare function FlowDiagram({ state, device, }: {
|
|
3
|
+
state: DeviceState;
|
|
4
|
+
device: DeviceInfo;
|
|
5
|
+
}): import("react").JSX.Element;
|
|
6
|
+
export declare function DiagramLegend(): import("react").JSX.Element;
|
|
7
|
+
/** The flows the diagram animates, as text */
|
|
8
|
+
export declare function activeFlows(state: DeviceState): string[];
|
|
9
|
+
export declare function FlowSummary({ state }: {
|
|
10
|
+
state: DeviceState;
|
|
11
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
// Schematic of the H600: inlet, two treatment trains, UV, storage, backup
|
|
3
|
+
// and outlets. Pipes are colored and animated only while a routine, valve,
|
|
4
|
+
// pump or sensor signal shows water moving through them. Pipes that their
|
|
5
|
+
// valves leave open, but without water moving, are drawn with more contrast.
|
|
6
|
+
//
|
|
7
|
+
// Plain React without hooks, so it also renders as a server component. The
|
|
8
|
+
// class names are prefixed with `hl-`, see `styles.css`.
|
|
9
|
+
import { capacityNote, caption, IO, sideIo, } from "./model.js";
|
|
10
|
+
/**
|
|
11
|
+
* Times in tooltips, in the runtime's locale and time zone. They can differ
|
|
12
|
+
* between server and browser, so the `<title>` elements that show them have
|
|
13
|
+
* `suppressHydrationWarning`.
|
|
14
|
+
*/
|
|
15
|
+
function formatTime(t) {
|
|
16
|
+
if (t === undefined)
|
|
17
|
+
return "";
|
|
18
|
+
return new Date(t).toLocaleTimeString([], {
|
|
19
|
+
hour: "2-digit",
|
|
20
|
+
minute: "2-digit",
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function Pipe({ d, kind, active, open = false, filled = false, still = false, square = false, arrow, title, }) {
|
|
24
|
+
const state = active === undefined
|
|
25
|
+
? "unknown"
|
|
26
|
+
: filled
|
|
27
|
+
? "filled"
|
|
28
|
+
: active
|
|
29
|
+
? "active"
|
|
30
|
+
: open
|
|
31
|
+
? "open"
|
|
32
|
+
: "idle";
|
|
33
|
+
return (_jsxs("g", { className: `hl-pipe hl-kind-${kind} is-${state}${still ? " is-still" : ""}${square ? " is-square" : ""}`, children: [title && _jsx("title", { children: title }), _jsx("path", { d: d, className: "hl-pipe-base" }), state === "filled" && _jsx("path", { d: d, className: "hl-pipe-water" }), active && _jsx("path", { d: d, className: "hl-pipe-flow" }), arrow && (_jsx("path", { className: "hl-pipe-arrow", d: arrow.dir === "down"
|
|
34
|
+
? `M${arrow.x - 7} ${arrow.y} L${arrow.x + 7} ${arrow.y} L${arrow.x} ${arrow.y + 9} Z`
|
|
35
|
+
: arrow.dir === "right"
|
|
36
|
+
? `M${arrow.x} ${arrow.y - 7} L${arrow.x} ${arrow.y + 7} L${arrow.x + 9} ${arrow.y} Z`
|
|
37
|
+
: `M${arrow.x} ${arrow.y - 7} L${arrow.x} ${arrow.y + 7} L${arrow.x - 9} ${arrow.y} Z` }))] }));
|
|
38
|
+
}
|
|
39
|
+
function ioTitle(label, name, io, words) {
|
|
40
|
+
if (!io)
|
|
41
|
+
return `${label}: no data (${name})`;
|
|
42
|
+
const since = io.since ? ` since ${formatTime(io.since)}` : "";
|
|
43
|
+
const manual = io.manual ? ", switched manually" : "";
|
|
44
|
+
return `${label}: ${io.on ? words[0] : words[1]}${since}${manual} (${name} = ${io.value})`;
|
|
45
|
+
}
|
|
46
|
+
/** An on/off valve. Parallel to the pipe while open, across it while closed */
|
|
47
|
+
function Valve({ x, y, vertical = false, kind, io, active = false, name, label, labelAnchor = "start", labelDx = 16, labelDy = 4, }) {
|
|
48
|
+
const state = io === undefined ? "unknown" : io.on ? "open" : "closed";
|
|
49
|
+
const s = 10;
|
|
50
|
+
// Unknown valves are drawn half-way, neither open nor closed
|
|
51
|
+
const angle = (vertical ? 90 : 0) + (state === "open" ? 0 : state === "closed" ? 90 : 45);
|
|
52
|
+
const title = ioTitle(label || caption({}, name), name, io, [
|
|
53
|
+
"open",
|
|
54
|
+
"closed",
|
|
55
|
+
]);
|
|
56
|
+
return (_jsxs("g", { className: `hl-valve hl-kind-${kind} is-${state}${state === "open" && active ? " is-flowing" : ""}`, tabIndex: 0, role: "img", "aria-label": title, children: [_jsx("title", { suppressHydrationWarning: true, children: title }), _jsx("rect", { x: x - 14, y: y - 14, width: 28, height: 28, className: "hl-hit" }), _jsxs("g", { className: "hl-valve-body", style: {
|
|
57
|
+
transform: `rotate(${angle}deg)`,
|
|
58
|
+
transformOrigin: `${x}px ${y}px`,
|
|
59
|
+
}, children: [_jsx("polygon", { points: `${x - s},${y - 8} ${x - s},${y + 8} ${x},${y}` }), _jsx("polygon", { points: `${x + s},${y - 8} ${x + s},${y + 8} ${x},${y}` })] }), label && (_jsx("text", { x: x + labelDx, y: y + labelDy, textAnchor: labelAnchor, className: "hl-diagram-label", children: label }))] }));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The pipe between the backwash valves, level with the waste pipes below T1
|
|
63
|
+
*/
|
|
64
|
+
const RUN_Y = 404;
|
|
65
|
+
/** The vertical center of UV-C */
|
|
66
|
+
const UV_Y = 466;
|
|
67
|
+
/** Half the width of a pipe */
|
|
68
|
+
const PIPE = 3.5;
|
|
69
|
+
/** Height of a distributor triangle, from its tip to its base */
|
|
70
|
+
const DISTRIBUTOR = 24;
|
|
71
|
+
/** Stroke width of a distributor's outline, as in .distributor polygon */
|
|
72
|
+
const OUTLINE = 1.5;
|
|
73
|
+
/** Stroke width of a closed side's outline, as in its .is-closed polygon */
|
|
74
|
+
const CLOSED_OUTLINE = 3;
|
|
75
|
+
/**
|
|
76
|
+
* Moves each edge of a convex polygon inwards by d, so a stroke of width 2d
|
|
77
|
+
* stays inside the original shape
|
|
78
|
+
*/
|
|
79
|
+
function inset(points, d) {
|
|
80
|
+
const n = points.length;
|
|
81
|
+
const area = points.reduce((sum, [x1, y1], i) => {
|
|
82
|
+
const [x2, y2] = points[(i + 1) % n];
|
|
83
|
+
return sum + x1 * y2 - x2 * y1;
|
|
84
|
+
}, 0);
|
|
85
|
+
const sign = area > 0 ? 1 : -1;
|
|
86
|
+
// Each edge as a point on its moved line and its direction
|
|
87
|
+
const edges = points.map(([x1, y1], i) => {
|
|
88
|
+
const [x2, y2] = points[(i + 1) % n];
|
|
89
|
+
const len = Math.hypot(x2 - x1, y2 - y1);
|
|
90
|
+
const [dx, dy] = [(x2 - x1) / len, (y2 - y1) / len];
|
|
91
|
+
return { x: x1 - sign * dy * d, y: y1 + sign * dx * d, dx, dy };
|
|
92
|
+
});
|
|
93
|
+
return edges.map((b, i) => {
|
|
94
|
+
const a = edges[(i + n - 1) % n];
|
|
95
|
+
const t = ((b.x - a.x) * b.dy - (b.y - a.y) * b.dx) / (a.dx * b.dy - a.dy * b.dx);
|
|
96
|
+
return [a.x + t * a.dx, a.y + t * a.dy];
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Where the pipes of a distributor at (x, y) end: the pipes cross at (x, y)
|
|
101
|
+
* and end where the triangle is as wide as a pipe
|
|
102
|
+
*/
|
|
103
|
+
function distributorEnds(x, y, tip) {
|
|
104
|
+
const d = DISTRIBUTOR - 2 * PIPE;
|
|
105
|
+
return tip === "left"
|
|
106
|
+
? { common: x - d, branches: [y + d, y - d] }
|
|
107
|
+
: { common: tip === "up" ? y - d : y + d, branches: [x - d, x + d] };
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* A valve that connects one common pipe to one of two branches, drawn as a
|
|
111
|
+
* triangle with its tip at the common pipe and its other tips at the
|
|
112
|
+
* branches. Its pipes cross at (x, y). The common pipe is an inlet from above
|
|
113
|
+
* or from the left, or an outlet below that the branches join into. The
|
|
114
|
+
* water flows through the part of the triangle between the outer borders of
|
|
115
|
+
* the common pipe and the open branch's pipe, so it lines up with both. The
|
|
116
|
+
* rest is an outline.
|
|
117
|
+
*/
|
|
118
|
+
function Distributor({ x, y, tip = "up", kind, io, name, label, words, branches, labelAnchor = "middle", labelDx = 0, labelDy = 4, strong = false, }) {
|
|
119
|
+
const p = PIPE;
|
|
120
|
+
const w = DISTRIBUTOR;
|
|
121
|
+
// Drawn with the tip above, then turned for a tip on the left or flipped
|
|
122
|
+
// for a tip below
|
|
123
|
+
const up = tip !== "left";
|
|
124
|
+
const at = ([dx, dy]) => tip === "up"
|
|
125
|
+
? `${x + dx},${y + dy}`
|
|
126
|
+
: tip === "down"
|
|
127
|
+
? `${x + dx},${y - dy}`
|
|
128
|
+
: `${x + dy},${y - dx}`;
|
|
129
|
+
const shape = (points) => points.map(at).join(" ");
|
|
130
|
+
// Outlined parts, with the outline inside so it lines up with the pipes
|
|
131
|
+
const outline = (points, width = OUTLINE) => shape(inset(points, width / 2));
|
|
132
|
+
// With the tip on the left, the left branch turns to the bottom
|
|
133
|
+
const [left, right] = up ? branches : [branches[1], branches[0]];
|
|
134
|
+
const state = (branch) => branch.open === undefined
|
|
135
|
+
? "unknown"
|
|
136
|
+
: !branch.open
|
|
137
|
+
? "closed"
|
|
138
|
+
: branch.active
|
|
139
|
+
? "flowing"
|
|
140
|
+
: "open";
|
|
141
|
+
const open = left.open ? -1 : right.open ? 1 : 0;
|
|
142
|
+
const title = ioTitle(label, name, io, words);
|
|
143
|
+
return (_jsxs("g", { className: `hl-distributor hl-kind-${kind}`, tabIndex: 0, role: "img", "aria-label": title, children: [_jsx("title", { suppressHydrationWarning: true, children: title }), _jsx("rect", { x: up ? x - w - 4 : x + p - w - 4, y: tip === "up" ? y + p - w - 4 : tip === "down" ? y - p - 4 : y - w - 4, width: up ? 2 * w + 8 : w + 8, height: up ? w + 8 : 2 * w + 8, className: "hl-hit" }), _jsx("g", { className: "hl-valve-body", children: open === 0 || left.open === undefined ? (_jsx("polygon", { points: outline([
|
|
144
|
+
[0, p - w],
|
|
145
|
+
[-w, p],
|
|
146
|
+
[w, p],
|
|
147
|
+
], state(left) === "closed" ? CLOSED_OUTLINE : OUTLINE), className: `is-${state(left)}` })) : (_jsxs(_Fragment, { children: [_jsx("polygon", { points: shape([
|
|
148
|
+
[open * w, p],
|
|
149
|
+
[0, p - w],
|
|
150
|
+
[-open * p, 2 * p - w],
|
|
151
|
+
[-open * p, p],
|
|
152
|
+
]), className: `is-${state(open < 0 ? left : right)}` }), _jsx("polygon", { points: outline([
|
|
153
|
+
[-open * p, 2 * p - w],
|
|
154
|
+
[-open * w, p],
|
|
155
|
+
[-open * p, p],
|
|
156
|
+
], CLOSED_OUTLINE), className: "is-closed" })] })) }), _jsx("text", { x: x + labelDx, y: y + labelDy, textAnchor: labelAnchor, className: strong ? "hl-diagram-label is-bold" : "hl-diagram-label", children: label })] }));
|
|
157
|
+
}
|
|
158
|
+
/** Curved impeller blades around (0, 0), from the hub out to radius r */
|
|
159
|
+
function impellerPath(r) {
|
|
160
|
+
const hub = r * 0.3;
|
|
161
|
+
const point = (a, d) => `${(d * Math.cos(a)).toFixed(2)} ${(d * Math.sin(a)).toFixed(2)}`;
|
|
162
|
+
return Array.from({ length: 6 }, (_, i) => {
|
|
163
|
+
const a = (i * Math.PI) / 3;
|
|
164
|
+
return `M${point(a, hub)} Q${point(a + 0.2, r * 0.7)} ${point(a + 0.75, r)}`;
|
|
165
|
+
}).join(" ");
|
|
166
|
+
}
|
|
167
|
+
/** A pump: an impeller in its casing, spinning while the pump runs */
|
|
168
|
+
function Pump({ x, y, r = 15, kind, io, name, label, labelAnchor = "start", labelDx = 22, labelDy = 4, }) {
|
|
169
|
+
const state = io === undefined ? "unknown" : io.on ? "on" : "off";
|
|
170
|
+
const blades = r * 0.72;
|
|
171
|
+
const title = ioTitle(label, name, io, ["running", "off"]);
|
|
172
|
+
return (_jsxs("g", { className: `hl-pump hl-kind-${kind} is-${state}`, tabIndex: 0, role: "img", "aria-label": title, children: [_jsx("title", { suppressHydrationWarning: true, children: title }), _jsx("circle", { cx: x, cy: y, r: r, className: "hl-pump-casing" }), _jsx("g", { transform: `translate(${x} ${y})`, children: _jsxs("g", { className: "hl-impeller", children: [_jsx("circle", { r: blades + 1, className: "hl-impeller-box" }), _jsx("path", { d: impellerPath(blades), className: "hl-impeller-blades" }), _jsx("circle", { r: r * 0.22, className: "hl-impeller-hub" })] }) }), _jsx("text", { x: x + (labelAnchor === "end" ? -labelDx : labelDx), y: y + labelDy, textAnchor: labelAnchor, className: "hl-diagram-label", children: label })] }));
|
|
173
|
+
}
|
|
174
|
+
/** A demand or float sensor */
|
|
175
|
+
function Sensor({ x, y, kind, io, name, label, labelAnchor = "start", labelDx = 12, }) {
|
|
176
|
+
const state = io === undefined ? "unknown" : io.on ? "on" : "off";
|
|
177
|
+
const title = ioTitle(label, name, io, ["on", "off"]);
|
|
178
|
+
return (_jsxs("g", { className: `hl-sensor hl-kind-${kind} is-${state}`, tabIndex: 0, role: "img", "aria-label": title, children: [_jsx("title", { suppressHydrationWarning: true, children: title }), _jsx("circle", { cx: x, cy: y, r: 6 }), _jsx("text", { x: x + labelDx, y: y + 4, textAnchor: labelAnchor, className: "hl-diagram-label", children: label })] }));
|
|
179
|
+
}
|
|
180
|
+
function Bubbles({ x, y, w, h, active, }) {
|
|
181
|
+
if (!active)
|
|
182
|
+
return null;
|
|
183
|
+
const columns = 5;
|
|
184
|
+
return (_jsx("g", { className: "hl-bubbles", "aria-hidden": true, children: Array.from({ length: columns * 2 }, (_, i) => {
|
|
185
|
+
const cx = x + ((i % columns) + 0.5) * (w / columns);
|
|
186
|
+
const delay = (i * 0.37) % 1.6;
|
|
187
|
+
return (_jsx("circle", { cx: cx, cy: y + h - 8, r: i % 3 === 0 ? 2.5 : 1.8, style: {
|
|
188
|
+
animationDelay: `${delay}s`,
|
|
189
|
+
["--rise"]: `${-(h - 24)}px`,
|
|
190
|
+
} }, i));
|
|
191
|
+
}) }));
|
|
192
|
+
}
|
|
193
|
+
/** Drops of water falling inside a tank from `y` onto its surface */
|
|
194
|
+
function Drips({ x, y, bottom, active, kind = "grey", }) {
|
|
195
|
+
if (!active || bottom === undefined || bottom - y < 4)
|
|
196
|
+
return null;
|
|
197
|
+
return (_jsx("g", { className: `hl-drips hl-kind-${kind}`, "aria-hidden": true, children: [0, 0.3, 0.6].map((delay) => (_jsx("circle", { cx: x, cy: y, r: 1.6, style: {
|
|
198
|
+
animationDelay: `${delay}s`,
|
|
199
|
+
["--fall"]: `${bottom - y}px`,
|
|
200
|
+
} }, delay))) }));
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* The animation delay of a pattern that continues a pipe's flow pattern
|
|
204
|
+
* `length` px down the pipe: a step of 14 px takes 0.9 s, see .pipe-flow
|
|
205
|
+
*/
|
|
206
|
+
function flowDelay(length) {
|
|
207
|
+
return (-((14 - (length % 14)) % 14) / 14) * 0.9;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Rings in the water around where a pipe enters the tank, each growing from
|
|
211
|
+
* the pipe a step of 14 px behind the next, or shrinking towards it with
|
|
212
|
+
* `out`. They fade out towards the tank's center
|
|
213
|
+
*/
|
|
214
|
+
function WaterRings({ id, x, y, center, radius, delay, out = false, }) {
|
|
215
|
+
const rings = Math.ceil(radius / 14) + 1;
|
|
216
|
+
return (_jsxs("g", { className: `hl-water-rings${out ? " is-out" : ""}`, children: [_jsxs("linearGradient", { id: `${id}-fade`, gradientUnits: "userSpaceOnUse", x1: x, y1: 0, x2: center, y2: 0, children: [_jsx("stop", { offset: 0, stopColor: "#fff" }), _jsx("stop", { offset: 1, stopColor: "#000" })] }), _jsx("mask", { id: `${id}-mask`, children: _jsx("rect", { x: Math.min(x, center), y: y - radius, width: Math.abs(center - x), height: 2 * radius, fill: `url(#${id}-fade)` }) }), _jsx("g", { mask: `url(#${id}-mask)`, children: Array.from({ length: rings }, (_, i) => (_jsx("circle", { cx: x, cy: y, r: rings * 14, className: "hl-pressure-ring", style: {
|
|
217
|
+
transform: `scale(${i / rings})`,
|
|
218
|
+
animationDuration: `${rings * 0.9}s`,
|
|
219
|
+
animationDelay: `${delay - i * 0.9}s`,
|
|
220
|
+
} }, i))) })] }));
|
|
221
|
+
}
|
|
222
|
+
/** How full the tank's shell is, 0 to 1, or undefined without a reading */
|
|
223
|
+
function fillOf(level) {
|
|
224
|
+
if (level?.liters === undefined || level.max <= 0)
|
|
225
|
+
return undefined;
|
|
226
|
+
// The shell stands for the tank's capacity, which can be more than the
|
|
227
|
+
// sensor's range
|
|
228
|
+
const size = level.capacity ?? level.max;
|
|
229
|
+
return Math.max(0, Math.min(1, level.liters / size));
|
|
230
|
+
}
|
|
231
|
+
function Tank({ x, y, w, h, level, kind, label, sub, side, aeration, circulation, pressurized, pressureHeld = false, venting, small, square = false, base = 0, }) {
|
|
232
|
+
const known = fillOf(level) !== undefined;
|
|
233
|
+
const size = level?.capacity ?? level?.max ?? 0;
|
|
234
|
+
const fill = fillOf(level) ?? 0;
|
|
235
|
+
const percent = `${Math.round(fill * 100)}%`;
|
|
236
|
+
const trend = level?.trend;
|
|
237
|
+
const arrow = trend === undefined || Math.abs(trend) < 0.3 ? "" : trend > 0 ? "↑" : "↓";
|
|
238
|
+
const fillHeight = base + (h - base) * fill;
|
|
239
|
+
const name = [label, side ?? sub].filter(Boolean).join(" ");
|
|
240
|
+
const title = !known
|
|
241
|
+
? `${name}: no level data`
|
|
242
|
+
: small
|
|
243
|
+
? `${name}: ${percent} full. ${capacityNote(level)}`.trimEnd()
|
|
244
|
+
: `${name}: ${Math.round(level.liters)} L (${percent})${trend !== undefined
|
|
245
|
+
? `, ${trend >= 0 ? "+" : ""}${trend.toFixed(1)} L/min`
|
|
246
|
+
: ""}. ${capacityNote(level)}`.trimEnd();
|
|
247
|
+
const clipId = `hl-pressure-${label}-${side ?? sub ?? ""}`;
|
|
248
|
+
const ringX = venting ?? x + w / 2;
|
|
249
|
+
// Enough rings to reach the far corners of the space above the water
|
|
250
|
+
const rings = Math.ceil(Math.hypot(Math.max(ringX - x, x + w - ringX), h - fillHeight) / 14) + 1;
|
|
251
|
+
// Venting rings vanish where the pipe's dashes start, at its beginning
|
|
252
|
+
const phase = venting === undefined && pressurized ? flowDelay(pressurized) : 0;
|
|
253
|
+
const textX = small === "end" ? x + w + 10 : small ? x - 10 : x + 12;
|
|
254
|
+
const anchor = small === "start" ? "end" : "start";
|
|
255
|
+
return (_jsxs("g", { className: `hl-tank hl-kind-${kind}`, tabIndex: 0, role: "img", "aria-label": title, children: [_jsx("title", { children: title }), _jsx("rect", { x: x, y: y, width: w, height: h, rx: square ? 0 : 5, className: known ? "hl-tank-shell" : "hl-tank-shell is-unknown" }), known && (_jsxs(_Fragment, { children: [_jsx("rect", { x: x + 1, y: y + h - fillHeight, width: w - 2, height: Math.max(0, fillHeight - 1), rx: !square && fillHeight > 8 ? 4 : 0, className: "hl-tank-fill" }), _jsx("line", { x1: x + 1, x2: x + w - 1, y1: y + h - fillHeight, y2: y + h - fillHeight, className: "hl-tank-surface" })] })), known && circulation && fillHeight > 4 && (
|
|
256
|
+
// The water spreads into the tank as rings, as the air does when
|
|
257
|
+
// pressurized, and gathers towards the pipe it leaves through. Rings
|
|
258
|
+
// start where the entering pipe's dashes leave off, and vanish where
|
|
259
|
+
// the leaving pipe's dashes start
|
|
260
|
+
_jsxs("g", { className: "hl-circulation", "aria-hidden": true, children: [_jsx("clipPath", { id: `${clipId}-water`, children: _jsx("rect", { x: x + 1, y: y + h - fillHeight, width: w - 2, height: fillHeight - 1, rx: !square && fillHeight > 8 ? 4 : 0 }) }), _jsx("g", { clipPath: `url(#${clipId}-water)`, children: [circulation.from, circulation.to].map((end, i) => (_jsx(WaterRings, { id: `${clipId}-${i ? "out" : "in"}`, x: end, y: circulation.y, center: x + w / 2, radius: Math.hypot(w / 2, circulation.y - (y + h - fillHeight)), delay: i ? 0 : flowDelay(circulation.length), out: i === 1 }, i))) })] })), [0.25, 0.5, 0.75].map((f) => (_jsx("line", { x1: x + w - (small ? 5 : 8), x2: x + w, y1: y + h - base - (h - base) * f, y2: y + h - base - (h - base) * f, className: "hl-tank-tick" }, f))), _jsx(Bubbles, { x: x, y: y, w: w, h: h, active: aeration }), known &&
|
|
261
|
+
(pressurized || venting !== undefined) &&
|
|
262
|
+
h - fillHeight > 4 && (
|
|
263
|
+
// The air pipe's flow continues into the space above the water, as
|
|
264
|
+
// half circles spreading from where the pipe enters onto the surface.
|
|
265
|
+
// They start where the pipe's dashes left off, `pressurized` pixels
|
|
266
|
+
// down the pipe: a step of 14 px takes 0.9 s, see .pipe-flow. While
|
|
267
|
+
// venting, they move in towards the release air pipe instead
|
|
268
|
+
_jsxs("g", { className: `hl-pressure${venting !== undefined ? " is-venting" : pressureHeld ? " is-held" : ""}`, "aria-hidden": true, children: [_jsx("clipPath", { id: clipId, children: _jsx("rect", { x: x + 1, y: y + 1, width: w - 2, height: h - fillHeight - 1, rx: square ? 0 : 4 }) }), _jsxs("linearGradient", { id: `${clipId}-fade`, gradientUnits: "userSpaceOnUse", x1: 0, y1: y, x2: 0, y2: y + h, children: [_jsx("stop", { offset: 0, stopColor: "#fff" }), _jsx("stop", { offset: 1, stopColor: "#000" })] }), _jsx("mask", { id: `${clipId}-mask`, children: _jsx("rect", { x: x, y: y, width: w, height: h, fill: `url(#${clipId}-fade)` }) }), _jsxs("g", { clipPath: `url(#${clipId})`, children: [_jsx("rect", { x: x, y: y, width: w, height: h - fillHeight, className: "hl-pressure-fill" }), _jsx("g", { mask: `url(#${clipId}-mask)`, children: Array.from({ length: rings }, (_, i) => (
|
|
269
|
+
// Each ring grows from the pipe to the outermost one's
|
|
270
|
+
// radius, a step of 14 px behind the next
|
|
271
|
+
_jsx("circle", { cx: ringX, cy: y, r: rings * 14, className: "hl-pressure-ring", style: {
|
|
272
|
+
transform: `scale(${i / rings})`,
|
|
273
|
+
animationDuration: `${rings * 0.9}s`,
|
|
274
|
+
animationDelay: `${phase - i * 0.9}s`,
|
|
275
|
+
} }, i))) })] })] })), _jsxs("text", { x: textX, y: small ? y + h / 2 - 6 : y + 22, textAnchor: anchor, className: "hl-tank-label", children: [label, sub && (_jsx("tspan", { className: "hl-tank-sub", dx: 6, children: sub }))] }), known && small && (_jsx("text", { x: textX, y: y + h / 2 + 20, textAnchor: anchor, className: "hl-tank-value", children: percent })), known && !small && (_jsxs(_Fragment, { children: [_jsxs("text", { x: x + 12, y: y + h - (h > 100 ? 30 : 26), className: "hl-tank-value", children: [Math.round(level.liters), " L", " ", arrow && _jsx("tspan", { className: "hl-tank-trend", children: arrow })] }), _jsxs("text", { x: x + 12, y: y + h - 12, className: "hl-tank-meta", children: [percent, " of ", level.capacity ? "~" : "", Math.round(size), " L"] })] }))] }));
|
|
276
|
+
}
|
|
277
|
+
/** T4 has float sensors instead of a level reading */
|
|
278
|
+
function BackupTank({ x, y, w, h, state, }) {
|
|
279
|
+
const { t4, io } = state;
|
|
280
|
+
const maxY = y + h * 0.55;
|
|
281
|
+
const minY = y + h * 0.82;
|
|
282
|
+
// The water is at least as high as the highest wet float
|
|
283
|
+
const fillTop = t4.max ? maxY : t4.min ? minY : undefined;
|
|
284
|
+
return (_jsxs("g", { className: "hl-tank hl-kind-mains", children: [_jsx("rect", { x: x, y: y, width: w, height: h, className: t4.max === undefined && t4.min === undefined
|
|
285
|
+
? "hl-tank-shell is-unknown"
|
|
286
|
+
: "hl-tank-shell" }), fillTop !== undefined && (_jsxs(_Fragment, { children: [_jsx("rect", { x: x + 1, y: fillTop, width: w - 2, height: y + h - fillTop - 1, className: "hl-tank-fill" }), _jsx("line", { x1: x + 1, x2: x + w - 1, y1: fillTop, y2: fillTop, className: "hl-tank-surface is-dashed" })] })), _jsxs("text", { x: x + 12, y: y + 22, className: "hl-tank-label", children: ["T4", _jsx("tspan", { className: "hl-tank-sub", dx: 6, children: "Backup" })] }), _jsx(Sensor, { x: x + w - 14, y: maxY, kind: "mains", io: io[IO.t4Max], name: IO.t4Max, label: "Max", labelAnchor: "end", labelDx: -12 }), _jsx(Sensor, { x: x + w - 14, y: minY, kind: "mains", io: io[IO.t4Min], name: IO.t4Min, label: "Min", labelAnchor: "end", labelDx: -12 }), _jsx("text", { x: x + 12, y: y + 40, className: "hl-tank-meta", children: t4.label })] }));
|
|
287
|
+
}
|
|
288
|
+
export function FlowDiagram({ state, device, }) {
|
|
289
|
+
const { io, tanks, inlet, supply, t3 } = state;
|
|
290
|
+
const ab = io[IO.abSelector];
|
|
291
|
+
const selected = ab ? (ab.on ? "B" : "A") : undefined;
|
|
292
|
+
const bypass = io[IO.bypass];
|
|
293
|
+
// Switched on in the app
|
|
294
|
+
const bypassOverride = state.systemBehaviors.some((b) => b.name === "bypassByAppBypassValve");
|
|
295
|
+
const bypassEnds = distributorEnds(500, 24, "left");
|
|
296
|
+
const abEnds = distributorEnds(500, 100, "up");
|
|
297
|
+
// The backup valve lines up with the bottom of T3 and T4
|
|
298
|
+
const backupY = 640 - PIPE;
|
|
299
|
+
const backupEnds = distributorEnds(260, backupY, "down");
|
|
300
|
+
const train = (side) => {
|
|
301
|
+
const a = side === "A";
|
|
302
|
+
// Tank areas are to scale: T1 ~24 L, T2 ~200 L, T3 ~280 L (TANK_CAPACITY),
|
|
303
|
+
// except that T1 reaches further down, to fit the transfer pipe on its side
|
|
304
|
+
const t1x = a ? 140 : 839;
|
|
305
|
+
const t2x = a ? 214 : 614;
|
|
306
|
+
const t1c = t1x + 10;
|
|
307
|
+
const t1Bottom = 384;
|
|
308
|
+
const t2c = t2x + 86;
|
|
309
|
+
const transfer = io[sideIo("transfer_path", side)];
|
|
310
|
+
const waste = io[sideIo("waste_clean_tank", side)];
|
|
311
|
+
const air = io[sideIo("air_pump", side)];
|
|
312
|
+
const airTop = 151;
|
|
313
|
+
const addAir = io[sideIo("add_air_valve", side)];
|
|
314
|
+
const addAirY = airTop + 3 * 14;
|
|
315
|
+
// Air only reaches T2 while the add air valve isn't closed
|
|
316
|
+
const addingAir = air?.on && addAir?.on !== false;
|
|
317
|
+
// After air was added, T2 holds the pressure until the release air valve
|
|
318
|
+
// opens. Its pattern stays, standing still
|
|
319
|
+
const holdingAir = !addingAir && state.trains[side].pressurized;
|
|
320
|
+
// The release air pipe leaves T2's top on the inner side and ends level
|
|
321
|
+
// with the air pump's center, open to the room
|
|
322
|
+
const release = io[sideIo("release_air", side)];
|
|
323
|
+
const releaseX = a ? t2x + 172 - 14 : t2x + 14;
|
|
324
|
+
// The air pipe into T1 branches off above the add air valve, runs down
|
|
325
|
+
// between T1 and T2, and enters T1's bottom from below, next to the waste
|
|
326
|
+
// pipe. The waste pipe leaves T1's bottom on the outer side
|
|
327
|
+
const teeY = 166;
|
|
328
|
+
const airX = a ? t1x + 21 - 5 : t1x + 5;
|
|
329
|
+
const wasteX = a ? t1x + 5.5 : t1x + 21 - 5.5;
|
|
330
|
+
const wasteY = t1Bottom + 20;
|
|
331
|
+
// Below T1, the air pipe's lower edge lines up with the waste pipe's
|
|
332
|
+
// (5 px air pipe, 7 px waste pipe)
|
|
333
|
+
const airBelowY = wasteY + PIPE - 2.5;
|
|
334
|
+
// The air pipe into T1 and the transfer pipe run down between T1 and T2,
|
|
335
|
+
// evenly spread across the space between them, the air pipe closer to T1
|
|
336
|
+
const t1Edge = a ? t1x + 21 : t1x;
|
|
337
|
+
const t2Edge = a ? t2x : t2x + 172;
|
|
338
|
+
const gapX = t1Edge + (t2Edge - t1Edge) / 3;
|
|
339
|
+
const transferX = t1Edge + ((t2Edge - t1Edge) * 2) / 3;
|
|
340
|
+
// The upper exchange pipe runs down past T2's far side
|
|
341
|
+
const t2FarEdge = a ? t2x + 172 : t2x;
|
|
342
|
+
const exchangeX = t2FarEdge + (a ? 14 : -14);
|
|
343
|
+
const bubbles = io[sideIo("bubbles_block", side)];
|
|
344
|
+
// The bubbles block valve closes while its signal is on, blocking the air
|
|
345
|
+
// into T1. HDM shows it open while the signal is off
|
|
346
|
+
const bubblesValve = bubbles && { ...bubbles, on: !bubbles.on };
|
|
347
|
+
// The valve sits a multiple of 14 px from the tee, as the add air valve
|
|
348
|
+
// does. Air only reaches T1 while it isn't closed
|
|
349
|
+
const bubblesX = a ? t2c - 4 * 14 : t2c + 4 * 14;
|
|
350
|
+
const bubbling = air?.on && bubblesValve?.on !== false;
|
|
351
|
+
const receiving = inlet.receiving.includes(side);
|
|
352
|
+
const drainX = a ? 30 : 970;
|
|
353
|
+
const transferring = transfer?.on;
|
|
354
|
+
const skimming = state.trains[side].skimming;
|
|
355
|
+
const t2Level = tanks[a ? "t2a" : "t2b"];
|
|
356
|
+
const t2Fill = fillOf(t2Level);
|
|
357
|
+
const t1Fill = fillOf(tanks[a ? "t1a" : "t1b"]);
|
|
358
|
+
// T1's percentage starts at T2's bottom, so equal percentages line up.
|
|
359
|
+
// The water below it is always there
|
|
360
|
+
const t1Surface = t1Fill === undefined ? undefined : 360 - (360 - 232) * t1Fill;
|
|
361
|
+
// Two pipes connect T1 and T2, both entering T2 at the same height, at
|
|
362
|
+
// its lower corners (7 px pipe, 5 px corner radius). The upper one leaves
|
|
363
|
+
// T1 with its upper edge at T1's 40% water level, so the bubbles
|
|
364
|
+
// circulate water from that level up. It passes behind T2, runs down past
|
|
365
|
+
// its far side and enters it there
|
|
366
|
+
const exchangeYs = [360 - (360 - 232) * 0.4 + PIPE, 360 - 5 - PIPE];
|
|
367
|
+
/** An exchange pipe whose highest part is at `y` holds water */
|
|
368
|
+
const exchangeFilled = (y) => (t1Surface !== undefined && t1Surface <= y - PIPE + 1e-6) ||
|
|
369
|
+
(t2Fill !== undefined && 360 - 128 * t2Fill <= y - PIPE);
|
|
370
|
+
// While the bubbles circulate water, it moves through T2 from the upper
|
|
371
|
+
// pipe into the lower one
|
|
372
|
+
const circulating = bubbling === true && exchangeFilled(exchangeYs[0]);
|
|
373
|
+
// Otherwise, the upper pipe's way down holds water up to T2's surface, as
|
|
374
|
+
// its lower end is always below it
|
|
375
|
+
const exchangeSurface = t2Fill === undefined
|
|
376
|
+
? undefined
|
|
377
|
+
: Math.max(exchangeYs[0], 360 - 128 * t2Fill);
|
|
378
|
+
// The transfer pipe leaves T1 towards T2, halfway between the lower
|
|
379
|
+
// exchange pipe and T1's bottom. It crosses the air pipe, turns down
|
|
380
|
+
// between T1 and T2, passes below T2 and enters UV-C from the side
|
|
381
|
+
const transferY = (exchangeYs[1] + PIPE + t1Bottom) / 2;
|
|
382
|
+
return (_jsxs("g", { children: [_jsxs("text", { x: a ? 20 : 980, y: 146, textAnchor: a ? "start" : "end", className: "hl-train-label", children: ["Train ", side] }), _jsx(Pipe, { d: a
|
|
383
|
+
? `M${abEnds.branches[0]} 100 H${t1c} V232`
|
|
384
|
+
: `M${abEnds.branches[1]} 100 H${t1c} V232`, kind: "grey", active: receiving, open: selected === side, square: true }), _jsx(Pipe, { d: `M${t2c} ${teeY} H${bubblesX}`, kind: "air", active: air?.on }), _jsx(Pipe, { d: `M${bubblesX} ${teeY} H${gapX} V${airBelowY} H${airX} V${t1Bottom}`, kind: "air", active: bubbling, open: bubblesValve?.on }), _jsx(Valve, { x: bubblesX, y: teeY, kind: "air", io: bubblesValve, active: bubbling, name: sideIo("bubbles_block", side), label: "Bubbles block", labelAnchor: a ? "start" : "end", labelDx: gapX + (a ? 10 : -10) - bubblesX, labelDy: -14 }), _jsx(Pipe, { d: `M${t2c} ${airTop} V${addAirY}`, kind: "air", active: air?.on }), _jsx(Pipe, { d: `M${t2c} ${addAirY} V232`, kind: "air", active: addingAir || holdingAir, still: holdingAir, open: addAir?.on }), _jsx(Valve, { x: t2c, y: addAirY, vertical: true, kind: "air", io: addAir, active: addingAir, name: sideIo("add_air_valve", side), label: "Add air", labelAnchor: a ? "start" : "end", labelDx: a ? 16 : -16 }), _jsx(Pump, { x: t2c, y: 136, r: 13, kind: "air", io: air, name: sideIo("air_pump", side), label: "Air", labelAnchor: a ? "start" : "end", labelDx: 20 }), release?.on && (
|
|
385
|
+
// The air leaves the pipe's open end as circles that fade out at
|
|
386
|
+
// the size of the air pump. A circle starts where the pipe's dashes
|
|
387
|
+
// leave off, 96 px up the pipe, see the rings in Tank
|
|
388
|
+
_jsx("circle", { cx: releaseX, cy: 136, r: 14, className: "hl-vent-ring", style: {
|
|
389
|
+
animationDelay: `${(-((14 - (96 % 14)) % 14) / 14) * 0.9}s`,
|
|
390
|
+
}, "aria-hidden": true })), _jsx(Pipe, { d: `M${releaseX} 232 V136`, kind: "air", active: release?.on, open: release?.on }), _jsx(Valve, { x: releaseX, y: 162, vertical: true, kind: "air", io: release, active: release?.on, name: sideIo("release_air", side), label: "Release air", labelAnchor: a ? "start" : "end", labelDx: a ? 16 : -16 }), exchangeYs.map((y, i) => {
|
|
391
|
+
const filled = exchangeFilled(y);
|
|
392
|
+
return (_jsxs("g", { children: [_jsx("path", { d: `M${gapX - 4} ${y} H${gapX + 4}`, className: "hl-pipe-gap" }), _jsx(Pipe, { d: i === 0
|
|
393
|
+
? `M${t1Edge} ${y} H${exchangeX} V${exchangeYs[1]} H${t2FarEdge}`
|
|
394
|
+
: `M${t2Edge} ${y} H${t1Edge}`, kind: "grey", active: filled && bubbling === true, filled: filled }), i === 0 &&
|
|
395
|
+
!filled &&
|
|
396
|
+
exchangeSurface !== undefined &&
|
|
397
|
+
exchangeSurface < exchangeYs[1] && (_jsx(Pipe, { d: `M${exchangeX} ${exchangeYs[1]} V${exchangeSurface}`, kind: "grey", active: false, filled: true, square: true })), i === 0 && (
|
|
398
|
+
// Gaps where the upper pipe passes behind T2's walls
|
|
399
|
+
_jsx("path", { d: `M${t2Edge + (a ? -3 : 3)} ${y} H${t2Edge} M${t2FarEdge} ${y} H${t2FarEdge + (a ? 3 : -3)}`, className: "hl-pipe-gap" }))] }, y));
|
|
400
|
+
}), _jsx(Tank, { x: t1x, y: 232, w: 21, h: t1Bottom - 232, level: tanks[a ? "t1a" : "t1b"], kind: "grey", label: "T1", side: side, aeration: bubbling, small: a ? "start" : "end", square: true, base: t1Bottom - 360 }), _jsx(Drips, { x: t1c, y: 232, bottom: t1Surface, active: receiving }), _jsx(Tank, { x: t2x, y: 232, w: 172, h: 128, level: t2Level, kind: "grey", label: "T2", side: side, circulation: circulating
|
|
401
|
+
? {
|
|
402
|
+
from: t2FarEdge,
|
|
403
|
+
to: t2Edge,
|
|
404
|
+
y: exchangeYs[1],
|
|
405
|
+
length: Math.abs(exchangeX - t1Edge) +
|
|
406
|
+
exchangeYs[1] -
|
|
407
|
+
exchangeYs[0] +
|
|
408
|
+
Math.abs(exchangeX - t2FarEdge),
|
|
409
|
+
}
|
|
410
|
+
: undefined, pressurized: (addingAir || holdingAir) && 232 - addAirY, pressureHeld: holdingAir, venting: release?.on ? releaseX : undefined }), _jsx(Pipe, { d: a
|
|
411
|
+
? `M140 237 H${drainX} V${wasteY}`
|
|
412
|
+
: `M860 237 H${drainX} V${wasteY}`, kind: "waste", active: skimming, title: `Skim overflow of T1 ${side}${skimming ? ": filth spilling over to the drain (inferred from the FILTH_REMOVAL routine)" : ""}` }), _jsx("text", { x: a ? 57 : 943, y: 228, textAnchor: "middle", className: "hl-diagram-label", children: "Skim" }), _jsx(Pipe, { d: `M${wasteX} ${t1Bottom} V${wasteY} H${drainX}`, kind: "waste", active: waste?.on, open: waste?.on }), _jsx(Pipe, { d: `M${drainX} ${wasteY} V470`, kind: "waste", active: skimming || waste?.on, open: waste?.on, arrow: { x: drainX, y: 470, dir: "down" } }), _jsx(Valve, { x: (wasteX + drainX) / 2, y: wasteY, kind: "waste", io: waste, active: waste?.on, name: sideIo("waste_clean_tank", side), label: "Waste", labelAnchor: "middle", labelDx: 0, labelDy: 24 }), _jsx("text", { x: drainX, y: 498, textAnchor: "middle", className: "hl-diagram-label", children: "Drain" }), _jsx("path", { d: `M${gapX - 4} ${transferY} H${gapX + 4}`, className: "hl-pipe-gap" }), _jsx(Pipe, { d: `M${t1Edge} ${transferY} H${transferX} V${UV_Y} H${a ? 460 : 540}`, kind: "clean", active: transferring, open: transferring }), _jsx(Valve, { x: a ? 380 : 620, y: UV_Y, kind: "clean", io: transfer, active: transferring, name: sideIo("transfer_path", side), label: "Transfer", labelAnchor: "middle", labelDx: 0, labelDy: 24 })] }, side));
|
|
413
|
+
};
|
|
414
|
+
const backup = io[IO.backupWater];
|
|
415
|
+
const recycledToPump = supply.pumping && supply.source !== "backup";
|
|
416
|
+
const backupToPump = supply.pumping && supply.source === "backup";
|
|
417
|
+
const circulatingThroughUv = t3.circulating && supply.pumping;
|
|
418
|
+
const backFlushing = io[IO.backFlush]?.on && supply.pumping;
|
|
419
|
+
const backwash = {
|
|
420
|
+
A: io[sideIo("diffuser_backwash", "A")],
|
|
421
|
+
B: io[sideIo("diffuser_backwash", "B")],
|
|
422
|
+
};
|
|
423
|
+
const backwashing = {
|
|
424
|
+
A: backwash.A?.on && supply.pumping,
|
|
425
|
+
B: backwash.B?.on && supply.pumping,
|
|
426
|
+
};
|
|
427
|
+
// Water only leaves UV-C for T3 while something feeds the chamber and the
|
|
428
|
+
// UV valve isn't closed.
|
|
429
|
+
const t3ReceivingFromUv = (t3.receivingFrom.length > 0 || circulatingThroughUv) &&
|
|
430
|
+
io[IO.uvValve]?.on !== false;
|
|
431
|
+
const t3Fill = fillOf(tanks.t3);
|
|
432
|
+
const outletKind = supply.source === "backup" ? "mains" : "clean";
|
|
433
|
+
// UV-C passes on mains water only when circulation from T4 is its sole feed
|
|
434
|
+
const uvOutletKind = t3.receivingFrom.length === 0 && circulatingThroughUv
|
|
435
|
+
? outletKind
|
|
436
|
+
: "clean";
|
|
437
|
+
const off = (connected) => connected === false ? " is-disconnected" : "";
|
|
438
|
+
return (_jsxs("svg", { viewBox: "0 -38 1000 863", className: "hl-flow-diagram", role: "group", "aria-label": "Water flow through the H600", children: [_jsx("defs", { children: _jsx("pattern", { id: "hl-hatch", width: "6", height: "6", patternUnits: "userSpaceOnUse", patternTransform: "rotate(45)", children: _jsx("line", { x1: "0", y1: "0", x2: "0", y2: "6", className: "hl-hatch-line" }) }) }), _jsx("text", { x: 60, y: 10, className: "hl-diagram-label is-strong", children: "Greywater from showers and baths" }), _jsx(Pipe, { d: `M60 24 H${bypassEnds.common}`, kind: "grey", active: inlet.receiving.length > 0 || inlet.bypass, open: bypass?.on || (bypass?.on === false && selected !== undefined), square: true }), _jsx(Pipe, { d: `M500 ${bypassEnds.branches[0]} V${abEnds.common}`, kind: "grey", active: inlet.receiving.length > 0, open: bypass?.on === false && selected !== undefined, square: true }), _jsx(Pipe, { d: `M500 ${bypassEnds.branches[1]} V-22 H935`, kind: "grey", active: inlet.bypass, open: bypass?.on, square: true, arrow: { x: 935, y: -22, dir: "right" } }), _jsx(Distributor, { x: 500, y: 24, tip: "left", kind: "grey", io: bypass, name: IO.bypass, label: bypassOverride ? "Bypass (user override)" : "Bypass", strong: bypassOverride, words: ["to the sewer", "to the trains"], branches: [
|
|
439
|
+
{ open: bypass?.on, active: inlet.bypass === true },
|
|
440
|
+
{
|
|
441
|
+
open: bypass && !bypass.on,
|
|
442
|
+
active: inlet.receiving.length > 0,
|
|
443
|
+
},
|
|
444
|
+
], labelAnchor: "start", labelDx: 14 }), _jsx("text", { x: 948, y: -18, className: "hl-diagram-label", children: "Sewer" }), train("A"), train("B"), _jsx(Distributor, { x: 500, y: 100, kind: "grey", io: ab, name: IO.abSelector, label: "A/B valve", words: ["to train B", "to train A"], branches: [
|
|
445
|
+
{
|
|
446
|
+
open: selected && selected === "A",
|
|
447
|
+
active: inlet.receiving.includes("A"),
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
open: selected && selected === "B",
|
|
451
|
+
active: inlet.receiving.includes("B"),
|
|
452
|
+
},
|
|
453
|
+
], labelDy: 24 }), _jsx(Pipe, { d: `M500 ${UV_Y + 17} V540`, kind: uvOutletKind, active: t3ReceivingFromUv, open: io[IO.uvValve]?.on }), _jsxs("g", { className: `hl-uv is-${t3.uv === undefined ? "unknown" : t3.uv ? "on" : "off"}`, tabIndex: 0, role: "img", "aria-label": ioTitle("UV-C", IO.uvPower, io[IO.uvPower], ["on", "off"]), children: [_jsx("title", { suppressHydrationWarning: true, children: ioTitle("UV-C", IO.uvPower, io[IO.uvPower], ["on", "off"]) }), _jsx("rect", { x: 460, y: UV_Y - 17, width: 80, height: 34, rx: 6 }), _jsx("text", { x: 500, y: UV_Y + 5, textAnchor: "middle", children: "UV-C" })] }), _jsx(Valve, { x: 500, y: (UV_Y + 17 + 540) / 2, vertical: true, kind: uvOutletKind, io: io[IO.uvValve], active: t3ReceivingFromUv, name: IO.uvValve, label: "UV valve" }), _jsx(Tank, { x: 346, y: 540, w: 309, h: 100, level: tanks.t3, kind: "clean", label: "T3", sub: "Recycled water", square: true }), _jsx(Drips, { x: 500, y: 540, bottom: t3Fill === undefined ? undefined : 640 - 100 * t3Fill, active: !!t3ReceivingFromUv, kind: uvOutletKind }), _jsx(Pipe, { d: `M655 ${backupY} H970 V735`, kind: "waste", active: t3.draining, open: io[IO.wasteStorageTank]?.on, square: true, arrow: { x: 970, y: 735, dir: "down" } }), _jsx(Valve, { x: 790, y: backupY, kind: "waste", io: io[IO.wasteStorageTank], active: t3.draining, name: IO.wasteStorageTank, label: "T3 drain", labelAnchor: "middle", labelDx: 0, labelDy: -16 }), _jsx("text", { x: 970, y: 763, textAnchor: "middle", className: "hl-diagram-label", children: "Drain" }), _jsx(BackupTank, { x: 60, y: 540, w: 130, h: 100, state: state }), _jsx("path", { d: `M700 ${backupY - 4} V${backupY + 4}`, className: "hl-pipe-gap" }), _jsx("path", { d: `M700 ${UV_Y - 4} V${UV_Y + 4}`, className: "hl-pipe-gap" }), _jsx(Pipe, { d: `M560 740 H700 V${RUN_Y}`, kind: outletKind, active: circulatingThroughUv || backwashing.A || backwashing.B, open: t3.circulating || backwash.A?.on || backwash.B?.on }), _jsx(Pipe, { d: `M700 ${RUN_Y} H500`, kind: outletKind, active: circulatingThroughUv || backwashing.A, open: t3.circulating || backwash.A?.on }), _jsx(Pipe, { d: `M500 ${RUN_Y} V${UV_Y - 17}`, kind: outletKind, active: circulatingThroughUv, open: t3.circulating }), ["A", "B"].map((side) => {
|
|
454
|
+
const a = side === "A";
|
|
455
|
+
return (_jsxs("g", { children: [_jsx(Pipe, { d: a ? `M500 ${RUN_Y} H300 V360` : `M700 ${RUN_Y} V360`, kind: outletKind, active: backwashing[side], open: backwash[side]?.on }), _jsx(Valve, { x: a ? 300 : 700, y: (RUN_Y + 360) / 2, vertical: true, kind: outletKind, io: backwash[side], active: backwashing[side], name: sideIo("diffuser_backwash", side), label: "Backwash", labelAnchor: a ? "end" : "start", labelDx: a ? -16 : 16 })] }, side));
|
|
456
|
+
}), _jsx(Valve, { x: 500, y: (RUN_Y + UV_Y - 17) / 2, vertical: true, kind: outletKind, io: io[IO.circulation], active: circulatingThroughUv, name: IO.circulation, label: "Circulation", labelAnchor: "end", labelDx: -14 }), _jsx(Pipe, { d: `M190 ${backupY} H${backupEnds.branches[0]}`, kind: "mains", active: backupToPump, open: backup?.on, square: true }), _jsx(Pipe, { d: `M346 ${backupY} H${backupEnds.branches[1]}`, kind: "clean", active: recycledToPump, open: backup?.on === false, square: true }), _jsx(Pipe, { d: `M260 ${backupEnds.common} V724`, kind: outletKind, active: supply.pumping, open: backup !== undefined, square: true }), _jsx(Distributor, { x: 260, y: backupY, tip: "down", kind: outletKind, io: backup, name: IO.backupWater, label: "Backup valve", words: ["from T4", "from T3"], branches: [
|
|
457
|
+
{ open: backup?.on, active: backupToPump === true },
|
|
458
|
+
{ open: backup && !backup.on, active: recycledToPump === true },
|
|
459
|
+
], labelDy: -14 }), _jsx(Pump, { x: 260, y: 740, r: 16, kind: outletKind, io: io[IO.distributionPump], name: IO.distributionPump, label: "Distribution pump", labelAnchor: "end" }), _jsx(Pipe, { d: "M500 740 V640", kind: outletKind, active: backFlushing, open: io[IO.backFlush]?.on }), _jsx(Valve, { x: 500, y: 690, vertical: true, kind: outletKind, io: io[IO.backFlush], active: backFlushing, name: IO.backFlush, label: "Back flush" }), _jsx(Pipe, { d: "M276 740 H560", kind: outletKind, active: supply.toOutlets ?? false, open: true }), _jsxs("g", { className: `hl-outlet${off(device.outlets.toilet)}`, children: [_jsx(Pipe, { d: "M360 740 V790", kind: outletKind, active: supply.toilet ?? false, open: true, arrow: { x: 360, y: 790, dir: "down" } }), _jsx(Sensor, { x: 360, y: 765, kind: outletKind, io: io[IO.toilet], name: IO.toilet, label: "" }), _jsx("text", { x: 360, y: 815, textAnchor: "middle", className: "hl-diagram-label", children: "Toilets" })] }), _jsxs("g", { className: `hl-outlet${off(device.outlets.washingMachine)}`, children: [_jsx(Pipe, { d: "M460 740 V790", kind: outletKind, active: supply.wash ?? false, open: true, arrow: { x: 460, y: 790, dir: "down" } }), _jsx(Sensor, { x: 460, y: 765, kind: outletKind, io: io[IO.wash], name: IO.wash, label: "" }), _jsx("text", { x: 460, y: 815, textAnchor: "middle", className: "hl-diagram-label", children: "Washer" })] }), _jsxs("g", { className: `hl-outlet${off(device.outlets.auxiliary)}`, children: [_jsx(Pipe, { d: "M560 740 V790", kind: outletKind, active: supply.auxiliary, open: io[IO.auxiliary]?.on, arrow: { x: 560, y: 790, dir: "down" } }), _jsx(Valve, { x: 560, y: 765, vertical: true, kind: outletKind, io: io[IO.auxiliary], active: supply.auxiliary, name: IO.auxiliary, label: "" }), _jsx("text", { x: 560, y: 815, textAnchor: "middle", className: "hl-diagram-label", children: "Auxiliary" })] })] }));
|
|
460
|
+
}
|
|
461
|
+
export function DiagramLegend() {
|
|
462
|
+
const items = [
|
|
463
|
+
["grey", "Greywater"],
|
|
464
|
+
["clean", "Treated water"],
|
|
465
|
+
["mains", "Mains backup"],
|
|
466
|
+
["waste", "Filth removal"],
|
|
467
|
+
];
|
|
468
|
+
return (_jsxs("ul", { className: "hl-legend", "aria-label": "Legend", children: [items.map(([kind, text]) => (_jsxs("li", { children: [_jsx("span", { className: `hl-legend-swatch hl-kind-${kind}` }), text] }, kind))), _jsxs("li", { children: [_jsx("span", { className: "hl-legend-swatch is-open" }), "Open, no flow"] }), _jsxs("li", { children: [_jsx("span", { className: "hl-legend-swatch is-idle" }), "No flow"] })] }));
|
|
469
|
+
}
|
|
470
|
+
/** The flows the diagram animates, as text */
|
|
471
|
+
export function activeFlows(state) {
|
|
472
|
+
const { inlet, trains, io, t3, supply } = state;
|
|
473
|
+
const flows = [];
|
|
474
|
+
for (const side of inlet.receiving)
|
|
475
|
+
flows.push(`Greywater → train ${side}`);
|
|
476
|
+
if (inlet.bypass)
|
|
477
|
+
flows.push("Greywater → sewer (bypass)");
|
|
478
|
+
for (const side of ["A", "B"]) {
|
|
479
|
+
if (trains[side].t2ToT1)
|
|
480
|
+
flows.push(`T2 ${side} → T1 ${side}`);
|
|
481
|
+
if (trains[side].skimming) {
|
|
482
|
+
flows.push(`T1 ${side} → skim overflow → drain (inferred)`);
|
|
483
|
+
}
|
|
484
|
+
if (io[sideIo("waste_clean_tank", side)]?.on) {
|
|
485
|
+
flows.push(`T1 ${side} → drain`);
|
|
486
|
+
}
|
|
487
|
+
if (io[sideIo("transfer_path", side)]?.on) {
|
|
488
|
+
flows.push(`Train ${side} → UV → T3`);
|
|
489
|
+
}
|
|
490
|
+
if (io[sideIo("diffuser_backwash", side)]?.on && supply.pumping) {
|
|
491
|
+
flows.push(`Backwash → T2 ${side}`);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (t3.circulating && supply.pumping)
|
|
495
|
+
flows.push("T3 → UV → T3");
|
|
496
|
+
if (io[IO.backFlush]?.on && supply.pumping)
|
|
497
|
+
flows.push("Back flush → T3");
|
|
498
|
+
if (t3.draining)
|
|
499
|
+
flows.push("T3 → drain");
|
|
500
|
+
if (supply.toOutlets) {
|
|
501
|
+
const to = [
|
|
502
|
+
supply.toilet && "toilets",
|
|
503
|
+
supply.wash && "washer",
|
|
504
|
+
supply.auxiliary && "auxiliary",
|
|
505
|
+
].filter(Boolean);
|
|
506
|
+
flows.push(`${supply.source === "backup" ? "T4" : "T3"} → ${to.length ? to.join(", ") : "outlets"}`);
|
|
507
|
+
}
|
|
508
|
+
return flows;
|
|
509
|
+
}
|
|
510
|
+
export function FlowSummary({ state }) {
|
|
511
|
+
const flows = activeFlows(state);
|
|
512
|
+
return (_jsxs("p", { className: "hl-flow-summary", children: [_jsx("span", { className: "hl-flow-summary-label", children: "Water moving: " }), flows.length ? flows.join(" · ") : "None"] }));
|
|
513
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED