hydraloop-diagram-react 1.0.1 → 1.2.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.
@@ -20,7 +20,7 @@ function formatTime(t) {
20
20
  minute: "2-digit",
21
21
  });
22
22
  }
23
- function Pipe({ d, kind, active, open = false, filled = false, still = false, square = false, arrow, title, }) {
23
+ function Pipe({ d, kind, active, open = false, filled = false, still = false, square = false, arrow, title, phase, }) {
24
24
  const state = active === undefined
25
25
  ? "unknown"
26
26
  : filled
@@ -30,11 +30,15 @@ function Pipe({ d, kind, active, open = false, filled = false, still = false, sq
30
30
  : open
31
31
  ? "open"
32
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"
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", style: phase === undefined
34
+ ? undefined
35
+ : { animationDelay: `${flowDelay(phase)}s` } })), arrow && (_jsx("path", { className: "hl-pipe-arrow", d: arrow.dir === "down"
34
36
  ? `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` }))] }));
37
+ : arrow.dir === "up"
38
+ ? `M${arrow.x - 7} ${arrow.y} L${arrow.x + 7} ${arrow.y} L${arrow.x} ${arrow.y - 9} Z`
39
+ : arrow.dir === "right"
40
+ ? `M${arrow.x} ${arrow.y - 7} L${arrow.x} ${arrow.y + 7} L${arrow.x + 9} ${arrow.y} Z`
41
+ : `M${arrow.x} ${arrow.y - 7} L${arrow.x} ${arrow.y + 7} L${arrow.x - 9} ${arrow.y} Z` }))] }));
38
42
  }
39
43
  function ioTitle(label, name, io, words) {
40
44
  if (!io)
@@ -62,10 +66,57 @@ function Valve({ x, y, vertical = false, kind, io, active = false, name, label,
62
66
  * The pipe between the backwash valves, level with the waste pipes below T1
63
67
  */
64
68
  const RUN_Y = 404;
65
- /** The vertical center of UV-C */
66
- const UV_Y = 466;
67
69
  /** Half the width of a pipe */
68
70
  const PIPE = 3.5;
71
+ /** Half the height of UV-C */
72
+ const UV_H = 17;
73
+ /**
74
+ * The space above and below UV-C: from the bottom edge of the circulation
75
+ * pipe's top run to UV-C's top, and from UV-C's bottom to the top of T3
76
+ */
77
+ const UV_GAP = 57;
78
+ /** The vertical center of UV-C */
79
+ const UV_Y = RUN_Y + PIPE + UV_GAP + UV_H;
80
+ /** The top of T3 and T4 */
81
+ const TANK_Y = UV_Y + UV_H + UV_GAP;
82
+ /** The height of T3 and T4 */
83
+ const TANK_H = 100;
84
+ /** The bottom of T3 and T4 */
85
+ const TANK_BOTTOM = TANK_Y + TANK_H;
86
+ /** The distribution pump and the pipe to the outlets */
87
+ const PUMP_Y = TANK_BOTTOM + 100;
88
+ /**
89
+ * The x of each train's T2, which leaves 30 px between the release air labels.
90
+ * Each train's other parts are placed relative to it
91
+ */
92
+ const T2_X = { A: 288, B: 540 };
93
+ /** T4's left edge */
94
+ const T4_X = 60;
95
+ /**
96
+ * The outer edge of the "Sewer" labels: on the left lined up with T4's left
97
+ * edge, mirrored on the right
98
+ */
99
+ const SEWER_LABEL_X = { left: T4_X, right: 1000 - T4_X };
100
+ /** The width of a "Sewer" label */
101
+ const SEWER_LABEL_W = 38;
102
+ /** The space between the end of a pipe to the sewer and its label */
103
+ const SEWER_LABEL_DX = 13;
104
+ /** Where the pipes to the sewer end, in an arrow pointing at their label */
105
+ const SEWER_END = {
106
+ left: SEWER_LABEL_X.left + SEWER_LABEL_W + SEWER_LABEL_DX,
107
+ right: SEWER_LABEL_X.right - SEWER_LABEL_W - SEWER_LABEL_DX,
108
+ };
109
+ /** The mains pipe into T4, level with the transfer pipes into UV-C */
110
+ const MAINS_Y = UV_Y;
111
+ /** Where the mains pipe enters T4's top */
112
+ const T4_INLET_X = 167;
113
+ /**
114
+ * The air gap between the end of the mains pipe and T4's top, which keeps
115
+ * mains water from flowing back into the pipe. The water drips across it
116
+ */
117
+ const T4_AIR_GAP = 14;
118
+ /** The center of each T2, where its backwash pipe enters from below */
119
+ const T2_CENTER = { A: T2_X.A + 86, B: T2_X.B + 86 };
69
120
  /** Height of a distributor triangle, from its tip to its base */
70
121
  const DISTRIBUTOR = 24;
71
122
  /** Stroke width of a distributor's outline, as in .distributor polygon */
@@ -115,7 +166,7 @@ function distributorEnds(x, y, tip) {
115
166
  * the common pipe and the open branch's pipe, so it lines up with both. The
116
167
  * rest is an outline.
117
168
  */
118
- function Distributor({ x, y, tip = "up", kind, io, name, label, words, branches, labelAnchor = "middle", labelDx = 0, labelDy = 4, strong = false, }) {
169
+ function Distributor({ x, y, tip = "up", kind, io, name, label, words, branches, labelAnchor = "middle", labelDx = 0, labelDy = 4, strong = false, idle = false, phase = 0, }) {
119
170
  const p = PIPE;
120
171
  const w = DISTRIBUTOR;
121
172
  // Drawn with the tip above, then turned for a tip on the left or flipped
@@ -135,10 +186,24 @@ function Distributor({ x, y, tip = "up", kind, io, name, label, words, branches,
135
186
  ? "unknown"
136
187
  : !branch.open
137
188
  ? "closed"
138
- : branch.active
139
- ? "flowing"
140
- : "open";
189
+ : idle
190
+ ? "idle"
191
+ : branch.active
192
+ ? "flowing"
193
+ : "open";
141
194
  const open = left.open ? -1 : right.open ? 1 : 0;
195
+ // The flow's dashes continue through the open side, along the pipes'
196
+ // center lines: from the common pipe's end to where the pipes cross and on
197
+ // to the branch's end. Into an outlet below, they run the other way
198
+ const flowing = open !== 0 && state(open < 0 ? left : right) === "flowing";
199
+ const d = w - 2 * p;
200
+ const flowPoints = [
201
+ [0, -d],
202
+ [0, 0],
203
+ [open * d, 0],
204
+ ];
205
+ if (tip === "down")
206
+ flowPoints.reverse();
142
207
  const title = ioTitle(label, name, io, words);
143
208
  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
209
  [0, p - w],
@@ -153,7 +218,7 @@ function Distributor({ x, y, tip = "up", kind, io, name, label, words, branches,
153
218
  [-open * p, 2 * p - w],
154
219
  [-open * w, p],
155
220
  [-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 })] }));
221
+ ], CLOSED_OUTLINE), className: "is-closed" })] })) }), flowing && (_jsx("g", { className: "hl-pipe is-active is-square", children: _jsx("path", { d: `M${flowPoints.map(at).join(" L")}`, className: "hl-pipe-flow", style: { animationDelay: `${flowDelay(phase)}s` } }) })), _jsx("text", { x: x + labelDx, y: y + labelDy, textAnchor: labelAnchor, className: strong ? "hl-diagram-label is-bold" : "hl-diagram-label", children: label })] }));
157
222
  }
