Skip to content

Commit 0c7dbdc

Browse files
committed
Better bar chart
1 parent a32696d commit 0c7dbdc

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

client/src/probability-lab/ui/charts/bar-chart.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,17 @@ export default function drawBarChart(canvas, labels, values, theory) {
5757
if (labels.length === 0) return;
5858

5959
const gap = labels.length > 1 ? Math.min(14, plotW / (labels.length * 2)) : 0;
60-
const barW = (plotW - gap * (labels.length - 1)) / labels.length;
60+
const slotW = (plotW - gap * (labels.length - 1)) / labels.length;
61+
const barW = slotW * 0.8; // Bars are 80% of slot width
6162

6263
ctx.textAlign = 'center';
6364
ctx.textBaseline = 'top';
6465

6566
for (let i = 0; i < labels.length; i += 1) {
6667
const value = clamp(values[i] ?? 0, 0, 1);
6768
const theoryValue = clamp(theory[i] ?? 0, 0, 1);
68-
const x = padding.left + i * (barW + gap);
69+
const slotX = padding.left + i * (slotW + gap);
70+
const x = slotX + (slotW - barW) / 2; // Center bar in its slot
6971
const barH = value * plotH;
7072
const y = padding.top + plotH - barH;
7173

@@ -93,7 +95,7 @@ export default function drawBarChart(canvas, labels, values, theory) {
9395
ctx.fillStyle = strong;
9496
ctx.font = '12px var(--body-family)';
9597
const label = String(labels[i]);
96-
ctx.fillText(label, x + barW / 2, padding.top + plotH + 8);
98+
ctx.fillText(label, slotX + slotW / 2, padding.top + plotH + 8); // Center label on slot
9799
}
98100
});
99101
}

0 commit comments

Comments
 (0)