@smartnet360/svelte-components 0.0.67 → 0.0.69

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.
@@ -0,0 +1,270 @@
1
+ <script lang="ts">
2
+ /**
3
+ * CellLabelsLayer - Renders tech-aware cell labels positioned along azimuth
4
+ *
5
+ * Features:
6
+ * - Groups cells by site + azimuth (with configurable tolerance)
7
+ * - Projects labels along bearing from site center
8
+ * - Stacks multiple labels vertically when cells share direction
9
+ * - Tech-specific field selection (2G vs 4G/5G)
10
+ * - Configurable styling (size, color, halo, zoom)
11
+ */
12
+
13
+ import { onMount, onDestroy } from 'svelte';
14
+ import { useMapbox } from '../../../core/hooks/useMapbox';
15
+ import { waitForStyleLoad, generateLayerId, generateSourceId } from '../../../shared/utils/mapboxHelpers';
16
+ import type { CellStoreContext } from '../stores/cellStoreContext.svelte';
17
+ import type { Cell } from '../types';
18
+ import { parseTechBand } from '../utils/techBandParser';
19
+ import { calculateRadius } from '../utils/zoomScaling';
20
+ import * as turf from '@turf/turf';
21
+
22
+ interface Props {
23
+ /** Cell store context */
24
+ store: CellStoreContext;
25
+ /** Unique namespace for layer/source IDs */
26
+ namespace: string;
27
+ }
28
+
29
+ let { store, namespace }: Props = $props();
30
+
31
+ const mapStore = useMapbox();
32
+ const sourceId = generateSourceId(namespace, 'cell-labels');
33
+ const layerId = generateLayerId(namespace, 'cell-labels');
34
+
35
+ let map = $state<mapboxgl.Map | null>(null);
36
+ let unsubscribe: (() => void) | null = null;
37
+
38
+ /**
39
+ * Get label text for a cell based on tech and selected field
40
+ */
41
+ function getCellLabelText(cell: Cell, field: keyof Cell | 'none'): string {
42
+ if (field === 'none') return '';
43
+
44
+ const value = cell[field];
45
+ return value == null ? '' : String(value);
46
+ }
47
+
48
+ /**
49
+ * Round azimuth to nearest tolerance value
50
+ */
51
+ function roundAzimuth(azimuth: number, tolerance: number): number {
52
+ return Math.round(azimuth / tolerance) * tolerance;
53
+ }
54
+
55
+ /**
56
+ * Group cells by site + rounded azimuth
57
+ */
58
+ function groupCellsByAzimuth(cells: Cell[], tolerance: number): Map<string, Cell[]> {
59
+ const groups = new Map<string, Cell[]>();
60
+
61
+ cells.forEach(cell => {
62
+ const roundedAzimuth = roundAzimuth(cell.azimuth, tolerance);
63
+ const groupKey = `${cell.siteId}:${roundedAzimuth}`;
64
+
65
+ if (!groups.has(groupKey)) {
66
+ groups.set(groupKey, []);
67
+ }
68
+ groups.get(groupKey)!.push(cell);
69
+ });
70
+
71
+ return groups;
72
+ }
73
+
74
+ /**
75
+ * Build GeoJSON features for cell labels
76
+ */
77
+ function buildLabelFeatures(): GeoJSON.FeatureCollection {
78
+ const features: GeoJSON.Feature[] = [];
79
+
80
+ if (!store.showLabels || store.filteredCells.length === 0 || !map) {
81
+ return { type: 'FeatureCollection', features: [] };
82
+ }
83
+
84
+ // Get current zoom level
85
+ const currentZoom = map.getZoom();
86
+
87
+ // Group cells by site + azimuth
88
+ const cellGroups = groupCellsByAzimuth(store.filteredCells, store.azimuthTolerance);
89
+
90
+ cellGroups.forEach((cells, groupKey) => {
91
+ // Sort cells within group for consistent stacking
92
+ cells.sort((a, b) => a.id.localeCompare(b.id));
93
+
94
+ // Calculate total height of all labels in this group
95
+ const totalGroupHeight = cells.length * store.labelSize * 1.5;
96
+ // Center offset: shift entire group up by half its height
97
+ const groupCenterOffset = -totalGroupHeight / 2;
98
+
99
+ cells.forEach((cell, index) => {
100
+ // Determine which fields to use based on tech
101
+ const is2G = cell.tech === '2G';
102
+ const primaryField = is2G ? store.primaryLabelField2G : store.primaryLabelField4G5G;
103
+ const secondaryField = is2G ? store.secondaryLabelField2G : store.secondaryLabelField4G5G;
104
+
105
+ // Get label text
106
+ const primaryText = getCellLabelText(cell, primaryField);
107
+ const secondaryText = getCellLabelText(cell, secondaryField);
108
+
109
+ // Build combined label (on single line with separator)
110
+ let labelText = primaryText;
111
+ if (secondaryText) {
112
+ labelText += ` | ${secondaryText}`;
113
+ }
114
+
115
+ if (!labelText.trim()) return; // Skip if no text
116
+
117
+ // Calculate zoom-aware radius for this cell
118
+ const techBandParsed = parseTechBand(cell.fband);
119
+ const techBandKey = techBandParsed?.key || '4G_1800'; // Fallback to default
120
+ const cellRadius = calculateRadius(store.baseRadius, techBandKey, currentZoom);
121
+
122
+ // Position label at a percentage of the arc radius (configurable via labelOffset)
123
+ // labelOffset is treated as a percentage (e.g., 300 = 300% = beyond arc, 70 = 70% = inside arc)
124
+ const labelDistance = (cellRadius * store.labelOffset) / 100;
125
+
126
+ // Project label position along azimuth
127
+ const origin = turf.point([cell.siteLongitude, cell.siteLatitude]);
128
+ const labelPosition = turf.destination(
129
+ origin,
130
+ labelDistance / 1000, // Convert meters to kilometers
131
+ cell.azimuth,
132
+ { units: 'kilometers' }
133
+ );
134
+
135
+ // Calculate vertical offset for stacking (pixels)
136
+ // Position within the centered group
137
+ const stackOffset = groupCenterOffset + (index * store.labelSize * 1.5) + (store.labelSize * 0.75);
138
+
139
+ features.push({
140
+ type: 'Feature',
141
+ geometry: labelPosition.geometry,
142
+ properties: {
143
+ text: labelText,
144
+ stackOffset,
145
+ cellId: cell.id
146
+ }
147
+ });
148
+ });
149
+ });
150
+
151
+ return { type: 'FeatureCollection', features };
152
+ }
153
+
154
+ /**
155
+ * Update label layer on map
156
+ */
157
+ function updateLabels() {
158
+ if (!map || !map.getSource(sourceId)) return;
159
+
160
+ const geojson = buildLabelFeatures();
161
+ const source = map.getSource(sourceId) as mapboxgl.GeoJSONSource;
162
+ source.setData(geojson);
163
+
164
+ // Also update paint/layout properties when labels are refreshed
165
+ if (map.getLayer(layerId)) {
166
+ map.setLayoutProperty(layerId, 'text-size', store.labelSize);
167
+ map.setPaintProperty(layerId, 'text-color', store.labelColor);
168
+ map.setPaintProperty(layerId, 'text-halo-color', store.labelHaloColor);
169
+ map.setPaintProperty(layerId, 'text-halo-width', store.labelHaloWidth);
170
+ map.setLayerZoomRange(layerId, store.minLabelZoom, 24);
171
+ }
172
+ }
173
+
174
+ onMount(async () => {
175
+ unsubscribe = mapStore.subscribe(async (m) => {
176
+ if (!m) {
177
+ map = null;
178
+ return;
179
+ }
180
+
181
+ map = m;
182
+
183
+ // Wait for style to load
184
+ await waitForStyleLoad(map);
185
+
186
+ // Add source
187
+ if (!map.getSource(sourceId)) {
188
+ map.addSource(sourceId, {
189
+ type: 'geojson',
190
+ data: { type: 'FeatureCollection', features: [] }
191
+ });
192
+ }
193
+
194
+ // Add label layer
195
+ if (!map.getLayer(layerId)) {
196
+ map.addLayer({
197
+ id: layerId,
198
+ type: 'symbol',
199
+ source: sourceId,
200
+ minzoom: store.minLabelZoom,
201
+ layout: {
202
+ 'text-field': ['get', 'text'],
203
+ 'text-font': ['Open Sans Regular', 'Arial Unicode MS Regular'],
204
+ 'text-size': store.labelSize,
205
+ 'text-anchor': 'center', // Center horizontally only
206
+ 'text-offset': [
207
+ 0,
208
+ ['/', ['get', 'stackOffset'], store.labelSize] // Offset includes centering adjustment
209
+ ],
210
+ 'text-allow-overlap': true,
211
+ 'text-ignore-placement': false,
212
+ 'text-max-width': 999, // Essentially disable wrapping
213
+ 'text-justify': 'center' // Center horizontally
214
+ },
215
+ paint: {
216
+ 'text-color': store.labelColor,
217
+ 'text-halo-color': store.labelHaloColor,
218
+ 'text-halo-width': store.labelHaloWidth
219
+ }
220
+ });
221
+ }
222
+
223
+ // Initial render
224
+ updateLabels();
225
+
226
+ // Listen for zoom changes to update label positions
227
+ map.on('zoom', updateLabels);
228
+ });
229
+ });
230
+
231
+ // Watch for changes in store properties and update labels
232
+ $effect(() => {
233
+ // Dependencies that should trigger label refresh
234
+ store.filteredCells;
235
+ store.showLabels;
236
+ store.primaryLabelField4G5G;
237
+ store.secondaryLabelField4G5G;
238
+ store.primaryLabelField2G;
239
+ store.secondaryLabelField2G;
240
+ store.labelOffset;
241
+ store.azimuthTolerance;
242
+ store.baseRadius; // Zoom-based radius calculation depends on baseRadius
243
+
244
+ // Also watch style properties - when they change, updateLabels() will
245
+ // rebuild the GeoJSON which forces Mapbox to re-read paint properties from store
246
+ store.labelSize;
247
+ store.labelColor;
248
+ store.labelHaloColor;
249
+ store.labelHaloWidth;
250
+ store.minLabelZoom;
251
+
252
+ updateLabels();
253
+ });
254
+
255
+ onDestroy(() => {
256
+ unsubscribe?.();
257
+
258
+ if (map) {
259
+ // Remove zoom listener
260
+ map.off('zoom', updateLabels);
261
+
262
+ if (map.getLayer(layerId)) {
263
+ map.removeLayer(layerId);
264
+ }
265
+ if (map.getSource(sourceId)) {
266
+ map.removeSource(sourceId);
267
+ }
268
+ }
269
+ });
270
+ </script>
@@ -0,0 +1,10 @@
1
+ import type { CellStoreContext } from '../stores/cellStoreContext.svelte';
2
+ interface Props {
3
+ /** Cell store context */
4
+ store: CellStoreContext;
5
+ /** Unique namespace for layer/source IDs */
6
+ namespace: string;
7
+ }
8
+ declare const CellLabelsLayer: import("svelte").Component<Props, {}, "">;
9
+ type CellLabelsLayer = ReturnType<typeof CellLabelsLayer>;
10
+ export default CellLabelsLayer;
@@ -13,6 +13,18 @@ export interface CellStoreValue {
13
13
  lineWidth: number;
14
14
  fillOpacity: number;
15
15
  baseRadius: number;
16
+ showLabels: boolean;
17
+ primaryLabelField4G5G: keyof Cell;
18
+ secondaryLabelField4G5G: keyof Cell | 'none';
19
+ primaryLabelField2G: keyof Cell;
20
+ secondaryLabelField2G: keyof Cell | 'none';
21
+ labelSize: number;
22
+ labelColor: string;
23
+ labelOffset: number;
24
+ labelHaloColor: string;
25
+ labelHaloWidth: number;
26
+ minLabelZoom: number;
27
+ azimuthTolerance: number;
16
28
  statusStyles: Map<CellStatus, CellStatusStyle>;
17
29
  groupingConfig: CellTreeConfig;
18
30
  groupColorMap: Map<string, string>;
@@ -32,6 +44,18 @@ export interface CellStoreContext {
32
44
  readonly groupingConfig: CellTreeConfig;
33
45
  readonly groupColorMap: Map<string, string>;
34
46
  readonly cellGroupMap: Map<string, string>;
47
+ readonly showLabels: boolean;
48
+ readonly primaryLabelField4G5G: keyof Cell;
49
+ readonly secondaryLabelField4G5G: keyof Cell | 'none';
50
+ readonly primaryLabelField2G: keyof Cell;
51
+ readonly secondaryLabelField2G: keyof Cell | 'none';
52
+ readonly labelSize: number;
53
+ readonly labelColor: string;
54
+ readonly labelOffset: number;
55
+ readonly labelHaloColor: string;
56
+ readonly labelHaloWidth: number;
57
+ readonly minLabelZoom: number;
58
+ readonly azimuthTolerance: number;
35
59
  setFilteredCells(cells: Cell[]): void;
36
60
  setIncludePlannedCells(value: boolean): void;
37
61
  setShowCells(value: boolean): void;
@@ -46,6 +70,18 @@ export interface CellStoreContext {
46
70
  getGroupColor(groupKey: string): string | undefined;
47
71
  setGroupColor(groupKey: string, color: string): void;
48
72
  clearGroupColor(groupKey: string): void;
73
+ setShowLabels(value: boolean): void;
74
+ setPrimaryLabelField4G5G(field: keyof Cell): void;
75
+ setSecondaryLabelField4G5G(field: keyof Cell | 'none'): void;
76
+ setPrimaryLabelField2G(field: keyof Cell): void;
77
+ setSecondaryLabelField2G(field: keyof Cell | 'none'): void;
78
+ setLabelSize(value: number): void;
79
+ setLabelColor(value: string): void;
80
+ setLabelOffset(value: number): void;
81
+ setLabelHaloColor(value: string): void;
82
+ setLabelHaloWidth(value: number): void;
83
+ setMinLabelZoom(value: number): void;
84
+ setAzimuthTolerance(value: number): void;
49
85
  }
50
86
  /**
51
87
  * Create a cell store context with reactive state
@@ -57,7 +57,20 @@ export function createCellStoreContext(cells) {
57
57
  groupingConfig: persistedSettings.groupingConfig ?? DEFAULT_CELL_TREE_CONFIG,
58
58
  groupColorMap: initialColorMap,
59
59
  cellGroupMap: new Map(), // Will be populated when tree is built
60
- currentZoom: 12 // Default zoom
60
+ currentZoom: 12, // Default zoom
61
+ // Label settings with defaults
62
+ showLabels: persistedSettings.showLabels ?? false,
63
+ primaryLabelField4G5G: (persistedSettings.primaryLabelField4G5G ?? 'fband'),
64
+ secondaryLabelField4G5G: (persistedSettings.secondaryLabelField4G5G ?? 'none'),
65
+ primaryLabelField2G: (persistedSettings.primaryLabelField2G ?? 'bcch'),
66
+ secondaryLabelField2G: (persistedSettings.secondaryLabelField2G ?? 'none'),
67
+ labelSize: persistedSettings.labelSize ?? 12,
68
+ labelColor: persistedSettings.labelColor ?? '#000000',
69
+ labelOffset: persistedSettings.labelOffset ?? 300,
70
+ labelHaloColor: persistedSettings.labelHaloColor ?? '#ffffff',
71
+ labelHaloWidth: persistedSettings.labelHaloWidth ?? 1,
72
+ minLabelZoom: persistedSettings.minLabelZoom ?? 14,
73
+ azimuthTolerance: persistedSettings.azimuthTolerance ?? 25
61
74
  });
62
75
  // Derived: Filter cells by status based on includePlannedCells flag
63
76
  // IMPORTANT: This is a pure $derived - it only READS from state, never writes
@@ -79,7 +92,20 @@ export function createCellStoreContext(cells) {
79
92
  fillOpacity: state.fillOpacity,
80
93
  baseRadius: state.baseRadius,
81
94
  groupingConfig: state.groupingConfig,
82
- groupColors: groupColorsObj
95
+ groupColors: groupColorsObj,
96
+ // Label settings
97
+ showLabels: state.showLabels,
98
+ primaryLabelField4G5G: state.primaryLabelField4G5G,
99
+ secondaryLabelField4G5G: state.secondaryLabelField4G5G,
100
+ primaryLabelField2G: state.primaryLabelField2G,
101
+ secondaryLabelField2G: state.secondaryLabelField2G,
102
+ labelSize: state.labelSize,
103
+ labelColor: state.labelColor,
104
+ labelOffset: state.labelOffset,
105
+ labelHaloColor: state.labelHaloColor,
106
+ labelHaloWidth: state.labelHaloWidth,
107
+ minLabelZoom: state.minLabelZoom,
108
+ azimuthTolerance: state.azimuthTolerance
83
109
  };
84
110
  saveSettings(settings);
85
111
  });
@@ -107,6 +133,19 @@ export function createCellStoreContext(cells) {
107
133
  get groupingConfig() { return state.groupingConfig; },
108
134
  get groupColorMap() { return state.groupColorMap; },
109
135
  get cellGroupMap() { return state.cellGroupMap; },
136
+ // Label getters
137
+ get showLabels() { return state.showLabels; },
138
+ get primaryLabelField4G5G() { return state.primaryLabelField4G5G; },
139
+ get secondaryLabelField4G5G() { return state.secondaryLabelField4G5G; },
140
+ get primaryLabelField2G() { return state.primaryLabelField2G; },
141
+ get secondaryLabelField2G() { return state.secondaryLabelField2G; },
142
+ get labelSize() { return state.labelSize; },
143
+ get labelColor() { return state.labelColor; },
144
+ get labelOffset() { return state.labelOffset; },
145
+ get labelHaloColor() { return state.labelHaloColor; },
146
+ get labelHaloWidth() { return state.labelHaloWidth; },
147
+ get minLabelZoom() { return state.minLabelZoom; },
148
+ get azimuthTolerance() { return state.azimuthTolerance; },
110
149
  // Methods
111
150
  setFilteredCells(cells) {
112
151
  state.filteredCells = cells;
@@ -152,6 +191,43 @@ export function createCellStoreContext(cells) {
152
191
  clearGroupColor(groupKey) {
153
192
  state.groupColorMap.delete(groupKey);
154
193
  state.groupColorMap = new Map(state.groupColorMap);
194
+ },
195
+ // Label setters
196
+ setShowLabels(value) {
197
+ state.showLabels = value;
198
+ },
199
+ setPrimaryLabelField4G5G(field) {
200
+ state.primaryLabelField4G5G = field;
201
+ },
202
+ setSecondaryLabelField4G5G(field) {
203
+ state.secondaryLabelField4G5G = field;
204
+ },
205
+ setPrimaryLabelField2G(field) {
206
+ state.primaryLabelField2G = field;
207
+ },
208
+ setSecondaryLabelField2G(field) {
209
+ state.secondaryLabelField2G = field;
210
+ },
211
+ setLabelSize(value) {
212
+ state.labelSize = value;
213
+ },
214
+ setLabelColor(value) {
215
+ state.labelColor = value;
216
+ },
217
+ setLabelOffset(value) {
218
+ state.labelOffset = value;
219
+ },
220
+ setLabelHaloColor(value) {
221
+ state.labelHaloColor = value;
222
+ },
223
+ setLabelHaloWidth(value) {
224
+ state.labelHaloWidth = value;
225
+ },
226
+ setMinLabelZoom(value) {
227
+ state.minLabelZoom = value;
228
+ },
229
+ setAzimuthTolerance(value) {
230
+ state.azimuthTolerance = value;
155
231
  }
156
232
  };
157
233
  }
@@ -82,13 +82,19 @@ export interface ParsedTechBand {
82
82
  }
83
83
  /**
84
84
  * Available fields for grouping cells in the filter tree
85
+ * Now accepts any property key from Cell interface
85
86
  */
86
- export type CellGroupingField = 'tech' | 'band' | 'status' | 'siteId' | 'customSubgroup' | 'type' | 'planner' | 'none';
87
+ export type CellGroupingField = keyof Cell | 'none';
88
+ /**
89
+ * Optional label map for human-readable field names
90
+ * Maps field keys to display labels
91
+ */
92
+ export type CellGroupingLabels = Partial<Record<CellGroupingField, string>>;
87
93
  /**
88
94
  * Configuration for dynamic tree grouping
89
95
  */
90
96
  export interface CellTreeConfig {
91
- /** Primary grouping field (required) */
97
+ /** Primary grouping field (required, cannot be 'none') */
92
98
  level1: Exclude<CellGroupingField, 'none'>;
93
99
  /** Secondary grouping field (optional, can be 'none') */
94
100
  level2: CellGroupingField;
@@ -8,5 +8,5 @@
8
8
  */
9
9
  export const DEFAULT_CELL_TREE_CONFIG = {
10
10
  level1: 'tech',
11
- level2: 'band'
11
+ level2: 'frq'
12
12
  };
@@ -2,9 +2,9 @@
2
2
  * Cell Tree Builder
3
3
  *
4
4
  * Build hierarchical tree structure for cell filtering
5
- * Structure: Tech Band Status → Individual Cells (configurable)
5
+ * Structure: Configurable hierarchy with any Cell properties
6
6
  */
7
- import type { Cell, CellTreeConfig } from '../types';
7
+ import type { Cell, CellTreeConfig, CellGroupingLabels } from '../types';
8
8
  import type { TreeNode } from '../../../../core/TreeView/tree.model';
9
9
  /**
10
10
  * Build hierarchical tree from flat cell array with dynamic grouping
@@ -12,9 +12,10 @@ import type { TreeNode } from '../../../../core/TreeView/tree.model';
12
12
  * @param cells - Array of cells to build tree from
13
13
  * @param config - Grouping configuration (level1, level2)
14
14
  * @param colorMap - Optional map of leaf group IDs to custom colors
15
+ * @param labelMap - Optional map of field keys to human-readable labels
15
16
  * @returns Object with tree and cell-to-group lookup map
16
17
  */
17
- export declare function buildCellTree(cells: Cell[], config: CellTreeConfig, colorMap?: Map<string, string>): {
18
+ export declare function buildCellTree(cells: Cell[], config: CellTreeConfig, colorMap?: Map<string, string>, labelMap?: CellGroupingLabels): {
18
19
  tree: TreeNode;
19
20
  cellGroupMap: Map<string, string>;
20
21
  };
@@ -2,55 +2,54 @@
2
2
  * Cell Tree Builder
3
3
  *
4
4
  * Build hierarchical tree structure for cell filtering
5
- * Structure: Tech Band Status → Individual Cells (configurable)
5
+ * Structure: Configurable hierarchy with any Cell properties
6
6
  */
7
+ /**
8
+ * Smart sort comparator that handles numeric suffixes
9
+ *
10
+ * Examples:
11
+ * "700", "1800" → sorted as 700, 1800 (numeric)
12
+ * "LTE700", "LTE1800" → sorted as 700, 1800 (numeric suffix)
13
+ * "On_Air", "Planned" → sorted alphabetically
14
+ *
15
+ * @param a - First value to compare
16
+ * @param b - Second value to compare
17
+ * @returns Sort order (-1, 0, 1)
18
+ */
19
+ function smartSort(a, b) {
20
+ // Extract trailing 3-4 digits
21
+ const numRegex = /(\d{3,4})$/;
22
+ const matchA = a.match(numRegex);
23
+ const matchB = b.match(numRegex);
24
+ // If both have numeric suffixes, compare numerically
25
+ if (matchA && matchB) {
26
+ const numA = parseInt(matchA[1], 10);
27
+ const numB = parseInt(matchB[1], 10);
28
+ return numA - numB;
29
+ }
30
+ // Otherwise alphabetical
31
+ return a.localeCompare(b);
32
+ }
7
33
  /**
8
34
  * Get the value of a grouping field from a cell
9
35
  */
10
36
  function getGroupingValue(cell, field) {
11
- switch (field) {
12
- case 'tech':
13
- return cell.tech;
14
- case 'band':
15
- return cell.frq; // Use numeric band from 'frq' field
16
- case 'status':
17
- return cell.status;
18
- case 'siteId':
19
- return cell.siteId;
20
- case 'customSubgroup':
21
- return cell.customSubgroup || 'Ungrouped';
22
- case 'type':
23
- return cell.type;
24
- case 'planner':
25
- return cell.planner || 'Unassigned';
26
- case 'none':
27
- return '';
28
- default:
29
- return 'Unknown';
30
- }
37
+ if (field === 'none')
38
+ return '';
39
+ const value = cell[field];
40
+ // Handle null/undefined
41
+ if (value == null)
42
+ return 'Unassigned';
43
+ // Convert to string
44
+ return String(value);
31
45
  }
32
46
  /**
33
47
  * Get a human-readable label for a grouping field value
34
48
  */
35
- function getGroupLabel(field, value, count) {
36
- switch (field) {
37
- case 'tech':
38
- return `${value} (${count})`;
39
- case 'band':
40
- return `${value} MHz (${count})`;
41
- case 'status':
42
- return `${value} (${count})`;
43
- case 'siteId':
44
- return `${value} (${count})`;
45
- case 'customSubgroup':
46
- return `${value} (${count})`;
47
- case 'type':
48
- return `${value} (${count})`;
49
- case 'planner':
50
- return `${value} (${count})`;
51
- default:
52
- return `${value} (${count})`;
53
- }
49
+ function getGroupLabel(field, value, count, labelMap) {
50
+ // Use custom label if provided
51
+ const fieldLabel = labelMap?.[field] || String(field);
52
+ return `${value} (${count})`;
54
53
  }
55
54
  /**
56
55
  * Generate a unique node ID based on grouping path
@@ -67,21 +66,22 @@ function generateNodeId(field, value, parentId) {
67
66
  * @param cells - Array of cells to build tree from
68
67
  * @param config - Grouping configuration (level1, level2)
69
68
  * @param colorMap - Optional map of leaf group IDs to custom colors
69
+ * @param labelMap - Optional map of field keys to human-readable labels
70
70
  * @returns Object with tree and cell-to-group lookup map
71
71
  */
72
- export function buildCellTree(cells, config, colorMap) {
72
+ export function buildCellTree(cells, config, colorMap, labelMap) {
73
73
  const { level1, level2 } = config;
74
74
  // If level2 is 'none', create flat 2-level tree
75
75
  if (level2 === 'none') {
76
- return buildFlatTree(cells, level1, colorMap);
76
+ return buildFlatTree(cells, level1, colorMap, labelMap);
77
77
  }
78
78
  // Otherwise, create nested 3-level tree
79
- return buildNestedTree(cells, level1, level2, colorMap);
79
+ return buildNestedTree(cells, level1, level2, colorMap, labelMap);
80
80
  }
81
81
  /**
82
82
  * Build flat 2-level tree (Root → Level1 groups)
83
83
  */
84
- function buildFlatTree(cells, level1, colorMap) {
84
+ function buildFlatTree(cells, level1, colorMap, labelMap) {
85
85
  // Group cells by level1 field
86
86
  const groups = new Map();
87
87
  const cellGroupMap = new Map();
@@ -92,8 +92,8 @@ function buildFlatTree(cells, level1, colorMap) {
92
92
  }
93
93
  groups.get(value).push(cell);
94
94
  });
95
- // Sort groups alphabetically
96
- const sortedGroups = Array.from(groups.entries()).sort(([a], [b]) => a.localeCompare(b));
95
+ // Sort groups with smart numeric/alphabetical sorting
96
+ const sortedGroups = Array.from(groups.entries()).sort(([a], [b]) => smartSort(a, b));
97
97
  // Build tree nodes and populate cellGroupMap
98
98
  const children = sortedGroups.map(([value, groupCells]) => {
99
99
  const nodeId = generateNodeId(level1, value);
@@ -105,7 +105,7 @@ function buildFlatTree(cells, level1, colorMap) {
105
105
  });
106
106
  return {
107
107
  id: nodeId,
108
- label: getGroupLabel(level1, value, groupCells.length),
108
+ label: getGroupLabel(level1, value, groupCells.length, labelMap),
109
109
  defaultChecked: true,
110
110
  children: [],
111
111
  metadata: {
@@ -131,7 +131,7 @@ function buildFlatTree(cells, level1, colorMap) {
131
131
  /**
132
132
  * Build nested 3-level tree (Root → Level1 → Level2 groups)
133
133
  */
134
- function buildNestedTree(cells, level1, level2, colorMap) {
134
+ function buildNestedTree(cells, level1, level2, colorMap, labelMap) {
135
135
  // Group cells by level1, then by level2
136
136
  const level1Groups = new Map();
137
137
  const cellGroupMap = new Map();
@@ -147,13 +147,13 @@ function buildNestedTree(cells, level1, level2, colorMap) {
147
147
  }
148
148
  level2Groups.get(value2).push(cell);
149
149
  });
150
- // Sort level1 groups
151
- const sortedLevel1 = Array.from(level1Groups.entries()).sort(([a], [b]) => a.localeCompare(b));
150
+ // Sort level1 groups with smart numeric/alphabetical sorting
151
+ const sortedLevel1 = Array.from(level1Groups.entries()).sort(([a], [b]) => smartSort(a, b));
152
152
  // Build tree nodes and populate cellGroupMap
153
153
  const children = sortedLevel1.map(([value1, level2Groups]) => {
154
154
  const parentId = generateNodeId(level1, value1);
155
- // Sort level2 groups
156
- const sortedLevel2 = Array.from(level2Groups.entries()).sort(([a], [b]) => a.localeCompare(b));
155
+ // Sort level2 groups with smart numeric/alphabetical sorting
156
+ const sortedLevel2 = Array.from(level2Groups.entries()).sort(([a], [b]) => smartSort(a, b));
157
157
  const level2Children = sortedLevel2.map(([value2, groupCells]) => {
158
158
  const nodeId = generateNodeId(level2, value2, parentId);
159
159
  const color = colorMap?.get(nodeId);
@@ -164,7 +164,7 @@ function buildNestedTree(cells, level1, level2, colorMap) {
164
164
  });
165
165
  return {
166
166
  id: nodeId,
167
- label: getGroupLabel(level2, value2, groupCells.length),
167
+ label: getGroupLabel(level2, value2, groupCells.length, labelMap),
168
168
  defaultChecked: true,
169
169
  children: [],
170
170
  metadata: {
@@ -182,7 +182,7 @@ function buildNestedTree(cells, level1, level2, colorMap) {
182
182
  const totalCells = Array.from(level2Groups.values()).flat().length;
183
183
  return {
184
184
  id: parentId,
185
- label: getGroupLabel(level1, value1, totalCells),
185
+ label: getGroupLabel(level1, value1, totalCells, labelMap),
186
186
  defaultChecked: true,
187
187
  children: level2Children,
188
188
  metadata: {