|
2 | 2 | import { clamp } from '../../shared/math.js'; |
3 | 3 | import { getCssVar } from './charts/colors.js'; |
4 | 4 |
|
| 5 | +/** |
| 6 | + * Abbreviates an outcome label for compact display. |
| 7 | + * Single word: returns first letter capitalized (e.g., "Unlocked" → "U") |
| 8 | + * Multiple words: returns first letter of each word capitalized (e.g., "Camera Error" → "CE") |
| 9 | + */ |
| 10 | +function abbreviateOutcome(outcome) { |
| 11 | + if (!outcome || typeof outcome !== 'string') return ''; |
| 12 | + const trimmed = outcome.trim(); |
| 13 | + if (!trimmed) return ''; |
| 14 | + |
| 15 | + const words = trimmed.split(/\s+/).filter(word => word.length > 0); |
| 16 | + if (words.length === 0) return ''; |
| 17 | + |
| 18 | + if (words.length === 1) { |
| 19 | + // Single word: return first letter capitalized |
| 20 | + return words[0][0].toUpperCase(); |
| 21 | + } |
| 22 | + |
| 23 | + // Multiple words: return first letter of each word capitalized |
| 24 | + return words.map(word => word[0].toUpperCase()).join(''); |
| 25 | +} |
| 26 | + |
5 | 27 | function renderCustomDevice(target, def, index, { compact = false } = {}) { |
6 | 28 | const wrapper = document.createElement('div'); |
7 | 29 | wrapper.className = `pl-custom-device${compact ? ' pl-custom-device--mini' : ''}`; |
@@ -32,7 +54,8 @@ function renderCustomDevice(target, def, index, { compact = false } = {}) { |
32 | 54 | const item = document.createElement('div'); |
33 | 55 | item.className = 'pl-custom-outcome body-xsmall'; |
34 | 56 | if (i === index) item.classList.add('pl-custom-outcome--selected'); |
35 | | - item.textContent = def.labels[i]; |
| 57 | + // Use abbreviated labels in compact mode (two-device mode) |
| 58 | + item.textContent = compact ? abbreviateOutcome(def.labels[i]) : def.labels[i]; |
36 | 59 | grid.append(item); |
37 | 60 | } |
38 | 61 |
|
|
0 commit comments