@collabdt/core 0.4.0 → 0.4.1
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/core/components/AppSidebarContent.d.ts.map +1 -1
- package/dist/core/components/AppSidebarContent.js +2 -7
- package/dist/core/components/AppSidebarContent.js.map +1 -1
- package/dist/core/components/ui/LegendCard.d.ts +8 -3
- package/dist/core/components/ui/LegendCard.d.ts.map +1 -1
- package/dist/core/components/ui/LegendCard.js +36 -18
- package/dist/core/components/ui/LegendCard.js.map +1 -1
- package/dist/core/components/ui/Sensors/SensorDetailDialog.d.ts.map +1 -1
- package/dist/core/components/ui/Sensors/SensorDetailDialog.js +56 -19
- package/dist/core/components/ui/Sensors/SensorDetailDialog.js.map +1 -1
- package/dist/core/components/ui/Sensors/SensorLegend.d.ts +6 -3
- package/dist/core/components/ui/Sensors/SensorLegend.d.ts.map +1 -1
- package/dist/core/components/ui/Sensors/SensorLegend.js +95 -27
- package/dist/core/components/ui/Sensors/SensorLegend.js.map +1 -1
- package/dist/core/components/ui/Sensors/SensorMultiSeriesChart.d.ts +10 -4
- package/dist/core/components/ui/Sensors/SensorMultiSeriesChart.d.ts.map +1 -1
- package/dist/core/components/ui/Sensors/SensorMultiSeriesChart.js +60 -9
- package/dist/core/components/ui/Sensors/SensorMultiSeriesChart.js.map +1 -1
- package/dist/core/components/ui/Sensors/SensorsSection.d.ts +1 -2
- package/dist/core/components/ui/Sensors/SensorsSection.d.ts.map +1 -1
- package/dist/core/components/ui/Sensors/SensorsSection.js +34 -4
- package/dist/core/components/ui/Sensors/SensorsSection.js.map +1 -1
- package/dist/core/components/ui/Sensors/buildingSensorColours.d.ts +49 -0
- package/dist/core/components/ui/Sensors/buildingSensorColours.d.ts.map +1 -0
- package/dist/core/components/ui/Sensors/buildingSensorColours.js +68 -0
- package/dist/core/components/ui/Sensors/buildingSensorColours.js.map +1 -0
- package/dist/core/components/ui/Sensors/sensorScope.js +1 -1
- package/dist/core/components/ui/Sensors/sensorScope.js.map +1 -1
- package/dist/core/components/ui/Sensors/sensorVisibility.d.ts +47 -0
- package/dist/core/components/ui/Sensors/sensorVisibility.d.ts.map +1 -0
- package/dist/core/components/ui/Sensors/sensorVisibility.js +29 -0
- package/dist/core/components/ui/Sensors/sensorVisibility.js.map +1 -0
- package/dist/core/components/ui/Sensors/useBuildingSensorColours.d.ts +30 -0
- package/dist/core/components/ui/Sensors/useBuildingSensorColours.d.ts.map +1 -0
- package/dist/core/components/ui/Sensors/useBuildingSensorColours.js +92 -0
- package/dist/core/components/ui/Sensors/useBuildingSensorColours.js.map +1 -0
- package/dist/core/components/ui/Sensors/useSensorSeriesMulti.d.ts +1 -1
- package/dist/core/components/ui/Sensors/useSensorSeriesMulti.d.ts.map +1 -1
- package/dist/core/components/ui/Sensors/useSensorSeriesMulti.js.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useSensorMarkers.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useSensorMarkers.js +17 -17
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useSensorMarkers.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/index.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/index.js +27 -1
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/index.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingSensorDetails.d.ts +36 -0
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingSensorDetails.d.ts.map +1 -0
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingSensorDetails.js +95 -0
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingSensorDetails.js.map +1 -0
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingsTools.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingsTools.js +55 -42
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/DatabaseBuildingPopover/src/BuildingsTools.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/buildingColourExpression.d.ts +32 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/buildingColourExpression.d.ts.map +1 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/buildingColourExpression.js +56 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/buildingColourExpression.js.map +1 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/index.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/index.js +61 -39
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/index.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/src/BuildingSensorMarkers.d.ts +18 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/src/BuildingSensorMarkers.d.ts.map +1 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/src/BuildingSensorMarkers.js +61 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/BuildingLayers/src/BuildingSensorMarkers.js.map +1 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/index.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/index.js +36 -19
- package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/index.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/sensorClusterColour.d.ts +22 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/sensorClusterColour.d.ts.map +1 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/sensorClusterColour.js +36 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/SensorsLayer/sensorClusterColour.js.map +1 -0
- package/dist/core/components/viewers/map/src/MapLayers/src/mapLayersUtils.d.ts +5 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/mapLayersUtils.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/mapLayersUtils.js +6 -2
- package/dist/core/components/viewers/map/src/MapLayers/src/mapLayersUtils.js.map +1 -1
- package/dist/core/i18n/messages/en.json +11 -1
- package/dist/core/i18n/messages/es.json +11 -1
- package/dist/core/i18n/messages/fr.json +11 -1
- package/dist/core/store/Menus/context.d.ts.map +1 -1
- package/dist/core/store/Menus/context.js +4 -2
- package/dist/core/store/Menus/context.js.map +1 -1
- package/dist/core/store/Menus/reducer.d.ts +15 -26
- package/dist/core/store/Menus/reducer.d.ts.map +1 -1
- package/dist/core/store/Menus/reducer.js +38 -4
- package/dist/core/store/Menus/reducer.js.map +1 -1
- package/dist/core/utils/appContent.d.ts +15 -0
- package/dist/core/utils/appContent.d.ts.map +1 -0
- package/dist/core/utils/appContent.js +24 -0
- package/dist/core/utils/appContent.js.map +1 -0
- package/dist/core/utils/colourUtils.d.ts +9 -0
- package/dist/core/utils/colourUtils.d.ts.map +1 -1
- package/dist/core/utils/colourUtils.js +16 -0
- package/dist/core/utils/colourUtils.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,55 +1,123 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as LR from "lucide-react";
|
|
3
4
|
import { useTranslations } from "next-intl";
|
|
4
5
|
import * as React from "react";
|
|
5
6
|
import { useSensors } from "../../../hooks/sensors/sensors";
|
|
6
7
|
import { useSensorTypes } from "../../../hooks/sensorTypes/sensorTypes";
|
|
7
8
|
import { MenusContext } from "../../../store";
|
|
9
|
+
import { Button } from "../Button";
|
|
10
|
+
import {
|
|
11
|
+
DropdownMenu,
|
|
12
|
+
DropdownMenuTrigger,
|
|
13
|
+
DropdownMenuContent,
|
|
14
|
+
DropdownMenuRadioGroup,
|
|
15
|
+
DropdownMenuRadioItem
|
|
16
|
+
} from "../DropdownMenu";
|
|
8
17
|
import { LegendCard } from "../LegendCard";
|
|
9
18
|
import { observedDomain, rampStops, resolveDomain, resolveRamp, valueOffset } from "./sensorColour";
|
|
10
|
-
import {
|
|
19
|
+
import { activeSensorTypeId, legendScopeSensors } from "./sensorVisibility";
|
|
20
|
+
import { latestValues, useSensorSeriesMulti } from "./useSensorSeriesMulti";
|
|
11
21
|
const format = new Intl.NumberFormat(void 0, { maximumFractionDigits: 1 });
|
|
12
22
|
const typeLabel = (name) => name.replace(/_/g, " ");
|
|
13
23
|
function SensorLegend() {
|
|
14
|
-
var _a, _b, _c, _d, _e;
|
|
24
|
+
var _a, _b, _c, _d, _e, _f;
|
|
15
25
|
const t = useTranslations("SensorLegend");
|
|
16
|
-
const { state } = React.useContext(MenusContext);
|
|
17
|
-
const {
|
|
26
|
+
const { state, dispatch } = React.useContext(MenusContext);
|
|
27
|
+
const {
|
|
28
|
+
focusedSensorId,
|
|
29
|
+
currentSensorId,
|
|
30
|
+
currentViewer,
|
|
31
|
+
visibleSensorTypes,
|
|
32
|
+
visibleSensorTags,
|
|
33
|
+
sensorLegendVisible,
|
|
34
|
+
sensorLegendTypeId
|
|
35
|
+
} = state.menus;
|
|
36
|
+
const viewer = currentViewer;
|
|
18
37
|
const { sensors } = useSensors();
|
|
19
38
|
const { sensorTypes } = useSensorTypes();
|
|
20
39
|
const activeId = focusedSensorId != null ? focusedSensorId : currentSensorId;
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
40
|
+
const activeSensor = activeId == null ? void 0 : sensors.find((s) => s.id === activeId);
|
|
41
|
+
const activeTypeId = activeSensorTypeId(sensors, {
|
|
42
|
+
legendTypeId: sensorLegendTypeId == null ? void 0 : sensorLegendTypeId[viewer],
|
|
43
|
+
activeSensorId: activeId
|
|
44
|
+
});
|
|
45
|
+
const sensorType = sensorTypes.find((ty) => ty.id === activeTypeId);
|
|
46
|
+
const caretSensor = (activeSensor == null ? void 0 : activeSensor.typeId) === activeTypeId ? activeSensor : void 0;
|
|
47
|
+
const inScope = legendScopeSensors(
|
|
48
|
+
sensors,
|
|
49
|
+
{
|
|
50
|
+
viewer,
|
|
51
|
+
visibleTypeIds: (_a = visibleSensorTypes == null ? void 0 : visibleSensorTypes[viewer]) != null ? _a : [],
|
|
52
|
+
visibleTags: (_b = visibleSensorTags == null ? void 0 : visibleSensorTags[viewer]) != null ? _b : []
|
|
53
|
+
},
|
|
54
|
+
activeTypeId
|
|
28
55
|
);
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
(s) => s.typeId != null && s.typeId === (sensor == null ? void 0 : sensor.typeId) && s.viewer === currentViewer
|
|
56
|
+
const { seriesById } = useSensorSeriesMulti(inScope, { enabled: inScope.length > 0 });
|
|
57
|
+
const selectableTypes = sensorTypes.filter(
|
|
58
|
+
(ty) => sensors.some((s) => s.viewer === viewer && s.typeId === ty.id)
|
|
33
59
|
);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
60
|
+
const selectType = React.useCallback((sensorTypeId) => {
|
|
61
|
+
dispatch({ type: "SET_SENSOR_LEGEND_TYPE_ID", payload: { viewer, sensorTypeId } });
|
|
62
|
+
dispatch({ type: "TOGGLE_SENSOR_TYPE_VISIBILITY", payload: { viewer, sensorTypeId, force: true } });
|
|
63
|
+
dispatch({ type: "SET_FOCUSED_SENSOR_ID", payload: { sensorId: null } });
|
|
64
|
+
}, [dispatch, viewer]);
|
|
65
|
+
const closeLegend = React.useCallback(() => {
|
|
66
|
+
dispatch({ type: "TOGGLE_SENSOR_LEGEND", payload: { viewer, visible: false } });
|
|
67
|
+
}, [dispatch, viewer]);
|
|
68
|
+
if ((sensorLegendVisible == null ? void 0 : sensorLegendVisible[viewer]) === false) return null;
|
|
69
|
+
if (!sensorType) return null;
|
|
70
|
+
if (inScope.length === 0) return null;
|
|
71
|
+
const ramp = resolveRamp(sensorType);
|
|
72
|
+
const typePoints = [...seriesById.values()].flatMap((series) => series.points);
|
|
73
|
+
const domain = resolveDomain(sensorType, observedDomain(typePoints));
|
|
74
|
+
const caretSeries = caretSensor ? seriesById.get(caretSensor.id) : void 0;
|
|
75
|
+
const unit = (_d = caretSeries == null ? void 0 : caretSeries.unit) != null ? _d : (_c = [...seriesById.values()].find((s) => s.unit)) == null ? void 0 : _c.unit;
|
|
76
|
+
const valueLabels = caretSeries == null ? void 0 : caretSeries.valueLabels;
|
|
77
|
+
const latest = caretSensor ? latestValues(seriesById).get(caretSensor.id) : void 0;
|
|
78
|
+
const hasReading = latest !== void 0;
|
|
37
79
|
const gradient = `linear-gradient(to right, ${rampStops(ramp).map((s) => `${s.colour} ${s.offset * 100}%`).join(", ")})`;
|
|
38
|
-
const [low, mid, high] = [domain.min, (domain.min + domain.max) / 2, domain.max];
|
|
39
80
|
const readingText = hasReading ? (_e = valueLabels == null ? void 0 : valueLabels[latest]) != null ? _e : `${format.format(latest)}${unit ? ` ${unit}` : ""}` : t("noReading");
|
|
81
|
+
const title = /* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
82
|
+
/* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
|
|
83
|
+
Button,
|
|
84
|
+
{
|
|
85
|
+
variant: "ghost",
|
|
86
|
+
size: "sm",
|
|
87
|
+
title: t("selectType"),
|
|
88
|
+
className: "-ml-2 h-7 gap-1 px-2 text-sm font-medium",
|
|
89
|
+
"data-testid": "sensor-legend-type-trigger",
|
|
90
|
+
children: [
|
|
91
|
+
typeLabel(String(sensorType.name)),
|
|
92
|
+
/* @__PURE__ */ jsx(LR.ChevronDown, { size: 14, className: "opacity-70" })
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
) }),
|
|
96
|
+
/* @__PURE__ */ jsx(DropdownMenuContent, { align: "start", children: /* @__PURE__ */ jsx(
|
|
97
|
+
DropdownMenuRadioGroup,
|
|
98
|
+
{
|
|
99
|
+
value: String(sensorType.id),
|
|
100
|
+
onValueChange: (value) => selectType(Number(value)),
|
|
101
|
+
children: selectableTypes.map((ty) => /* @__PURE__ */ jsx(DropdownMenuRadioItem, { value: String(ty.id), children: typeLabel(String(ty.name)) }, ty.id))
|
|
102
|
+
}
|
|
103
|
+
) })
|
|
104
|
+
] });
|
|
40
105
|
return /* @__PURE__ */ jsx(
|
|
41
106
|
LegendCard,
|
|
42
107
|
{
|
|
43
|
-
title
|
|
44
|
-
|
|
108
|
+
title,
|
|
109
|
+
titleLabel: typeLabel(String(sensorType.name)),
|
|
110
|
+
count: inScope.length,
|
|
111
|
+
onClose: closeLegend,
|
|
112
|
+
closeLabel: t("close"),
|
|
45
113
|
testId: "sensor-legend-card",
|
|
46
114
|
countTestId: "sensor-legend-count",
|
|
47
115
|
children: /* @__PURE__ */ jsxs("div", { className: "px-3 py-2", children: [
|
|
48
116
|
/* @__PURE__ */ jsxs("div", { className: "mb-2 flex items-baseline justify-between gap-2", children: [
|
|
49
|
-
/* @__PURE__ */ jsx("span", { className: "truncate text-xs text-muted-foreground", children:
|
|
50
|
-
/* @__PURE__ */ jsx("span", { className: "shrink-0 text-xs font-medium tabular-nums", children: readingText })
|
|
117
|
+
/* @__PURE__ */ jsx("span", { className: "truncate text-xs text-muted-foreground", children: (_f = caretSensor == null ? void 0 : caretSensor.name) != null ? _f : "" }),
|
|
118
|
+
caretSensor && /* @__PURE__ */ jsx("span", { className: "shrink-0 text-xs font-medium tabular-nums", children: readingText })
|
|
51
119
|
] }),
|
|
52
|
-
/* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
120
|
+
domain == null ? /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: t("noRange") }) : /* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
53
121
|
/* @__PURE__ */ jsx("div", { className: "relative h-2", children: hasReading && /* @__PURE__ */ jsx(
|
|
54
122
|
"div",
|
|
55
123
|
{
|
|
@@ -69,9 +137,9 @@ function SensorLegend() {
|
|
|
69
137
|
}
|
|
70
138
|
),
|
|
71
139
|
/* @__PURE__ */ jsxs("div", { className: "mt-1 flex justify-between text-[10px] tabular-nums text-muted-foreground", children: [
|
|
72
|
-
/* @__PURE__ */ jsx("span", { children: format.format(
|
|
73
|
-
/* @__PURE__ */ jsx("span", { children: format.format(
|
|
74
|
-
/* @__PURE__ */ jsx("span", { children: format.format(
|
|
140
|
+
/* @__PURE__ */ jsx("span", { children: format.format(domain.min) }),
|
|
141
|
+
/* @__PURE__ */ jsx("span", { children: format.format((domain.min + domain.max) / 2) }),
|
|
142
|
+
/* @__PURE__ */ jsx("span", { children: format.format(domain.max) })
|
|
75
143
|
] })
|
|
76
144
|
] })
|
|
77
145
|
] })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/core/components/ui/Sensors/SensorLegend.tsx"],"sourcesContent":["'use client'\r\n\r\n// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport { useTranslations } from 'next-intl'\r\nimport * as React from 'react'\r\n\r\nimport { useSensors } from '../../../hooks/sensors/sensors'\r\nimport { useSensorTypes } from '../../../hooks/sensorTypes/sensorTypes'\r\nimport { MenusContext } from '../../../store'\r\nimport { LegendCard } from '../LegendCard'\r\n\r\nimport { observedDomain, rampStops, resolveDomain, resolveRamp, valueOffset } from './sensorColour'\r\nimport { useSensorSeries } from './useSensorSeries'\r\n\r\nimport type { ViewerNames } from '../../../types/dbTypes'\r\n\r\nconst format = new Intl.NumberFormat(undefined, { maximumFractionDigits: 1 })\r\n\r\n/** `Air_Quality` reads as `Air Quality`, matching how the cards title a type. */\r\nconst typeLabel = (name: string): string => name.replace(/_/g, ' ')\r\n\r\n/**\r\n * Colour legend for the focused sensor's type, shown in a viewer's bottom-left card stack.\r\n *\r\n * This is what makes the value ramp readable: it puts the domain's numbers next to the colours\r\n * used by the marker halos and the chart fill, so nothing in the scene is encoded by colour\r\n * alone. Renders nothing unless a sensor is focused and its type has a usable colour domain, so\r\n * an unconfigured type shows no legend rather than a meaningless gradient.\r\n */\r\nexport function SensorLegend(): React.ReactElement | null {\r\n const t = useTranslations('SensorLegend')\r\n const { state } = React.useContext(MenusContext)\r\n const { focusedSensorId, currentSensorId, currentViewer } = state.menus\r\n\r\n const { sensors } = useSensors()\r\n const { sensorTypes } = useSensorTypes()\r\n\r\n // A click-focused sensor wins; hover is the fallback so the legend still explains the colours\r\n // while the pointer sweeps the scene.\r\n const activeId = focusedSensorId ?? currentSensorId\r\n const sensor = activeId == null ? undefined : sensors.find(s => s.id === activeId)\r\n const sensorType = sensor ? sensorTypes.find(ty => ty.id === sensor.typeId) : undefined\r\n\r\n const { points, unit, valueLabels } = useSensorSeries(\r\n sensor?.url ?? '',\r\n sensor?.dataFormat ?? 'Json',\r\n sensor?.updateFrequency ?? 0,\r\n { enabled: !!sensor?.url },\r\n )\r\n\r\n const ramp = resolveRamp(sensorType)\r\n const domain = resolveDomain(sensorType, observedDomain(points))\r\n\r\n const sameType = sensors.filter(\r\n s => s.typeId != null && s.typeId === sensor?.typeId && s.viewer === (currentViewer as ViewerNames),\r\n )\r\n\r\n if (!sensor || !sensorType || !domain) return null\r\n\r\n const latest = points[points.length - 1]?.value\r\n const hasReading = typeof latest === 'number' && Number.isFinite(latest)\r\n const gradient = `linear-gradient(to right, ${rampStops(ramp)\r\n .map(s => `${s.colour} ${s.offset * 100}%`)\r\n .join(', ')})`\r\n const [low, mid, high] = [domain.min, (domain.min + domain.max) / 2, domain.max]\r\n\r\n const readingText = hasReading\r\n ? valueLabels?.[latest] ?? `${format.format(latest)}${unit ? ` ${unit}` : ''}`\r\n : t('noReading')\r\n\r\n return (\r\n <LegendCard\r\n title={typeLabel(String(sensorType.name))}\r\n count={sameType.length}\r\n testId=\"sensor-legend-card\"\r\n countTestId=\"sensor-legend-count\"\r\n >\r\n <div className=\"px-3 py-2\">\r\n <div className=\"mb-2 flex items-baseline justify-between gap-2\">\r\n <span className=\"truncate text-xs text-muted-foreground\">{sensor.name}</span>\r\n <span className=\"shrink-0 text-xs font-medium tabular-nums\">{readingText}</span>\r\n </div>\r\n\r\n <div className=\"relative\">\r\n {/* Caret sits above the ramp at the current value. */}\r\n <div className=\"relative h-2\">\r\n {hasReading && (\r\n <div\r\n data-testid=\"sensor-legend-caret\"\r\n className=\"absolute top-0 -translate-x-1/2\"\r\n style={{ left: `${valueOffset(latest, domain) * 100}%` }}\r\n >\r\n <div className=\"h-2 w-0.5 rounded-full bg-foreground\" />\r\n </div>\r\n )}\r\n </div>\r\n <div\r\n data-testid=\"sensor-legend-ramp\"\r\n aria-hidden=\"true\"\r\n className=\"h-2.5 w-full rounded-full\"\r\n style={{ background: gradient }}\r\n />\r\n <div className=\"mt-1 flex justify-between text-[10px] tabular-nums text-muted-foreground\">\r\n <span>{format.format(low)}</span>\r\n <span>{format.format(mid)}</span>\r\n <span>{format.format(high)}</span>\r\n </div>\r\n </div>\r\n </div>\r\n </LegendCard>\r\n )\r\n}\r\n"],"mappings":";AAgFQ,SACE,KADF;AA3ER,SAAS,uBAAuB;AAChC,YAAY,WAAW;AAEvB,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAE3B,SAAS,gBAAgB,WAAW,eAAe,aAAa,mBAAmB;AACnF,SAAS,uBAAuB;AAIhC,MAAM,SAAS,IAAI,KAAK,aAAa,QAAW,EAAE,uBAAuB,EAAE,CAAC;AAG5E,MAAM,YAAY,CAAC,SAAyB,KAAK,QAAQ,MAAM,GAAG;AAU3D,SAAS,eAA0C;AA/B1D;AAgCE,QAAM,IAAI,gBAAgB,cAAc;AACxC,QAA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AAI,IAAI,KAAK,EAAE,KAC1E,EAAE,WAAW;AAEjB,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO,UAAU,OAAO,WAAW,IAAI,CAAC;AAAA,MACxC,OAAO,SAAS;AAAA,MAChB,QAAO;AAAA,MACP,aAAY;AAAA,MAEZ,+BAAC,SAAI,WAAU,aACb;AAAA,6BAAC,SAAI,WAAU,kDACb;AAAA,8BAAC,UAAK,WAAU,0CAA0C,iBAAO,MAAK;AAAA,UACtE,oBAAC,UAAK,WAAU,6CAA6C,uBAAY;AAAA,WAC3E;AAAA,QAEA,qBAAC,SAAI,WAAU,YAEb;AAAA,8BAAC,SAAI,WAAU,gBACZ,wBACC;AAAA,YAAC;AAAA;AAAA,cACC,eAAY;AAAA,cACZ,WAAU;AAAA,cACV,OAAO,EAAE,MAAM,GAAG,YAAY,QAAQ,MAAM,IAAI,GAAG,IAAI;AAAA,cAEvD,8BAAC,SAAI,WAAU,wCAAuC;AAAA;AAAA,UACxD,GAEJ;AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACC,eAAY;AAAA,cACZ,eAAY;AAAA,cACZ,WAAU;AAAA,cACV,OAAO,EAAE,YAAY,SAAS;AAAA;AAAA,UAChC;AAAA,UACA,qBAAC,SAAI,WAAU,4EACb;AAAA,gCAAC,UAAM,iBAAO,OAAO,GAAG,GAAE;AAAA,YAC1B,oBAAC,UAAM,iBAAO,OAAO,GAAG,GAAE;AAAA,YAC1B,oBAAC,UAAM,iBAAO,OAAO,IAAI,GAAE;AAAA,aAC7B;AAAA,WACF;AAAA,SACF;AAAA;AAAA,EACF;AAEJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/core/components/ui/Sensors/SensorLegend.tsx"],"sourcesContent":["'use client'\r\n\r\n// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport * as LR from 'lucide-react'\r\nimport { useTranslations } from 'next-intl'\r\nimport * as React from 'react'\r\n\r\nimport { useSensors } from '../../../hooks/sensors/sensors'\r\nimport { useSensorTypes } from '../../../hooks/sensorTypes/sensorTypes'\r\nimport { MenusContext } from '../../../store'\r\nimport { Button } from '../Button'\r\nimport {\r\n DropdownMenu,\r\n DropdownMenuTrigger,\r\n DropdownMenuContent,\r\n DropdownMenuRadioGroup,\r\n DropdownMenuRadioItem,\r\n} from '../DropdownMenu'\r\nimport { LegendCard } from '../LegendCard'\r\n\r\nimport { observedDomain, rampStops, resolveDomain, resolveRamp, valueOffset } from './sensorColour'\r\nimport { activeSensorTypeId, legendScopeSensors } from './sensorVisibility'\r\nimport { latestValues, useSensorSeriesMulti } from './useSensorSeriesMulti'\r\n\r\nimport type { ViewerNames } from '../../../types/dbTypes'\r\n\r\nconst format = new Intl.NumberFormat(undefined, { maximumFractionDigits: 1 })\r\n\r\n/** `Air_Quality` reads as `Air Quality`, matching how the cards title a type. */\r\nconst typeLabel = (name: string): string => name.replace(/_/g, ' ')\r\n\r\n/**\r\n * Colour legend for the viewer's active sensor type, shown in the bottom-left card stack.\r\n *\r\n * This is what makes the value ramp readable: it puts the domain's numbers next to the colours\r\n * used by the marker halos and the chart fill, so nothing in the scene is encoded by colour\r\n * alone. Its title doubles as the type picker, which also retargets the halos and the map's\r\n * building colours.\r\n *\r\n * It exists only while it has something to explain: dismissed by its own close button, or with\r\n * no visible sensor of the active type, it renders nothing.\r\n */\r\nexport function SensorLegend(): React.ReactElement | null {\r\n const t = useTranslations('SensorLegend')\r\n const { state, dispatch } = React.useContext(MenusContext)\r\n const {\r\n focusedSensorId,\r\n currentSensorId,\r\n currentViewer,\r\n visibleSensorTypes,\r\n visibleSensorTags,\r\n sensorLegendVisible,\r\n sensorLegendTypeId,\r\n } = state.menus\r\n const viewer = currentViewer as ViewerNames\r\n\r\n const { sensors } = useSensors()\r\n const { sensorTypes } = useSensorTypes()\r\n\r\n // A click-focused sensor wins; hover is the fallback so the legend still explains the colours\r\n // while the pointer sweeps the scene.\r\n const activeId = focusedSensorId ?? currentSensorId\r\n const activeSensor = activeId == null ? undefined : sensors.find(s => s.id === activeId)\r\n const activeTypeId = activeSensorTypeId(sensors, {\r\n legendTypeId: sensorLegendTypeId?.[viewer],\r\n activeSensorId: activeId,\r\n })\r\n const sensorType = sensorTypes.find(ty => ty.id === activeTypeId)\r\n\r\n // After the type is changed from the dropdown the focused sensor belongs to another type, so\r\n // there is no reading to mark: the card shows the ramp alone until a sensor is picked.\r\n const caretSensor = activeSensor?.typeId === activeTypeId ? activeSensor : undefined\r\n\r\n const inScope = legendScopeSensors(\r\n sensors,\r\n {\r\n viewer,\r\n visibleTypeIds: visibleSensorTypes?.[viewer] ?? [],\r\n visibleTags: visibleSensorTags?.[viewer] ?? [],\r\n },\r\n activeTypeId,\r\n )\r\n\r\n // Polls the whole type, not just the focused sensor. Two reasons: the ramp has to be drawable\r\n // with nothing focused, and a type whose configured range is unusable can only get a domain\r\n // from what its sensors are actually reporting. It also makes the legend's domain identical to\r\n // the one the marker halos use, which is resolved across the same set.\r\n const { seriesById } = useSensorSeriesMulti(inScope, { enabled: inScope.length > 0 })\r\n\r\n // Types worth offering: every type placed in this viewer, visible or not. Picking a hidden\r\n // one turns it on below, so the list does not have to be pre-filtered by visibility.\r\n const selectableTypes = sensorTypes.filter(\r\n ty => sensors.some(s => s.viewer === viewer && s.typeId === ty.id),\r\n )\r\n\r\n const selectType = React.useCallback((sensorTypeId: number) => {\r\n dispatch({ type: 'SET_SENSOR_LEGEND_TYPE_ID', payload: { viewer, sensorTypeId } })\r\n // Without this the legend would hide itself the moment it retargets to a hidden type.\r\n dispatch({ type: 'TOGGLE_SENSOR_TYPE_VISIBILITY', payload: { viewer, sensorTypeId, force: true } })\r\n // Drops the caret, since the focused sensor is no longer of the displayed type. A null\r\n // payload deliberately leaves the pin above intact.\r\n dispatch({ type: 'SET_FOCUSED_SENSOR_ID', payload: { sensorId: null } })\r\n }, [dispatch, viewer])\r\n\r\n const closeLegend = React.useCallback(() => {\r\n dispatch({ type: 'TOGGLE_SENSOR_LEGEND', payload: { viewer, visible: false } })\r\n }, [dispatch, viewer])\r\n\r\n if (sensorLegendVisible?.[viewer] === false) return null\r\n if (!sensorType) return null\r\n // The one rule tying the card to the scene: no visible sensors of this type, no legend. Covers\r\n // the type switch, the tag switch and hide-all in a single condition.\r\n if (inScope.length === 0) return null\r\n\r\n const ramp = resolveRamp(sensorType)\r\n const typePoints = [...seriesById.values()].flatMap(series => series.points)\r\n const domain = resolveDomain(sensorType, observedDomain(typePoints))\r\n\r\n const caretSeries = caretSensor ? seriesById.get(caretSensor.id) : undefined\r\n const unit = caretSeries?.unit ?? [...seriesById.values()].find(s => s.unit)?.unit\r\n const valueLabels = caretSeries?.valueLabels\r\n const latest = caretSensor ? latestValues(seriesById).get(caretSensor.id) : undefined\r\n const hasReading = latest !== undefined\r\n const gradient = `linear-gradient(to right, ${rampStops(ramp)\r\n .map(s => `${s.colour} ${s.offset * 100}%`)\r\n .join(', ')})`\r\n\r\n const readingText = hasReading\r\n ? valueLabels?.[latest] ?? `${format.format(latest)}${unit ? ` ${unit}` : ''}`\r\n : t('noReading')\r\n\r\n const title = (\r\n <DropdownMenu>\r\n <DropdownMenuTrigger asChild>\r\n <Button\r\n variant=\"ghost\"\r\n size=\"sm\"\r\n title={t('selectType')}\r\n className=\"-ml-2 h-7 gap-1 px-2 text-sm font-medium\"\r\n data-testid=\"sensor-legend-type-trigger\"\r\n >\r\n {typeLabel(String(sensorType.name))}\r\n <LR.ChevronDown size={14} className=\"opacity-70\" />\r\n </Button>\r\n </DropdownMenuTrigger>\r\n <DropdownMenuContent align=\"start\">\r\n <DropdownMenuRadioGroup\r\n value={String(sensorType.id)}\r\n onValueChange={value => selectType(Number(value))}\r\n >\r\n {selectableTypes.map(ty => (\r\n <DropdownMenuRadioItem key={ty.id} value={String(ty.id)}>\r\n {typeLabel(String(ty.name))}\r\n </DropdownMenuRadioItem>\r\n ))}\r\n </DropdownMenuRadioGroup>\r\n </DropdownMenuContent>\r\n </DropdownMenu>\r\n )\r\n\r\n return (\r\n <LegendCard\r\n title={title}\r\n titleLabel={typeLabel(String(sensorType.name))}\r\n count={inScope.length}\r\n onClose={closeLegend}\r\n closeLabel={t('close')}\r\n testId=\"sensor-legend-card\"\r\n countTestId=\"sensor-legend-count\"\r\n >\r\n <div className=\"px-3 py-2\">\r\n <div className=\"mb-2 flex items-baseline justify-between gap-2\">\r\n <span className=\"truncate text-xs text-muted-foreground\">{caretSensor?.name ?? ''}</span>\r\n {caretSensor && (\r\n <span className=\"shrink-0 text-xs font-medium tabular-nums\">{readingText}</span>\r\n )}\r\n </div>\r\n\r\n {/* An unconfigured type still gets a card, so the picker that reached it stays reachable. */}\r\n {domain == null ? (\r\n <p className=\"text-xs text-muted-foreground\">{t('noRange')}</p>\r\n ) : (\r\n <div className=\"relative\">\r\n {/* Caret sits above the ramp at the current value. */}\r\n <div className=\"relative h-2\">\r\n {hasReading && (\r\n <div\r\n data-testid=\"sensor-legend-caret\"\r\n className=\"absolute top-0 -translate-x-1/2\"\r\n style={{ left: `${valueOffset(latest, domain) * 100}%` }}\r\n >\r\n <div className=\"h-2 w-0.5 rounded-full bg-foreground\" />\r\n </div>\r\n )}\r\n </div>\r\n <div\r\n data-testid=\"sensor-legend-ramp\"\r\n aria-hidden=\"true\"\r\n className=\"h-2.5 w-full rounded-full\"\r\n style={{ background: gradient }}\r\n />\r\n <div className=\"mt-1 flex justify-between text-[10px] tabular-nums text-muted-foreground\">\r\n <span>{format.format(domain.min)}</span>\r\n <span>{format.format((domain.min + domain.max) / 2)}</span>\r\n <span>{format.format(domain.max)}</span>\r\n </div>\r\n </div>\r\n )}\r\n </div>\r\n </LegendCard>\r\n )\r\n}\r\n"],"mappings":";AAwIQ,SAQE,KARF;AAnIR,YAAY,QAAQ;AACpB,SAAS,uBAAuB;AAChC,YAAY,WAAW;AAEvB,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,cAAc;AACvB;AA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,WAAU,YAEb;AAAA,8BAAC,SAAI,WAAU,gBACZ,wBACC;AAAA,YAAC;AAAA;AAAA,cACC,eAAY;AAAA,cACZ,WAAU;AAAA,cACV,OAAO,EAAE,MAAM,GAAG,YAAY,QAAQ,MAAM,IAAI,GAAG,IAAI;AAAA,cAEvD,8BAAC,SAAI,WAAU,wCAAuC;AAAA;AAAA,UACxD,GAEJ;AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACC,eAAY;AAAA,cACZ,eAAY;AAAA,cACZ,WAAU;AAAA,cACV,OAAO,EAAE,YAAY,SAAS;AAAA;AAAA,UAChC;AAAA,UACA,qBAAC,SAAI,WAAU,4EACb;AAAA,gCAAC,UAAM,iBAAO,OAAO,OAAO,GAAG,GAAE;AAAA,YACjC,oBAAC,UAAM,iBAAO,QAAQ,OAAO,MAAM,OAAO,OAAO,CAAC,GAAE;AAAA,YACpD,oBAAC,UAAM,iBAAO,OAAO,OAAO,GAAG,GAAE;AAAA,aACnC;AAAA,WACF;AAAA,SAEJ;AAAA;AAAA,EACF;AAEJ;","names":[]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { type RangeBounds } from './sensorRange';
|
|
2
3
|
import type { SensorSeries } from './sensorData';
|
|
3
4
|
export interface MultiSeriesEntry {
|
|
4
5
|
id: number;
|
|
@@ -10,17 +11,22 @@ interface SensorMultiSeriesChartProps {
|
|
|
10
11
|
focusedId: number;
|
|
11
12
|
/** Click a line or a legend row to focus that sensor everywhere. */
|
|
12
13
|
onFocus: (sensorId: number) => void;
|
|
13
|
-
/** Colour for the focused line. Siblings are
|
|
14
|
-
|
|
14
|
+
/** Colour for the focused line, carrying its current value. Siblings are not coloured. */
|
|
15
|
+
focusColour: string;
|
|
15
16
|
unit?: string;
|
|
16
17
|
valueLabels?: Record<number, string>;
|
|
17
18
|
timeZone: string;
|
|
18
19
|
emptyText: string;
|
|
19
20
|
othersLabel: (count: number) => string;
|
|
21
|
+
/** Window to show. `null` spans everything. Ignored unless `onBoundsChange` is supplied. */
|
|
22
|
+
bounds?: RangeBounds | null;
|
|
23
|
+
/** Supplying this renders the brush. Dragging it reports the new window in milliseconds. */
|
|
24
|
+
onBoundsChange?: (bounds: RangeBounds) => void;
|
|
20
25
|
}
|
|
21
26
|
/**
|
|
22
27
|
* Every sensor in scope over time, using the emphasis pattern: the focused sensor is the only
|
|
23
|
-
* coloured line and the rest are recessive hairlines.
|
|
28
|
+
* coloured line and the rest are recessive hairlines. That one colour is the focused sensor's
|
|
29
|
+
* own value ramp colour, so the line matches its bar, its halo and the legend caret.
|
|
24
30
|
*
|
|
25
31
|
* Why not a colour per sensor: a type can hold dozens of sensors, and past a handful of hues
|
|
26
32
|
* adjacent series stop being distinguishable (especially under colour-vision deficiency). Here
|
|
@@ -28,6 +34,6 @@ interface SensorMultiSeriesChartProps {
|
|
|
28
34
|
* colour, so it holds at any series count. Clicking a line or a legend row re-focuses, which
|
|
29
35
|
* also moves the marker halos and the viewer legend.
|
|
30
36
|
*/
|
|
31
|
-
export declare function SensorMultiSeriesChart({ sensors, seriesById, focusedId, onFocus,
|
|
37
|
+
export declare function SensorMultiSeriesChart({ sensors, seriesById, focusedId, onFocus, focusColour, unit, valueLabels, timeZone, emptyText, othersLabel, bounds, onBoundsChange, }: SensorMultiSeriesChartProps): React.ReactElement;
|
|
32
38
|
export {};
|
|
33
39
|
//# sourceMappingURL=SensorMultiSeriesChart.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SensorMultiSeriesChart.d.ts","sourceRoot":"","sources":["../../../../../src/core/components/ui/Sensors/SensorMultiSeriesChart.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"SensorMultiSeriesChart.d.ts","sourceRoot":"","sources":["../../../../../src/core/components/ui/Sensors/SensorMultiSeriesChart.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,MA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ianGrid, Line, LineChart, Tooltip, XAxis, YAxis } from "recharts";
|
|
4
|
+
import { Brush, CartesianGrid, Line, LineChart, Tooltip, XAxis, YAxis } from "recharts";
|
|
5
5
|
import { formatInZone } from "../../../utils/timeUtils";
|
|
6
6
|
import { ChartContainer } from "../chart";
|
|
7
|
+
import { indicesForBounds } from "./sensorRange";
|
|
7
8
|
import { mergeSeriesRows, rowsValueDomain } from "./sensorSeriesRows";
|
|
8
9
|
const TOOLTIP_LIMIT = 8;
|
|
9
10
|
const valueNumber = new Intl.NumberFormat(void 0, { maximumFractionDigits: 1 });
|
|
@@ -18,7 +19,13 @@ function SeriesTooltip({
|
|
|
18
19
|
othersLabel
|
|
19
20
|
}) {
|
|
20
21
|
if (!active || !(payload == null ? void 0 : payload.length)) return null;
|
|
21
|
-
const
|
|
22
|
+
const seen = /* @__PURE__ */ new Set();
|
|
23
|
+
const entries = payload.filter((p) => typeof p.value === "number").filter((p) => {
|
|
24
|
+
const key = String(p.dataKey);
|
|
25
|
+
if (seen.has(key)) return false;
|
|
26
|
+
seen.add(key);
|
|
27
|
+
return true;
|
|
28
|
+
}).sort((a, b) => Number(b.value) - Number(a.value));
|
|
22
29
|
const shown = entries.slice(0, TOOLTIP_LIMIT);
|
|
23
30
|
const hidden = entries.length - shown.length;
|
|
24
31
|
return /* @__PURE__ */ jsxs("div", { className: "rounded-md border bg-background px-2.5 py-1.5 text-xs shadow-md", children: [
|
|
@@ -45,12 +52,14 @@ function SensorMultiSeriesChart({
|
|
|
45
52
|
seriesById,
|
|
46
53
|
focusedId,
|
|
47
54
|
onFocus,
|
|
48
|
-
|
|
55
|
+
focusColour,
|
|
49
56
|
unit,
|
|
50
57
|
valueLabels,
|
|
51
58
|
timeZone,
|
|
52
59
|
emptyText,
|
|
53
|
-
othersLabel
|
|
60
|
+
othersLabel,
|
|
61
|
+
bounds = null,
|
|
62
|
+
onBoundsChange
|
|
54
63
|
}) {
|
|
55
64
|
const [hoveredId, setHoveredId] = React.useState(null);
|
|
56
65
|
const ids = sensors.map((s) => s.id);
|
|
@@ -64,6 +73,7 @@ function SensorMultiSeriesChart({
|
|
|
64
73
|
var _a;
|
|
65
74
|
return (_a = valueLabels == null ? void 0 : valueLabels[value]) != null ? _a : `${valueNumber.format(value)}${unit ? ` ${unit}` : ""}`;
|
|
66
75
|
};
|
|
76
|
+
const formatAxis = (value) => formatInZone(Number(value), timeZone, { hour: "2-digit", minute: "2-digit", hourCycle: "h23" });
|
|
67
77
|
const renderTooltip = /* @__PURE__ */ jsx(
|
|
68
78
|
SeriesTooltip,
|
|
69
79
|
{
|
|
@@ -78,8 +88,17 @@ function SensorMultiSeriesChart({
|
|
|
78
88
|
return /* @__PURE__ */ jsx("div", { className: "flex h-[260px] items-center justify-center text-sm text-muted-foreground", children: emptyText });
|
|
79
89
|
}
|
|
80
90
|
const yDomain = valueDomain ? valueDomain.max > valueDomain.min ? [valueDomain.min, valueDomain.max] : [valueDomain.min - 1, valueDomain.max + 1] : void 0;
|
|
91
|
+
const showBrush = onBoundsChange != null && rows.length > 1;
|
|
92
|
+
const brushRange = showBrush ? indicesForBounds(rows, bounds) : null;
|
|
93
|
+
const reportBounds = (range) => {
|
|
94
|
+
var _a, _b, _c, _d;
|
|
95
|
+
const from = (_b = rows[(_a = range.startIndex) != null ? _a : 0]) == null ? void 0 : _b.t;
|
|
96
|
+
const to = (_d = rows[(_c = range.endIndex) != null ? _c : rows.length - 1]) == null ? void 0 : _d.t;
|
|
97
|
+
if (from == null || to == null) return;
|
|
98
|
+
onBoundsChange == null ? void 0 : onBoundsChange({ from, to });
|
|
99
|
+
};
|
|
81
100
|
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 sm:flex-row", children: [
|
|
82
|
-
/* @__PURE__ */ jsx("div", { className: "min-w-0 flex-1", children: /* @__PURE__ */ jsx(ChartContainer, { config: chartConfig, className: "h-[
|
|
101
|
+
/* @__PURE__ */ jsx("div", { className: "min-w-0 flex-1", children: /* @__PURE__ */ jsx(ChartContainer, { config: chartConfig, className: `w-full ${showBrush ? "h-[300px]" : "h-[260px]"}`, children: /* @__PURE__ */ jsxs(LineChart, { data: rows, margin: { left: 0, right: 12, top: 10 }, children: [
|
|
83
102
|
/* @__PURE__ */ jsx(CartesianGrid, { vertical: false, opacity: 0.4 }),
|
|
84
103
|
/* @__PURE__ */ jsx(
|
|
85
104
|
YAxis,
|
|
@@ -108,10 +127,30 @@ function SensorMultiSeriesChart({
|
|
|
108
127
|
tickMargin: 8,
|
|
109
128
|
interval: "preserveStartEnd",
|
|
110
129
|
tick: { fontSize: 11 },
|
|
111
|
-
tickFormatter:
|
|
130
|
+
tickFormatter: formatAxis
|
|
112
131
|
}
|
|
113
132
|
),
|
|
114
133
|
/* @__PURE__ */ jsx(Tooltip, { content: renderTooltip }),
|
|
134
|
+
sensors.map((sensor) => /* @__PURE__ */ jsx(
|
|
135
|
+
Line,
|
|
136
|
+
{
|
|
137
|
+
dataKey: String(sensor.id),
|
|
138
|
+
type: "monotone",
|
|
139
|
+
stroke: "transparent",
|
|
140
|
+
strokeWidth: 12,
|
|
141
|
+
dot: false,
|
|
142
|
+
activeDot: false,
|
|
143
|
+
connectNulls: true,
|
|
144
|
+
isAnimationActive: false,
|
|
145
|
+
legendType: "none",
|
|
146
|
+
tooltipType: "none",
|
|
147
|
+
onClick: () => onFocus(sensor.id),
|
|
148
|
+
onMouseEnter: () => setHoveredId(sensor.id),
|
|
149
|
+
onMouseLeave: () => setHoveredId(null),
|
|
150
|
+
style: { pointerEvents: "stroke", cursor: "pointer" }
|
|
151
|
+
},
|
|
152
|
+
`hit-${sensor.id}`
|
|
153
|
+
)),
|
|
115
154
|
sensors.map((sensor) => {
|
|
116
155
|
const isFocused = sensor.id === focusedId;
|
|
117
156
|
const isHovered = sensor.id === hoveredId;
|
|
@@ -121,7 +160,7 @@ function SensorMultiSeriesChart({
|
|
|
121
160
|
dataKey: String(sensor.id),
|
|
122
161
|
name: sensor.name,
|
|
123
162
|
type: "monotone",
|
|
124
|
-
stroke: isFocused ?
|
|
163
|
+
stroke: isFocused ? focusColour : "hsl(var(--muted-foreground))",
|
|
125
164
|
strokeWidth: isFocused ? 2 : isHovered ? 2 : 1,
|
|
126
165
|
strokeOpacity: isFocused ? 1 : isHovered ? 0.9 : 0.35,
|
|
127
166
|
strokeLinecap: "round",
|
|
@@ -135,7 +174,19 @@ function SensorMultiSeriesChart({
|
|
|
135
174
|
},
|
|
136
175
|
sensor.id
|
|
137
176
|
);
|
|
138
|
-
})
|
|
177
|
+
}),
|
|
178
|
+
showBrush && brushRange && /* @__PURE__ */ jsx(
|
|
179
|
+
Brush,
|
|
180
|
+
{
|
|
181
|
+
dataKey: "t",
|
|
182
|
+
height: 22,
|
|
183
|
+
travellerWidth: 8,
|
|
184
|
+
startIndex: brushRange.startIndex,
|
|
185
|
+
endIndex: brushRange.endIndex,
|
|
186
|
+
tickFormatter: (value) => formatAxis(Number(value)),
|
|
187
|
+
onChange: (range) => reportBounds(range)
|
|
188
|
+
}
|
|
189
|
+
)
|
|
139
190
|
] }) }) }),
|
|
140
191
|
/* @__PURE__ */ jsx("ul", { className: "max-h-[260px] shrink-0 overflow-y-auto sm:w-44", children: sensors.map((sensor) => {
|
|
141
192
|
const isFocused = sensor.id === focusedId;
|
|
@@ -155,7 +206,7 @@ function SensorMultiSeriesChart({
|
|
|
155
206
|
"aria-hidden": "true",
|
|
156
207
|
className: "h-0.5 w-3 shrink-0 rounded-full",
|
|
157
208
|
style: {
|
|
158
|
-
backgroundColor: isFocused ?
|
|
209
|
+
backgroundColor: isFocused ? focusColour : "hsl(var(--muted-foreground))",
|
|
159
210
|
opacity: isFocused ? 1 : 0.5
|
|
160
211
|
}
|
|
161
212
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/core/components/ui/Sensors/SensorMultiSeriesChart.tsx"],"sourcesContent":["'use client'\r\n\r\n// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport * as React from 'react'\r\nimport { CartesianGrid, Line, LineChart, Tooltip, XAxis, YAxis } from 'recharts'\r\n\r\nimport { formatInZone } from '../../../utils/timeUtils'\r\nimport { ChartContainer, type ChartConfig } from '../chart'\r\n\r\nimport { mergeSeriesRows, rowsValueDomain } from './sensorSeriesRows'\r\n\r\nimport type { SensorSeries } from './sensorData'\r\n\r\n/** How many series the tooltip lists before collapsing the tail into a count. */\r\nconst TOOLTIP_LIMIT = 8\r\n\r\nconst valueNumber = new Intl.NumberFormat(undefined, { maximumFractionDigits: 1 })\r\n\r\nexport interface MultiSeriesEntry {\r\n id: number\r\n name: string\r\n}\r\n\r\ninterface TooltipPayloadEntry {\r\n dataKey?: string | number | ((obj: unknown) => unknown)\r\n value?: unknown\r\n}\r\n\r\ninterface SeriesTooltipProps {\r\n active?: boolean\r\n payload?: TooltipPayloadEntry[]\r\n label?: unknown\r\n nameById: Map<number, string>\r\n focusedId: number\r\n timeZone: string\r\n formatValue: (value: number) => string\r\n othersLabel: (count: number) => string\r\n}\r\n\r\n/**\r\n * Declared at module scope, not inline in the chart: a component defined during render is a new\r\n * type on every pass, so React would tear down and rebuild the tooltip subtree each time.\r\n */\r\nfunction SeriesTooltip({\r\n active,\r\n payload,\r\n label,\r\n nameById,\r\n focusedId,\r\n timeZone,\r\n formatValue,\r\n othersLabel,\r\n}: SeriesTooltipProps): React.ReactElement | null {\r\n if (!active || !payload?.length) return null\r\n const entries = payload\r\n .filter(p => typeof p.value === 'number')\r\n .sort((a, b) => Number(b.value) - Number(a.value))\r\n const shown = entries.slice(0, TOOLTIP_LIMIT)\r\n const hidden = entries.length - shown.length\r\n\r\n return (\r\n <div className=\"rounded-md border bg-background px-2.5 py-1.5 text-xs shadow-md\">\r\n <div className=\"mb-1 font-medium\">\r\n {formatInZone(Number(label), timeZone, {\r\n month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit', hourCycle: 'h23',\r\n })}\r\n </div>\r\n {shown.map(p => {\r\n const id = Number(p.dataKey)\r\n return (\r\n <div key={String(p.dataKey)} className=\"flex items-baseline justify-between gap-3\">\r\n <span className={id === focusedId ? 'font-medium' : 'text-muted-foreground'}>\r\n {nameById.get(id) ?? String(p.dataKey)}\r\n </span>\r\n <span className=\"tabular-nums\">{formatValue(Number(p.value))}</span>\r\n </div>\r\n )\r\n })}\r\n {hidden > 0 && <div className=\"mt-1 text-muted-foreground\">{othersLabel(hidden)}</div>}\r\n </div>\r\n )\r\n}\r\n\r\ninterface SensorMultiSeriesChartProps {\r\n sensors: MultiSeriesEntry[]\r\n seriesById: Map<number, SensorSeries>\r\n focusedId: number\r\n /** Click a line or a legend row to focus that sensor everywhere. */\r\n onFocus: (sensorId: number) => void\r\n /** Colour for the focused line. Siblings are deliberately not coloured. */\r\n accentColour: string\r\n unit?: string\r\n valueLabels?: Record<number, string>\r\n timeZone: string\r\n emptyText: string\r\n othersLabel: (count: number) => string\r\n}\r\n\r\n/**\r\n * Every sensor in scope over time, using the emphasis pattern: the focused sensor is the only\r\n * coloured line and the rest are recessive hairlines.\r\n *\r\n * Why not a colour per sensor: a type can hold dozens of sensors, and past a handful of hues\r\n * adjacent series stop being distinguishable (especially under colour-vision deficiency). Here\r\n * identity comes from the legend list, the hover lift and the shared tooltip rather than from\r\n * colour, so it holds at any series count. Clicking a line or a legend row re-focuses, which\r\n * also moves the marker halos and the viewer legend.\r\n */\r\nexport function SensorMultiSeriesChart({\r\n sensors,\r\n seriesById,\r\n focusedId,\r\n onFocus,\r\n accentColour,\r\n unit,\r\n valueLabels,\r\n timeZone,\r\n emptyText,\r\n othersLabel,\r\n}: SensorMultiSeriesChartProps): React.ReactElement {\r\n const [hoveredId, setHoveredId] = React.useState<number | null>(null)\r\n\r\n const ids = sensors.map(s => s.id)\r\n const rows = React.useMemo(() => mergeSeriesRows(seriesById, ids), [seriesById, ids.join(',')])\r\n const valueDomain = rowsValueDomain(rows, ids)\r\n const nameById = new Map(sensors.map(s => [s.id, s.name]))\r\n\r\n // ChartContainer needs a config entry per key to size its CSS vars; colours come from the\r\n // Line props instead, since they depend on focus rather than identity.\r\n const chartConfig: ChartConfig = Object.fromEntries(\r\n sensors.map(s => [String(s.id), { label: s.name }]),\r\n )\r\n\r\n const formatValue = (value: number): string =>\r\n valueLabels?.[value] ?? `${valueNumber.format(value)}${unit ? ` ${unit}` : ''}`\r\n\r\n // Recharts renders `content` itself, so pass an element carrying the extra props; it merges\r\n // its own active/payload/label in.\r\n const renderTooltip = (\r\n <SeriesTooltip\r\n nameById={nameById}\r\n focusedId={focusedId}\r\n timeZone={timeZone}\r\n formatValue={formatValue}\r\n othersLabel={othersLabel}\r\n />\r\n )\r\n\r\n if (rows.length === 0) {\r\n return <div className=\"flex h-[260px] items-center justify-center text-sm text-muted-foreground\">{emptyText}</div>\r\n }\r\n\r\n const yDomain: [number, number] | undefined = valueDomain\r\n ? valueDomain.max > valueDomain.min\r\n ? [valueDomain.min, valueDomain.max]\r\n : [valueDomain.min - 1, valueDomain.max + 1]\r\n : undefined\r\n\r\n return (\r\n <div className=\"flex flex-col gap-3 sm:flex-row\">\r\n <div className=\"min-w-0 flex-1\">\r\n <ChartContainer config={chartConfig} className=\"h-[260px] w-full\">\r\n <LineChart data={rows} margin={{ left: 0, right: 12, top: 10 }}>\r\n <CartesianGrid vertical={false} opacity={0.4} />\r\n <YAxis\r\n domain={yDomain}\r\n tickLine={false}\r\n axisLine={false}\r\n width={44}\r\n tickMargin={4}\r\n tick={{ fontSize: 11 }}\r\n tickFormatter={(value: number) => valueLabels?.[value] ?? valueNumber.format(value)}\r\n />\r\n <XAxis\r\n dataKey=\"t\"\r\n type=\"number\"\r\n scale=\"time\"\r\n domain={['dataMin', 'dataMax']}\r\n tickLine={false}\r\n axisLine={false}\r\n tickMargin={8}\r\n interval=\"preserveStartEnd\"\r\n tick={{ fontSize: 11 }}\r\n tickFormatter={(value: number) =>\r\n formatInZone(Number(value), timeZone, { hour: '2-digit', minute: '2-digit', hourCycle: 'h23' })}\r\n />\r\n {/* One crosshair readout listing every series, so the pointer never has to land on\r\n a specific 1px line to read a value. */}\r\n <Tooltip content={renderTooltip} />\r\n {sensors.map(sensor => {\r\n const isFocused = sensor.id === focusedId\r\n const isHovered = sensor.id === hoveredId\r\n return (\r\n <Line\r\n key={sensor.id}\r\n dataKey={String(sensor.id)}\r\n name={sensor.name}\r\n type=\"monotone\"\r\n // Colour marks focus, never identity: see the component doc.\r\n stroke={isFocused ? accentColour : 'hsl(var(--muted-foreground))'}\r\n strokeWidth={isFocused ? 2 : isHovered ? 2 : 1}\r\n strokeOpacity={isFocused ? 1 : isHovered ? 0.9 : 0.35}\r\n strokeLinecap=\"round\"\r\n strokeLinejoin=\"round\"\r\n dot={false}\r\n activeDot={{ r: 4 }}\r\n connectNulls\r\n isAnimationActive={false}\r\n onClick={() => onFocus(sensor.id)}\r\n style={{ cursor: 'pointer' }}\r\n />\r\n )\r\n })}\r\n </LineChart>\r\n </ChartContainer>\r\n </div>\r\n\r\n {/* The dependable identity channel: names, not colours. */}\r\n <ul className=\"max-h-[260px] shrink-0 overflow-y-auto sm:w-44\">\r\n {sensors.map(sensor => {\r\n const isFocused = sensor.id === focusedId\r\n return (\r\n <li key={sensor.id}>\r\n <button\r\n type=\"button\"\r\n onClick={() => onFocus(sensor.id)}\r\n onMouseEnter={() => setHoveredId(sensor.id)}\r\n onMouseLeave={() => setHoveredId(null)}\r\n aria-current={isFocused}\r\n className={`flex w-full items-center gap-2 rounded px-2 py-1 text-left text-xs hover:bg-accent ${\r\n isFocused ? 'font-medium' : 'text-muted-foreground'\r\n }`}\r\n >\r\n <span\r\n aria-hidden=\"true\"\r\n className=\"h-0.5 w-3 shrink-0 rounded-full\"\r\n style={{\r\n backgroundColor: isFocused ? accentColour : 'hsl(var(--muted-foreground))',\r\n opacity: isFocused ? 1 : 0.5,\r\n }}\r\n />\r\n <span className=\"truncate\">{sensor.name}</span>\r\n </button>\r\n </li>\r\n )\r\n })}\r\n </ul>\r\n </div>\r\n )\r\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,GAAG,EAAE;AAAA,YAClB,cAAY;AAAA,YACZ,mBAAmB;AAAA,YACnB,SAAS,MAAM,QAAQ,OAAO,EAAE;AAAA,YAChC,OAAO,EAAE,QAAQ,UAAU;AAAA;AAAA,UAftB,OAAO;AAAA,QAgBd;AAAA,MAEJ,CAAC;AAAA,OACH,GACF,GACF;AAAA,IAGA,oBAAC,QAAG,WAAU,kDACX,kBAAQ,IAAI,YAAU;AACrB,YAAM,YAAY,OAAO,OAAO;AAChC,aACE,oBAAC,QACC;AAAA,QAAC;AAAA;AAAA,UACC,MAAK;AAAA,UACL,SAAS,MAAM,QAAQ,OAAO,EAAE;AAAA,UAChC,cAAc,MAAM,aAAa,OAAO,EAAE;AAAA,UAC1C,cAAc,MAAM,aAAa,IAAI;AAAA,UACrC,gBAAc;AAAA,UACd,WAAW,sFACT,YAAY,gBAAgB,uBAC9B;AAAA,UAEA;AAAA;AAAA,cAAC;AAAA;AAAA,gBACC,eAAY;AAAA,gBACZ,WAAU;AAAA,gBACV,OAAO;AAAA,kBACL,iBAAiB,YAAY,eAAe;AAAA,kBAC5C,SAAS,YAAY,IAAI;AAAA,gBAC3B;AAAA;AAAA,YACF;AAAA,YACA,oBAAC,UAAK,WAAU,YAAY,iBAAO,MAAK;AAAA;AAAA;AAAA,MAC1C,KApBO,OAAO,EAqBhB;AAAA,IAEJ,CAAC,GACH;AAAA,KACF;AAEJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/core/components/ui/Sensors/SensorMultiSeriesChart.tsx"],"sourcesContent":["'use client'\r\n\r\n// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport * as React from 'react'\r\nimport { Brush, CartesianGrid, Line, LineChart, Tooltip, XAxis, YAxis } from 'recharts'\r\n\r\nimport { formatInZone } from '../../../utils/timeUtils'\r\nimport { ChartContainer, type ChartConfig } from '../chart'\r\n\r\nimport { indicesForBounds, type RangeBounds } from './sensorRange'\r\nimport { mergeSeriesRows, rowsValueDomain } from './sensorSeriesRows'\r\n\r\nimport type { SensorSeries } from './sensorData'\r\n\r\n/** How many series the tooltip lists before collapsing the tail into a count. */\r\nconst TOOLTIP_LIMIT = 8\r\n\r\nconst valueNumber = new Intl.NumberFormat(undefined, { maximumFractionDigits: 1 })\r\n\r\nexport interface MultiSeriesEntry {\r\n id: number\r\n name: string\r\n}\r\n\r\ninterface TooltipPayloadEntry {\r\n dataKey?: string | number | ((obj: unknown) => unknown)\r\n value?: unknown\r\n}\r\n\r\ninterface SeriesTooltipProps {\r\n active?: boolean\r\n payload?: TooltipPayloadEntry[]\r\n label?: unknown\r\n nameById: Map<number, string>\r\n focusedId: number\r\n timeZone: string\r\n formatValue: (value: number) => string\r\n othersLabel: (count: number) => string\r\n}\r\n\r\n/**\r\n * Declared at module scope, not inline in the chart: a component defined during render is a new\r\n * type on every pass, so React would tear down and rebuild the tooltip subtree each time.\r\n */\r\nfunction SeriesTooltip({\r\n active,\r\n payload,\r\n label,\r\n nameById,\r\n focusedId,\r\n timeZone,\r\n formatValue,\r\n othersLabel,\r\n}: SeriesTooltipProps): React.ReactElement | null {\r\n if (!active || !payload?.length) return null\r\n // Each series is drawn twice, once as an invisible wide hit target, so recharts hands us two\r\n // payload entries per sensor. Keep the first of each dataKey.\r\n const seen = new Set<string>()\r\n const entries = payload\r\n .filter(p => typeof p.value === 'number')\r\n .filter(p => {\r\n const key = String(p.dataKey)\r\n if (seen.has(key)) return false\r\n seen.add(key)\r\n return true\r\n })\r\n .sort((a, b) => Number(b.value) - Number(a.value))\r\n const shown = entries.slice(0, TOOLTIP_LIMIT)\r\n const hidden = entries.length - shown.length\r\n\r\n return (\r\n <div className=\"rounded-md border bg-background px-2.5 py-1.5 text-xs shadow-md\">\r\n <div className=\"mb-1 font-medium\">\r\n {formatInZone(Number(label), timeZone, {\r\n month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit', hourCycle: 'h23',\r\n })}\r\n </div>\r\n {shown.map(p => {\r\n const id = Number(p.dataKey)\r\n return (\r\n <div key={String(p.dataKey)} className=\"flex items-baseline justify-between gap-3\">\r\n <span className={id === focusedId ? 'font-medium' : 'text-muted-foreground'}>\r\n {nameById.get(id) ?? String(p.dataKey)}\r\n </span>\r\n <span className=\"tabular-nums\">{formatValue(Number(p.value))}</span>\r\n </div>\r\n )\r\n })}\r\n {hidden > 0 && <div className=\"mt-1 text-muted-foreground\">{othersLabel(hidden)}</div>}\r\n </div>\r\n )\r\n}\r\n\r\ninterface SensorMultiSeriesChartProps {\r\n sensors: MultiSeriesEntry[]\r\n seriesById: Map<number, SensorSeries>\r\n focusedId: number\r\n /** Click a line or a legend row to focus that sensor everywhere. */\r\n onFocus: (sensorId: number) => void\r\n /** Colour for the focused line, carrying its current value. Siblings are not coloured. */\r\n focusColour: string\r\n unit?: string\r\n valueLabels?: Record<number, string>\r\n timeZone: string\r\n emptyText: string\r\n othersLabel: (count: number) => string\r\n /** Window to show. `null` spans everything. Ignored unless `onBoundsChange` is supplied. */\r\n bounds?: RangeBounds | null\r\n /** Supplying this renders the brush. Dragging it reports the new window in milliseconds. */\r\n onBoundsChange?: (bounds: RangeBounds) => void\r\n}\r\n\r\n/**\r\n * Every sensor in scope over time, using the emphasis pattern: the focused sensor is the only\r\n * coloured line and the rest are recessive hairlines. That one colour is the focused sensor's\r\n * own value ramp colour, so the line matches its bar, its halo and the legend caret.\r\n *\r\n * Why not a colour per sensor: a type can hold dozens of sensors, and past a handful of hues\r\n * adjacent series stop being distinguishable (especially under colour-vision deficiency). Here\r\n * identity comes from the legend list, the hover lift and the shared tooltip rather than from\r\n * colour, so it holds at any series count. Clicking a line or a legend row re-focuses, which\r\n * also moves the marker halos and the viewer legend.\r\n */\r\nexport function SensorMultiSeriesChart({\r\n sensors,\r\n seriesById,\r\n focusedId,\r\n onFocus,\r\n focusColour,\r\n unit,\r\n valueLabels,\r\n timeZone,\r\n emptyText,\r\n othersLabel,\r\n bounds = null,\r\n onBoundsChange,\r\n}: SensorMultiSeriesChartProps): React.ReactElement {\r\n const [hoveredId, setHoveredId] = React.useState<number | null>(null)\r\n\r\n const ids = sensors.map(s => s.id)\r\n const rows = React.useMemo(() => mergeSeriesRows(seriesById, ids), [seriesById, ids.join(',')])\r\n const valueDomain = rowsValueDomain(rows, ids)\r\n const nameById = new Map(sensors.map(s => [s.id, s.name]))\r\n\r\n // ChartContainer needs a config entry per key to size its CSS vars; colours come from the\r\n // Line props instead, since they depend on focus rather than identity.\r\n const chartConfig: ChartConfig = Object.fromEntries(\r\n sensors.map(s => [String(s.id), { label: s.name }]),\r\n )\r\n\r\n const formatValue = (value: number): string =>\r\n valueLabels?.[value] ?? `${valueNumber.format(value)}${unit ? ` ${unit}` : ''}`\r\n\r\n const formatAxis = (value: number): string =>\r\n formatInZone(Number(value), timeZone, { hour: '2-digit', minute: '2-digit', hourCycle: 'h23' })\r\n\r\n // Recharts renders `content` itself, so pass an element carrying the extra props; it merges\r\n // its own active/payload/label in.\r\n const renderTooltip = (\r\n <SeriesTooltip\r\n nameById={nameById}\r\n focusedId={focusedId}\r\n timeZone={timeZone}\r\n formatValue={formatValue}\r\n othersLabel={othersLabel}\r\n />\r\n )\r\n\r\n if (rows.length === 0) {\r\n return <div className=\"flex h-[260px] items-center justify-center text-sm text-muted-foreground\">{emptyText}</div>\r\n }\r\n\r\n const yDomain: [number, number] | undefined = valueDomain\r\n ? valueDomain.max > valueDomain.min\r\n ? [valueDomain.min, valueDomain.max]\r\n : [valueDomain.min - 1, valueDomain.max + 1]\r\n : undefined\r\n\r\n // The brush windows the merged rows, so a preset picked upstream and a drag down here are the\r\n // same operation expressed in two units: the caller works in times, recharts in row indices.\r\n const showBrush = onBoundsChange != null && rows.length > 1\r\n const brushRange = showBrush ? indicesForBounds(rows, bounds) : null\r\n const reportBounds = (range: { startIndex?: number; endIndex?: number }) => {\r\n const from = rows[range.startIndex ?? 0]?.t\r\n const to = rows[range.endIndex ?? rows.length - 1]?.t\r\n if (from == null || to == null) return\r\n onBoundsChange?.({ from, to })\r\n }\r\n\r\n return (\r\n <div className=\"flex flex-col gap-3 sm:flex-row\">\r\n <div className=\"min-w-0 flex-1\">\r\n <ChartContainer config={chartConfig} className={`w-full ${showBrush ? 'h-[300px]' : 'h-[260px]'}`}>\r\n <LineChart data={rows} margin={{ left: 0, right: 12, top: 10 }}>\r\n <CartesianGrid vertical={false} opacity={0.4} />\r\n <YAxis\r\n domain={yDomain}\r\n tickLine={false}\r\n axisLine={false}\r\n width={44}\r\n tickMargin={4}\r\n tick={{ fontSize: 11 }}\r\n tickFormatter={(value: number) => valueLabels?.[value] ?? valueNumber.format(value)}\r\n />\r\n <XAxis\r\n dataKey=\"t\"\r\n type=\"number\"\r\n scale=\"time\"\r\n domain={['dataMin', 'dataMax']}\r\n tickLine={false}\r\n axisLine={false}\r\n tickMargin={8}\r\n interval=\"preserveStartEnd\"\r\n tick={{ fontSize: 11 }}\r\n tickFormatter={formatAxis}\r\n />\r\n {/* One crosshair readout listing every series, so the pointer never has to land on\r\n a specific 1px line to read a value. */}\r\n <Tooltip content={renderTooltip} />\r\n {/* Transparent fat copies of every series, drawn under the real ones: a recessive\r\n line is a 1px path and all but unclickable, so this is what actually catches the\r\n pointer. `pointerEvents: stroke` hit-tests the widened stroke, not the fill. */}\r\n {sensors.map(sensor => (\r\n <Line\r\n key={`hit-${sensor.id}`}\r\n dataKey={String(sensor.id)}\r\n type=\"monotone\"\r\n stroke=\"transparent\"\r\n strokeWidth={12}\r\n dot={false}\r\n activeDot={false}\r\n connectNulls\r\n isAnimationActive={false}\r\n legendType=\"none\"\r\n tooltipType=\"none\"\r\n onClick={() => onFocus(sensor.id)}\r\n onMouseEnter={() => setHoveredId(sensor.id)}\r\n onMouseLeave={() => setHoveredId(null)}\r\n style={{ pointerEvents: 'stroke', cursor: 'pointer' }}\r\n />\r\n ))}\r\n {sensors.map(sensor => {\r\n const isFocused = sensor.id === focusedId\r\n const isHovered = sensor.id === hoveredId\r\n return (\r\n <Line\r\n key={sensor.id}\r\n dataKey={String(sensor.id)}\r\n name={sensor.name}\r\n type=\"monotone\"\r\n // Colour marks focus, never identity: see the component doc.\r\n stroke={isFocused ? focusColour : 'hsl(var(--muted-foreground))'}\r\n strokeWidth={isFocused ? 2 : isHovered ? 2 : 1}\r\n strokeOpacity={isFocused ? 1 : isHovered ? 0.9 : 0.35}\r\n strokeLinecap=\"round\"\r\n strokeLinejoin=\"round\"\r\n dot={false}\r\n activeDot={{ r: 4 }}\r\n connectNulls\r\n isAnimationActive={false}\r\n onClick={() => onFocus(sensor.id)}\r\n style={{ cursor: 'pointer' }}\r\n />\r\n )\r\n })}\r\n {showBrush && brushRange && (\r\n <Brush\r\n dataKey=\"t\"\r\n height={22}\r\n travellerWidth={8}\r\n startIndex={brushRange.startIndex}\r\n endIndex={brushRange.endIndex}\r\n tickFormatter={(value) => formatAxis(Number(value))}\r\n onChange={(range) => reportBounds(range as { startIndex?: number; endIndex?: number })}\r\n />\r\n )}\r\n </LineChart>\r\n </ChartContainer>\r\n </div>\r\n\r\n {/* The dependable identity channel: names, not colours. */}\r\n <ul className=\"max-h-[260px] shrink-0 overflow-y-auto sm:w-44\">\r\n {sensors.map(sensor => {\r\n const isFocused = sensor.id === focusedId\r\n return (\r\n <li key={sensor.id}>\r\n <button\r\n type=\"button\"\r\n onClick={() => onFocus(sensor.id)}\r\n onMouseEnter={() => setHoveredId(sensor.id)}\r\n onMouseLeave={() => setHoveredId(null)}\r\n aria-current={isFocused}\r\n className={`flex w-full items-center gap-2 rounded px-2 py-1 text-left text-xs hover:bg-accent ${\r\n isFocused ? 'font-medium' : 'text-muted-foreground'\r\n }`}\r\n >\r\n <span\r\n aria-hidden=\"true\"\r\n className=\"h-0.5 w-3 shrink-0 rounded-full\"\r\n style={{\r\n backgroundColor: isFocused ? focusColour : 'hsl(var(--muted-foreground))',\r\n opacity: isFocused ? 1 : 0.5,\r\n }}\r\n />\r\n <span className=\"truncate\">{sensor.name}</span>\r\n </button>\r\n </li>\r\n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Q,OAAO,EAAE;AAAA,YAChC,OAAO,EAAE,QAAQ,UAAU;AAAA;AAAA,UAftB,OAAO;AAAA,QAgBd;AAAA,MAEJ,CAAC;AAAA,MACA,aAAa,cACZ;AAAA,QAAC;AAAA;AAAA,UACC,SAAQ;AAAA,UACR,QAAQ;AAAA,UACR,gBAAgB;AAAA,UAChB,YAAY,WAAW;AAAA,UACvB,UAAU,WAAW;AAAA,UACrB,eAAe,CAAC,UAAU,WAAW,OAAO,KAAK,CAAC;AAAA,UAClD,UAAU,CAAC,UAAU,aAAa,KAAmD;AAAA;AAAA,MACvF;AAAA,OAEJ,GACF,GACF;AAAA,IAGA,oBAAC,QAAG,WAAU,kDACX,kBAAQ,IAAI,YAAU;AACrB,YAAM,YAAY,OAAO,OAAO;AAChC,aACE,oBAAC,QACC;AAAA,QAAC;AAAA;AAAA,UACC,MAAK;AAAA,UACL,SAAS,MAAM,QAAQ,OAAO,EAAE;AAAA,UAChC,cAAc,MAAM,aAAa,OAAO,EAAE;AAAA,UAC1C,cAAc,MAAM,aAAa,IAAI;AAAA,UACrC,gBAAc;AAAA,UACd,WAAW,sFACT,YAAY,gBAAgB,uBAC9B;AAAA,UAEA;AAAA;AAAA,cAAC;AAAA;AAAA,gBACC,eAAY;AAAA,gBACZ,WAAU;AAAA,gBACV,OAAO;AAAA,kBACL,iBAAiB,YAAY,cAAc;AAAA,kBAC3C,SAAS,YAAY,IAAI;AAAA,gBAC3B;AAAA;AAAA,YACF;AAAA,YACA,oBAAC,UAAK,WAAU,YAAY,iBAAO,MAAK;AAAA;AAAA;AAAA,MAC1C,KApBO,OAAO,EAqBhB;AAAA,IAEJ,CAAC,GACH;AAAA,KACF;AAEJ;","names":[]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
export declare const UNTAGGED_TAG = "__untagged__";
|
|
2
|
+
export { UNTAGGED_TAG } from './sensorVisibility';
|
|
4
3
|
export declare function SensorsSection(): React.JSX.Element;
|
|
5
4
|
//# sourceMappingURL=SensorsSection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SensorsSection.d.ts","sourceRoot":"","sources":["../../../../../src/core/components/ui/Sensors/SensorsSection.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"SensorsSection.d.ts","sourceRoot":"","sources":["../../../../../src/core/components/ui/Sensors/SensorsSection.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAuC9B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,wBAAgB,cAAc,sBAsW7B"}
|
|
@@ -26,15 +26,16 @@ import { SensorInput } from "./SensorInput";
|
|
|
26
26
|
import { SensorsSectionSkeleton } from "./SensorsSectionSkeleton";
|
|
27
27
|
import { resolveLucideIcon } from "./sensorUtils";
|
|
28
28
|
import { valueColoursBySensor } from "./sensorValueColours";
|
|
29
|
+
import { activeSensorTypeId, legendScopeSensors, UNTAGGED_TAG } from "./sensorVisibility";
|
|
29
30
|
import { useSensorSeriesMulti } from "./useSensorSeriesMulti";
|
|
30
31
|
const readingNumber = new Intl.NumberFormat(void 0, { maximumFractionDigits: 1 });
|
|
31
|
-
|
|
32
|
+
import { UNTAGGED_TAG as UNTAGGED_TAG2 } from "./sensorVisibility";
|
|
32
33
|
function SensorsSection() {
|
|
33
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
34
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
34
35
|
const t = useTranslations("SensorsSection");
|
|
35
36
|
const { dispatch: toolsDispatch } = React.useContext(ToolsContext);
|
|
36
37
|
const { state: menusState, dispatch: menusDispatch } = React.useContext(MenusContext);
|
|
37
|
-
const { currentViewer, visibleSensorTypes, visibleSensorTags, focusedSensorId } = menusState.menus;
|
|
38
|
+
const { currentViewer, visibleSensorTypes, visibleSensorTags, focusedSensorId, sensorLegendVisible, sensorLegendTypeId } = menusState.menus;
|
|
38
39
|
const { sensors: allSensors } = useSensors();
|
|
39
40
|
const { sensorTypes, isLoading } = useSensorTypes();
|
|
40
41
|
const { state: buildingsState } = React.useContext(BuildingsContext);
|
|
@@ -132,6 +133,22 @@ function SensorsSection() {
|
|
|
132
133
|
menusDispatch({ type: "HIDE_ALL_SENSOR_TAGS_IN_VIEWER", payload: { viewer: currentViewer } });
|
|
133
134
|
}
|
|
134
135
|
}, [currentViewer, menusDispatch]);
|
|
136
|
+
const legendHasContent = legendScopeSensors(
|
|
137
|
+
allSensors,
|
|
138
|
+
{
|
|
139
|
+
viewer: currentViewer,
|
|
140
|
+
visibleTypeIds: (_h = visibleSensorTypes == null ? void 0 : visibleSensorTypes[currentViewer]) != null ? _h : [],
|
|
141
|
+
visibleTags: (_i = visibleSensorTags == null ? void 0 : visibleSensorTags[currentViewer]) != null ? _i : []
|
|
142
|
+
},
|
|
143
|
+
activeSensorTypeId(allSensors, {
|
|
144
|
+
legendTypeId: sensorLegendTypeId == null ? void 0 : sensorLegendTypeId[currentViewer],
|
|
145
|
+
activeSensorId: focusedSensorId
|
|
146
|
+
})
|
|
147
|
+
).length > 0;
|
|
148
|
+
const legendVisible = legendHasContent && (sensorLegendVisible == null ? void 0 : sensorLegendVisible[currentViewer]) !== false;
|
|
149
|
+
const toggleLegend = React.useCallback(() => {
|
|
150
|
+
menusDispatch({ type: "TOGGLE_SENSOR_LEGEND", payload: { viewer: currentViewer } });
|
|
151
|
+
}, [currentViewer, menusDispatch]);
|
|
135
152
|
const toggleSensorTagVisibility = React.useCallback((tag) => {
|
|
136
153
|
menusDispatch({
|
|
137
154
|
type: "TOGGLE_SENSOR_TAG_VISIBILITY",
|
|
@@ -183,6 +200,19 @@ function SensorsSection() {
|
|
|
183
200
|
onChange: (e) => setSearchQuery(e.target.value)
|
|
184
201
|
}
|
|
185
202
|
),
|
|
203
|
+
/* @__PURE__ */ jsx(
|
|
204
|
+
Button,
|
|
205
|
+
{
|
|
206
|
+
variant: legendVisible ? "default" : "outline",
|
|
207
|
+
size: "icon",
|
|
208
|
+
title: t("toggleLegend"),
|
|
209
|
+
"aria-pressed": legendVisible,
|
|
210
|
+
disabled: !legendHasContent,
|
|
211
|
+
className: "flex-shrink-0",
|
|
212
|
+
onClick: toggleLegend,
|
|
213
|
+
children: /* @__PURE__ */ jsx(LR.Palette, { size: 16 })
|
|
214
|
+
}
|
|
215
|
+
),
|
|
186
216
|
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
187
217
|
/* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "outline", size: "icon", title: t("filters"), className: "flex-shrink-0", children: /* @__PURE__ */ jsx(LR.Funnel, { size: 16 }) }) }),
|
|
188
218
|
/* @__PURE__ */ jsxs(DropdownMenuContent, { align: "end", children: [
|
|
@@ -310,6 +340,6 @@ function SensorsSection() {
|
|
|
310
340
|
}
|
|
311
341
|
export {
|
|
312
342
|
SensorsSection,
|
|
313
|
-
UNTAGGED_TAG
|
|
343
|
+
UNTAGGED_TAG2 as UNTAGGED_TAG
|
|
314
344
|
};
|
|
315
345
|
//# sourceMappingURL=SensorsSection.js.map
|