Skip to content

Commit 540fbe9

Browse files
committed
Improve solvent label readability in UI
1 parent 1711565 commit 540fbe9

3 files changed

Lines changed: 125 additions & 64 deletions

File tree

‎src/components/cmd_bar/r01_layout.js‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,36 @@ const styles = () => (
3434
)
3535
);
3636

37+
const chemSubStyle = {
38+
fontSize: '0.85em',
39+
position: 'relative',
40+
top: '0.24em',
41+
lineHeight: 1,
42+
};
43+
44+
const renderReadableSubscript = (txt = '') => {
45+
if (typeof txt !== 'string') return txt;
46+
const regex = /([A-Za-z])(\d+)/g;
47+
if (!regex.test(txt)) return txt;
48+
regex.lastIndex = 0;
49+
const parts = [];
50+
let cursor = 0;
51+
let match = regex.exec(txt);
52+
while (match) {
53+
const [raw, prefix, digits] = match;
54+
const at = match.index;
55+
if (at > cursor) parts.push(txt.slice(cursor, at));
56+
parts.push(prefix);
57+
parts.push(
58+
<span key={`${at}-${digits}`} style={chemSubStyle}>{digits}</span>,
59+
);
60+
cursor = at + raw.length;
61+
match = regex.exec(txt);
62+
}
63+
if (cursor < txt.length) parts.push(txt.slice(cursor));
64+
return parts;
65+
};
66+
3767
const shiftSelect = (
3868
classes, layoutSt, setShiftRefAct, shiftSt, curveSt,
3969
) => {
@@ -73,7 +103,8 @@ const shiftSelect = (
73103
{listShift.map((ref) => (
74104
<MenuItem value={ref.name} key={ref.name}>
75105
<span className={classNames(classes.txtOpt, 'option-sv-bar-shift')}>
76-
{`${ref.name}: ${Format.strNumberFixedDecimal(ref.value, 2)} ppm`}
106+
{renderReadableSubscript(ref.name)}
107+
{`: ${Format.strNumberFixedDecimal(ref.value, 2)} ppm`}
77108
</span>
78109
</MenuItem>
79110
))}

‎src/components/panel/info.js‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,36 @@ const normalizeQuillValue = (val) => {
120120
return val;
121121
};
122122

123+
const chemSubStyle = {
124+
fontSize: '0.85em',
125+
position: 'relative',
126+
top: '0.24em',
127+
lineHeight: 1,
128+
};
129+
130+
const renderReadableSubscript = (txt = '') => {
131+
if (typeof txt !== 'string') return txt;
132+
const regex = /([A-Za-z])(\d+)/g;
133+
if (!regex.test(txt)) return txt;
134+
regex.lastIndex = 0;
135+
const parts = [];
136+
let cursor = 0;
137+
let match = regex.exec(txt);
138+
while (match) {
139+
const [raw, prefix, digits] = match;
140+
const at = match.index;
141+
if (at > cursor) parts.push(txt.slice(cursor, at));
142+
parts.push(prefix);
143+
parts.push(
144+
<span key={`${at}-${digits}`} style={chemSubStyle}>{digits}</span>,
145+
);
146+
cursor = at + raw.length;
147+
match = regex.exec(txt);
148+
}
149+
if (cursor < txt.length) parts.push(txt.slice(cursor));
150+
return parts;
151+
};
152+
123153
const handleDescriptionChanged = (content, delta, source, editor, onDescriptionChanged) => {
124154
if (!onDescriptionChanged) return;
125155
onDescriptionChanged(normalizeQuillValue(content), delta, source, editor);
@@ -314,7 +344,7 @@ const InfoPanel = ({
314344
? (
315345
<div className={classNames(classes.rowRoot, classes.rowOdd)}>
316346
<span className={classNames(classes.tTxt, classes.tHead, 'txt-sv-panel-txt')}>Solv : </span>
317-
<span className={classNames(classes.tTxt, 'txt-sv-panel-txt')}>{showSolvName}</span>
347+
<span className={classNames(classes.tTxt, 'txt-sv-panel-txt')}>{renderReadableSubscript(showSolvName)}</span>
318348
</div>
319349
)
320350
: null

0 commit comments

Comments
 (0)