158
223
  /** Curved impeller blades around (0, 0), from the hub out to radius r */
159
224
  function impellerPath(r) {
@@ -186,7 +251,7 @@ function Bubbles({ x, y, w, h, active, }) {
186
251
  const delay = (i * 0.37) % 1.6;
187
252
  return (_jsx("circle", { cx: cx, cy: y + h - 8, r: i % 3 === 0 ? 2.5 : 1.8, style: {
188
253
  animationDelay: `${delay}s`,
189
- ["--rise"]: `${-(h - 24)}px`,
254
+ ["--hl-rise"]: `${-(h - 24)}px`,
190
255
  } }, i));
191
256
  }) }));
192
257
  }
@@ -196,7 +261,7 @@ function Drips({ x, y, bottom, active, kind = "grey", }) {
196
261
  return null;
197
262
  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
263
  animationDelay: `${delay}s`,
199
- ["--fall"]: `${bottom - y}px`,
264
+ ["--hl-fall"]: `${bottom - y}px`,
200
265
  } }, delay))) }));
201
266
  }
202
267
  /**
@@ -228,7 +293,7 @@ function fillOf(level) {
228
293
  const size = level.capacity ?? level.max;
229
294
  return Math.max(0, Math.min(1, level.liters / size));
230
295
  }
231
- function Tank({ x, y, w, h, level, kind, label, sub, side, aeration, circulation, pressurized, pressureHeld = false, venting, small, square = false, base = 0, }) {
296
+ function Tank({ x, y, w, h, level, kind, label, sub, side, aeration, circulation, pressurized, pressureHeld = false, airX, venting, small, square = false, base = 0, inlinePercent = false, }) {
232
297
  const known = fillOf(level) !== undefined;
233
298
  const size = level?.capacity ?? level?.max ?? 0;
234
299
  const fill = fillOf(level) ?? 0;
@@ -245,13 +310,13 @@ function Tank({ x, y, w, h, level, kind, label, sub, side, aeration, circulation
245
310
  ? `, ${trend >= 0 ? "+" : ""}${trend.toFixed(1)} L/min`
246
311
  : ""}. ${capacityNote(level)}`.trimEnd();
247
312
  const clipId = `hl-pressure-${label}-${side ?? sub ?? ""}`;
248
- const ringX = venting ?? x + w / 2;
313
+ const ringX = venting ?? airX ?? x + w / 2;
249
314
  // Enough rings to reach the far corners of the space above the water
250
315
  const rings = Math.ceil(Math.hypot(Math.max(ringX - x, x + w - ringX), h - fillHeight) / 14) + 1;
251
316
  // Venting rings vanish where the pipe's dashes start, at its beginning
252
317
  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";
318
+ const textX = small ? x + w / 2 : x + 12;
319
+ const anchor = small ? "middle" : "start";
255
320
  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
321
  // The water spreads into the tank as rings, as the air does when
257
322
  // pressurized, and gathers towards the pipe it leaves through. Rings
@@ -272,10 +337,13 @@ function Tank({ x, y, w, h, level, kind, label, sub, side, aeration, circulation
272
337
  transform: `scale(${i / rings})`,
273
338
  animationDuration: `${rings * 0.9}s`,
274
339
  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"] })] }))] }));
340
+ } }, i))) })] })] })), _jsxs("text", { x: textX, y: y + 22, textAnchor: anchor, className: "hl-tank-label", children: [label, sub && (_jsx("tspan", { className: "hl-tank-sub", dx: 6, children: sub }))] }), pressureHeld && (
341
+ // Air pumped in before holds its pressure, in the top right corner,
342
+ // level with the label
343
+ _jsx("text", { x: x + w - 12, y: y + 22, textAnchor: "end", className: "hl-tank-meta", children: "pressurized" })), known && !small && inlinePercent && (_jsxs("text", { x: x + 12, y: y + h - 14, className: "hl-tank-value", children: [Math.round(level.liters), " L", " ", arrow && _jsxs("tspan", { className: "hl-tank-trend", children: [arrow, " "] }), _jsx("tspan", { className: "hl-tank-meta", children: percent })] })), known && !small && !inlinePercent && (_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
344
  }
277
345
  /** T4 has float sensors instead of a level reading */
