Skip to content

Commit f469415

Browse files
committed
Improve device view for two custom devices (only first capitalized letter rather than full outcome)
1 parent f469b64 commit f469415

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

client/src/probability-lab/ui/device-view.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@
22
import { clamp } from '../../shared/math.js';
33
import { getCssVar } from './charts/colors.js';
44

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+
527
function renderCustomDevice(target, def, index, { compact = false } = {}) {
628
const wrapper = document.createElement('div');
729
wrapper.className = `pl-custom-device${compact ? ' pl-custom-device--mini' : ''}`;
@@ -32,7 +54,8 @@ function renderCustomDevice(target, def, index, { compact = false } = {}) {
3254
const item = document.createElement('div');
3355
item.className = 'pl-custom-outcome body-xsmall';
3456
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];
3659
grid.append(item);
3760
}
3861

0 commit comments

Comments
 (0)