Dashboard: blood test chart only (no table), hover callouts with the value

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Riaan Doorduin
2026-11-15 13:58:00 +02:00
parent 03dabb2a3a
commit e41249e8b5

View File

@@ -134,9 +134,8 @@ h3.sub { margin: 8px 0 0; font: 600 16px var(--body) }
</div> </div>
<div id="bpBlock" hidden> <div id="bpBlock" hidden>
<h3 class="sub" id="bpHead">Blood pressure and haemoglobin (entered by hand)</h3> <h3 class="sub" id="bpHead">Blood pressure and haemoglobin (entered by hand)</h3>
<div class="grid2" id="bpGrid"> <div id="bpGrid">
<div class="card" style="align-content:start"><p class="note" id="bpNote" hidden></p><div class="legend" id="hBpLeg"></div><div class="chartbox" style="height:420px"><canvas id="cBp" role="img" aria-label="Blood pressure, haemoglobin and blood test results over time"></canvas></div></div> <div class="card" style="align-content:start"><p class="note" id="bpNote" hidden></p><div class="legend" id="hBpLeg"></div><div class="chartbox" style="height:420px"><canvas id="cBp" role="img" aria-label="Blood pressure, haemoglobin and blood test results over time"></canvas></div></div>
<div class="scroll" id="bpTable"><table id="tBp"></table></div>
</div> </div>
</div> </div>
</section> </section>
@@ -435,21 +434,20 @@ if (hd) (function () {
leg('hBpLeg', [...(B.length ? [['Systolic', color(4)], ['Diastolic', color(0)]] : []), ...(HB.length ? [['Haemoglobin', color(2)]] : []), leg('hBpLeg', [...(B.length ? [['Systolic', color(4)], ['Diastolic', color(0)]] : []), ...(HB.length ? [['Haemoglobin', color(2)]] : []),
...labs.map((l, i) => [`${name}${l ? ' ' + l : ''}`, color(cols[i % 3])]), ...(tgt.length ? [[`${name} target`, css('--muted'), true]] : [])]); ...labs.map((l, i) => [`${name}${l ? ' ' + l : ''}`, color(cols[i % 3])]), ...(tgt.length ? [[`${name} target`, css('--muted'), true]] : [])]);
const ds = [ const ds = [
...(B.length ? [line(B.map(b => ({ x: b.t, y: b.sys })), color(4), { label: 'Systolic', unit: 'mmHg', pointRadius: 3 }), line(B.map(b => ({ x: b.t, y: b.dia })), color(0), { label: 'Diastolic', unit: 'mmHg', pointRadius: 3 })] : []), ...(B.length ? [line(B.map(b => ({ x: b.t, y: b.sys, b })), color(4), { label: 'Systolic', unit: 'mmHg', pointRadius: 3 }), line(B.map(b => ({ x: b.t, y: b.dia, b })), color(0), { label: 'Diastolic', unit: 'mmHg', pointRadius: 3 })] : []),
...(HB.length ? [dots(HB, color(2), { label: 'Hb', unit: 'g/dL', pointRadius: 4, yAxisID: 'y2' })] : []), ...(HB.length ? [dots(HB, color(2), { label: 'Hb', unit: 'g/dL', pointRadius: 4, yAxisID: 'y2' })] : []),
...labs.map((l, i) => line(P.filter(r => (r.lab || '') === l).map(r => ({ x: r.t, y: r.v })), color(cols[i % 3]), { label: `${name}${l ? ' ' + l : ''}`, unit, pointRadius: 3, showLine: l === labs[0], yAxisID: 'y3' })), ...labs.map((l, i) => line(P.filter(r => (r.lab || '') === l).map(r => ({ x: r.t, y: r.v })), color(cols[i % 3]), { label: `${name}${l ? ' ' + l : ''}`, unit, pointRadius: 3, showLine: l === labs[0], yAxisID: 'y3' })),
...(tgt.length ? [0, 1].map(k => line(tgt.map(r => ({ x: r.t, y: r.target[k] })), css('--muted'), { label: `Target ${k ? 'max' : 'min'}`, unit, stepped: true, borderDash: [5, 4], borderWidth: 1.5, pointHoverRadius: 0, yAxisID: 'y3' })) : [])]; ...(tgt.length ? [0, 1].map(k => line(tgt.map(r => ({ x: r.t, y: r.target[k] })), css('--muted'), { label: `Target ${k ? 'max' : 'min'}`, unit, stepped: true, borderDash: [5, 4], borderWidth: 1.5, pointHoverRadius: 0, yAxisID: 'y3' })) : [])];
const ts = [...B.map(b => b.t), ...HB.map(h => h.x), ...P.map(r => r.t)], ttl = text => ({ display: true, text, color: css('--muted') }); const ts = [...B.map(b => b.t), ...HB.map(h => h.x), ...P.map(r => r.t)], ttl = text => ({ display: true, text, color: css('--muted') });
new Chart($('cBp'), { type: 'line', data: { datasets: ds }, new Chart($('cBp'), { type: 'line', data: { datasets: ds },
options: { maintainAspectRatio: false, parsing: false, plugins: { legend: { display: false }, tooltip: { ...tip, callbacks: { title: i => fmtD(i[0].raw.x), label: i => `${i.dataset.label}: ${i.raw.y} ${i.dataset.unit}` } } }, options: { maintainAspectRatio: false, parsing: false, interaction: { mode: 'nearest', intersect: false }, // hover near a point: a callout with its value
plugins: { legend: { display: false }, tooltip: { ...tip, filter: i => !i.dataset.label.startsWith('Target'), callbacks: { title: i => fmtD(i[0].raw.x),
label: i => i.raw.b ? `Blood pressure: ${i.raw.b.sys}/${i.raw.b.dia} mmHg` + (i.raw.b.pulse ? `, pulse ${i.raw.b.pulse}` : '') : `${i.dataset.label}: ${i.raw.y} ${i.dataset.unit}` } } },
scales: { x: { ...xAxis, min: Math.min(...ts) - 15 * 864e5, max: Math.max(...ts) + 15 * 864e5 }, scales: { x: { ...xAxis, min: Math.min(...ts) - 15 * 864e5, max: Math.max(...ts) + 15 * 864e5 },
y: { display: B.length > 0, grid, suggestedMin: 50, suggestedMax: 140, title: ttl('mmHg') }, y: { display: B.length > 0, grid, suggestedMin: 50, suggestedMax: 140, title: ttl('mmHg') },
y2: { display: HB.length > 0, position: 'right', grid: { display: false }, suggestedMin: 12, suggestedMax: 17, title: ttl('Hb g/dL') }, y2: { display: HB.length > 0, position: 'right', grid: { display: false }, suggestedMin: 12, suggestedMax: 17, title: ttl('Hb g/dL') },
y3: { display: LM.length > 0, position: 'right', grid: { display: B.length === 0 }, title: ttl(`${name} ${unit}`), type: lm === 'ferritin' ? 'logarithmic' : 'linear', y3: { display: LM.length > 0, position: 'right', grid: { display: B.length === 0 }, title: ttl(`${name} ${unit}`), type: lm === 'ferritin' ? 'logarithmic' : 'linear',
...(lm === 'ferritin' ? { afterBuildTicks: ax => { ax.ticks = [5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000].filter(v => v >= ax.min && v <= ax.max).map(value => ({ value })) } } : {}) } } } }); ...(lm === 'ferritin' ? { afterBuildTicks: ax => { ax.ticks = [5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000].filter(v => v >= ax.min && v <= ax.max).map(value => ({ value })) } } : {}) } } } });
$('bpTable').hidden = !B.length;
if (B.length) $('tBp').innerHTML = '<thead><tr><th class="l">Date</th><th>Blood pressure</th><th>Pulse</th><th>Hb g/dL</th><th class="l">Note</th></tr></thead><tbody>' +
[...B].reverse().map(b => `<tr><td>${b.d}</td><td>${b.sys}/${b.dia}</td><td>${b.pulse ?? ''}</td><td>${b.hb ?? ''}</td><td class="l dim">${(b.note || '').replace(/[<>&]/g, '')}</td></tr>`).join('') + '</tbody>';
} }
})(); })();