278
- function BackupTank({ x, y, w, h, state, }) {
346
+ function BackupTank({ x, y, w, h, state, inletX, inletY, filling = false, }) {
279
347
  const { t4, io } = state;
280
348
  const maxY = y + h * 0.55;
281
349
  const minY = y + h * 0.82;
@@ -283,35 +351,67 @@ function BackupTank({ x, y, w, h, state, }) {
283
351
  const fillTop = t4.max ? maxY : t4.min ? minY : undefined;
284
352
  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
353
  ? "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 })] }));
354
+ : "hl-tank-shell" }), _jsx("path", { d: `M${inletX - PIPE} ${y} H${inletX + PIPE}`, className: "hl-tank-gap" }), 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 }), _jsx(Drips, { x: inletX, y: inletY, bottom: fillTop ?? y + h, active: filling, kind: "mains" })] }));
287
355
  }
288
356
  export function FlowDiagram({ state, device, }) {
289
357
  const { io, tanks, inlet, supply, t3 } = state;
290
358
  const ab = io[IO.abSelector];
291
- const selected = ab ? (ab.on ? "B" : "A") : undefined;
292
359
  const bypass = io[IO.bypass];
360
+ // While the bypass is open, it's not known whether greywater comes in: its
361
+ // way to the sewer is drawn open, without flow, and the way to the trains
362
+ // neither open nor flowing. The A/B valve still shows its setting
363
+ const bypassOpen = bypass?.on === true;
364
+ const receivingSides = bypassOpen ? [] : inlet.receiving;
365
+ const abSide = ab ? (ab.on ? "B" : "A") : undefined;
366
+ const selected = bypassOpen ? undefined : abSide;
293
367
  // Switched on in the app
294
368
  const bypassOverride = state.systemBehaviors.some((b) => b.name === "bypassByAppBypassValve");
295
- const bypassEnds = distributorEnds(500, 24, "left");
296
- const abEnds = distributorEnds(500, 100, "up");
369
+ // The greywater inlet runs evenly spaced between the sewer pipe above it
370
+ // and the pipes to the trains below it, far enough apart to leave 5 px
371
+ // between the bypass and A/B valves
372
+ const abY = 100;
373
+ const inletY = abY - 49.5;
374
+ const sewerY = inletY - 49.5;
375
+ const bypassEnds = distributorEnds(500, inletY, "left");
376
+ const abEnds = distributorEnds(500, abY, "up");
297
377
  // The backup valve lines up with the bottom of T3 and T4
298
- const backupY = 640 - PIPE;
378
+ const backupY = TANK_BOTTOM - PIPE;
299
379
  const backupEnds = distributorEnds(260, backupY, "down");
380
+ // How far the water has come at each pipe and valve along the way, so the
381
+ // flow's dashes continue from one into the next, see flowDelay. The way
382
+ // through a distributor runs along the pipes' center lines
383
+ const throughDistributor = 2 * (DISTRIBUTOR - 2 * PIPE);
384
+ const bypassPhase = bypassEnds.common - 60;
385
+ const toAbPhase = bypassPhase + throughDistributor;
386
+ const abPhase = toAbPhase + abEnds.common - bypassEnds.branches[0];
387
+ const trainInletPhase = abPhase + throughDistributor;
388
+ const fromT4Length = backupEnds.branches[0] - 190;
389
+ const fromT3Length = 346 - backupEnds.branches[1];
300
390
  const train = (side) => {
301
391
  const a = side === "A";
302
392
  // Tank areas are to scale: T1 ~24 L, T2 ~200 L, T3 ~280 L (TANK_CAPACITY),
303
393
  // 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;
394
+ const t2x = T2_X[side];
395
+ const t1x = t2x + (a ? -74 : 225);
306
396
  const t1c = t1x + 10;
307
397
  const t1Bottom = 384;
308
- const t2c = t2x + 86;
398
+ // The add air and release air pipes enter T2's top evenly spread across
399
+ // it, the release air pipe on the inner side
400
+ const t2c = a ? t2x + 57 : t2x + 172 - 57;
309
401
  const transfer = io[sideIo("transfer_path", side)];
310
402
  const waste = io[sideIo("waste_clean_tank", side)];
311
403
  const air = io[sideIo("air_pump", side)];
312
- const airTop = 151;
404
+ const pumpY = 136;
405
+ const pumpR = 13;
313
406
  const addAir = io[sideIo("add_air_valve", side)];
314
- const addAirY = airTop + 3 * 14;
407
+ // The top run of the pipe into T1 and the add air valve are evenly spread
408
+ // between the air pump's bottom and T2's top
409
+ const airStep = (232 - (pumpY + pumpR)) / 3;
410
+ const teeY = pumpY + pumpR + airStep;
411
+ const addAirY = pumpY + pumpR + 2 * airStep;
412
+ // The pipe starts behind the pump, a multiple of 14 px above the valve,
413
+ // so the dashes of both parts line up, see .pipe-flow
414
+ const airTop = addAirY - 5 * 14;
315
415
  // Air only reaches T2 while the add air valve isn't closed
316
416
  const addingAir = air?.on && addAir?.on !== false;
317
417
  // After air was added, T2 holds the pressure until the release air valve
@@ -320,11 +420,14 @@ export function FlowDiagram({ state, device, }) {
320
420
  // The release air pipe leaves T2's top on the inner side and ends level
321
421
  // with the air pump's center, open to the room
322
422
  const release = io[sideIo("release_air", side)];
323
- const releaseX = a ? t2x + 172 - 14 : t2x + 14;
423
+ const releaseX = a ? t2x + 172 - 57 : t2x + 57;
424
+ // The pipe ends in an arrow (9 px tall) whose tip is level with the air
425
+ // pump's center, where the released air's arcs grow from
426
+ const releaseTip = pumpY;
427
+ const releaseTop = releaseTip + 9;
324
428
  // The air pipe into T1 branches off above the add air valve, runs down
325
429
  // between T1 and T2, and enters T1's bottom from below, next to the waste
326
430
  // pipe. The waste pipe leaves T1's bottom on the outer side
327
- const teeY = 166;
328
431
  const airX = a ? t1x + 21 - 5 : t1x + 5;
329
432
  const wasteX = a ? t1x + 5.5 : t1x + 21 - 5.5;
330
433
  const wasteY = t1Bottom + 20;
@@ -348,8 +451,12 @@ export function FlowDiagram({ state, device, }) {
348
451
  // does. Air only reaches T1 while it isn't closed
349
452
  const bubblesX = a ? t2c - 4 * 14 : t2c + 4 * 14;
350
453
  const bubbling = air?.on && bubblesValve?.on !== false;
351
- const receiving = inlet.receiving.includes(side);
352
- const drainX = a ? 30 : 970;
454
+ const receiving = receivingSides.includes(side);
455
+ // The drain leaves to the outside, its arrow pointing at its label
456
+ const drainEnd = a ? SEWER_END.left : SEWER_END.right;
457
+ // The skim overflow joins the drain 23 px before its end, which keeps it
458
+ // clear of T1's level in percent ("100%") next to T1
459
+ const drainX = drainEnd + (a ? 23 : -23);
353
460
  const transferring = transfer?.on;
354
461
  const skimming = state.trains[side].skimming;
355
462
  const t2Level = tanks[a ? "t2a" : "t2b"];
@@ -372,6 +479,18 @@ export function FlowDiagram({ state, device, }) {
372
479
  const circulating = bubbling === true && exchangeFilled(exchangeYs[0]);
373
480
  // Otherwise, the upper pipe's way down holds water up to T2's surface, as
374
481
  // its lower end is always below it
482
+ /** The exchange pipe at `exchangeYs[i]`, from where it leaves to where it enters */
483
+ const exchangePoints = (i) => i === 0
484
+ ? [
485
+ [t1Edge, exchangeYs[0]],
486
+ [exchangeX, exchangeYs[0]],
487
+ [exchangeX, exchangeYs[1]],
488
+ [t2FarEdge, exchangeYs[1]],
489
+ ]
490
+ : [
491
+ [t2Edge, exchangeYs[1]],
492
+ [t1Edge, exchangeYs[1]],
493
+ ];
375
494
  const exchangeSurface = t2Fill === undefined
376
495
  ? undefined
377
496
  : Math.max(exchangeYs[0], 360 - 128 * t2Fill);
@@ -379,25 +498,33 @@ export function FlowDiagram({ state, device, }) {
379
498
  // exchange pipe and T1's bottom. It crosses the air pipe, turns down
380
499
  // between T1 and T2, passes below T2 and enters UV-C from the side
381
500
  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) => {
501
+ const body = (_jsxs("g", { children: [_jsxs("text", { x: a ? SEWER_LABEL_X.left : SEWER_LABEL_X.right,
502
+ // The top of the capitals lines up with the top edge of the A/B
503
+ // inlet pipes (the label's cap height is 0.72 of its 15 px)
504
+ y: abY - PIPE + 15 * 0.72, textAnchor: a ? "start" : "end", className: "hl-train-label", children: ["Train ", side] }), _jsx(Pipe, { d: a
505
+ ? `M${abEnds.branches[0]} ${abY} H${t1c} V232`
506
+ : `M${abEnds.branches[1]} ${abY} H${t1c} V232`, kind: "grey", active: receiving, open: selected === side, square: true, phase: trainInletPhase }), _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: air?.on && bubblesValve?.on, square: true }), _jsx(Valve, { x: bubblesX, y: teeY, kind: "air", io: bubblesValve, active: bubbling, name: sideIo("bubbles_block", side), label: "Bubbles block",
507
+ // Above the pipe, ending short of the air pump
508
+ labelAnchor: a ? "end" : "start", labelDx: t2c + (a ? -21 : 21) - 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: air?.on && addAir?.on, square: true }), _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 ? "end" : "start", labelDx: a ? -16 : 16 }), _jsx(Pump, { x: t2c, y: pumpY, r: pumpR, kind: "air", io: air, name: sideIo("air_pump", side), label: "Air", labelAnchor: a ? "start" : "end", labelDx: 20 }), release?.on && (
509
+ // The air leaves past the arrow's tip as arcs that fade out at the
510
+ // size of the air pump. Each arc spans 270°, open towards the
511
+ // arrow, so its ends run out from the tip at 45° on either side. An
512
+ // arc starts where the pipe's dashes would leave off, continued
513
+ // through the arrow, see the rings in Tank
514
+ _jsx("path", { d: `M${releaseX - 14 * Math.SQRT1_2} ${releaseTip + 14 * Math.SQRT1_2} A14 14 0 1 1 ${releaseX + 14 * Math.SQRT1_2} ${releaseTip + 14 * Math.SQRT1_2}`, className: "hl-vent-ring", style: {
515
+ transformOrigin: `${releaseX}px ${releaseTip}px`,
516
+ animationDelay: `${flowDelay(232 - releaseTip)}s`,
517
+ }, "aria-hidden": true })), _jsx(Pipe, { d: `M${releaseX} 232 V${releaseTop}`, kind: "air", active: release?.on, open: release?.on, square: true, arrow: { x: releaseX, y: releaseTop, dir: "up" } }), _jsx(Valve, { x: releaseX,
518
+ // Level with the add air valve
519
+ y: addAirY, 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
520
  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 &&
521
+ return (_jsxs("g", { children: [_jsx("path", { d: `M${gapX - 4} ${y} H${gapX + 4}`, className: "hl-pipe-gap" }), _jsx(Pipe, { d: `M${exchangePoints(i).join(" L")}`, kind: "grey", active: filled && bubbling === true, filled: filled, square: true }), i === 0 &&
395
522
  !filled &&
396
523
  exchangeSurface !== undefined &&
397
524
  exchangeSurface < exchangeYs[1] && (_jsx(Pipe, { d: `M${exchangeX} ${exchangeYs[1]} V${exchangeSurface}`, kind: "grey", active: false, filled: true, square: true })), i === 0 && (
398
525
  // Gaps where the upper pipe passes behind T2's walls
399
526
  _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
527
+ }), _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: true, 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
528
  ? {
402
529
  from: t2FarEdge,
403
530
  to: t2Edge,
@@ -407,11 +534,40 @@ export function FlowDiagram({ state, device, }) {
407
534
  exchangeYs[0] +
408
535
  Math.abs(exchangeX - t2FarEdge),
409
536
  }
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));
537
+ : undefined, pressurized: (addingAir || holdingAir) && 232 - addAirY, pressureHeld: holdingAir, airX: t2c, venting: release?.on ? releaseX : undefined, inlinePercent: true }), exchangeYs.map((y, i) => {
538
+ const filled = exchangeFilled(y);
539
+ const points = exchangePoints(i);
540
+ const length = points
541
+ .slice(1)
542
+ .reduce((sum, [x2, y2], j) => sum + Math.hypot(x2 - points[j][0], y2 - points[j][1]), 0);
543
+ /**
544
+ * 1 px on either side of `at`, in the pipe's direction from one
545
+ * point to the next
546
+ */
547
+ const across = (at, [x1, y1], [x2, y2]) => {
548
+ const d = Math.hypot(x2 - x1, y2 - y1);
549
+ const [dx, dy] = [(x2 - x1) / d, (y2 - y1) / d];
550
+ return `M${at[0] - dx} ${at[1] - dy} L${at[0] + dx} ${at[1] + dy}`;
551
+ };
552
+ const n = points.length;
553
+ return [
554
+ { d: across(points[0], points[0], points[1]), phase: -1 },
555
+ {
556
+ d: across(points[n - 1], points[n - 2], points[n - 1]),
557
+ phase: length - 1,
558
+ },
559
+ ].map(({ d, phase }) => (_jsx(Pipe, { d: d, kind: "grey", active: filled && bubbling === true, filled: filled, square: true, phase: phase }, `${y}-${phase}`)));
560
+ }), _jsx(Pipe, { d: a
561
+ ? `M${t1x} 237 H${drainX} V${wasteY}`
562
+ : `M${t1x + 21} 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)" : ""}`, square: true }), _jsx("text", { x: drainX + (a ? 27 : -27), 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, square: true }), _jsx(Pipe, { d: `M${drainX} ${wasteY} H${drainEnd}`, kind: "waste", active: skimming || waste?.on, open: waste?.on, arrow: { x: drainEnd, y: wasteY, dir: a ? "left" : "right" } }), _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: a ? SEWER_LABEL_X.left : SEWER_LABEL_X.right, y: wasteY + 4, textAnchor: a ? "start" : "end", className: "hl-diagram-label", children: "Sewer" })] }, `body-${side}`));
563
+ // Drawn after the circulation pipes, so the transfer pipe passes in
564
+ // front of them
565
+ const transferPipe = (_jsxs("g", { children: [_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: "grey", active: transferring, open: transferring, square: true }), _jsx(Valve, { x: T2_CENTER[side], y: UV_Y, kind: "grey", io: transfer, active: transferring, name: sideIo("transfer_path", side), label: "Transfer", labelAnchor: "middle", labelDx: 0, labelDy: 24 })] }, `transfer-${side}`));
566
+ return { body, transferPipe };
413
567
  };
