@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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/core/components/ui/Sensors/SensorsSection.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\nimport { toast } from 'sonner'\r\n\r\nimport { useSensor, useSensors } from '../../../hooks/sensors/sensors'\r\nimport { useSensorTypes } from '../../../hooks/sensorTypes/sensorTypes'\r\nimport { AppConfigContext, BuildingsContext, MenusContext, ToolsContext } from '../../../store'\r\nimport { resolveDefaultTimeZone } from '../../../utils/timeUtils'\r\nimport { stringToColour } from '../../viewers/map/utils/stringToColour'\r\nimport { Button } from '../Button'\r\nimport { CollapsibleSection } from '../CollapsibleSection'\r\nimport { DropdownMenu } from '../DropdownMenu'\r\nimport {\r\n DropdownMenuTrigger,\r\n DropdownMenuContent,\r\n DropdownMenuLabel,\r\n DropdownMenuSeparator,\r\n DropdownMenuRadioGroup,\r\n DropdownMenuRadioItem,\r\n} from '../DropdownMenu'\r\nimport { SearchInput } from '../SearchInput'\r\n\r\nimport { CollapsibleSensorItem } from './CollapsibleSensorItem'\r\nimport { SensorInput } from './SensorInput'\r\nimport { SensorsSectionSkeleton } from './SensorsSectionSkeleton'\r\nimport { resolveLucideIcon } from './sensorUtils'\r\nimport { valueColoursBySensor } from './sensorValueColours'\r\nimport { useSensorSeriesMulti } from './useSensorSeriesMulti'\r\n\r\nimport type { Sensor } from '../../../types/dbTypes';\r\n\r\n/** Sidebar readings: compact, at most one decimal, so a row stays on one line. */\r\nconst readingNumber = new Intl.NumberFormat(undefined, { maximumFractionDigits: 1 })\r\n\r\n\r\ntype SensorAction = 'view' | 'edit' | 'delete'\r\n\r\n/** Stable key used in state for sensors with no tags — locale-independent */\r\nexport const UNTAGGED_TAG = '__untagged__'\r\n\r\nexport function SensorsSection() {\r\n // Translation\r\n const t = useTranslations('SensorsSection')\r\n\r\n const { dispatch: toolsDispatch } = React.useContext(ToolsContext)\r\n const { state: menusState, dispatch: menusDispatch } = React.useContext(MenusContext)\r\n const { currentViewer, visibleSensorTypes, visibleSensorTags, focusedSensorId } = menusState.menus\r\n\r\n const { sensors: allSensors }: { sensors: Sensor[] } = useSensors()\r\n const { sensorTypes, isLoading } = useSensorTypes()\r\n\r\n const {state: buildingsState} = React.useContext(BuildingsContext)\r\n const buildingId = buildingsState?.buildings?.building?.id || -1\r\n\r\n const { state: appConfigState, dispatch: appConfigDispatch } = React.useContext(AppConfigContext)\r\n\r\n const [sensorToDelete, setSensorToDelete] = React.useState<number | null>(null)\r\n const [editSensorId, setEditSensorId] = React.useState<number | null>(null)\r\n const [searchQuery, setSearchQuery] = React.useState('')\r\n const [groupBy, setGroupBy] = React.useState<'type' | 'tag'>('type')\r\n const { deleteSensor } = useSensor(sensorToDelete)\r\n\r\n const handleAddSensor = React.useCallback((currentSensorTypeId?: number) => {\r\n if (!currentViewer) return\r\n toolsDispatch({\r\n type: 'SET-TOOL',\r\n payload: {\r\n currentToolId:\r\n currentViewer === 'bim'\r\n ? 'bim-add-sensor'\r\n : currentViewer === 'map'\r\n ? 'map-add-sensor'\r\n : undefined,\r\n },\r\n })\r\n if (currentSensorTypeId) {\r\n menusDispatch({\r\n type: 'SET_CURRENT_SENSOR_TYPE_ID',\r\n payload: { currentSensorTypeId },\r\n })\r\n }\r\n }, [toolsDispatch, currentViewer])\r\n\r\n const handleSensorAction = React.useCallback((action: SensorAction, id: number) => {\r\n switch (action) {\r\n case 'view':\r\n // ⚠️ View sensor action not implemented\r\n break\r\n case 'edit':\r\n setEditSensorId(id)\r\n break\r\n case 'delete':\r\n toast.success(t('sensorDeleted'))\r\n setSensorToDelete(id)\r\n break\r\n default:\r\n break\r\n }\r\n }, [t])\r\n\r\n // Trigger deletion when sensorToDelete changes\r\n React.useEffect(() => {\r\n if (sensorToDelete !== null) {\r\n void deleteSensor()\r\n setSensorToDelete(null)\r\n }\r\n }, [sensorToDelete, deleteSensor])\r\n\r\n const currentSensors: Sensor[] = allSensors.filter((sensor) => currentViewer === sensor.viewer && (!sensor.buildingId || sensor.buildingId === buildingId))\r\n\r\n // Readings for every listed sensor, so each row can be ringed by its current value. This is the\r\n // only place that polls across types; the viewers poll the focused type alone. Bounded by\r\n // useSensorSeriesMulti's concurrency cap and only active while this panel is mounted.\r\n const { seriesById } = useSensorSeriesMulti(currentSensors, { enabled: currentSensors.length > 0 })\r\n const readings = React.useMemo(\r\n () => valueColoursBySensor(currentSensors, sensorTypes, seriesById),\r\n [seriesById, sensorTypes, currentSensors.map(s => s.id).join(',')],\r\n )\r\n const readingText = (sensorId: number): string | undefined => {\r\n const reading = readings.get(sensorId)\r\n if (!reading) return undefined\r\n const unit = seriesById.get(sensorId)?.unit\r\n const labels = seriesById.get(sensorId)?.valueLabels\r\n return labels?.[reading.value] ?? `${readingNumber.format(reading.value)}${unit ? ` ${unit}` : ''}`\r\n }\r\n\r\n // Default the display zone from the building's (else a sensor's) longitude, until the user overrides.\r\n // Depends on primitive longitudes (not the re-created currentSensors array) so it only runs on real change.\r\n const buildingLongitude = buildingsState?.buildings?.building?.buildingLongitude ?? null\r\n const firstSensorLongitude = currentSensors.find(s => typeof s.longitude === 'number')?.longitude ?? null\r\n const { displayTimeZone, displayTimeZoneUserSet } = appConfigState.appConfig\r\n React.useEffect(() => {\r\n if (displayTimeZoneUserSet) return\r\n // BIM sensors live in a building (use its longitude); map sensors carry their own.\r\n const candidates = currentViewer === 'bim'\r\n ? [buildingLongitude, firstSensorLongitude]\r\n : [firstSensorLongitude, buildingLongitude]\r\n const zone = resolveDefaultTimeZone(candidates)\r\n if (zone !== displayTimeZone) {\r\n appConfigDispatch({ type: 'SET_DEFAULT_TIME_ZONE', payload: { displayTimeZone: zone } })\r\n }\r\n }, [currentViewer, buildingLongitude, firstSensorLongitude, displayTimeZone, displayTimeZoneUserSet, appConfigDispatch])\r\n\r\n // Filter sensors based on search query\r\n const filteredSensors = React.useMemo(() => {\r\n if (!searchQuery.trim()) return currentSensors\r\n\r\n const query = searchQuery.toLowerCase()\r\n return currentSensors.filter((sensor) => {\r\n const sensorTypeName =\r\n sensorTypes.find(type => type.id === sensor.typeId)?.name ?? ''\r\n return (\r\n sensor.name?.toLowerCase().includes(query) ||\r\n sensorTypeName.toLowerCase().includes(query)\r\n )\r\n })\r\n }, [currentSensors, searchQuery])\r\n\r\n const toggleSensorTypeVisibility = React.useCallback((sensorTypeId: number) => {\r\n menusDispatch({\r\n type: 'TOGGLE_SENSOR_TYPE_VISIBILITY',\r\n payload: {\r\n viewer: currentViewer,\r\n sensorTypeId: sensorTypeId,\r\n },\r\n })\r\n }, [currentViewer, menusDispatch])\r\n\r\n const handleGroupByChange = React.useCallback((newGroupBy: 'type' | 'tag') => {\r\n setGroupBy(newGroupBy)\r\n // Clear the opposing visibility state so markers from the old filter don't bleed through\r\n if (newGroupBy === 'tag') {\r\n menusDispatch({ type: 'HIDE_ALL_SENSORS_IN_VIEWER', payload: { viewer: currentViewer } })\r\n } else {\r\n menusDispatch({ type: 'HIDE_ALL_SENSOR_TAGS_IN_VIEWER', payload: { viewer: currentViewer } })\r\n }\r\n }, [currentViewer, menusDispatch])\r\n\r\n const toggleSensorTagVisibility = React.useCallback((tag: string) => {\r\n menusDispatch({\r\n type: 'TOGGLE_SENSOR_TAG_VISIBILITY',\r\n payload: {\r\n viewer: currentViewer,\r\n sensorTag: tag,\r\n },\r\n })\r\n }, [currentViewer, menusDispatch])\r\n\r\n // Group sensors by type, using sensorTypes as the source of truth for types\r\n const sensorsByType = React.useMemo(() => {\r\n const grouped: Record<string, Sensor[]> = {}\r\n sensorTypes.forEach(type => {\r\n grouped[type.name] = []\r\n })\r\n filteredSensors.forEach(sensor => {\r\n const type = sensorTypes.find(t => t.id === sensor.typeId)\r\n const typeName = type?.name ?? 'Other'\r\n if (!grouped[typeName]) {\r\n grouped[typeName] = []\r\n }\r\n grouped[typeName].push(sensor)\r\n })\r\n // Remove empty groups\r\n Object.keys(grouped).forEach(key => {\r\n if (grouped[key].length === 0) {\r\n delete grouped[key]\r\n }\r\n })\r\n return grouped\r\n }, [filteredSensors, sensorTypes])\r\n\r\n // Group sensors by tag\r\n const sensorsByTag = React.useMemo(() => {\r\n const grouped: Record<string, Sensor[]> = {}\r\n filteredSensors.forEach(sensor => {\r\n const tags = sensor.tags && sensor.tags.length > 0 ? sensor.tags : [UNTAGGED_TAG]\r\n tags.forEach(tag => {\r\n if (!grouped[tag]) grouped[tag] = []\r\n grouped[tag].push(sensor)\r\n })\r\n })\r\n return grouped\r\n }, [filteredSensors])\r\n\r\n return (\r\n <div className=\"flex-1 flex flex-col space-y-4 overflow-hidden\">\r\n <div className=\"px-4 flex items-center gap-2\">\r\n <SearchInput\r\n placeholder={t('searchSensors')}\r\n value={searchQuery}\r\n onChange={e => setSearchQuery(e.target.value)}\r\n />\r\n <DropdownMenu>\r\n <DropdownMenuTrigger asChild>\r\n <Button variant=\"outline\" size=\"icon\" title={t('filters')} className=\"flex-shrink-0\">\r\n <LR.Funnel size={16} />\r\n </Button>\r\n </DropdownMenuTrigger>\r\n <DropdownMenuContent align=\"end\">\r\n <DropdownMenuLabel>{t('groupBy')}</DropdownMenuLabel>\r\n <DropdownMenuSeparator />\r\n <DropdownMenuRadioGroup value={groupBy} onValueChange={v => handleGroupByChange(v as 'type' | 'tag')}>\r\n <DropdownMenuRadioItem value=\"type\">\r\n <LR.Layers className=\"mr-2 h-4 w-4\" />\r\n {t('groupByType')}\r\n </DropdownMenuRadioItem>\r\n <DropdownMenuRadioItem value=\"tag\">\r\n <LR.Tag className=\"mr-2 h-4 w-4\" />\r\n {t('groupByTag')}\r\n </DropdownMenuRadioItem>\r\n </DropdownMenuRadioGroup>\r\n </DropdownMenuContent>\r\n </DropdownMenu>\r\n </div>\r\n {isLoading ? (\r\n <SensorsSectionSkeleton />\r\n ) :\r\n filteredSensors.length === 0 ? (\r\n <div className=\"p-4 text-muted-foreground text-sm flex flex-col items-center\">\r\n <div>{t('noSensorsFound')}</div>\r\n <Button\r\n className=\"mt-2 px-4 \"\r\n variant='outline'\r\n onClick={() => handleAddSensor()}\r\n >\r\n {t('addSensorTitle')}\r\n </Button>\r\n </div>\r\n ) : groupBy === 'type' ? (\r\n Object.entries(sensorsByType).map(([typeName, sensorsOfType]) => {\r\n const type = sensorTypes.find(t => t.name === typeName)\r\n const typeId = type?.id ?? -1\r\n\r\n const viewerTypes = visibleSensorTypes?.[currentViewer]\r\n const isTypeVisible = viewerTypes?.length > 0 && viewerTypes.includes(typeId)\r\n\r\n const sensorIcon = resolveLucideIcon(type?.icon)\r\n\r\n return (\r\n <CollapsibleSection\r\n key={typeName}\r\n title={typeName.replace(/_/g, ' ')}\r\n icon={sensorIcon}\r\n className=\"overflow-y-auto\"\r\n itemCount={sensorsOfType.length}\r\n onAddItem={() => handleAddSensor(typeId)}\r\n addItemTitle={t('addSensorTitle')}\r\n defaultOpen={false}\r\n switchVariant={{\r\n checked: isTypeVisible,\r\n onCheckedChange: () => toggleSensorTypeVisibility(typeId),\r\n }}\r\n >\r\n <div className=\"space-y-2 mx-2 pr-2\">\r\n {sensorsOfType.map((sensor) => (\r\n <CollapsibleSensorItem\r\n key={sensor.id}\r\n sensor={sensor}\r\n sensorType={type}\r\n onAction={handleSensorAction}\r\n isVisible={isTypeVisible}\r\n onMouseEnter={() => menusDispatch({ type: 'SET_CURRENT_SENSOR_ID', payload: { currentSensorId: sensor.id } })}\r\n onMouseLeave={() => menusDispatch({ type: 'SET_CURRENT_SENSOR_ID', payload: { currentSensorId: null } })}\r\n onSelect={() => menusDispatch({ type: 'SET_FOCUSED_SENSOR_ID', payload: { sensorId: sensor.id } })}\r\n isFocused={focusedSensorId === sensor.id}\r\n valueColour={readings.get(sensor.id)?.colour}\r\n valueText={readingText(sensor.id)}\r\n />\r\n ))}\r\n </div>\r\n </CollapsibleSection>\r\n )\r\n })\r\n ) : (\r\n Object.entries(sensorsByTag).map(([tag, sensorsOfTag]) => {\r\n const isTagVisible = visibleSensorTags?.[currentViewer]?.includes(tag) ?? false\r\n return (\r\n <CollapsibleSection\r\n key={tag}\r\n title={tag === UNTAGGED_TAG ? t('untagged') : tag}\r\n icon={LR.Tag}\r\n colour={stringToColour(tag, 'max')}\r\n className=\"overflow-y-auto\"\r\n itemCount={sensorsOfTag.length}\r\n defaultOpen={false}\r\n switchVariant={{\r\n checked: isTagVisible,\r\n onCheckedChange: () => toggleSensorTagVisibility(tag),\r\n }}\r\n >\r\n <div className=\"space-y-2 mx-2 pr-2\">\r\n {sensorsOfTag.map((sensor) => {\r\n const type = sensorTypes.find(tp => tp.id === sensor.typeId)\r\n return (\r\n <CollapsibleSensorItem\r\n key={sensor.id}\r\n sensor={sensor}\r\n sensorType={type}\r\n onAction={handleSensorAction}\r\n isVisible={isTagVisible}\r\n onMouseEnter={() => menusDispatch({ type: 'SET_CURRENT_SENSOR_ID', payload: { currentSensorId: sensor.id } })}\r\n onMouseLeave={() => menusDispatch({ type: 'SET_CURRENT_SENSOR_ID', payload: { currentSensorId: null } })}\r\n onSelect={() => menusDispatch({ type: 'SET_FOCUSED_SENSOR_ID', payload: { sensorId: sensor.id } })}\r\n isFocused={focusedSensorId === sensor.id}\r\n valueColour={readings.get(sensor.id)?.colour}\r\n valueText={readingText(sensor.id)}\r\n />\r\n )\r\n })}\r\n </div>\r\n </CollapsibleSection>\r\n )\r\n })\r\n )}\r\n\r\n {editSensorId != null && allSensors.some(s => s.id === editSensorId) && (\r\n <SensorInput\r\n viewer={currentViewer}\r\n layout=\"dialog\"\r\n isOpen={editSensorId != null}\r\n editSensor={allSensors.find(s => s.id === editSensorId)}\r\n onCancel={() => setEditSensorId(null)}\r\n onSaved={() => setEditSensorId(null)}\r\n />\r\n )}\r\n </div>\r\n )\r\n}\r\n"],"mappings":";AAyOQ,cAeM,YAfN;AApOR,YAAY,QAAQ;AACpB,SAAS,uBAAuB;AAChC,YAAY,WAAW;AACvB,SAAS,aAAa;AAEtB,SAAS,WAAW,kBAAkB;AACtC,SAAS,sBAAsB;AAC/B,SAAS,kBAAkB,kBAAkB,cAAc,oBAAoB;AAC/E,SAAS,8BAA8B;AACvC,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AACvB,SAAS,0BAA0B;AACnC,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAE5B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EAAE,MAAM,yBAAyB,SAAS,EAAE,iBAAiB,KAAK,EAAE,CAAC;AAAA,gBACvG,UAAU,MAAM,cAAc,EAAE,MAAM,yBAAyB,SAAS,EAAE,UAAU,OAAO,GAAG,EAAE,CAAC;AAAA,gBACjG,WAAW,oBAAoB,OAAO;AAAA,gBACtC,cAAaA,MAAA,SAAS,IAAI,OAAO,EAAE,MAAtB,gBAAAA,IAAyB;AAAA,gBACtC,WAAW,YAAY,OAAO,EAAE;AAAA;AAAA,cAV3B,OAAO;AAAA,YAWd;AAAA,UAEJ,CAAC,GACH;AAAA;AAAA,QA/BK;AAAA,MAgCP;AAAA,IAEF,CAAC;AAAA,IAGF,gBAAgB,QAAQ,WAAW,KAAK,OAAK,EAAE,OAAO,YAAY,KACjE;AAAA,MAAC;AAAA;AAAA,QACC,QAAQ;AAAA,QACR,QAAO;AAAA,QACP,QAAQ,gBAAgB;AAAA,QACxB,YAAY,WAAW,KAAK,OAAK,EAAE,OAAO,YAAY;AAAA,QACtD,UAAU,MAAM,gBAAgB,IAAI;AAAA,QACpC,SAAS,MAAM,gBAAgB,IAAI;AAAA;AAAA,IACrC;AAAA,KAEJ;AAEJ;","names":["_a","_b","_c","t"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/core/components/ui/Sensors/SensorsSection.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\nimport { toast } from 'sonner'\r\n\r\nimport { useSensor, useSensors } from '../../../hooks/sensors/sensors'\r\nimport { useSensorTypes } from '../../../hooks/sensorTypes/sensorTypes'\r\nimport { AppConfigContext, BuildingsContext, MenusContext, ToolsContext } from '../../../store'\r\nimport { resolveDefaultTimeZone } from '../../../utils/timeUtils'\r\nimport { stringToColour } from '../../viewers/map/utils/stringToColour'\r\nimport { Button } from '../Button'\r\nimport { CollapsibleSection } from '../CollapsibleSection'\r\nimport { DropdownMenu } from '../DropdownMenu'\r\nimport {\r\n DropdownMenuTrigger,\r\n DropdownMenuContent,\r\n DropdownMenuLabel,\r\n DropdownMenuSeparator,\r\n DropdownMenuRadioGroup,\r\n DropdownMenuRadioItem,\r\n} from '../DropdownMenu'\r\nimport { SearchInput } from '../SearchInput'\r\n\r\nimport { CollapsibleSensorItem } from './CollapsibleSensorItem'\r\nimport { SensorInput } from './SensorInput'\r\nimport { SensorsSectionSkeleton } from './SensorsSectionSkeleton'\r\nimport { resolveLucideIcon } from './sensorUtils'\r\nimport { valueColoursBySensor } from './sensorValueColours'\r\nimport { activeSensorTypeId, legendScopeSensors, UNTAGGED_TAG } from './sensorVisibility'\r\nimport { useSensorSeriesMulti } from './useSensorSeriesMulti'\r\n\r\nimport type { Sensor } from '../../../types/dbTypes';\r\n\r\n/** Sidebar readings: compact, at most one decimal, so a row stays on one line. */\r\nconst readingNumber = new Intl.NumberFormat(undefined, { maximumFractionDigits: 1 })\r\n\r\n\r\ntype SensorAction = 'view' | 'edit' | 'delete'\r\n\r\n// Re-exported from its own module so the pure helpers and the viewer layers can use it without\r\n// pulling this component in. Kept here because every existing import points at this path.\r\nexport { UNTAGGED_TAG } from './sensorVisibility'\r\n\r\nexport function SensorsSection() {\r\n // Translation\r\n const t = useTranslations('SensorsSection')\r\n\r\n const { dispatch: toolsDispatch } = React.useContext(ToolsContext)\r\n const { state: menusState, dispatch: menusDispatch } = React.useContext(MenusContext)\r\n const { currentViewer, visibleSensorTypes, visibleSensorTags, focusedSensorId, sensorLegendVisible, sensorLegendTypeId } = menusState.menus\r\n\r\n const { sensors: allSensors }: { sensors: Sensor[] } = useSensors()\r\n const { sensorTypes, isLoading } = useSensorTypes()\r\n\r\n const {state: buildingsState} = React.useContext(BuildingsContext)\r\n const buildingId = buildingsState?.buildings?.building?.id || -1\r\n\r\n const { state: appConfigState, dispatch: appConfigDispatch } = React.useContext(AppConfigContext)\r\n\r\n const [sensorToDelete, setSensorToDelete] = React.useState<number | null>(null)\r\n const [editSensorId, setEditSensorId] = React.useState<number | null>(null)\r\n const [searchQuery, setSearchQuery] = React.useState('')\r\n const [groupBy, setGroupBy] = React.useState<'type' | 'tag'>('type')\r\n const { deleteSensor } = useSensor(sensorToDelete)\r\n\r\n const handleAddSensor = React.useCallback((currentSensorTypeId?: number) => {\r\n if (!currentViewer) return\r\n toolsDispatch({\r\n type: 'SET-TOOL',\r\n payload: {\r\n currentToolId:\r\n currentViewer === 'bim'\r\n ? 'bim-add-sensor'\r\n : currentViewer === 'map'\r\n ? 'map-add-sensor'\r\n : undefined,\r\n },\r\n })\r\n if (currentSensorTypeId) {\r\n menusDispatch({\r\n type: 'SET_CURRENT_SENSOR_TYPE_ID',\r\n payload: { currentSensorTypeId },\r\n })\r\n }\r\n }, [toolsDispatch, currentViewer])\r\n\r\n const handleSensorAction = React.useCallback((action: SensorAction, id: number) => {\r\n switch (action) {\r\n case 'view':\r\n // ⚠️ View sensor action not implemented\r\n break\r\n case 'edit':\r\n setEditSensorId(id)\r\n break\r\n case 'delete':\r\n toast.success(t('sensorDeleted'))\r\n setSensorToDelete(id)\r\n break\r\n default:\r\n break\r\n }\r\n }, [t])\r\n\r\n // Trigger deletion when sensorToDelete changes\r\n React.useEffect(() => {\r\n if (sensorToDelete !== null) {\r\n void deleteSensor()\r\n setSensorToDelete(null)\r\n }\r\n }, [sensorToDelete, deleteSensor])\r\n\r\n const currentSensors: Sensor[] = allSensors.filter((sensor) => currentViewer === sensor.viewer && (!sensor.buildingId || sensor.buildingId === buildingId))\r\n\r\n // Readings for every listed sensor, so each row can be ringed by its current value. This is the\r\n // only place that polls across types; the viewers poll the focused type alone. Bounded by\r\n // useSensorSeriesMulti's concurrency cap and only active while this panel is mounted.\r\n const { seriesById } = useSensorSeriesMulti(currentSensors, { enabled: currentSensors.length > 0 })\r\n const readings = React.useMemo(\r\n () => valueColoursBySensor(currentSensors, sensorTypes, seriesById),\r\n [seriesById, sensorTypes, currentSensors.map(s => s.id).join(',')],\r\n )\r\n const readingText = (sensorId: number): string | undefined => {\r\n const reading = readings.get(sensorId)\r\n if (!reading) return undefined\r\n const unit = seriesById.get(sensorId)?.unit\r\n const labels = seriesById.get(sensorId)?.valueLabels\r\n return labels?.[reading.value] ?? `${readingNumber.format(reading.value)}${unit ? ` ${unit}` : ''}`\r\n }\r\n\r\n // Default the display zone from the building's (else a sensor's) longitude, until the user overrides.\r\n // Depends on primitive longitudes (not the re-created currentSensors array) so it only runs on real change.\r\n const buildingLongitude = buildingsState?.buildings?.building?.buildingLongitude ?? null\r\n const firstSensorLongitude = currentSensors.find(s => typeof s.longitude === 'number')?.longitude ?? null\r\n const { displayTimeZone, displayTimeZoneUserSet } = appConfigState.appConfig\r\n React.useEffect(() => {\r\n if (displayTimeZoneUserSet) return\r\n // BIM sensors live in a building (use its longitude); map sensors carry their own.\r\n const candidates = currentViewer === 'bim'\r\n ? [buildingLongitude, firstSensorLongitude]\r\n : [firstSensorLongitude, buildingLongitude]\r\n const zone = resolveDefaultTimeZone(candidates)\r\n if (zone !== displayTimeZone) {\r\n appConfigDispatch({ type: 'SET_DEFAULT_TIME_ZONE', payload: { displayTimeZone: zone } })\r\n }\r\n }, [currentViewer, buildingLongitude, firstSensorLongitude, displayTimeZone, displayTimeZoneUserSet, appConfigDispatch])\r\n\r\n // Filter sensors based on search query\r\n const filteredSensors = React.useMemo(() => {\r\n if (!searchQuery.trim()) return currentSensors\r\n\r\n const query = searchQuery.toLowerCase()\r\n return currentSensors.filter((sensor) => {\r\n const sensorTypeName =\r\n sensorTypes.find(type => type.id === sensor.typeId)?.name ?? ''\r\n return (\r\n sensor.name?.toLowerCase().includes(query) ||\r\n sensorTypeName.toLowerCase().includes(query)\r\n )\r\n })\r\n }, [currentSensors, searchQuery])\r\n\r\n const toggleSensorTypeVisibility = React.useCallback((sensorTypeId: number) => {\r\n menusDispatch({\r\n type: 'TOGGLE_SENSOR_TYPE_VISIBILITY',\r\n payload: {\r\n viewer: currentViewer,\r\n sensorTypeId: sensorTypeId,\r\n },\r\n })\r\n }, [currentViewer, menusDispatch])\r\n\r\n const handleGroupByChange = React.useCallback((newGroupBy: 'type' | 'tag') => {\r\n setGroupBy(newGroupBy)\r\n // Clear the opposing visibility state so markers from the old filter don't bleed through\r\n if (newGroupBy === 'tag') {\r\n menusDispatch({ type: 'HIDE_ALL_SENSORS_IN_VIEWER', payload: { viewer: currentViewer } })\r\n } else {\r\n menusDispatch({ type: 'HIDE_ALL_SENSOR_TAGS_IN_VIEWER', payload: { viewer: currentViewer } })\r\n }\r\n }, [currentViewer, menusDispatch])\r\n\r\n // Mirrors what the legend itself decides, so the button never claims the card is on while the\r\n // viewer is showing nothing. With no sensors of the active type there is nothing to toggle.\r\n const legendHasContent = legendScopeSensors(\r\n allSensors,\r\n {\r\n viewer: currentViewer,\r\n visibleTypeIds: visibleSensorTypes?.[currentViewer] ?? [],\r\n visibleTags: visibleSensorTags?.[currentViewer] ?? [],\r\n },\r\n activeSensorTypeId(allSensors, {\r\n legendTypeId: sensorLegendTypeId?.[currentViewer],\r\n activeSensorId: focusedSensorId,\r\n }),\r\n ).length > 0\r\n const legendVisible = legendHasContent && sensorLegendVisible?.[currentViewer] !== false\r\n\r\n const toggleLegend = React.useCallback(() => {\r\n menusDispatch({ type: 'TOGGLE_SENSOR_LEGEND', payload: { viewer: currentViewer } })\r\n }, [currentViewer, menusDispatch])\r\n\r\n const toggleSensorTagVisibility = React.useCallback((tag: string) => {\r\n menusDispatch({\r\n type: 'TOGGLE_SENSOR_TAG_VISIBILITY',\r\n payload: {\r\n viewer: currentViewer,\r\n sensorTag: tag,\r\n },\r\n })\r\n }, [currentViewer, menusDispatch])\r\n\r\n // Group sensors by type, using sensorTypes as the source of truth for types\r\n const sensorsByType = React.useMemo(() => {\r\n const grouped: Record<string, Sensor[]> = {}\r\n sensorTypes.forEach(type => {\r\n grouped[type.name] = []\r\n })\r\n filteredSensors.forEach(sensor => {\r\n const type = sensorTypes.find(t => t.id === sensor.typeId)\r\n const typeName = type?.name ?? 'Other'\r\n if (!grouped[typeName]) {\r\n grouped[typeName] = []\r\n }\r\n grouped[typeName].push(sensor)\r\n })\r\n // Remove empty groups\r\n Object.keys(grouped).forEach(key => {\r\n if (grouped[key].length === 0) {\r\n delete grouped[key]\r\n }\r\n })\r\n return grouped\r\n }, [filteredSensors, sensorTypes])\r\n\r\n // Group sensors by tag\r\n const sensorsByTag = React.useMemo(() => {\r\n const grouped: Record<string, Sensor[]> = {}\r\n filteredSensors.forEach(sensor => {\r\n const tags = sensor.tags && sensor.tags.length > 0 ? sensor.tags : [UNTAGGED_TAG]\r\n tags.forEach(tag => {\r\n if (!grouped[tag]) grouped[tag] = []\r\n grouped[tag].push(sensor)\r\n })\r\n })\r\n return grouped\r\n }, [filteredSensors])\r\n\r\n return (\r\n <div className=\"flex-1 flex flex-col space-y-4 overflow-hidden\">\r\n <div className=\"px-4 flex items-center gap-2\">\r\n <SearchInput\r\n placeholder={t('searchSensors')}\r\n value={searchQuery}\r\n onChange={e => setSearchQuery(e.target.value)}\r\n />\r\n <Button\r\n variant={legendVisible ? 'default' : 'outline'}\r\n size=\"icon\"\r\n title={t('toggleLegend')}\r\n aria-pressed={legendVisible}\r\n disabled={!legendHasContent}\r\n className=\"flex-shrink-0\"\r\n onClick={toggleLegend}\r\n >\r\n <LR.Palette size={16} />\r\n </Button>\r\n <DropdownMenu>\r\n <DropdownMenuTrigger asChild>\r\n <Button variant=\"outline\" size=\"icon\" title={t('filters')} className=\"flex-shrink-0\">\r\n <LR.Funnel size={16} />\r\n </Button>\r\n </DropdownMenuTrigger>\r\n <DropdownMenuContent align=\"end\">\r\n <DropdownMenuLabel>{t('groupBy')}</DropdownMenuLabel>\r\n <DropdownMenuSeparator />\r\n <DropdownMenuRadioGroup value={groupBy} onValueChange={v => handleGroupByChange(v as 'type' | 'tag')}>\r\n <DropdownMenuRadioItem value=\"type\">\r\n <LR.Layers className=\"mr-2 h-4 w-4\" />\r\n {t('groupByType')}\r\n </DropdownMenuRadioItem>\r\n <DropdownMenuRadioItem value=\"tag\">\r\n <LR.Tag className=\"mr-2 h-4 w-4\" />\r\n {t('groupByTag')}\r\n </DropdownMenuRadioItem>\r\n </DropdownMenuRadioGroup>\r\n </DropdownMenuContent>\r\n </DropdownMenu>\r\n </div>\r\n {isLoading ? (\r\n <SensorsSectionSkeleton />\r\n ) :\r\n filteredSensors.length === 0 ? (\r\n <div className=\"p-4 text-muted-foreground text-sm flex flex-col items-center\">\r\n <div>{t('noSensorsFound')}</div>\r\n <Button\r\n className=\"mt-2 px-4 \"\r\n variant='outline'\r\n onClick={() => handleAddSensor()}\r\n >\r\n {t('addSensorTitle')}\r\n </Button>\r\n </div>\r\n ) : groupBy === 'type' ? (\r\n Object.entries(sensorsByType).map(([typeName, sensorsOfType]) => {\r\n const type = sensorTypes.find(t => t.name === typeName)\r\n const typeId = type?.id ?? -1\r\n\r\n const viewerTypes = visibleSensorTypes?.[currentViewer]\r\n const isTypeVisible = viewerTypes?.length > 0 && viewerTypes.includes(typeId)\r\n\r\n const sensorIcon = resolveLucideIcon(type?.icon)\r\n\r\n return (\r\n <CollapsibleSection\r\n key={typeName}\r\n title={typeName.replace(/_/g, ' ')}\r\n icon={sensorIcon}\r\n className=\"overflow-y-auto\"\r\n itemCount={sensorsOfType.length}\r\n onAddItem={() => handleAddSensor(typeId)}\r\n addItemTitle={t('addSensorTitle')}\r\n defaultOpen={false}\r\n switchVariant={{\r\n checked: isTypeVisible,\r\n onCheckedChange: () => toggleSensorTypeVisibility(typeId),\r\n }}\r\n >\r\n <div className=\"space-y-2 mx-2 pr-2\">\r\n {sensorsOfType.map((sensor) => (\r\n <CollapsibleSensorItem\r\n key={sensor.id}\r\n sensor={sensor}\r\n sensorType={type}\r\n onAction={handleSensorAction}\r\n isVisible={isTypeVisible}\r\n onMouseEnter={() => menusDispatch({ type: 'SET_CURRENT_SENSOR_ID', payload: { currentSensorId: sensor.id } })}\r\n onMouseLeave={() => menusDispatch({ type: 'SET_CURRENT_SENSOR_ID', payload: { currentSensorId: null } })}\r\n onSelect={() => menusDispatch({ type: 'SET_FOCUSED_SENSOR_ID', payload: { sensorId: sensor.id } })}\r\n isFocused={focusedSensorId === sensor.id}\r\n valueColour={readings.get(sensor.id)?.colour}\r\n valueText={readingText(sensor.id)}\r\n />\r\n ))}\r\n </div>\r\n </CollapsibleSection>\r\n )\r\n })\r\n ) : (\r\n Object.entries(sensorsByTag).map(([tag, sensorsOfTag]) => {\r\n const isTagVisible = visibleSensorTags?.[currentViewer]?.includes(tag) ?? false\r\n return (\r\n <CollapsibleSection\r\n key={tag}\r\n title={tag === UNTAGGED_TAG ? t('untagged') : tag}\r\n icon={LR.Tag}\r\n colour={stringToColour(tag, 'max')}\r\n className=\"overflow-y-auto\"\r\n itemCount={sensorsOfTag.length}\r\n defaultOpen={false}\r\n switchVariant={{\r\n checked: isTagVisible,\r\n onCheckedChange: () => toggleSensorTagVisibility(tag),\r\n }}\r\n >\r\n <div className=\"space-y-2 mx-2 pr-2\">\r\n {sensorsOfTag.map((sensor) => {\r\n const type = sensorTypes.find(tp => tp.id === sensor.typeId)\r\n return (\r\n <CollapsibleSensorItem\r\n key={sensor.id}\r\n sensor={sensor}\r\n sensorType={type}\r\n onAction={handleSensorAction}\r\n isVisible={isTagVisible}\r\n onMouseEnter={() => menusDispatch({ type: 'SET_CURRENT_SENSOR_ID', payload: { currentSensorId: sensor.id } })}\r\n onMouseLeave={() => menusDispatch({ type: 'SET_CURRENT_SENSOR_ID', payload: { currentSensorId: null } })}\r\n onSelect={() => menusDispatch({ type: 'SET_FOCUSED_SENSOR_ID', payload: { sensorId: sensor.id } })}\r\n isFocused={focusedSensorId === sensor.id}\r\n valueColour={readings.get(sensor.id)?.colour}\r\n valueText={readingText(sensor.id)}\r\n />\r\n )\r\n })}\r\n </div>\r\n </CollapsibleSection>\r\n )\r\n })\r\n )}\r\n\r\n {editSensorId != null && allSensors.some(s => s.id === editSensorId) && (\r\n <SensorInput\r\n viewer={currentViewer}\r\n layout=\"dialog\"\r\n isOpen={editSensorId != null}\r\n editSensor={allSensors.find(s => s.id === editSensorId)}\r\n onCancel={() => setEditSensorId(null)}\r\n onSaved={() => setEditSensorId(null)}\r\n />\r\n )}\r\n </div>\r\n )\r\n}\r\n"],"mappings":";AA+PQ,cA0BM,YA1BN;AA1PR,YAAY,QAAQ;AACpB,SAAS,uBAAuB;AAChC,YAAY,WAAW;AACvB,SAAS,aAAa;AAEtB,SAAS,WAAW,kBAAkB;AACtC,SAAS,sBAAsB;AAC/B,SAAS,kBAAkB,kBAAkB,cAAc,oBAAoB;AAC/E,SAAS,8BAA8B;AACvC,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AACvB,SAAS,0BAA0B;AACnC,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAE5B,SAAS,6BAA6B;AACtC,SAAS,mBAAmB;AAC5B,SAAS,8BAA8B;AACvC,SAAS,yBAAyB;AAClC,SAAS,4BAA4B;AACrC,SAAS,oBAAoB,oBAAoB,oBAAoB;AACrE,SAAS,4BAA4B;AAKrC,MAAM,gBAAgB,IAAI,KAAK,aAAa,QAAW,EAAE,uBAAuB,EAAE,CAAC;AAOnF,SAAS,gBAAAA,qBAAoB;AAEtB,SAAS,iBAAiB;AAhDjC;AAkDE,QAAM,IAAI,gBAAgB,gBAAgB;AAE1C,QAAM,EAAE,UAAU,cAAc,IAAI,MAAM,WAAW,YAAY;AACjE,QAAM,EAAE,OAAO,YAAY,UAAU,cAAc,IAAI,MAAM,WAAW,YAAY;AACpF,QAAM,EAAE,eAAe,oBAAoB,mBAAmB,iBAAiB,qBAAqB,mBAAmB,IAAI,WAAW;AAEtI,QAAM,EAAE,SAAS,WAAW,IAA2B,WAAW;AAClE,QAAM,EAAE,aAAa,UAAU,IAAI,eAAe;AAElD,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gBACA,YAAY;AAAA,gBACZ,UAAU;AAAA,gBACV,WAAW;AAAA,gBACX,cAAc,MAAM,cAAc,EAAE,MAAM,yBAAyB,SAAS,EAAE,iBAAiB,OAAO,GAAG,EAAE,CAAC;AAAA,gBAC5G,cAAc,MAAM,cAAc,EAAE,MAAM,yBAAyB,SAAS,EAAE,iBAAiB,KAAK,EAAE,CAAC;AAAA,gBACvG,UAAU,MAAM,cAAc,EAAE,MAAM,yBAAyB,SAAS,EAAE,UAAU,OAAO,GAAG,EAAE,CAAC;AAAA,gBACjG,WAAW,oBAAoB,OAAO;AAAA,gBACtC,cAAaA,MAAA,SAAS,IAAI,OAAO,EAAE,MAAtB,gBAAAA,IAAyB;AAAA,gBACtC,WAAW,YAAY,OAAO,EAAE;AAAA;AAAA,cAV3B,OAAO;AAAA,YAWd;AAAA,UAEJ,CAAC,GACH;AAAA;AAAA,QA/BK;AAAA,MAgCP;AAAA,IAEF,CAAC;AAAA,IAGF,gBAAgB,QAAQ,WAAW,KAAK,OAAK,EAAE,OAAO,YAAY,KACjE;AAAA,MAAC;AAAA;AAAA,QACC,QAAQ;AAAA,QACR,QAAO;AAAA,QACP,QAAQ,gBAAgB;AAAA,QACxB,YAAY,WAAW,KAAK,OAAK,EAAE,OAAO,YAAY;AAAA,QACtD,UAAU,MAAM,gBAAgB,IAAI;AAAA,QACpC,SAAS,MAAM,gBAAgB,IAAI;AAAA;AAAA,IACrC;AAAA,KAEJ;AAEJ;","names":["UNTAGGED_TAG","_a","_b","_c","t"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ColourDomain } from './sensorColour';
|
|
2
|
+
import type { SensorSeries } from './sensorData';
|
|
3
|
+
import type { Sensor, SensorType } from '../../../types/dbTypes';
|
|
4
|
+
/** One building's sensors of a single type, reduced to a colourable number. */
|
|
5
|
+
export interface BuildingSensorAverage {
|
|
6
|
+
buildingId: number;
|
|
7
|
+
/** Mean of the contributing sensors' latest readings. */
|
|
8
|
+
average: number;
|
|
9
|
+
/** How many sensors reported a finite reading. Never zero: those buildings are omitted. */
|
|
10
|
+
sensorCount: number;
|
|
11
|
+
colour: string;
|
|
12
|
+
}
|
|
13
|
+
/** Enough of a sensor to aggregate it onto a building. */
|
|
14
|
+
export type AggregateSensor = Pick<Sensor, 'id' | 'typeId' | 'buildingId'>;
|
|
15
|
+
/**
|
|
16
|
+
* The type's colour domain, resolved the way the legend and the charts resolve it: the
|
|
17
|
+
* configured `minValue..maxValue`, else the range observed across the polled sensors.
|
|
18
|
+
*
|
|
19
|
+
* `null` means the type has no usable domain, which callers must read as "no colours
|
|
20
|
+
* configured" and answer by keeping their pre-colour appearance.
|
|
21
|
+
*/
|
|
22
|
+
export declare function typeDomain(sensorType: SensorType | null | undefined, seriesById: ReadonlyMap<number, SensorSeries>): ColourDomain | null;
|
|
23
|
+
/**
|
|
24
|
+
* Mean latest reading and ramp colour per building, for one sensor type.
|
|
25
|
+
*
|
|
26
|
+
* Deliberately blind to `sensor.viewer`: a building's temperature is its temperature whether the
|
|
27
|
+
* sensor was placed on the map or inside the BIM model, so both feed the average. Every other
|
|
28
|
+
* consumer of sensors filters by viewer, so do not "fix" this to match them.
|
|
29
|
+
*/
|
|
30
|
+
export declare function buildingSensorAverages(sensors: readonly AggregateSensor[], sensorType: SensorType | null | undefined, seriesById: ReadonlyMap<number, SensorSeries>): Map<number, BuildingSensorAverage>;
|
|
31
|
+
/**
|
|
32
|
+
* Most recent reading time per building, epoch ms.
|
|
33
|
+
*
|
|
34
|
+
* Separate from the averages because a building can have a stale reading and still average
|
|
35
|
+
* cleanly; showing when the number is from is what makes a dead feed visible.
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildingLatestTimes(sensors: readonly AggregateSensor[], seriesById: ReadonlyMap<number, SensorSeries>): Map<number, number>;
|
|
38
|
+
/**
|
|
39
|
+
* The type the map should colour buildings by: pinned in the legend *and* switched on for the
|
|
40
|
+
* viewer. The single gate for whether this feature polls and paints at all, so toggling the type
|
|
41
|
+
* off both stops the requests and returns the footprints to their default colour.
|
|
42
|
+
*/
|
|
43
|
+
export declare function activeLegendTypeId(legendTypeId: number | null | undefined, visibleTypeIds: readonly number[] | undefined): number | null;
|
|
44
|
+
/**
|
|
45
|
+
* Stable key over the resolved colours, for effect deps that must not fire on equal polls.
|
|
46
|
+
* Sorted, so a reordered sensor list does not read as a change.
|
|
47
|
+
*/
|
|
48
|
+
export declare function buildingColoursKey(averages: ReadonlyMap<number, BuildingSensorAverage>): string;
|
|
49
|
+
//# sourceMappingURL=buildingSensorColours.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildingSensorColours.d.ts","sourceRoot":"","sources":["../../../../../src/core/components/ui/Sensors/buildingSensorColours.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAEhE,+EAA+E;AAC/E,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,CAAA;IAClB,yDAAyD;IACzD,OAAO,EAAE,MAAM,CAAA;IACf,2FAA2F;IAC3F,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;CACf;AAED,0DAA0D;AAC1D,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,GAAG,QAAQ,GAAG,YAAY,CAAC,CAAA;AAE1E;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,UAAU,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,EACzC,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,YAAY,CAAC,GAC5C,YAAY,GAAG,IAAI,CAIrB;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,SAAS,eAAe,EAAE,EACnC,UAAU,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,EACzC,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,YAAY,CAAC,GAC5C,GAAG,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAqCpC;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,SAAS,eAAe,EAAE,EACnC,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,YAAY,CAAC,GAC5C,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAWrB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACvC,cAAc,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GAC5C,MAAM,GAAG,IAAI,CAGf;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,qBAAqB,CAAC,GAAG,MAAM,CAK/F"}
|
|
@@ -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,CAAC,EAAE,QAAQ,YAAU,OAAO,MAAM;AACvE,SAAO,cAAc,YAAY,eAAe,MAAM,CAAC;AACzD;AASO,SAAS,uBACd,SACA,YACA,YACoC;AACpC,QAAM,WAAW,oBAAI,IAAmC;AACxD,MAAI,CAAC,WAAY,QAAO;AAExB,QAAM,SAAS,WAAW,YAAY,UAAU;AAChD,MAAI,CAAC,OAAQ,QAAO;AAEpB,QAAM,SAAS,aAAa,UAAU;AACtC,QAAM,SAAS,oBAAI,IAA4C;AAE/D,aAAW,UAAU,SAAS;AAC5B,QAAI,OAAO,cAAc,KAAM;AAC/B,QAAI,OAAO,WAAW,WAAW,GAAI;AACrC,UAAM,QAAQ,OAAO,IAAI,OAAO,EAAE;AAClC,QAAI,UAAU,OAAW;AACzB,UAAM,QAAQ,OAAO,IAAI,OAAO,UAAU;AAC1C,QAAI,OAAO;AACT,YAAM,OAAO;AACb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ourcesContent":["// 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,4BAA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OAAO,UAAU;AAC1C,UAAI,KAAM,MAAK,KAAK,MAAM;AAAA,UACrB,SAAQ,IAAI,OAAO,YAAY,CAAC,MAAM,CAAC;AAAA,IAC9C;AACA,eAAW,QAAQ,QAAQ,OAAO,EAAG,MAAK,KAAK,CAAC,GAAG,MAAM,EAAE,KAAK,cAAc,EAAE,IAAI,CAAC;AACrF,WAAO;AAAA,EACT,GAAG,CAAC,UAAU,CAAC;AAEf,QAAM,WAAW,MAAM;AAAA,IACrB,MAAM,qBAAqB,SAAS,aAAa,UAAU;AAAA,IAC3D,CAAC,YAAY,aAAa,UAAU;AAAA,EACtC;AAEA,QAAM,qBAAqB,MAAM;AAAA,IAC/B,MAAM,oBAAoB,SAAS,UAAU;AAAA,IAC7C,CAAC,YAAY,UAAU;AAAA,EACzB;AAIA,QAAM,QAAO,MAAC,GAAG,WAAW,OAAO,CAAC,EAAE,KAAK,YAAU,OAAO,IAAI,MAAnD,mBAAsD;AAEnE,MAAI,UAAU,MAAM;AAClB,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,YAAY;AAAA,MACZ,UAAU;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,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@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSensorMarkers.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/core/components/viewers/bim/src/tools/AddToBim/src/useSensorMarkers.ts"],"names":[],"mappings":"AAcA,OAAO,EAAe,KAAK,MAAM,EAAE,MAAM,oCAAoC,CAAA;AAQ7E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"useSensorMarkers.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/core/components/viewers/bim/src/tools/AddToBim/src/useSensorMarkers.ts"],"names":[],"mappings":"AAcA,OAAO,EAAe,KAAK,MAAM,EAAE,MAAM,oCAAoC,CAAA;AAQ7E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM;iCAyFP;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE;8BAMtC,MAAM;;;;;;;EAqF1D"}
|