@collabdt/core 0.4.0 → 0.4.3
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/ConfirmDialog.d.ts +2 -1
- package/dist/core/components/ConfirmDialog.d.ts.map +1 -1
- package/dist/core/components/ConfirmDialog.js +8 -0
- package/dist/core/components/ConfirmDialog.js.map +1 -1
- package/dist/core/components/authentication/AuthPage.d.ts.map +1 -1
- package/dist/core/components/authentication/AuthPage.js +1 -2
- package/dist/core/components/authentication/AuthPage.js.map +1 -1
- package/dist/core/components/authentication/auth.css +4 -1
- package/dist/core/components/organizationConfig/src/CountrySubdivisionFields.d.ts +2 -0
- package/dist/core/components/organizationConfig/src/CountrySubdivisionFields.d.ts.map +1 -0
- package/dist/core/components/organizationConfig/src/CountrySubdivisionFields.js +180 -0
- package/dist/core/components/organizationConfig/src/CountrySubdivisionFields.js.map +1 -0
- package/dist/core/components/organizationConfig/src/organizationConfigContent.d.ts.map +1 -1
- package/dist/core/components/organizationConfig/src/organizationConfigContent.js +13 -0
- package/dist/core/components/organizationConfig/src/organizationConfigContent.js.map +1 -1
- package/dist/core/components/settings/index.js +1 -1
- package/dist/core/components/settings/index.js.map +1 -1
- package/dist/core/components/settings/src/AccountSettingsPanel.d.ts.map +1 -1
- package/dist/core/components/settings/src/AccountSettingsPanel.js +6 -7
- package/dist/core/components/settings/src/AccountSettingsPanel.js.map +1 -1
- package/dist/core/components/ui/AnimatedBackground.d.ts +2 -2
- package/dist/core/components/ui/AnimatedBackground.d.ts.map +1 -1
- package/dist/core/components/ui/AnimatedBackground.js +7 -8
- package/dist/core/components/ui/AnimatedBackground.js.map +1 -1
- package/dist/core/components/ui/FilesManager/src/FileItemComponent.d.ts.map +1 -1
- package/dist/core/components/ui/FilesManager/src/FileItemComponent.js +1 -1
- package/dist/core/components/ui/FilesManager/src/FileItemComponent.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 +37 -19
- package/dist/core/components/ui/LegendCard.js.map +1 -1
- package/dist/core/components/ui/Progress.js +2 -2
- package/dist/core/components/ui/Progress.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 +36 -6
- 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/BimViewer.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/BimViewer.js +10 -6
- package/dist/core/components/viewers/bim/BimViewer.js.map +1 -1
- package/dist/core/components/viewers/bim/src/BimMeasurements/BimMeasurementManager.d.ts +161 -0
- package/dist/core/components/viewers/bim/src/BimMeasurements/BimMeasurementManager.d.ts.map +1 -0
- package/dist/core/components/viewers/bim/src/BimMeasurements/BimMeasurementManager.js +382 -0
- package/dist/core/components/viewers/bim/src/BimMeasurements/BimMeasurementManager.js.map +1 -0
- package/dist/core/components/viewers/bim/src/BimMeasurements/measurementSettings.d.ts +80 -0
- package/dist/core/components/viewers/bim/src/BimMeasurements/measurementSettings.d.ts.map +1 -0
- package/dist/core/components/viewers/bim/src/BimMeasurements/measurementSettings.js +48 -0
- package/dist/core/components/viewers/bim/src/BimMeasurements/measurementSettings.js.map +1 -0
- package/dist/core/components/viewers/bim/src/BimSidebar/src/SettingsTab/index.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/BimSidebar/src/SettingsTab/index.js +3 -1
- package/dist/core/components/viewers/bim/src/BimSidebar/src/SettingsTab/index.js.map +1 -1
- package/dist/core/components/viewers/bim/src/BimSidebar/src/SettingsTab/src/MeasurementSettings.d.ts +11 -0
- package/dist/core/components/viewers/bim/src/BimSidebar/src/SettingsTab/src/MeasurementSettings.d.ts.map +1 -0
- package/dist/core/components/viewers/bim/src/BimSidebar/src/SettingsTab/src/MeasurementSettings.js +186 -0
- package/dist/core/components/viewers/bim/src/BimSidebar/src/SettingsTab/src/MeasurementSettings.js.map +1 -0
- package/dist/core/components/viewers/bim/src/Highlighter/index.d.ts +10 -0
- package/dist/core/components/viewers/bim/src/Highlighter/index.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/Highlighter/index.js +28 -6
- package/dist/core/components/viewers/bim/src/Highlighter/index.js.map +1 -1
- package/dist/core/components/viewers/bim/src/LoadModels.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/LoadModels.js +5 -2
- package/dist/core/components/viewers/bim/src/LoadModels.js.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/renderCSS2DMarkers.d.ts +5 -0
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/renderCSS2DMarkers.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/renderCSS2DMarkers.js +26 -14
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/renderCSS2DMarkers.js.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useFilePlacement.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useFilePlacement.js +4 -2
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useFilePlacement.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 +21 -18
- package/dist/core/components/viewers/bim/src/tools/AddToBim/src/useSensorMarkers.js.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/ClippingTool/ClippingTool.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/ClippingTool/ClippingTool.js +15 -10
- package/dist/core/components/viewers/bim/src/tools/ClippingTool/ClippingTool.js.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/measureBimTool.d.ts.map +1 -1
- package/dist/core/components/viewers/bim/src/tools/measureBimTool.js +52 -60
- package/dist/core/components/viewers/bim/src/tools/measureBimTool.js.map +1 -1
- package/dist/core/components/viewers/map/MapViewer.d.ts.map +1 -1
- package/dist/core/components/viewers/map/MapViewer.js +1 -1
- package/dist/core/components/viewers/map/MapViewer.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/MapFeaturePopoverMenu/src/NonDatabaseBuildingPopover.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/NonDatabaseBuildingPopover.js +5 -5
- package/dist/core/components/viewers/map/src/MapFeaturePopoverMenu/src/NonDatabaseBuildingPopover.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/BimLayer/index.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/BimLayer/index.js +9 -6
- package/dist/core/components/viewers/map/src/MapLayers/src/BimLayer/index.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 +82 -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/CommentLayer/index.js +3 -3
- package/dist/core/components/viewers/map/src/MapLayers/src/CommentLayer/index.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/FileLayer/index.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/FileLayer/index.js +22 -2
- package/dist/core/components/viewers/map/src/MapLayers/src/FileLayer/index.js.map +1 -1
- 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 +39 -22
- 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/components/viewers/map/src/SimpleMap.d.ts +1 -1
- package/dist/core/components/viewers/map/src/SimpleMap.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/SimpleMap.js +4 -10
- package/dist/core/components/viewers/map/src/SimpleMap.js.map +1 -1
- package/dist/core/components/viewers/map/src/tools/AddTools/AddDataset/DatasetAdder.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/tools/AddTools/AddDataset/DatasetAdder.js +4 -0
- package/dist/core/components/viewers/map/src/tools/AddTools/AddDataset/DatasetAdder.js.map +1 -1
- package/dist/core/components/viewers/pointcloud/src/PointCloudLoadingState/index.d.ts.map +1 -1
- package/dist/core/components/viewers/pointcloud/src/PointCloudLoadingState/index.js +16 -3
- package/dist/core/components/viewers/pointcloud/src/PointCloudLoadingState/index.js.map +1 -1
- package/dist/core/components/viewers/pointcloud/src/PointCloudSidebar/src/FileTab/src/PointCloudSection.d.ts.map +1 -1
- package/dist/core/components/viewers/pointcloud/src/PointCloudSidebar/src/FileTab/src/PointCloudSection.js +105 -26
- package/dist/core/components/viewers/pointcloud/src/PointCloudSidebar/src/FileTab/src/PointCloudSection.js.map +1 -1
- package/dist/core/components/viewers/pointcloud/src/PointCloudSidebar/src/SettingsTab/src/PerformanceSettings.js +6 -6
- package/dist/core/components/viewers/pointcloud/src/PointCloudSidebar/src/SettingsTab/src/PerformanceSettings.js.map +1 -1
- package/dist/core/i18n/messages/en.json +29 -2
- package/dist/core/i18n/messages/es.json +29 -2
- package/dist/core/i18n/messages/fr.json +29 -2
- 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/store/PointCloud/reducer.js +1 -1
- package/dist/core/store/PointCloud/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/dist/core/utils/markerUtils.d.ts +11 -0
- package/dist/core/utils/markerUtils.d.ts.map +1 -1
- package/dist/core/utils/markerUtils.js +2 -0
- package/dist/core/utils/markerUtils.js.map +1 -1
- package/package.json +1 -1
- package/dist/core/components/viewers/bim/src/BimMeasurements/LenghtMeasurement.d.ts +0 -21
- package/dist/core/components/viewers/bim/src/BimMeasurements/LenghtMeasurement.d.ts.map +0 -1
- package/dist/core/components/viewers/bim/src/BimMeasurements/LenghtMeasurement.js +0 -92
- package/dist/core/components/viewers/bim/src/BimMeasurements/LenghtMeasurement.js.map +0 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { colourForValue, observedDomain, resolveDomain, resolveRamp } from "./sensorColour";
|
|
2
|
+
import { latestValues } from "./useSensorSeriesMulti";
|
|
3
|
+
function typeDomain(sensorType, seriesById) {
|
|
4
|
+
if (!sensorType) return null;
|
|
5
|
+
const points = [...seriesById.values()].flatMap((series) => series.points);
|
|
6
|
+
return resolveDomain(sensorType, observedDomain(points));
|
|
7
|
+
}
|
|
8
|
+
function buildingSensorAverages(sensors, sensorType, seriesById) {
|
|
9
|
+
const averages = /* @__PURE__ */ new Map();
|
|
10
|
+
if (!sensorType) return averages;
|
|
11
|
+
const domain = typeDomain(sensorType, seriesById);
|
|
12
|
+
if (!domain) return averages;
|
|
13
|
+
const latest = latestValues(seriesById);
|
|
14
|
+
const totals = /* @__PURE__ */ new Map();
|
|
15
|
+
for (const sensor of sensors) {
|
|
16
|
+
if (sensor.buildingId == null) continue;
|
|
17
|
+
if (sensor.typeId !== sensorType.id) continue;
|
|
18
|
+
const value = latest.get(sensor.id);
|
|
19
|
+
if (value === void 0) continue;
|
|
20
|
+
const total = totals.get(sensor.buildingId);
|
|
21
|
+
if (total) {
|
|
22
|
+
total.sum += value;
|
|
23
|
+
total.count += 1;
|
|
24
|
+
} else {
|
|
25
|
+
totals.set(sensor.buildingId, { sum: value, count: 1 });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const ramp = resolveRamp(sensorType);
|
|
29
|
+
for (const [buildingId, { sum, count }] of totals) {
|
|
30
|
+
const average = sum / count;
|
|
31
|
+
if (!Number.isFinite(average)) continue;
|
|
32
|
+
averages.set(buildingId, {
|
|
33
|
+
buildingId,
|
|
34
|
+
average,
|
|
35
|
+
sensorCount: count,
|
|
36
|
+
colour: colourForValue(average, ramp, domain)
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return averages;
|
|
40
|
+
}
|
|
41
|
+
function buildingLatestTimes(sensors, seriesById) {
|
|
42
|
+
var _a;
|
|
43
|
+
const times = /* @__PURE__ */ new Map();
|
|
44
|
+
for (const sensor of sensors) {
|
|
45
|
+
if (sensor.buildingId == null) continue;
|
|
46
|
+
const points = (_a = seriesById.get(sensor.id)) == null ? void 0 : _a.points;
|
|
47
|
+
const last = points == null ? void 0 : points[points.length - 1];
|
|
48
|
+
if (!last || !Number.isFinite(last.t)) continue;
|
|
49
|
+
const current = times.get(sensor.buildingId);
|
|
50
|
+
if (current === void 0 || last.t > current) times.set(sensor.buildingId, last.t);
|
|
51
|
+
}
|
|
52
|
+
return times;
|
|
53
|
+
}
|
|
54
|
+
function activeLegendTypeId(legendTypeId, visibleTypeIds) {
|
|
55
|
+
if (legendTypeId == null) return null;
|
|
56
|
+
return (visibleTypeIds == null ? void 0 : visibleTypeIds.includes(legendTypeId)) ? legendTypeId : null;
|
|
57
|
+
}
|
|
58
|
+
function buildingColoursKey(averages) {
|
|
59
|
+
return [...averages.values()].map((a) => `${a.buildingId}:${a.colour}`).sort().join("|");
|
|
60
|
+
}
|
|
61
|
+
export {
|
|
62
|
+
activeLegendTypeId,
|
|
63
|
+
buildingColoursKey,
|
|
64
|
+
buildingLatestTimes,
|
|
65
|
+
buildingSensorAverages,
|
|
66
|
+
typeDomain
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=buildingSensorColours.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/core/components/ui/Sensors/buildingSensorColours.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport { colourForValue, observedDomain, resolveDomain, resolveRamp } from './sensorColour'\r\nimport { latestValues } from './useSensorSeriesMulti'\r\n\r\nimport type { ColourDomain } from './sensorColour'\r\nimport type { SensorSeries } from './sensorData'\r\nimport type { Sensor, SensorType } from '../../../types/dbTypes'\r\n\r\n/** One building's sensors of a single type, reduced to a colourable number. */\r\nexport interface BuildingSensorAverage {\r\n buildingId: number\r\n /** Mean of the contributing sensors' latest readings. */\r\n average: number\r\n /** How many sensors reported a finite reading. Never zero: those buildings are omitted. */\r\n sensorCount: number\r\n colour: string\r\n}\r\n\r\n/** Enough of a sensor to aggregate it onto a building. */\r\nexport type AggregateSensor = Pick<Sensor, 'id' | 'typeId' | 'buildingId'>\r\n\r\n/**\r\n * The type's colour domain, resolved the way the legend and the charts resolve it: the\r\n * configured `minValue..maxValue`, else the range observed across the polled sensors.\r\n *\r\n * `null` means the type has no usable domain, which callers must read as \"no colours\r\n * configured\" and answer by keeping their pre-colour appearance.\r\n */\r\nexport function typeDomain(\r\n sensorType: SensorType | null | undefined,\r\n seriesById: ReadonlyMap<number, SensorSeries>,\r\n): ColourDomain | null {\r\n if (!sensorType) return null\r\n const points = [...seriesById.values()].flatMap(series => series.points)\r\n return resolveDomain(sensorType, observedDomain(points))\r\n}\r\n\r\n/**\r\n * Mean latest reading and ramp colour per building, for one sensor type.\r\n *\r\n * Deliberately blind to `sensor.viewer`: a building's temperature is its temperature whether the\r\n * sensor was placed on the map or inside the BIM model, so both feed the average. Every other\r\n * consumer of sensors filters by viewer, so do not \"fix\" this to match them.\r\n */\r\nexport function buildingSensorAverages(\r\n sensors: readonly AggregateSensor[],\r\n sensorType: SensorType | null | undefined,\r\n seriesById: ReadonlyMap<number, SensorSeries>,\r\n): Map<number, BuildingSensorAverage> {\r\n const averages = new Map<number, BuildingSensorAverage>()\r\n if (!sensorType) return averages\r\n\r\n const domain = typeDomain(sensorType, seriesById)\r\n if (!domain) return averages\r\n\r\n const latest = latestValues(seriesById)\r\n const totals = new Map<number, { sum: number; count: number }>()\r\n\r\n for (const sensor of sensors) {\r\n if (sensor.buildingId == null) continue\r\n if (sensor.typeId !== sensorType.id) continue\r\n const value = latest.get(sensor.id)\r\n if (value === undefined) continue\r\n const total = totals.get(sensor.buildingId)\r\n if (total) {\r\n total.sum += value\r\n total.count += 1\r\n } else {\r\n totals.set(sensor.buildingId, { sum: value, count: 1 })\r\n }\r\n }\r\n\r\n const ramp = resolveRamp(sensorType)\r\n for (const [buildingId, { sum, count }] of totals) {\r\n const average = sum / count\r\n if (!Number.isFinite(average)) continue\r\n averages.set(buildingId, {\r\n buildingId,\r\n average,\r\n sensorCount: count,\r\n colour: colourForValue(average, ramp, domain),\r\n })\r\n }\r\n\r\n return averages\r\n}\r\n\r\n/**\r\n * Most recent reading time per building, epoch ms.\r\n *\r\n * Separate from the averages because a building can have a stale reading and still average\r\n * cleanly; showing when the number is from is what makes a dead feed visible.\r\n */\r\nexport function buildingLatestTimes(\r\n sensors: readonly AggregateSensor[],\r\n seriesById: ReadonlyMap<number, SensorSeries>,\r\n): Map<number, number> {\r\n const times = new Map<number, number>()\r\n for (const sensor of sensors) {\r\n if (sensor.buildingId == null) continue\r\n const points = seriesById.get(sensor.id)?.points\r\n const last = points?.[points.length - 1]\r\n if (!last || !Number.isFinite(last.t)) continue\r\n const current = times.get(sensor.buildingId)\r\n if (current === undefined || last.t > current) times.set(sensor.buildingId, last.t)\r\n }\r\n return times\r\n}\r\n\r\n/**\r\n * The type the map should colour buildings by: pinned in the legend *and* switched on for the\r\n * viewer. The single gate for whether this feature polls and paints at all, so toggling the type\r\n * off both stops the requests and returns the footprints to their default colour.\r\n */\r\nexport function activeLegendTypeId(\r\n legendTypeId: number | null | undefined,\r\n visibleTypeIds: readonly number[] | undefined,\r\n): number | null {\r\n if (legendTypeId == null) return null\r\n return visibleTypeIds?.includes(legendTypeId) ? legendTypeId : null\r\n}\r\n\r\n/**\r\n * Stable key over the resolved colours, for effect deps that must not fire on equal polls.\r\n * Sorted, so a reordered sensor list does not read as a change.\r\n */\r\nexport function buildingColoursKey(averages: ReadonlyMap<number, BuildingSensorAverage>): string {\r\n return [...averages.values()]\r\n .map(a => `${a.buildingId}:${a.colour}`)\r\n .sort()\r\n .join('|')\r\n}\r\n"],"mappings":"AAGA,SAAS,gBAAgB,gBAAgB,eAAe,mBAAmB;AAC3E,SAAS,oBAAoB;AA0BtB,SAAS,WACd,YACA,YACqB;AACrB,MAAI,CAAC,WAAY,QAAO;AACxB,QAAM,SAAS,CAAC,GAAG,WAAW,OAAO,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AAQ,CAAC,OAAO,SAAS,KAAK,CAAC,EAAG;AACvC,UAAM,UAAU,MAAM,IAAI,OAAO,UAAU;AAC3C,QAAI,YAAY,UAAa,KAAK,IAAI,QAAS,OAAM,IAAI,OAAO,YAAY,KAAK,CAAC;AAAA,EACpF;AACA,SAAO;AACT;AAOO,SAAS,mBACd,cACA,gBACe;AACf,MAAI,gBAAgB,KAAM,QAAO;AACjC,UAAO,iDAAgB,SAAS,iBAAgB,eAAe;AACjE;AAMO,SAAS,mBAAmB,UAA8D;AAC/F,SAAO,CAAC,GAAG,SAAS,OAAO,CAAC,EACzB,IAAI,OAAK,GAAG,EAAE,UAAU,IAAI,EAAE,MAAM,EAAE,EACtC,KAAK,EACL,KAAK,GAAG;AACb;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/core/components/ui/Sensors/sensorScope.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport { UNTAGGED_TAG } from './
|
|
1
|
+
{"version":3,"sources":["../../../../../src/core/components/ui/Sensors/sensorScope.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport { UNTAGGED_TAG } from './sensorVisibility'\r\n\r\nimport type { Sensor } from '../../../types/dbTypes'\r\n\r\n/** Which sensors the detail dialog's charts cover. */\r\nexport type ScopeMode = 'sensor' | 'type' | 'tag'\r\n\r\nexport interface SensorScope {\r\n mode: ScopeMode\r\n /** Only read when `mode` is `tag`. `UNTAGGED_TAG` selects sensors with no tags. */\r\n tag?: string | null\r\n}\r\n\r\ntype ScopeSensor = Pick<Sensor, 'id' | 'typeId' | 'tags' | 'viewer'>\r\n\r\n/** The tags a sensor counts under, treating \"no tags\" as the untagged sentinel. */\r\nexport function tagsOf(sensor: Pick<Sensor, 'tags'>): string[] {\r\n return sensor.tags && sensor.tags.length > 0 ? sensor.tags : [UNTAGGED_TAG]\r\n}\r\n\r\n/**\r\n * The sensors in scope for the charts, always including `focused` itself so the emphasised\r\n * series never disappears from its own dialog.\r\n *\r\n * - `sensor`: just the focused sensor.\r\n * - `type`: every sensor sharing its type, in the same viewer.\r\n * - `tag`: the `type` set narrowed to one tag.\r\n *\r\n * Ordering is stable (ascending id) so a line keeps its position between polls, and comparing\r\n * against `typeId` requires a real type: sensors with no type never group together.\r\n */\r\nexport function sensorsInScope<T extends ScopeSensor>(\r\n focused: T,\r\n all: T[],\r\n scope: SensorScope,\r\n): T[] {\r\n if (scope.mode === 'sensor') return [focused]\r\n\r\n const sameType = all.filter(\r\n s => focused.typeId != null && s.typeId === focused.typeId && s.viewer === focused.viewer,\r\n )\r\n\r\n const scoped = scope.mode === 'tag' && scope.tag\r\n ? sameType.filter(s => s.id === focused.id || tagsOf(s).includes(scope.tag as string))\r\n : sameType\r\n\r\n // `focused` may be filtered out by its own viewer/type being unset; put it back.\r\n const withFocused = scoped.some(s => s.id === focused.id) ? scoped : [focused, ...scoped]\r\n return [...withFocused].sort((a, b) => a.id - b.id)\r\n}\r\n\r\n/** Tags available to filter by within the focused sensor's type, sorted for a stable menu. */\r\nexport function tagsForScope<T extends ScopeSensor>(focused: T, all: T[]): string[] {\r\n const sameType = all.filter(\r\n s => focused.typeId != null && s.typeId === focused.typeId && s.viewer === focused.viewer,\r\n )\r\n const tags = new Set<string>()\r\n for (const sensor of sameType) {\r\n for (const tag of tagsOf(sensor)) tags.add(tag)\r\n }\r\n // Untagged sorts last so real tags lead the menu.\r\n return [...tags].sort((a, b) => {\r\n if (a === UNTAGGED_TAG) return 1\r\n if (b === UNTAGGED_TAG) return -1\r\n return a.localeCompare(b)\r\n })\r\n}\r\n"],"mappings":"AAGA,SAAS,oBAAoB;AAgBtB,SAAS,OAAO,QAAwC;AAC7D,SAAO,OAAO,QAAQ,OAAO,KAAK,SAAS,IAAI,OAAO,OAAO,CAAC,YAAY;AAC5E;AAaO,SAAS,eACd,SACA,KACA,OACK;AACL,MAAI,MAAM,SAAS,SAAU,QAAO,CAAC,OAAO;AAE5C,QAAM,WAAW,IAAI;AAAA,IACnB,OAAK,QAAQ,UAAU,QAAQ,EAAE,WAAW,QAAQ,UAAU,EAAE,WAAW,QAAQ;AAAA,EACrF;AAEA,QAAM,SAAS,MAAM,SAAS,SAAS,MAAM,MACzC,SAAS,OAAO,OAAK,EAAE,OAAO,QAAQ,MAAM,OAAO,CAAC,EAAE,SAAS,MAAM,GAAa,CAAC,IACnF;AAGJ,QAAM,cAAc,OAAO,KAAK,OAAK,EAAE,OAAO,QAAQ,EAAE,IAAI,SAAS,CAAC,SAAS,GAAG,MAAM;AACxF,SAAO,CAAC,GAAG,WAAW,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,KAAK,EAAE,EAAE;AACpD;AAGO,SAAS,aAAoC,SAAY,KAAoB;AAClF,QAAM,WAAW,IAAI;AAAA,IACnB,OAAK,QAAQ,UAAU,QAAQ,EAAE,WAAW,QAAQ,UAAU,EAAE,WAAW,QAAQ;AAAA,EACrF;AACA,QAAM,OAAO,oBAAI,IAAY;AAC7B,aAAW,UAAU,UAAU;AAC7B,eAAW,OAAO,OAAO,MAAM,EAAG,MAAK,IAAI,GAAG;AAAA,EAChD;AAEA,SAAO,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,MAAM;AAC9B,QAAI,MAAM,aAAc,QAAO;AAC/B,QAAI,MAAM,aAAc,QAAO;AAC/B,WAAO,EAAE,cAAc,CAAC;AAAA,EAC1B,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Sensor, ViewerNames } from '../../../types/dbTypes';
|
|
2
|
+
/**
|
|
3
|
+
* Stable key used in state for sensors with no tags. Locale-independent.
|
|
4
|
+
*
|
|
5
|
+
* Defined here rather than in `SensorsSection` so the pure modules and the map/BIM layers can
|
|
6
|
+
* reach it without importing the sidebar component; `SensorsSection` re-exports it.
|
|
7
|
+
*/
|
|
8
|
+
export declare const UNTAGGED_TAG = "__untagged__";
|
|
9
|
+
/** The slice of `MenusState` that decides whether a sensor is drawn, for one viewer. */
|
|
10
|
+
export interface SensorVisibilityScope {
|
|
11
|
+
viewer: ViewerNames;
|
|
12
|
+
visibleTypeIds: readonly number[];
|
|
13
|
+
visibleTags: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
/** Enough of a sensor to decide its visibility. Keeps callers free to pass enriched rows. */
|
|
16
|
+
export type VisibilityCandidate = Pick<Sensor, 'viewer' | 'typeId' | 'tags'>;
|
|
17
|
+
/**
|
|
18
|
+
* Whether a sensor is drawn in a viewer.
|
|
19
|
+
*
|
|
20
|
+
* Type and tag are alternatives, not filters that compose: the sidebar groups by one or the
|
|
21
|
+
* other and clears the opposing state when you switch, so a sensor shows if either channel
|
|
22
|
+
* selects it. A sensor carrying no tags is selected by `UNTAGGED_TAG`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function isSensorVisible(sensor: VisibilityCandidate, scope: SensorVisibilityScope): boolean;
|
|
25
|
+
/** `isSensorVisible` over a list, preserving the caller's element type. */
|
|
26
|
+
export declare function visibleSensors<T extends VisibilityCandidate>(sensors: readonly T[], scope: SensorVisibilityScope): T[];
|
|
27
|
+
/**
|
|
28
|
+
* The sensor type the viewer is currently explaining: what the legend titles itself with, what
|
|
29
|
+
* the marker halos colour by, and what the map colours buildings by.
|
|
30
|
+
*
|
|
31
|
+
* A type pinned in the legend dropdown wins, so those three stay in agreement after the user
|
|
32
|
+
* retargets the legend. Otherwise it follows the active sensor, which callers resolve
|
|
33
|
+
* differently: the legend lets hover stand in for focus, the viewers use focus alone so halos
|
|
34
|
+
* do not flicker as the pointer sweeps the scene.
|
|
35
|
+
*/
|
|
36
|
+
export declare function activeSensorTypeId(sensors: readonly Pick<Sensor, 'id' | 'typeId'>[], opts: {
|
|
37
|
+
legendTypeId?: number | null;
|
|
38
|
+
activeSensorId?: number | null;
|
|
39
|
+
}): number | null;
|
|
40
|
+
/**
|
|
41
|
+
* The sensors that keep the legend on screen: the active type's visible ones in this viewer.
|
|
42
|
+
*
|
|
43
|
+
* Shared so the card and the sidebar's show/hide button agree on whether there is a legend at
|
|
44
|
+
* all; an empty result means the card renders nothing and the button has nothing to toggle.
|
|
45
|
+
*/
|
|
46
|
+
export declare function legendScopeSensors<T extends VisibilityCandidate>(sensors: readonly T[], scope: SensorVisibilityScope, activeTypeId: number | null): T[];
|
|
47
|
+
//# sourceMappingURL=sensorVisibility.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sensorVisibility.d.ts","sourceRoot":"","sources":["../../../../../src/core/components/ui/Sensors/sensorVisibility.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAEjE;;;;;GAKG;AACH,eAAO,MAAM,YAAY,iBAAiB,CAAA;AAE1C,wFAAwF;AACxF,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,WAAW,CAAA;IACnB,cAAc,EAAE,SAAS,MAAM,EAAE,CAAA;IACjC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAA;CAC/B;AAED,6FAA6F;AAC7F,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,MAAM,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC,CAAA;AAE5E;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,mBAAmB,EAAE,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAOlG;AAED,2EAA2E;AAC3E,wBAAgB,cAAc,CAAC,CAAC,SAAS,mBAAmB,EAC1D,OAAO,EAAE,SAAS,CAAC,EAAE,EACrB,KAAK,EAAE,qBAAqB,GAC3B,CAAC,EAAE,CAEL;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,SAAS,IAAI,CAAC,MAAM,EAAE,IAAI,GAAG,QAAQ,CAAC,EAAE,EACjD,IAAI,EAAE;IAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GACrE,MAAM,GAAG,IAAI,CAIf;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,mBAAmB,EAC9D,OAAO,EAAE,SAAS,CAAC,EAAE,EACrB,KAAK,EAAE,qBAAqB,EAC5B,YAAY,EAAE,MAAM,GAAG,IAAI,GAC1B,CAAC,EAAE,CAGL"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const UNTAGGED_TAG = "__untagged__";
|
|
2
|
+
function isSensorVisible(sensor, scope) {
|
|
3
|
+
var _a;
|
|
4
|
+
if (sensor.viewer !== scope.viewer) return false;
|
|
5
|
+
const matchesType = sensor.typeId != null && scope.visibleTypeIds.includes(sensor.typeId);
|
|
6
|
+
const matchesTag = ((_a = sensor.tags) == null ? void 0 : _a.length) ? sensor.tags.some((tag) => scope.visibleTags.includes(tag)) : scope.visibleTags.includes(UNTAGGED_TAG);
|
|
7
|
+
return matchesType || matchesTag;
|
|
8
|
+
}
|
|
9
|
+
function visibleSensors(sensors, scope) {
|
|
10
|
+
return sensors.filter((sensor) => isSensorVisible(sensor, scope));
|
|
11
|
+
}
|
|
12
|
+
function activeSensorTypeId(sensors, opts) {
|
|
13
|
+
var _a, _b;
|
|
14
|
+
if (opts.legendTypeId != null) return opts.legendTypeId;
|
|
15
|
+
if (opts.activeSensorId == null) return null;
|
|
16
|
+
return (_b = (_a = sensors.find((sensor) => sensor.id === opts.activeSensorId)) == null ? void 0 : _a.typeId) != null ? _b : null;
|
|
17
|
+
}
|
|
18
|
+
function legendScopeSensors(sensors, scope, activeTypeId) {
|
|
19
|
+
if (activeTypeId == null) return [];
|
|
20
|
+
return visibleSensors(sensors, scope).filter((sensor) => sensor.typeId === activeTypeId);
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
UNTAGGED_TAG,
|
|
24
|
+
activeSensorTypeId,
|
|
25
|
+
isSensorVisible,
|
|
26
|
+
legendScopeSensors,
|
|
27
|
+
visibleSensors
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=sensorVisibility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/core/components/ui/Sensors/sensorVisibility.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport type { Sensor, ViewerNames } from '../../../types/dbTypes'\r\n\r\n/**\r\n * Stable key used in state for sensors with no tags. Locale-independent.\r\n *\r\n * Defined here rather than in `SensorsSection` so the pure modules and the map/BIM layers can\r\n * reach it without importing the sidebar component; `SensorsSection` re-exports it.\r\n */\r\nexport const UNTAGGED_TAG = '__untagged__'\r\n\r\n/** The slice of `MenusState` that decides whether a sensor is drawn, for one viewer. */\r\nexport interface SensorVisibilityScope {\r\n viewer: ViewerNames\r\n visibleTypeIds: readonly number[]\r\n visibleTags: readonly string[]\r\n}\r\n\r\n/** Enough of a sensor to decide its visibility. Keeps callers free to pass enriched rows. */\r\nexport type VisibilityCandidate = Pick<Sensor, 'viewer' | 'typeId' | 'tags'>\r\n\r\n/**\r\n * Whether a sensor is drawn in a viewer.\r\n *\r\n * Type and tag are alternatives, not filters that compose: the sidebar groups by one or the\r\n * other and clears the opposing state when you switch, so a sensor shows if either channel\r\n * selects it. A sensor carrying no tags is selected by `UNTAGGED_TAG`.\r\n */\r\nexport function isSensorVisible(sensor: VisibilityCandidate, scope: SensorVisibilityScope): boolean {\r\n if (sensor.viewer !== scope.viewer) return false\r\n const matchesType = sensor.typeId != null && scope.visibleTypeIds.includes(sensor.typeId)\r\n const matchesTag = sensor.tags?.length\r\n ? sensor.tags.some(tag => scope.visibleTags.includes(tag))\r\n : scope.visibleTags.includes(UNTAGGED_TAG)\r\n return matchesType || matchesTag\r\n}\r\n\r\n/** `isSensorVisible` over a list, preserving the caller's element type. */\r\nexport function visibleSensors<T extends VisibilityCandidate>(\r\n sensors: readonly T[],\r\n scope: SensorVisibilityScope,\r\n): T[] {\r\n return sensors.filter(sensor => isSensorVisible(sensor, scope))\r\n}\r\n\r\n/**\r\n * The sensor type the viewer is currently explaining: what the legend titles itself with, what\r\n * the marker halos colour by, and what the map colours buildings by.\r\n *\r\n * A type pinned in the legend dropdown wins, so those three stay in agreement after the user\r\n * retargets the legend. Otherwise it follows the active sensor, which callers resolve\r\n * differently: the legend lets hover stand in for focus, the viewers use focus alone so halos\r\n * do not flicker as the pointer sweeps the scene.\r\n */\r\nexport function activeSensorTypeId(\r\n sensors: readonly Pick<Sensor, 'id' | 'typeId'>[],\r\n opts: { legendTypeId?: number | null; activeSensorId?: number | null },\r\n): number | null {\r\n if (opts.legendTypeId != null) return opts.legendTypeId\r\n if (opts.activeSensorId == null) return null\r\n return sensors.find(sensor => sensor.id === opts.activeSensorId)?.typeId ?? null\r\n}\r\n\r\n/**\r\n * The sensors that keep the legend on screen: the active type's visible ones in this viewer.\r\n *\r\n * Shared so the card and the sidebar's show/hide button agree on whether there is a legend at\r\n * all; an empty result means the card renders nothing and the button has nothing to toggle.\r\n */\r\nexport function legendScopeSensors<T extends VisibilityCandidate>(\r\n sensors: readonly T[],\r\n scope: SensorVisibilityScope,\r\n activeTypeId: number | null,\r\n): T[] {\r\n if (activeTypeId == null) return []\r\n return visibleSensors(sensors, scope).filter(sensor => sensor.typeId === activeTypeId)\r\n}\r\n"],"mappings":"AAWO,MAAM,eAAe;AAmBrB,SAAS,gBAAgB,QAA6B,OAAuC;AA9BpG;AA+BE,MAAI,OAAO,WAAW,MAAM,OAAQ,QAAO;AAC3C,QAAM,cAAc,OAAO,UAAU,QAAQ,MAAM,eAAe,SAAS,OAAO,MAAM;AACxF,QAAM,eAAa,YAAO,SAAP,mBAAa,UAC5B,OAAO,KAAK,KAAK,SAAO,MAAM,YAAY,SAAS,GAAG,CAAC,IACvD,MAAM,YAAY,SAAS,YAAY;AAC3C,SAAO,eAAe;AACxB;AAGO,SAAS,eACd,SACA,OACK;AACL,SAAO,QAAQ,OAAO,YAAU,gBAAgB,QAAQ,KAAK,CAAC;AAChE;AAWO,SAAS,mBACd,SACA,MACe;AA3DjB;AA4DE,MAAI,KAAK,gBAAgB,KAAM,QAAO,KAAK;AAC3C,MAAI,KAAK,kBAAkB,KAAM,QAAO;AACxC,UAAO,mBAAQ,KAAK,YAAU,OAAO,OAAO,KAAK,cAAc,MAAxD,mBAA2D,WAA3D,YAAqE;AAC9E;AAQO,SAAS,mBACd,SACA,OACA,cACK;AACL,MAAI,gBAAgB,KAAM,QAAO,CAAC;AAClC,SAAO,eAAe,SAAS,KAAK,EAAE,OAAO,YAAU,OAAO,WAAW,YAAY;AACvF;","names":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type BuildingSensorAverage } from './buildingSensorColours';
|
|
2
|
+
import { type SensorReading } from './sensorValueColours';
|
|
3
|
+
import type { ColourDomain } from './sensorColour';
|
|
4
|
+
import type { Sensor, SensorType, ViewerNames } from '../../../types/dbTypes';
|
|
5
|
+
export interface UseBuildingSensorColoursResult {
|
|
6
|
+
/** `null` when nothing should be coloured. Also the poll gate. */
|
|
7
|
+
typeId: number | null;
|
|
8
|
+
sensorType?: SensorType;
|
|
9
|
+
/** Identity is stable while `colourKey` is, so it is safe in an effect dep list. */
|
|
10
|
+
averages: ReadonlyMap<number, BuildingSensorAverage>;
|
|
11
|
+
colourKey: string;
|
|
12
|
+
domain: ColourDomain | null;
|
|
13
|
+
/** The active type's sensors, grouped by the building they are attached to. */
|
|
14
|
+
sensorsByBuilding: ReadonlyMap<number, Sensor[]>;
|
|
15
|
+
/** Latest reading and ramp colour per sensor, for listing them individually. */
|
|
16
|
+
readings: ReadonlyMap<number, SensorReading>;
|
|
17
|
+
/** Most recent reading time per building, epoch ms, so a stale feed is visible. */
|
|
18
|
+
latestAtByBuilding: ReadonlyMap<number, number>;
|
|
19
|
+
/** Unit symbol reported by the feeds, when they agree on one. */
|
|
20
|
+
unit?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Per-building aggregate of the sensor type the viewer is currently explaining.
|
|
24
|
+
*
|
|
25
|
+
* Polls only while a type is pinned in the legend *and* switched on for the viewer, so the map
|
|
26
|
+
* fans out no requests until the user asks to see a type. Both the footprint colours and the
|
|
27
|
+
* per-building sensor counts are derived from this one poll.
|
|
28
|
+
*/
|
|
29
|
+
export declare function useBuildingSensorColours(viewer: ViewerNames): UseBuildingSensorColoursResult;
|
|
30
|
+
//# sourceMappingURL=useBuildingSensorColours.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBuildingSensorColours.d.ts","sourceRoot":"","sources":["../../../../../src/core/components/ui/Sensors/useBuildingSensorColours.ts"],"names":[],"mappings":"AAWA,OAAO,EAML,KAAK,qBAAqB,EAC3B,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAwB,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAI/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAE7E,MAAM,WAAW,8BAA8B;IAC7C,kEAAkE;IAClE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,oFAAoF;IACpF,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAA;IACpD,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,YAAY,GAAG,IAAI,CAAA;IAC3B,+EAA+E;IAC/E,iBAAiB,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;IAChD,gFAAgF;IAChF,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC5C,mFAAmF;IACnF,kBAAkB,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/C,iEAAiE;IACjE,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAOD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,WAAW,GAAG,8BAA8B,CA8F5F"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { useSensors } from "../../../hooks/sensors/sensors";
|
|
4
|
+
import { useSensorTypes } from "../../../hooks/sensorTypes/sensorTypes";
|
|
5
|
+
import { MenusContext } from "../../../store";
|
|
6
|
+
import {
|
|
7
|
+
activeLegendTypeId,
|
|
8
|
+
buildingColoursKey,
|
|
9
|
+
buildingLatestTimes,
|
|
10
|
+
buildingSensorAverages,
|
|
11
|
+
typeDomain
|
|
12
|
+
} from "./buildingSensorColours";
|
|
13
|
+
import { valueColoursBySensor } from "./sensorValueColours";
|
|
14
|
+
import { activeSensorTypeId } from "./sensorVisibility";
|
|
15
|
+
import { useSensorSeriesMulti } from "./useSensorSeriesMulti";
|
|
16
|
+
const EMPTY_AVERAGES = /* @__PURE__ */ new Map();
|
|
17
|
+
const EMPTY_BY_BUILDING = /* @__PURE__ */ new Map();
|
|
18
|
+
const EMPTY_READINGS = /* @__PURE__ */ new Map();
|
|
19
|
+
const EMPTY_TIMES = /* @__PURE__ */ new Map();
|
|
20
|
+
function useBuildingSensorColours(viewer) {
|
|
21
|
+
var _a;
|
|
22
|
+
const { state } = React.useContext(MenusContext);
|
|
23
|
+
const { visibleSensorTypes, sensorLegendTypeId, focusedSensorId } = state.menus;
|
|
24
|
+
const { sensors } = useSensors();
|
|
25
|
+
const { sensorTypes } = useSensorTypes();
|
|
26
|
+
const typeId = activeLegendTypeId(
|
|
27
|
+
activeSensorTypeId(sensors, {
|
|
28
|
+
legendTypeId: sensorLegendTypeId == null ? void 0 : sensorLegendTypeId[viewer],
|
|
29
|
+
activeSensorId: focusedSensorId
|
|
30
|
+
}),
|
|
31
|
+
visibleSensorTypes == null ? void 0 : visibleSensorTypes[viewer]
|
|
32
|
+
);
|
|
33
|
+
const sensorType = typeId == null ? void 0 : sensorTypes.find((t) => t.id === typeId);
|
|
34
|
+
const targets = typeId == null ? [] : sensors.filter((s) => s.typeId === typeId && s.buildingId != null);
|
|
35
|
+
const targetsKey = targets.map((s) => s.id).join(",");
|
|
36
|
+
const { seriesById } = useSensorSeriesMulti(targets, { enabled: targets.length > 0 });
|
|
37
|
+
const domain = typeDomain(sensorType, seriesById);
|
|
38
|
+
const rawAverages = React.useMemo(
|
|
39
|
+
() => buildingSensorAverages(targets, sensorType, seriesById),
|
|
40
|
+
[seriesById, sensorType, targetsKey]
|
|
41
|
+
);
|
|
42
|
+
const colourKey = buildingColoursKey(rawAverages);
|
|
43
|
+
const averages = React.useMemo(() => rawAverages, [colourKey]);
|
|
44
|
+
const sensorsByBuilding = React.useMemo(() => {
|
|
45
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
46
|
+
for (const sensor of targets) {
|
|
47
|
+
if (sensor.buildingId == null) continue;
|
|
48
|
+
const list = grouped.get(sensor.buildingId);
|
|
49
|
+
if (list) list.push(sensor);
|
|
50
|
+
else grouped.set(sensor.buildingId, [sensor]);
|
|
51
|
+
}
|
|
52
|
+
for (const list of grouped.values()) list.sort((a, b) => a.name.localeCompare(b.name));
|
|
53
|
+
return grouped;
|
|
54
|
+
}, [targetsKey]);
|
|
55
|
+
const readings = React.useMemo(
|
|
56
|
+
() => valueColoursBySensor(targets, sensorTypes, seriesById),
|
|
57
|
+
[seriesById, sensorTypes, targetsKey]
|
|
58
|
+
);
|
|
59
|
+
const latestAtByBuilding = React.useMemo(
|
|
60
|
+
() => buildingLatestTimes(targets, seriesById),
|
|
61
|
+
[seriesById, targetsKey]
|
|
62
|
+
);
|
|
63
|
+
const unit = (_a = [...seriesById.values()].find((series) => series.unit)) == null ? void 0 : _a.unit;
|
|
64
|
+
if (typeId == null) {
|
|
65
|
+
return {
|
|
66
|
+
typeId: null,
|
|
67
|
+
sensorType: void 0,
|
|
68
|
+
averages: EMPTY_AVERAGES,
|
|
69
|
+
colourKey: "",
|
|
70
|
+
domain: null,
|
|
71
|
+
sensorsByBuilding: EMPTY_BY_BUILDING,
|
|
72
|
+
readings: EMPTY_READINGS,
|
|
73
|
+
latestAtByBuilding: EMPTY_TIMES,
|
|
74
|
+
unit: void 0
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
typeId,
|
|
79
|
+
sensorType,
|
|
80
|
+
averages,
|
|
81
|
+
colourKey,
|
|
82
|
+
domain,
|
|
83
|
+
sensorsByBuilding,
|
|
84
|
+
readings,
|
|
85
|
+
latestAtByBuilding,
|
|
86
|
+
unit
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export {
|
|
90
|
+
useBuildingSensorColours
|
|
91
|
+
};
|
|
92
|
+
//# sourceMappingURL=useBuildingSensorColours.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/core/components/ui/Sensors/useBuildingSensorColours.ts"],"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\n\r\nimport { useSensors } from '../../../hooks/sensors/sensors'\r\nimport { useSensorTypes } from '../../../hooks/sensorTypes/sensorTypes'\r\nimport { MenusContext } from '../../../store'\r\n\r\nimport {\r\n activeLegendTypeId,\r\n buildingColoursKey,\r\n buildingLatestTimes,\r\n buildingSensorAverages,\r\n typeDomain,\r\n type BuildingSensorAverage,\r\n} from './buildingSensorColours'\r\nimport { valueColoursBySensor, type SensorReading } from './sensorValueColours'\r\nimport { activeSensorTypeId } from './sensorVisibility'\r\nimport { useSensorSeriesMulti } from './useSensorSeriesMulti'\r\n\r\nimport type { ColourDomain } from './sensorColour'\r\nimport type { Sensor, SensorType, ViewerNames } from '../../../types/dbTypes'\r\n\r\nexport interface UseBuildingSensorColoursResult {\r\n /** `null` when nothing should be coloured. Also the poll gate. */\r\n typeId: number | null\r\n sensorType?: SensorType\r\n /** Identity is stable while `colourKey` is, so it is safe in an effect dep list. */\r\n averages: ReadonlyMap<number, BuildingSensorAverage>\r\n colourKey: string\r\n domain: ColourDomain | null\r\n /** The active type's sensors, grouped by the building they are attached to. */\r\n sensorsByBuilding: ReadonlyMap<number, Sensor[]>\r\n /** Latest reading and ramp colour per sensor, for listing them individually. */\r\n readings: ReadonlyMap<number, SensorReading>\r\n /** Most recent reading time per building, epoch ms, so a stale feed is visible. */\r\n latestAtByBuilding: ReadonlyMap<number, number>\r\n /** Unit symbol reported by the feeds, when they agree on one. */\r\n unit?: string\r\n}\r\n\r\nconst EMPTY_AVERAGES: ReadonlyMap<number, BuildingSensorAverage> = new Map()\r\nconst EMPTY_BY_BUILDING: ReadonlyMap<number, Sensor[]> = new Map()\r\nconst EMPTY_READINGS: ReadonlyMap<number, SensorReading> = new Map()\r\nconst EMPTY_TIMES: ReadonlyMap<number, number> = new Map()\r\n\r\n/**\r\n * Per-building aggregate of the sensor type the viewer is currently explaining.\r\n *\r\n * Polls only while a type is pinned in the legend *and* switched on for the viewer, so the map\r\n * fans out no requests until the user asks to see a type. Both the footprint colours and the\r\n * per-building sensor counts are derived from this one poll.\r\n */\r\nexport function useBuildingSensorColours(viewer: ViewerNames): UseBuildingSensorColoursResult {\r\n const { state } = React.useContext(MenusContext)\r\n const { visibleSensorTypes, sensorLegendTypeId, focusedSensorId } = state.menus\r\n\r\n const { sensors } = useSensors()\r\n const { sensorTypes } = useSensorTypes()\r\n\r\n // Same type the legend titles itself with and the halos colour by, then gated on that type\r\n // still being switched on. Hover is deliberately not a fallback here: repainting every\r\n // footprint as the pointer sweeps the map would be unusable.\r\n const typeId = activeLegendTypeId(\r\n activeSensorTypeId(sensors, {\r\n legendTypeId: sensorLegendTypeId?.[viewer],\r\n activeSensorId: focusedSensorId,\r\n }),\r\n visibleSensorTypes?.[viewer],\r\n )\r\n const sensorType = typeId == null ? undefined : sensorTypes.find(t => t.id === typeId)\r\n\r\n // Every sensor of the type that is attached to a building, in either viewer: a building's\r\n // temperature is its temperature wherever the sensor was placed.\r\n const targets = typeId == null\r\n ? []\r\n : sensors.filter(s => s.typeId === typeId && s.buildingId != null)\r\n const targetsKey = targets.map(s => s.id).join(',')\r\n\r\n const { seriesById } = useSensorSeriesMulti(targets, { enabled: targets.length > 0 })\r\n\r\n const domain = typeDomain(sensorType, seriesById)\r\n\r\n // `targets` is a fresh array on every render, so the deps key on `targetsKey` instead.\r\n const rawAverages = React.useMemo(\r\n () => buildingSensorAverages(targets, sensorType, seriesById),\r\n [seriesById, sensorType, targetsKey],\r\n )\r\n\r\n // The poll rebuilds `seriesById` every 15s, so its identity says nothing about whether the\r\n // colours moved. Freezing on the colour key is what stops the map repainting on every tick.\r\n // Deps are deliberately narrower than the value returned: equal colours must keep the\r\n // previous map identity, which is the whole point of this memo.\r\n const colourKey = buildingColoursKey(rawAverages)\r\n const averages = React.useMemo(() => rawAverages, [colourKey])\r\n\r\n const sensorsByBuilding = React.useMemo(() => {\r\n const grouped = new Map<number, Sensor[]>()\r\n for (const sensor of targets) {\r\n if (sensor.buildingId == null) continue\r\n const list = grouped.get(sensor.buildingId)\r\n if (list) list.push(sensor)\r\n else grouped.set(sensor.buildingId, [sensor])\r\n }\r\n for (const list of grouped.values()) list.sort((a, b) => a.name.localeCompare(b.name))\r\n return grouped\r\n }, [targetsKey])\r\n\r\n const readings = React.useMemo(\r\n () => valueColoursBySensor(targets, sensorTypes, seriesById),\r\n [seriesById, sensorTypes, targetsKey],\r\n )\r\n\r\n const latestAtByBuilding = React.useMemo(\r\n () => buildingLatestTimes(targets, seriesById),\r\n [seriesById, targetsKey],\r\n )\r\n\r\n // Feeds of one type normally agree; take the first that reports one rather than inventing a\r\n // rule for the mismatch case.\r\n const unit = [...seriesById.values()].find(series => series.unit)?.unit\r\n\r\n if (typeId == null) {\r\n return {\r\n typeId: null,\r\n sensorType: undefined,\r\n averages: EMPTY_AVERAGES,\r\n colourKey: '',\r\n domain: null,\r\n sensorsByBuilding: EMPTY_BY_BUILDING,\r\n readings: EMPTY_READINGS,\r\n latestAtByBuilding: EMPTY_TIMES,\r\n unit: undefined,\r\n }\r\n }\r\n\r\n return {\r\n typeId,\r\n sensorType,\r\n averages,\r\n colourKey,\r\n domain,\r\n sensorsByBuilding,\r\n readings,\r\n latestAtByBuilding,\r\n unit,\r\n }\r\n}\r\n"],"mappings":";AAKA,YAAY,WAAW;AAEvB,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAE7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,4BAAgD;AACzD,SAAS,0BAA0B;AACnC,SAAS,4BAA4B;AAuBrC,MAAM,iBAA6D,oBAAI,IAAI;AAC3E,MAAM,oBAAmD,oBAAI,IAAI;AACjE,MAAM,iBAAqD,oBAAI,IAAI;AACnE,MAAM,cAA2C,oBAAI,IAAI;AASlD,SAAS,yBAAyB,QAAqD;AAxD9F;AAyDE,QAAM,EAAE,MAAM,IAAI,MAAM,WAAW,YAAY;AAC/C,QAAM,EAAE,oBAAoB,oBAAoB,gBAAgB,IAAI,MAAM;AAE1E,QAAM,EAAE,QAAQ,IAAI,WAAW;AAC/B,QAAM,EAAE,YAAY,IAAI,eAAe;AAKvC,QAAM,SAAS;AAAA,IACb,mBAAmB,SAAS;AAAA,MAC1B,cAAc,yDAAqB;AAAA,MACnC,gBAAgB;AAAA,IAClB,CAAC;AAAA,IACD,yDAAqB;AAAA,EACvB;AACA,QAAM,aAAa,UAAU,OAAO,SAAY,YAAY,KAAK,OAAK,EAAE,OAAO,MAAM;AAIrF,QAAM,UAAU,UAAU,OACtB,CAAC,IACD,QAAQ,OAAO,OAAK,EAAE,WAAW,UAAU,EAAE,cAAc,IAAI;AACnE,Q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AU;AAAA,MACV,WAAW;AAAA,MACX,QAAQ;AAAA,MACR,mBAAmB;AAAA,MACnB,UAAU;AAAA,MACV,oBAAoB;AAAA,MACpB,MAAM;AAAA,IACR;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -28,5 +28,5 @@ export declare function useSensorSeriesMulti(sensors: MultiSeriesSensor[], opts:
|
|
|
28
28
|
pollMs?: number;
|
|
29
29
|
}): UseSensorSeriesMultiResult;
|
|
30
30
|
/** Latest observed value per sensor id, for halos and current-value comparisons. */
|
|
31
|
-
export declare function latestValues(seriesById:
|
|
31
|
+
export declare function latestValues(seriesById: ReadonlyMap<number, SensorSeries>): Map<number, number>;
|
|
32
32
|
//# sourceMappingURL=useSensorSeriesMulti.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSensorSeriesMulti.d.ts","sourceRoot":"","sources":["../../../../../src/core/components/ui/Sensors/useSensorSeriesMulti.ts"],"names":[],"mappings":"AAOA,OAAO,EAAqB,KAAK,YAAY,EAAE,MAAM,cAAc,CAAA;AAEnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAQ9D,yEAAyE;AACzE,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAA;IACV,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,UAAU,EAAE,gBAAgB,GAAG,GAAG,gBAAgB,EAAE,CAAA;CACrD;AAED,MAAM,WAAW,0BAA0B;IACzC,0FAA0F;IAC1F,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;IACrC,SAAS,EAAE,OAAO,CAAA;CACnB;AAcD;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,iBAAiB,EAAE,EAC5B,IAAI,EAAE;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1C,0BAA0B,CAsE5B;AAED,oFAAoF;AACpF,wBAAgB,YAAY,CAAC,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"useSensorSeriesMulti.d.ts","sourceRoot":"","sources":["../../../../../src/core/components/ui/Sensors/useSensorSeriesMulti.ts"],"names":[],"mappings":"AAOA,OAAO,EAAqB,KAAK,YAAY,EAAE,MAAM,cAAc,CAAA;AAEnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAQ9D,yEAAyE;AACzE,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAA;IACV,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,UAAU,EAAE,gBAAgB,GAAG,GAAG,gBAAgB,EAAE,CAAA;CACrD;AAED,MAAM,WAAW,0BAA0B;IACzC,0FAA0F;IAC1F,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;IACrC,SAAS,EAAE,OAAO,CAAA;CACnB;AAcD;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,iBAAiB,EAAE,EAC5B,IAAI,EAAE;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1C,0BAA0B,CAsE5B;AAED,oFAAoF;AACpF,wBAAgB,YAAY,CAAC,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAO/F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/core/components/ui/Sensors/useSensorSeriesMulti.ts"],"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\n\r\nimport { parseSensorSeries, type SensorSeries } from './sensorData'\r\n\r\nimport type { SensorDataFormat } from '../../../types/dbTypes'\r\n\r\nconst MIN_POLL_MS = 1000\r\n/** Slower than a single card's own frequency: this hook exists to watch a whole set at once. */\r\nconst DEFAULT_POLL_MS = 15_000\r\n/** Cap on sockets opened at once, so a type with 30 sensors does not fan out 30 requests. */\r\nconst MAX_CONCURRENT = 6\r\n\r\n/** The minimum a sensor needs to expose for its series to be fetched. */\r\nexport interface MultiSeriesSensor {\r\n id: number\r\n url?: string | null\r\n dataFormat: SensorDataFormat | `${SensorDataFormat}`\r\n}\r\n\r\nexport interface UseSensorSeriesMultiResult {\r\n /** Parsed series keyed by sensor id. Sensors that have never loaded are simply absent. */\r\n seriesById: Map<number, SensorSeries>\r\n isLoading: boolean\r\n}\r\n\r\n/** Runs `worker` over `items` with at most `limit` in flight at a time. */\r\nasync function runPool<T>(items: T[], limit: number, worker: (item: T) => Promise<void>): Promise<void> {\r\n let cursor = 0\r\n const lanes = Array.from({ length: Math.min(limit, items.length) }, async () => {\r\n while (cursor < items.length) {\r\n const item = items[cursor++]\r\n await worker(item)\r\n }\r\n })\r\n await Promise.all(lanes)\r\n}\r\n\r\n/**\r\n * Fetch and poll the series for several sensors at once, parsed by the same\r\n * `parseSensorSeries` the single-sensor hook uses.\r\n *\r\n * Differences from `useSensorSeries`: one shared interval for the whole set rather than each\r\n * sensor's own `updateFrequency`, and a concurrency cap. A sensor whose fetch fails keeps its\r\n * last good series, and sensors dropped from `sensors` are evicted. Re-renders that pass an\r\n * equal-but-new array do not re-subscribe, since the effect keys on the set's identity string.\r\n *\r\n * The latest value for a sensor is `points[points.length - 1]?.value` - derive it at the call\r\n * site rather than reaching for a second hook.\r\n */\r\nexport function useSensorSeriesMulti(\r\n sensors: MultiSeriesSensor[],\r\n opts: { enabled: boolean; pollMs?: number },\r\n): UseSensorSeriesMultiResult {\r\n const { enabled, pollMs } = opts\r\n const [seriesById, setSeriesById] = React.useState<Map<number, SensorSeries>>(() => new Map())\r\n const [isLoading, setIsLoading] = React.useState(false)\r\n\r\n // Only sensors with a URL can be fetched; the key is what the effect actually depends on.\r\n const targets = sensors.filter((s): s is MultiSeriesSensor & { url: string } => !!s.url)\r\n const targetsKey = targets.map(s => `${s.id}:${s.url}:${s.dataFormat}`).join('|')\r\n\r\n // Read through a ref so a new array identity with identical contents does not re-subscribe.\r\n const targetsRef = React.useRef(targets)\r\n targetsRef.current = targets\r\n\r\n React.useEffect(() => {\r\n if (!enabled || targetsKey === '') {\r\n setSeriesById(new Map())\r\n setIsLoading(false)\r\n return\r\n }\r\n\r\n let cancelled = false\r\n const controller = new AbortController()\r\n const batch = targetsRef.current\r\n const liveIds = new Set(batch.map(s => s.id))\r\n\r\n const load = async (showLoading: boolean) => {\r\n if (showLoading) setIsLoading(true)\r\n const fetched = new Map<number, SensorSeries>()\r\n\r\n await runPool(batch, MAX_CONCURRENT, async (sensor) => {\r\n try {\r\n const res = await fetch(sensor.url, { signal: controller.signal })\r\n const text = await res.text()\r\n fetched.set(sensor.id, parseSensorSeries(text, sensor.dataFormat))\r\n } catch (err) {\r\n if (cancelled || controller.signal.aborted) return\r\n console.error('Error fetching sensor data:', err)\r\n // Leave this sensor out of `fetched` so the merge below keeps its last good series.\r\n }\r\n })\r\n\r\n if (cancelled) return\r\n\r\n setSeriesById(prev => {\r\n const merged = new Map<number, SensorSeries>()\r\n // Carry forward only sensors still in the set, then overlay this round's results.\r\n for (const [id, series] of prev) {\r\n if (liveIds.has(id)) merged.set(id, series)\r\n }\r\n for (const [id, series] of fetched) merged.set(id, series)\r\n return merged\r\n })\r\n\r\n if (showLoading) setIsLoading(false)\r\n }\r\n\r\n void load(true)\r\n const timer = setInterval(\r\n () => void load(false),\r\n Math.max(pollMs ?? DEFAULT_POLL_MS, MIN_POLL_MS),\r\n )\r\n\r\n return () => {\r\n cancelled = true\r\n controller.abort()\r\n clearInterval(timer)\r\n }\r\n }, [targetsKey, enabled, pollMs])\r\n\r\n return { seriesById, isLoading }\r\n}\r\n\r\n/** Latest observed value per sensor id, for halos and current-value comparisons. */\r\nexport function latestValues(seriesById:
|
|
1
|
+
{"version":3,"sources":["../../../../../src/core/components/ui/Sensors/useSensorSeriesMulti.ts"],"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\n\r\nimport { parseSensorSeries, type SensorSeries } from './sensorData'\r\n\r\nimport type { SensorDataFormat } from '../../../types/dbTypes'\r\n\r\nconst MIN_POLL_MS = 1000\r\n/** Slower than a single card's own frequency: this hook exists to watch a whole set at once. */\r\nconst DEFAULT_POLL_MS = 15_000\r\n/** Cap on sockets opened at once, so a type with 30 sensors does not fan out 30 requests. */\r\nconst MAX_CONCURRENT = 6\r\n\r\n/** The minimum a sensor needs to expose for its series to be fetched. */\r\nexport interface MultiSeriesSensor {\r\n id: number\r\n url?: string | null\r\n dataFormat: SensorDataFormat | `${SensorDataFormat}`\r\n}\r\n\r\nexport interface UseSensorSeriesMultiResult {\r\n /** Parsed series keyed by sensor id. Sensors that have never loaded are simply absent. */\r\n seriesById: Map<number, SensorSeries>\r\n isLoading: boolean\r\n}\r\n\r\n/** Runs `worker` over `items` with at most `limit` in flight at a time. */\r\nasync function runPool<T>(items: T[], limit: number, worker: (item: T) => Promise<void>): Promise<void> {\r\n let cursor = 0\r\n const lanes = Array.from({ length: Math.min(limit, items.length) }, async () => {\r\n while (cursor < items.length) {\r\n const item = items[cursor++]\r\n await worker(item)\r\n }\r\n })\r\n await Promise.all(lanes)\r\n}\r\n\r\n/**\r\n * Fetch and poll the series for several sensors at once, parsed by the same\r\n * `parseSensorSeries` the single-sensor hook uses.\r\n *\r\n * Differences from `useSensorSeries`: one shared interval for the whole set rather than each\r\n * sensor's own `updateFrequency`, and a concurrency cap. A sensor whose fetch fails keeps its\r\n * last good series, and sensors dropped from `sensors` are evicted. Re-renders that pass an\r\n * equal-but-new array do not re-subscribe, since the effect keys on the set's identity string.\r\n *\r\n * The latest value for a sensor is `points[points.length - 1]?.value` - derive it at the call\r\n * site rather than reaching for a second hook.\r\n */\r\nexport function useSensorSeriesMulti(\r\n sensors: MultiSeriesSensor[],\r\n opts: { enabled: boolean; pollMs?: number },\r\n): UseSensorSeriesMultiResult {\r\n const { enabled, pollMs } = opts\r\n const [seriesById, setSeriesById] = React.useState<Map<number, SensorSeries>>(() => new Map())\r\n const [isLoading, setIsLoading] = React.useState(false)\r\n\r\n // Only sensors with a URL can be fetched; the key is what the effect actually depends on.\r\n const targets = sensors.filter((s): s is MultiSeriesSensor & { url: string } => !!s.url)\r\n const targetsKey = targets.map(s => `${s.id}:${s.url}:${s.dataFormat}`).join('|')\r\n\r\n // Read through a ref so a new array identity with identical contents does not re-subscribe.\r\n const targetsRef = React.useRef(targets)\r\n targetsRef.current = targets\r\n\r\n React.useEffect(() => {\r\n if (!enabled || targetsKey === '') {\r\n setSeriesById(new Map())\r\n setIsLoading(false)\r\n return\r\n }\r\n\r\n let cancelled = false\r\n const controller = new AbortController()\r\n const batch = targetsRef.current\r\n const liveIds = new Set(batch.map(s => s.id))\r\n\r\n const load = async (showLoading: boolean) => {\r\n if (showLoading) setIsLoading(true)\r\n const fetched = new Map<number, SensorSeries>()\r\n\r\n await runPool(batch, MAX_CONCURRENT, async (sensor) => {\r\n try {\r\n const res = await fetch(sensor.url, { signal: controller.signal })\r\n const text = await res.text()\r\n fetched.set(sensor.id, parseSensorSeries(text, sensor.dataFormat))\r\n } catch (err) {\r\n if (cancelled || controller.signal.aborted) return\r\n console.error('Error fetching sensor data:', err)\r\n // Leave this sensor out of `fetched` so the merge below keeps its last good series.\r\n }\r\n })\r\n\r\n if (cancelled) return\r\n\r\n setSeriesById(prev => {\r\n const merged = new Map<number, SensorSeries>()\r\n // Carry forward only sensors still in the set, then overlay this round's results.\r\n for (const [id, series] of prev) {\r\n if (liveIds.has(id)) merged.set(id, series)\r\n }\r\n for (const [id, series] of fetched) merged.set(id, series)\r\n return merged\r\n })\r\n\r\n if (showLoading) setIsLoading(false)\r\n }\r\n\r\n void load(true)\r\n const timer = setInterval(\r\n () => void load(false),\r\n Math.max(pollMs ?? DEFAULT_POLL_MS, MIN_POLL_MS),\r\n )\r\n\r\n return () => {\r\n cancelled = true\r\n controller.abort()\r\n clearInterval(timer)\r\n }\r\n }, [targetsKey, enabled, pollMs])\r\n\r\n return { seriesById, isLoading }\r\n}\r\n\r\n/** Latest observed value per sensor id, for halos and current-value comparisons. */\r\nexport function latestValues(seriesById: ReadonlyMap<number, SensorSeries>): Map<number, number> {\r\n const latest = new Map<number, number>()\r\n for (const [id, series] of seriesById) {\r\n const last = series.points[series.points.length - 1]\r\n if (last && Number.isFinite(last.value)) latest.set(id, last.value)\r\n }\r\n return latest\r\n}\r\n"],"mappings":";AAKA,YAAY,WAAW;AAEvB,SAAS,yBAA4C;AAIrD,MAAM,cAAc;AAEpB,MAAM,kBAAkB;AAExB,MAAM,iBAAiB;AAgBvB,eAAe,QAAW,OAAY,OAAe,QAAmD;AACtG,MAAI,SAAS;AACb,QAAM,QAAQ,MAAM,KAAK,EAAE,QAAQ,KAAK,IAAI,OAAO,MAAM,MAAM,EAAE,GAAG,YAAY;AAC9E,WAAO,SAAS,MAAM,QAAQ;AAC5B,YAAM,OAAO,MAAM,QAAQ;AAC3B,YAAM,OAAO,IAAI;AAAA,IACnB;AAAA,EACF,CAAC;AACD,QAAM,QAAQ,IAAI,KAAK;AACzB;AAcO,SAAS,qBACd,SACA,MAC4B;AAC5B,QAAM,EAAE,SAAS,OAAO,IAAI;AAC5B,QAAM,CAAC,YAAY,aAAa,IAAI,MAAM,SAAoC,MAAM,oBAAI,IAAI,CAAC;AAC7F,QAAM,CAAC,WAAW,YAAY,IAAI,MAAM,SAAS,KAAK;AAGtD,QAAM,UAAU,QAAQ,OAAO,CAAC,MAAgD,CAAC,CAAC,EAAE,GAAG;AACvF,QAAM,aA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AI;AACd,UAAM,QAAQ;AAAA,MACZ,MAAM,KAAK,KAAK,KAAK;AAAA,MACrB,KAAK,IAAI,0BAAU,iBAAiB,WAAW;AAAA,IACjD;AAEA,WAAO,MAAM;AACX,kBAAY;AACZ,iBAAW,MAAM;AACjB,oBAAc,KAAK;AAAA,IACrB;AAAA,EACF,GAAG,CAAC,YAAY,SAAS,MAAM,CAAC;AAEhC,SAAO,EAAE,YAAY,UAAU;AACjC;AAGO,SAAS,aAAa,YAAoE;AAC/F,QAAM,SAAS,oBAAI,IAAoB;AACvC,aAAW,CAAC,IAAI,MAAM,KAAK,YAAY;AACrC,UAAM,OAAO,OAAO,OAAO,OAAO,OAAO,SAAS,CAAC;AACnD,QAAI,QAAQ,OAAO,SAAS,KAAK,KAAK,EAAG,QAAO,IAAI,IAAI,KAAK,KAAK;AAAA,EACpE;AACA,SAAO;AACT;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BimViewer.d.ts","sourceRoot":"","sources":["../../../../../src/core/components/viewers/bim/BimViewer.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAkB/B,wBAAgB,SAAS,
|
|
1
|
+
{"version":3,"file":"BimViewer.d.ts","sourceRoot":"","sources":["../../../../../src/core/components/viewers/bim/BimViewer.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAkB/B,wBAAgB,SAAS,sBAuQxB"}
|
|
@@ -133,17 +133,21 @@ function BimViewer() {
|
|
|
133
133
|
let cancelled = false;
|
|
134
134
|
void createViewer(() => cancelled);
|
|
135
135
|
return () => {
|
|
136
|
+
var _a2;
|
|
136
137
|
cancelled = true;
|
|
137
138
|
if (resizeObserverRef.current) {
|
|
138
139
|
resizeObserverRef.current.disconnect();
|
|
139
140
|
}
|
|
140
|
-
|
|
141
|
-
componentsRef.current.dispose();
|
|
141
|
+
try {
|
|
142
|
+
(_a2 = componentsRef.current) == null ? void 0 : _a2.dispose();
|
|
143
|
+
} catch (error) {
|
|
144
|
+
console.error("BIM teardown did not complete cleanly", error);
|
|
145
|
+
} finally {
|
|
142
146
|
componentsRef.current = null;
|
|
147
|
+
bimDispatch({
|
|
148
|
+
type: "DISPOSE-BIM"
|
|
149
|
+
});
|
|
143
150
|
}
|
|
144
|
-
bimDispatch({
|
|
145
|
-
type: "DISPOSE-BIM"
|
|
146
|
-
});
|
|
147
151
|
};
|
|
148
152
|
}, []);
|
|
149
153
|
useBimCoordinateSystem((_c = (_b = (_a = bimState.bim.world) == null ? void 0 : _a.camera) == null ? void 0 : _b.controls) != null ? _c : null);
|
|
@@ -192,7 +196,7 @@ function BimViewer() {
|
|
|
192
196
|
}
|
|
193
197
|
}
|
|
194
198
|
),
|
|
195
|
-
/* @__PURE__ */ jsx("div", { className: "absolute bottom-3 left-3 z-10 flex flex-col gap-2 pointer-events-none", children: /* @__PURE__ */ jsx(SensorLegend, {}) }),
|
|
199
|
+
/* @__PURE__ */ jsx("div", { className: "absolute bottom-20 md:bottom-3 left-3 z-10 flex max-w-[calc(100vw-1.5rem)] flex-col gap-2 pointer-events-none", children: /* @__PURE__ */ jsx(SensorLegend, {}) }),
|
|
196
200
|
/* @__PURE__ */ jsx(PropertiesMenu, {})
|
|
197
201
|
]
|
|
198
202
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/core/components/viewers/bim/BimViewer.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 OBC from \"@thatopen/components\";\r\nimport * as OBF from \"@thatopen/components-front\"\r\nimport { useTranslations, useLocale } from 'next-intl';\r\nimport * as React from \"react\";\r\nimport * as THREE from \"three\";\r\n\r\nimport { ToolsContext, BimContext, MenusContext } from \"../../../store\";\r\nimport { SensorLegend } from \"../../ui/Sensors/SensorLegend\";\r\nimport { useBimCoordinateSystem } from \"../useCoordinateSystem\";\r\n\r\nimport { BimLoadingState } from \"./src/BimLoadingState\";\r\nimport { CurrentCamera } from './src/CurrentCamera';\r\nimport { CurrentWorld } from \"./src/CurrentWorld\";\r\nimport { ElevationsTool } from \"./src/ElevationsTool\";\r\nimport { FloorplanTool } from \"./src/FloorplanTool\";\r\nimport { Highlighter } from \"./src/Highlighter\";\r\nimport { ViewModeCoordinator } from \"./src/lib/ViewModeCoordinator\";\r\nimport { PropertiesMenu } from \"./src/propertiesMenu\";\r\nimport { ViewportGizmo } from \"./src/ViewportGizmo\";\r\n\r\n\r\nexport function BimViewer() {\r\n\r\n const t = useTranslations('ViewportGizmo');\r\n const locale = useLocale();\r\n\r\n const { dispatch: bimDispatch, state: bimState } = React.useContext(BimContext);\r\n const { bimComponents } = bimState.bim;\r\n\r\n const { dispatch: toolsDispatch, state: toolsState } = React.useContext(ToolsContext);\r\n const { currentToolId } = toolsState.tools;\r\n\r\n const { state: menusState } = React.useContext(MenusContext);\r\n const { currentViewer } = menusState.menus;\r\n\r\n\r\n const containerRef = React.useRef<HTMLDivElement>(null);\r\n const workerUrlRef = React.useRef<string | null>(null);\r\n const resizeObserverRef = React.useRef<ResizeObserver | null>(null);\r\n // Tracks the Components instance THIS mount created, so cleanup disposes the\r\n // real one and the create-guard can't be defeated by a stale [] closure.\r\n const componentsRef = React.useRef<OBC.Components | null>(null);\r\n\r\n const createViewer = React.useCallback(\r\n async (isCancelled: () => boolean) => {\r\n // Re-entrancy guard keyed to the ref we actually set — NOT the stale\r\n // `bimComponents` from this useCallback's [] closure (always null on\r\n // first run, so it could never stop a second init). Without this,\r\n // React StrictMode (dev) and rapid viewer remounts (prod) build a\r\n // second Components + PostproductionRenderer — a second <canvas> —\r\n // and whichever instance wins the SET_COMPONENTS race may be the one\r\n // whose canvas was detached on remount. Models then load into a scene\r\n // that is never painted: the spatial tree builds (metadata) but no\r\n // geometry shows and floorplan nav drives the dead world's camera.\r\n if (!containerRef.current || componentsRef.current) return;\r\n\r\n const container = containerRef.current;\r\n const components = new OBC.Components();\r\n const worlds = components.get(OBC.Worlds);\r\n const world = worlds.create<\r\n OBC.ShadowedScene,\r\n OBC.OrthoPerspectiveCamera,\r\n OBF.PostproductionRenderer\r\n >();\r\n\r\n world.scene = new OBC.ShadowedScene(components);\r\n\r\n world.renderer = new OBF.PostproductionRenderer(components, container);\r\n world.camera = new OBC.OrthoPerspectiveCamera(components);\r\n\r\n components.init();\r\n\r\n world.scene.setup();\r\n world.scene.three.background = null;\r\n\r\n const grids = components.get(OBC.Grids);\r\n const grid = grids.create(world);\r\n\r\n if (grid) {\r\n bimDispatch({\r\n \"type\": \"SET_GRID\",\r\n \"payload\": { grid }\r\n });\r\n }\r\n\r\n const axesHelper = new THREE.AxesHelper(5);\r\n world.scene.three.add(axesHelper);\r\n\r\n const fragments = components.get(OBC.FragmentsManager);\r\n\r\n const githubUrl =\r\n \"https://thatopen.github.io/engine_fragment/resources/worker.mjs\";\r\n const fetchedUrl = await fetch(githubUrl);\r\n const workerBlob = await fetchedUrl.blob();\r\n const workerFile = new File([workerBlob], \"worker.mjs\", {\r\n type: \"text/javascript\",\r\n });\r\n const workerUrl = URL.createObjectURL(workerFile);\r\n workerUrlRef.current = workerUrl; // Store reference for cleanup\r\n fragments.init(workerUrl);\r\n\r\n world.camera.controls.addEventListener(\"control\", () =>\r\n fragments.core.update(),\r\n );\r\n\r\n world.camera.controls.restThreshold = 0.005;\r\n world.camera.controls.addEventListener(\"rest\", () =>\r\n fragments.core.update(true)\r\n );\r\n\r\n components.get(CurrentWorld).world = world;\r\n components.get(CurrentCamera).camera = world.camera;\r\n components.get(Highlighter);\r\n components.get(ViewModeCoordinator);\r\n components.get(FloorplanTool);\r\n components.get(ElevationsTool);\r\n\r\n // Grid injection is safe here — fragments.core is initialized.\r\n if (grid) {\r\n components.get(FloorplanTool).setGrid(grid);\r\n components.get(ElevationsTool).setGrid(grid);\r\n }\r\n\r\n // Enable shadows\r\n world.renderer.three.shadowMap.enabled = true;\r\n world.renderer.three.shadowMap.type = THREE.PCFSoftShadowMap;\r\n world.scene.setup({\r\n shadows: {\r\n cascade: 1,\r\n resolution: 1024,\r\n },\r\n });\r\n\r\n world.scene.distanceRenderer.excludedObjects.add(grid.three);\r\n\r\n await world.scene.updateShadows();\r\n\r\n world.camera.controls.addEventListener(\"rest\", async () => {\r\n await world.scene.updateShadows();\r\n });\r\n\r\n world.scene.three.background = null;\r\n\r\n // If this init was superseded (StrictMode re-run) or the viewer\r\n // unmounted while we awaited the worker fetch / shadow update, throw\r\n // this instance away instead of publishing it. Prevents an orphaned\r\n // world (whose canvas is detached) from winning the store and starving\r\n // the visible canvas of geometry.\r\n if (isCancelled()) {\r\n components.dispose();\r\n return;\r\n }\r\n componentsRef.current = components;\r\n bimDispatch({\r\n type: \"SET_COMPONENTS\",\r\n payload: { bimComponents: components, world, fragments }\r\n });\r\n\r\n // Ensure canvas takes full container size\r\n const canvas = container.querySelector('canvas');\r\n if (canvas) {\r\n canvas.style.width = '100%';\r\n canvas.style.height = '100%';\r\n canvas.style.display = 'block';\r\n }\r\n\r\n // Handle resize using container dimensions\r\n const handleResize = () => {\r\n const width = container.clientWidth;\r\n const height = container.clientHeight;\r\n if (width && height) {\r\n world.renderer?.resize(new THREE.Vector2(width, height));\r\n }\r\n };\r\n\r\n // Initial resize\r\n handleResize();\r\n\r\n // Watch for container size changes using ResizeObserver. This\r\n // already covers the window-resize case: when the window resizes,\r\n // the flex layout reshapes this container, and ResizeObserver\r\n // fires.\r\n const resizeObserver = new ResizeObserver(() => {\r\n handleResize();\r\n });\r\n resizeObserver.observe(container);\r\n resizeObserverRef.current = resizeObserver;\r\n\r\n // The ResizeObserver above is sufficient for redraws. A window\r\n // 'resize' listener here previously leaked on every mount (no matching\r\n // removeEventListener), so it was removed.\r\n }, []\r\n );\r\n\r\n React.useEffect(() => {\r\n let cancelled = false;\r\n void createViewer(() => cancelled);\r\n\r\n // Cleanup: mark this init cancelled (so an in-flight createViewer disposes\r\n // itself instead of publishing), and dispose the instance we actually\r\n // created (componentsRef). The old `if (bimComponents)` read the stale []\r\n // closure value (null at mount), so the real Components was never disposed\r\n // — leaking its renderer/canvas and letting orphans race the store.\r\n return () => {\r\n cancelled = true;\r\n if (resizeObserverRef.current) {\r\n resizeObserverRef.current.disconnect();\r\n }\r\n if (componentsRef.current) {\r\n componentsRef.current.dispose();\r\n componentsRef.current = null;\r\n }\r\n bimDispatch({\r\n type: \"DISPOSE-BIM\"\r\n });\r\n };\r\n }, []);\r\n\r\n // Enforce Y-up coordinate system for Three.js / camera-controls.\r\n // Runs whenever the world (and its controls) becomes available, and resets on unmount.\r\n useBimCoordinateSystem(bimState.bim.world?.camera?.controls ?? null);\r\n\r\n // Control ViewportGizmo based on current viewer\r\n React.useEffect(() => {\r\n if (!bimComponents) return;\r\n\r\n const viewportGizmo = bimComponents.get(ViewportGizmo);\r\n\r\n viewportGizmo.setLabels({\r\n top: t('top'),\r\n right: t('right'),\r\n bottom: t('bottom'),\r\n left: t('left'),\r\n front: t('front'),\r\n back: t('back')\r\n });\r\n\r\n if (!viewportGizmo) return;\r\n\r\n if (currentViewer === 'bim') {\r\n viewportGizmo.enabled = true;\r\n viewportGizmo.add();\r\n } else {\r\n viewportGizmo.enabled = false;\r\n viewportGizmo.remove();\r\n }\r\n }, [bimComponents, currentViewer, locale, t]);\r\n\r\n return (\r\n <div\r\n style={{\r\n position: \"relative\",\r\n width: \"100%\",\r\n height: \"100%\",\r\n overflow: \"hidden\"\r\n }}\r\n >\r\n <BimLoadingState />\r\n <div\r\n className=\"bim-container\"\r\n id=\"bim-viewer-container\"\r\n ref={containerRef}\r\n style={{\r\n width: \"100%\",\r\n height: \"100%\",\r\n position: \"relative\",\r\n background: \"radial-gradient(circle, rgba(255, 255, 255, 1) 50%, rgba(220, 220, 220, 1) 100%)\",\r\n }}\r\n />\r\n {/* Bottom-left stack, mirroring MapViewer: cards stack upward with flex so a new\r\n overlay never needs a hand-tuned bottom offset. */}\r\n <div className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AAQ;AAAA,cACR,UAAU;AAAA,cACV,YAAY;AAAA,YAChB;AAAA;AAAA,QACJ;AAAA,QAGA,oBAAC,SAAI,WAAU,yEACX,8BAAC,gBAAa,GAClB;AAAA,QACA,oBAAC,kBAAe;AAAA;AAAA;AAAA,EACpB;AAER;","names":["_a"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/core/components/viewers/bim/BimViewer.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 OBC from \"@thatopen/components\";\r\nimport * as OBF from \"@thatopen/components-front\"\r\nimport { useTranslations, useLocale } from 'next-intl';\r\nimport * as React from \"react\";\r\nimport * as THREE from \"three\";\r\n\r\nimport { ToolsContext, BimContext, MenusContext } from \"../../../store\";\r\nimport { SensorLegend } from \"../../ui/Sensors/SensorLegend\";\r\nimport { useBimCoordinateSystem } from \"../useCoordinateSystem\";\r\n\r\nimport { BimLoadingState } from \"./src/BimLoadingState\";\r\nimport { CurrentCamera } from './src/CurrentCamera';\r\nimport { CurrentWorld } from \"./src/CurrentWorld\";\r\nimport { ElevationsTool } from \"./src/ElevationsTool\";\r\nimport { FloorplanTool } from \"./src/FloorplanTool\";\r\nimport { Highlighter } from \"./src/Highlighter\";\r\nimport { ViewModeCoordinator } from \"./src/lib/ViewModeCoordinator\";\r\nimport { PropertiesMenu } from \"./src/propertiesMenu\";\r\nimport { ViewportGizmo } from \"./src/ViewportGizmo\";\r\n\r\n\r\nexport function BimViewer() {\r\n\r\n const t = useTranslations('ViewportGizmo');\r\n const locale = useLocale();\r\n\r\n const { dispatch: bimDispatch, state: bimState } = React.useContext(BimContext);\r\n const { bimComponents } = bimState.bim;\r\n\r\n const { dispatch: toolsDispatch, state: toolsState } = React.useContext(ToolsContext);\r\n const { currentToolId } = toolsState.tools;\r\n\r\n const { state: menusState } = React.useContext(MenusContext);\r\n const { currentViewer } = menusState.menus;\r\n\r\n\r\n const containerRef = React.useRef<HTMLDivElement>(null);\r\n const workerUrlRef = React.useRef<string | null>(null);\r\n const resizeObserverRef = React.useRef<ResizeObserver | null>(null);\r\n // Tracks the Components instance THIS mount created, so cleanup disposes the\r\n // real one and the create-guard can't be defeated by a stale [] closure.\r\n const componentsRef = React.useRef<OBC.Components | null>(null);\r\n\r\n const createViewer = React.useCallback(\r\n async (isCancelled: () => boolean) => {\r\n // Re-entrancy guard keyed to the ref we actually set — NOT the stale\r\n // `bimComponents` from this useCallback's [] closure (always null on\r\n // first run, so it could never stop a second init). Without this,\r\n // React StrictMode (dev) and rapid viewer remounts (prod) build a\r\n // second Components + PostproductionRenderer — a second <canvas> —\r\n // and whichever instance wins the SET_COMPONENTS race may be the one\r\n // whose canvas was detached on remount. Models then load into a scene\r\n // that is never painted: the spatial tree builds (metadata) but no\r\n // geometry shows and floorplan nav drives the dead world's camera.\r\n if (!containerRef.current || componentsRef.current) return;\r\n\r\n const container = containerRef.current;\r\n const components = new OBC.Components();\r\n const worlds = components.get(OBC.Worlds);\r\n const world = worlds.create<\r\n OBC.ShadowedScene,\r\n OBC.OrthoPerspectiveCamera,\r\n OBF.PostproductionRenderer\r\n >();\r\n\r\n world.scene = new OBC.ShadowedScene(components);\r\n\r\n world.renderer = new OBF.PostproductionRenderer(components, container);\r\n world.camera = new OBC.OrthoPerspectiveCamera(components);\r\n\r\n components.init();\r\n\r\n world.scene.setup();\r\n world.scene.three.background = null;\r\n\r\n const grids = components.get(OBC.Grids);\r\n const grid = grids.create(world);\r\n\r\n if (grid) {\r\n bimDispatch({\r\n \"type\": \"SET_GRID\",\r\n \"payload\": { grid }\r\n });\r\n }\r\n\r\n const axesHelper = new THREE.AxesHelper(5);\r\n world.scene.three.add(axesHelper);\r\n\r\n const fragments = components.get(OBC.FragmentsManager);\r\n\r\n const githubUrl =\r\n \"https://thatopen.github.io/engine_fragment/resources/worker.mjs\";\r\n const fetchedUrl = await fetch(githubUrl);\r\n const workerBlob = await fetchedUrl.blob();\r\n const workerFile = new File([workerBlob], \"worker.mjs\", {\r\n type: \"text/javascript\",\r\n });\r\n const workerUrl = URL.createObjectURL(workerFile);\r\n workerUrlRef.current = workerUrl; // Store reference for cleanup\r\n fragments.init(workerUrl);\r\n\r\n world.camera.controls.addEventListener(\"control\", () =>\r\n fragments.core.update(),\r\n );\r\n\r\n world.camera.controls.restThreshold = 0.005;\r\n world.camera.controls.addEventListener(\"rest\", () =>\r\n fragments.core.update(true)\r\n );\r\n\r\n components.get(CurrentWorld).world = world;\r\n components.get(CurrentCamera).camera = world.camera;\r\n components.get(Highlighter);\r\n components.get(ViewModeCoordinator);\r\n components.get(FloorplanTool);\r\n components.get(ElevationsTool);\r\n\r\n // Grid injection is safe here — fragments.core is initialized.\r\n if (grid) {\r\n components.get(FloorplanTool).setGrid(grid);\r\n components.get(ElevationsTool).setGrid(grid);\r\n }\r\n\r\n // Enable shadows\r\n world.renderer.three.shadowMap.enabled = true;\r\n world.renderer.three.shadowMap.type = THREE.PCFSoftShadowMap;\r\n world.scene.setup({\r\n shadows: {\r\n cascade: 1,\r\n resolution: 1024,\r\n },\r\n });\r\n\r\n world.scene.distanceRenderer.excludedObjects.add(grid.three);\r\n\r\n await world.scene.updateShadows();\r\n\r\n world.camera.controls.addEventListener(\"rest\", async () => {\r\n await world.scene.updateShadows();\r\n });\r\n\r\n world.scene.three.background = null;\r\n\r\n // If this init was superseded (StrictMode re-run) or the viewer\r\n // unmounted while we awaited the worker fetch / shadow update, throw\r\n // this instance away instead of publishing it. Prevents an orphaned\r\n // world (whose canvas is detached) from winning the store and starving\r\n // the visible canvas of geometry.\r\n if (isCancelled()) {\r\n components.dispose();\r\n return;\r\n }\r\n componentsRef.current = components;\r\n bimDispatch({\r\n type: \"SET_COMPONENTS\",\r\n payload: { bimComponents: components, world, fragments }\r\n });\r\n\r\n // Ensure canvas takes full container size\r\n const canvas = container.querySelector('canvas');\r\n if (canvas) {\r\n canvas.style.width = '100%';\r\n canvas.style.height = '100%';\r\n canvas.style.display = 'block';\r\n }\r\n\r\n // Handle resize using container dimensions\r\n const handleResize = () => {\r\n const width = container.clientWidth;\r\n const height = container.clientHeight;\r\n if (width && height) {\r\n world.renderer?.resize(new THREE.Vector2(width, height));\r\n }\r\n };\r\n\r\n // Initial resize\r\n handleResize();\r\n\r\n // Watch for container size changes using ResizeObserver. This\r\n // already covers the window-resize case: when the window resizes,\r\n // the flex layout reshapes this container, and ResizeObserver\r\n // fires.\r\n const resizeObserver = new ResizeObserver(() => {\r\n handleResize();\r\n });\r\n resizeObserver.observe(container);\r\n resizeObserverRef.current = resizeObserver;\r\n\r\n // The ResizeObserver above is sufficient for redraws. A window\r\n // 'resize' listener here previously leaked on every mount (no matching\r\n // removeEventListener), so it was removed.\r\n }, []\r\n );\r\n\r\n React.useEffect(() => {\r\n let cancelled = false;\r\n void createViewer(() => cancelled);\r\n\r\n // Cleanup: mark this init cancelled (so an in-flight createViewer disposes\r\n // itself instead of publishing), and dispose the instance we actually\r\n // created (componentsRef). The old `if (bimComponents)` read the stale []\r\n // closure value (null at mount), so the real Components was never disposed\r\n // — leaking its renderer/canvas and letting orphans race the store.\r\n return () => {\r\n cancelled = true;\r\n if (resizeObserverRef.current) {\r\n resizeObserverRef.current.disconnect();\r\n }\r\n // OBC walks components in insertion order and does not guard the loop, so one\r\n // component throwing during teardown aborts every disposal after it — including\r\n // FragmentsManager, which it deliberately leaves for last. The store must be cleared\r\n // either way, or it keeps handing out a dead Components/world to whatever mounts next.\r\n try {\r\n componentsRef.current?.dispose();\r\n } catch (error) {\r\n console.error(\"BIM teardown did not complete cleanly\", error);\r\n } finally {\r\n componentsRef.current = null;\r\n bimDispatch({\r\n type: \"DISPOSE-BIM\"\r\n });\r\n }\r\n };\r\n }, []);\r\n\r\n // Enforce Y-up coordinate system for Three.js / camera-controls.\r\n // Runs whenever the world (and its controls) becomes available, and resets on unmount.\r\n useBimCoordinateSystem(bimState.bim.world?.camera?.controls ?? null);\r\n\r\n // Control ViewportGizmo based on current viewer\r\n React.useEffect(() => {\r\n if (!bimComponents) return;\r\n\r\n const viewportGizmo = bimComponents.get(ViewportGizmo);\r\n\r\n viewportGizmo.setLabels({\r\n top: t('top'),\r\n right: t('right'),\r\n bottom: t('bottom'),\r\n left: t('left'),\r\n front: t('front'),\r\n back: t('back')\r\n });\r\n\r\n if (!viewportGizmo) return;\r\n\r\n if (currentViewer === 'bim') {\r\n viewportGizmo.enabled = true;\r\n viewportGizmo.add();\r\n } else {\r\n viewportGizmo.enabled = false;\r\n viewportGizmo.remove();\r\n }\r\n }, [bimComponents, currentViewer, locale, t]);\r\n\r\n return (\r\n <div\r\n style={{\r\n position: \"relative\",\r\n width: \"100%\",\r\n height: \"100%\",\r\n overflow: \"hidden\"\r\n }}\r\n >\r\n <BimLoadingState />\r\n <div\r\n className=\"bim-container\"\r\n id=\"bim-viewer-container\"\r\n ref={containerRef}\r\n style={{\r\n width: \"100%\",\r\n height: \"100%\",\r\n position: \"relative\",\r\n background: \"radial-gradient(circle, rgba(255, 255, 255, 1) 50%, rgba(220, 220, 220, 1) 100%)\",\r\n }}\r\n />\r\n {/* Bottom-left stack, mirroring MapViewer: cards stack upward with flex so a new\r\n overlay never needs a hand-tuned bottom offset. */}\r\n <div className=\"absolute bottom-20 md:bottom-3 left-3 z-10 flex max-w-[calc(100vw-1.5rem)] flex-col gap-2 pointer-events-none\">\r\n <SensorLegend />\r\n </div>\r\n <PropertiesMenu />\r\n </div>\r\n );\r\n}"],"mappings":";AAqQQ,SAQI,KARJ;AAhQR,YAAY,SAAS;AACrB,YAAY,SAAS;AACrB,SAAS,iBAAiB,iBAAiB;AAC3C,YAAY,WAAW;AACvB,YAAY,WAAW;AAEvB,SAAS,cAAc,YAAY,oBAAoB;AACvD,SAAS,oBAAoB;AAC7B,SAAS,8BAA8B;AAEvC,SAAS,uBAAuB;AAChC,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AAC7B,SAAS,sBAAsB;AAC/B,SAAS,qBAAqB;AAC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