568
+ const trains = { A: train("A"), B: train("B") };
414
569
  const backup = io[IO.backupWater];
570
+ const preBackup = io[IO.preBackupWater];
415
571
  const recycledToPump = supply.pumping && supply.source !== "backup";
416
572
  const backupToPump = supply.pumping && supply.source === "backup";
417
573
  const circulatingThroughUv = t3.circulating && supply.pumping;
@@ -435,28 +591,34 @@ export function FlowDiagram({ state, device, }) {
435
591
  ? outletKind
436
592
  : "clean";
437
593
  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 },
594
+ return (_jsxs("svg", { viewBox: `0 -15 1000 ${PUMP_Y + 100}`, 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: inletY - 14, className: "hl-diagram-label is-strong", children: "Greywater from showers and baths" }), _jsx(Pipe, { d: `M60 ${inletY} H${bypassEnds.common}`, kind: "grey", active: receivingSides.length > 0
595
+ ? true
596
+ : inlet.bypass === undefined
597
+ ? undefined
598
+ : false, open: bypassOpen || (bypass?.on === false && selected !== undefined), square: true }), _jsx(Pipe, { d: `M500 ${bypassEnds.branches[0]} V${abEnds.common}`, kind: "grey", active: receivingSides.length > 0, open: bypass?.on === false && selected !== undefined, square: true, phase: toAbPhase }), _jsx(Pipe, { d: `M500 ${bypassEnds.branches[1]} V${sewerY} H${SEWER_END.right}`, kind: "grey", active: inlet.bypass === undefined ? undefined : false, open: bypassOpen, square: true, arrow: { x: SEWER_END.right, y: sewerY, dir: "right" }, phase: toAbPhase }), _jsx(Distributor, { x: 500, y: inletY, 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: [
599
+ { open: bypass?.on, active: false },
440
600
  {
441
601
  open: bypass && !bypass.on,
442
- active: inlet.receiving.length > 0,
602
+ active: receivingSides.length > 0,
443
603
  },
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: [
604
+ ], labelAnchor: "start", labelDx: 14, phase: bypassPhase }), _jsx("text", { x: SEWER_LABEL_X.right, y: sewerY + 4, textAnchor: "end", className: "hl-diagram-label", children: "Sewer" }), trains.A.body, trains.B.body, _jsx(Distributor, { x: 500, y: abY, kind: "grey", io: ab, name: IO.abSelector, label: "A/B valve", idle: bypassOpen, words: ["to train B", "to train A"], branches: [
445
605
  {
446
- open: selected && selected === "A",
447
- active: inlet.receiving.includes("A"),
606
+ open: abSide && abSide === "A",
607
+ active: receivingSides.includes("A"),
448
608
  },
449
609
  {
450
- open: selected && selected === "B",
451
- active: inlet.receiving.includes("B"),
610
+ open: abSide && abSide === "B",
611
+ active: receivingSides.includes("B"),
452
612
  },
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) => {
613
+ ], labelDy: 24, phase: abPhase }), _jsx(Pipe, { d: `M500 ${UV_Y + UV_H} V${TANK_Y}`, kind: uvOutletKind, active: t3ReceivingFromUv, open: io[IO.uvValve]?.on, square: true }), _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 - UV_H, width: 80, height: 2 * UV_H, rx: 6 }), _jsx("text", { x: 500, y: UV_Y + 5, textAnchor: "middle", children: "UV-C" })] }), _jsx(Valve, { x: 500, y: (UV_Y + UV_H + TANK_Y) / 2, vertical: true, kind: uvOutletKind, io: io[IO.uvValve], active: t3ReceivingFromUv, name: IO.uvValve, label: "UV valve" }), _jsx(Tank, { x: 346, y: TANK_Y, w: 309, h: TANK_H, level: tanks.t3, kind: "clean", label: "T3", sub: "Recycled water", square: true }), _jsx(Drips, { x: 500, y: TANK_Y, bottom: t3Fill === undefined ? undefined : TANK_BOTTOM - TANK_H * t3Fill, active: !!t3ReceivingFromUv, kind: uvOutletKind }), _jsx(Pipe, { d: `M655 ${backupY} H${SEWER_END.right}`, kind: "waste", active: t3.draining, open: io[IO.wasteStorageTank]?.on, square: true, arrow: { x: SEWER_END.right, y: backupY, dir: "right" } }), _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: SEWER_LABEL_X.right, y: backupY + 4, textAnchor: "end", className: "hl-diagram-label", children: "Sewer" }), _jsx(Pipe, { d: `M${T4_X} ${MAINS_Y} H${T4_INLET_X} V${TANK_Y - T4_AIR_GAP}`, kind: "mains", active: preBackup?.on, open: preBackup?.on, square: true }), _jsx(Valve, { x: (T4_X + T4_INLET_X) / 2, y: MAINS_Y, kind: "mains", io: preBackup, active: preBackup?.on, name: IO.preBackupWater, label: "Mains", labelAnchor: "middle", labelDx: 0, labelDy: -16 }), _jsx(BackupTank, { x: T4_X, y: TANK_Y, w: 130, h: TANK_H, state: state, inletX: T4_INLET_X, inletY: TANK_Y - T4_AIR_GAP, filling: preBackup?.on }), _jsx("path", { d: `M700 ${backupY - 4} V${backupY + 4}`, className: "hl-pipe-gap" }), _jsx(Pipe, { d: `M560 ${PUMP_Y} H700 V${RUN_Y} H${T2_CENTER.B}`, kind: outletKind, active: circulatingThroughUv || backwashing.A || backwashing.B, open: t3.circulating || backwash.A?.on || backwash.B?.on }), _jsx(Pipe, { d: `M${T2_CENTER.B} ${RUN_Y} H500`, kind: outletKind, active: circulatingThroughUv || backwashing.A, open: t3.circulating || backwash.A?.on }), _jsx(Pipe, { d: `M500 ${RUN_Y} V${UV_Y - UV_H}`, kind: outletKind, active: circulatingThroughUv, open: t3.circulating, square: true }), ["A", "B"].map((side) => {
454
614
  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: [
615
+ return (_jsxs("g", { children: [_jsx(Pipe, { d: a
616
+ ? `M500 ${RUN_Y} H${T2_CENTER.A} V360`
617
+ : `M${T2_CENTER.B} ${RUN_Y} V360`, kind: outletKind, active: backwashing[side], open: backwash[side]?.on, square: true }), _jsx(Valve, { x: T2_CENTER[side], 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));
618
+ }), _jsx(Valve, { x: 500, y: (RUN_Y + UV_Y - UV_H) / 2, vertical: true, kind: outletKind, io: io[IO.circulation], active: circulatingThroughUv, name: IO.circulation, label: "Circulation", labelAnchor: "end", labelDx: -14 }), _jsx("path", { d: `M696 ${UV_Y} H704`, className: "hl-pipe-gap" }), trains.A.transferPipe, trains.B.transferPipe, _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} V${PUMP_Y - 16}`, kind: outletKind, active: supply.pumping, open: backup !== undefined, square: true, phase: (backup?.on ? fromT4Length : fromT3Length) + throughDistributor }), _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
619
  { open: backup?.on, active: backupToPump === true },
458
620
  { 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" })] })] }));
621
+ ], labelDy: -14, phase: backup?.on ? fromT4Length : fromT3Length }), _jsx(Pump, { x: 260, y: PUMP_Y, r: 16, kind: outletKind, io: io[IO.distributionPump], name: IO.distributionPump, label: "Distribution pump", labelAnchor: "end" }), _jsx(Pipe, { d: `M500 ${PUMP_Y} V${TANK_BOTTOM}`, kind: outletKind, active: backFlushing, open: io[IO.backFlush]?.on, square: true }), _jsx(Valve, { x: 500, y: (PUMP_Y + TANK_BOTTOM) / 2, vertical: true, kind: outletKind, io: io[IO.backFlush], active: backFlushing, name: IO.backFlush, label: "Back flush" }), _jsx(Pipe, { d: `M276 ${PUMP_Y} H560`, kind: outletKind, active: supply.toOutlets ?? false, open: true }), _jsxs("g", { className: `hl-outlet${off(device.outlets.toilet)}`, children: [_jsx(Pipe, { d: `M360 ${PUMP_Y} V${PUMP_Y + 50}`, kind: outletKind, active: supply.toilet ?? false, open: true, arrow: { x: 360, y: PUMP_Y + 50, dir: "down" } }), _jsx(Sensor, { x: 360, y: PUMP_Y + 25, kind: outletKind, io: io[IO.toilet], name: IO.toilet, label: "" }), _jsx("text", { x: 360, y: PUMP_Y + 75, textAnchor: "middle", className: "hl-diagram-label", children: "Toilets" })] }), _jsxs("g", { className: `hl-outlet${off(device.outlets.washingMachine)}`, children: [_jsx(Pipe, { d: `M460 ${PUMP_Y} V${PUMP_Y + 50}`, kind: outletKind, active: supply.wash ?? false, open: true, arrow: { x: 460, y: PUMP_Y + 50, dir: "down" } }), _jsx(Sensor, { x: 460, y: PUMP_Y + 25, kind: outletKind, io: io[IO.wash], name: IO.wash, label: "" }), _jsx("text", { x: 460, y: PUMP_Y + 75, textAnchor: "middle", className: "hl-diagram-label", children: "Washer" })] }), _jsxs("g", { className: `hl-outlet${off(device.outlets.auxiliary)}`, children: [_jsx(Pipe, { d: `M560 ${PUMP_Y} V${PUMP_Y + 50}`, kind: outletKind, active: supply.auxiliary, open: io[IO.auxiliary]?.on, arrow: { x: 560, y: PUMP_Y + 50, dir: "down" } }), _jsx(Valve, { x: 560, y: PUMP_Y + 25, vertical: true, kind: outletKind, io: io[IO.auxiliary], active: supply.auxiliary, name: IO.auxiliary, label: "" }), _jsx("text", { x: 560, y: PUMP_Y + 75, textAnchor: "middle", className: "hl-diagram-label", children: "Auxiliary" })] })] }));
460
622
  }
461
623
  export function DiagramLegend() {
462
624
  const items = [
@@ -471,10 +633,12 @@ export function DiagramLegend() {
471
633
  export function activeFlows(state) {
472
634
  const { inlet, trains, io, t3, supply } = state;
473
635
  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)");
636
+ // While the bypass is open, it's not known whether greywater comes in
637
+ if (!inlet.bypass) {
638
+ for (const side of inlet.receiving) {
639
+ flows.push(`Greywater → train ${side}`);
640
+ }
641
+ }
478
642
  for (const side of ["A", "B"]) {
479
643
  if (trains[side].t2ToT1)
480
644
  flows.push(`T2 ${side} → T1 ${side}`);
@@ -497,6 +661,8 @@ export function activeFlows(state) {
497
661
  flows.push("Back flush → T3");
498
662
  if (t3.draining)
499
663
  flows.push("T3 → drain");
664
+ if (io[IO.preBackupWater]?.on)
665
+ flows.push("Mains → T4");
500
666
  if (supply.toOutlets) {
501
667
  const to = [
502
668
  supply.toilet && "toilets",
package/dist/model.js CHANGED
@@ -455,7 +455,9 @@ export function stateAt(ds, t) {
455
455
  // doesn't accept water for the ~4.5 h it lasts.
456
456
  // - The bypass opens when neither train can accept water. It is also tested
457
457
  // for about a minute every 12 hours, while the trains accept water.
458
- // So T2 is taken from its last venting, which happens about once an hour.
458
+ // So T2 is taken from its last venting. Besides each incoming water, T2 is
459
+ // vented for 30–80 s by the PRESSURE_RESET of STANDBY, about every 2 hours
460
+ // and right after each TRANSFER, which settles it just as well.
459
461
  // Greywater also fills T1, but T1 holds at most about 24 L.
460
462
  /** T2 at which a train is full and starts FILTH_REMOVAL */
461
463
  export const TRAIN_FULL_LITERS = 134;
@@ -518,8 +520,13 @@ function holdsPressure(ds, side, t) {
518
520
  const released = onIntervals(ds.io[sideIo("release_air", side)], -Infinity, t).at(-1)?.end;
519
521
  return added > (released ?? -Infinity);
520
522
  }
521
- /** Vent openings shorter than this don't settle the levels */
522
- const MIN_VENT = 60_000;
523
+ /**
524
+ * Vent openings shorter than this don't settle the levels. The vents of
525
+ * `STANDBY` · `PRESSURE_RESET` last 33–80 s and settle T2 within about
526
+ * 1–2 L of the long vents of `INCOMING_WATER`. Shorter openings, e.g. of
527
+ * 11 s during `FILTH_REMOVAL`, don't.
528
+ */
529
+ const MIN_VENT = 30_000;
523
530
  /** Openings of a release air valve that are long enough to settle T2 */
524
531
  export function ventings(points, until) {
525
532
  return onIntervals(points, -Infinity, until).filter((i) => i.end - i.start >= MIN_VENT);
package/dist/styles.css CHANGED
@@ -22,6 +22,7 @@
22
22
  --hl-subtle: #8f8f8f;
23
23
  --hl-border: #ebebeb;
24
24
  --hl-border-strong: #d4d4d4;
25
+ --hl-tank-border: #999999;
25
26
  --hl-focus: #0070f3;
26
27
 
27
28
  --hl-grey: #b26a00;
@@ -42,6 +43,7 @@
42
43
  --hl-subtle: #707070;
43
44
  --hl-border: #262626;
44
45
  --hl-border-strong: #3d3d3d;
46
+ --hl-tank-border: #6b6b6b;
45
47
  --hl-focus: #52a8ff;
46
48
 
47
49
  --hl-grey: #f0a43a;
@@ -62,6 +64,7 @@
62
64
  --hl-subtle: #707070;
63
65
  --hl-border: #262626;
64
66
  --hl-border-strong: #3d3d3d;
67
+ --hl-tank-border: #6b6b6b;
65
68
  --hl-focus: #52a8ff;
66
69
 
67
70
  --hl-grey: #f0a43a;
@@ -169,8 +172,9 @@
169
172
  .hl-pipe.is-open .hl-pipe-base {
170
173
  stroke: var(--hl-pipe-open);
171
174
  }
175
+ /* A pipe full of standing water, drawn like a tank, with its outline */
172
176
  .hl-pipe.is-filled .hl-pipe-base {
173
- stroke: var(--hl-border-strong);
177
+ stroke: var(--hl-tank-border);
174
178
  }
175
179
  /* The same color as .hl-tank-fill over the tank's background */
176
180
  .hl-pipe-water {
@@ -268,7 +272,8 @@
268
272
  fill: var(--hl-bg);
269
273
  stroke: var(--hl-muted);
270
274
  stroke-width: 1.5;
271
- stroke-linejoin: round;
275
+ stroke-linejoin: miter;
276
+ stroke-miterlimit: 10;
272
277
  }
273
278
  .hl-valve-body {
274
279
  transition: transform 0.3s ease;
@@ -295,7 +300,8 @@
295
300
  fill: var(--hl-bg);
296
301
  stroke: var(--hl-border-strong);
297
302
  stroke-width: 1.5;
298
- stroke-linejoin: round;
303
+ stroke-linejoin: miter;
304
+ stroke-miterlimit: 10;
299
305
  }
300
306
  .hl-distributor polygon.is-closed {
301
307
  stroke: var(--hl-pipe-idle);
@@ -305,6 +311,10 @@
305
311
  fill: var(--hl-pipe-open);
306
312
  stroke: none;
307
313
  }
314
+ .hl-distributor polygon.is-idle {
315
+ fill: var(--hl-pipe-idle);
316
+ stroke: none;
317
+ }
308
318
  .hl-distributor polygon.is-flowing {
309
319
  fill: var(--hl-k);
310
320
  stroke: none;
@@ -367,9 +377,14 @@
367
377
 
368
378
  .hl-tank-shell {
369
379
  fill: var(--hl-bg);
370
- stroke: var(--hl-border-strong);
380
+ stroke: var(--hl-tank-border);
371
381
  stroke-width: 1.5;
372
382
  }
383
+ /* An opening in a tank's wall, covering its outline */
384
+ .hl-tank-gap {
385
+ stroke: var(--hl-bg);
386
+ stroke-width: 3;
387
+ }
373
388
  .hl-tank-shell.is-unknown {
374
389
  fill: url(#hl-hatch);
375
390
  }
@@ -430,6 +445,10 @@
430
445
  fill: var(--hl-muted);
431
446
  font-variant-numeric: tabular-nums;
432
447
  }
448
+ .hl-tank-value .hl-tank-meta {
449
+ font-weight: 400;
450
+ letter-spacing: 0;
451
+ }
433
452
 
434
453
  .hl-bubbles circle {
435
454
  fill: var(--hl-air);
@@ -494,15 +513,15 @@
494
513
  transform: scale(1);
495
514
  }
496
515
  }
497
- /* Air leaving the release air pipe's open end, at the rings' pace. It fades
498
- out by the air pump's radius, 13 of the circle's 14 px */
516
+ /* Air leaving past the release air arrow's tip, at the rings' pace. It
517
+ fades out by the air pump's radius, 13 of the arc's 14 px. It grows from
518
+ the tip, set as its transform-origin inline */
499
519
  .hl-vent-ring {
500
520
  fill: none;
501
521
  stroke: var(--hl-air);
502
522
  stroke-width: 1.5;
503
523
  vector-effect: non-scaling-stroke;
504
- transform-box: fill-box;
505
- transform-origin: center;
524
+ transform-box: view-box;
506
525
  animation: hl-vent 0.9s linear infinite;
507
526
  }
508
527
  @keyframes hl-vent {
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "1.0.1";
1
+ export declare const VERSION = "1.2.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "1.0.1";
1
+ export const VERSION = "1.2.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hydraloop-diagram-react",
3
- "version": "1.0.1",
3
+ "version": "1.2.0",
4
4
  "description": "React flow diagram of a Hydraloop H600, and the model that derives what the device is doing from its signals",
5
5
  "type": "module",
6
6
  "exports": {
package/readme.md CHANGED
@@ -108,7 +108,8 @@ The colors are custom properties on `:root` without specificity, so the page can
108
108
  | `--hl-bg` | Background of tanks, valves and pumps, and the gaps where pipes cross. Must match the page's background |
109
109
  | `--hl-fg`, `--hl-muted`, `--hl-subtle` | Text, outlines and unknown states |
110
110
  | `--hl-border` | Hatching of tanks without level data |
111
- | `--hl-border-strong` | Tank outlines, and pipes with unknown state |
111
+ | `--hl-border-strong` | UV-C's outline, and pipes with unknown state |
112
+ | `--hl-tank-border` | Outlines of tanks and of the pipes between T1 and T2 while they hold water |
112
113
  | `--hl-focus` | Focused valves, pumps and tanks |
113
114
  | `--hl-grey`, `--hl-clean`, `--hl-mains`, `--hl-waste`, `--hl-air`, `--hl-uv` | The kinds of water, air and UV-C |
114
115
  | `--hl-pipe-idle`, `--hl-pipe-open` | Pipes without water moving, closed and open |