Skip to content

Commit 69104f1

Browse files
space out barplots
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 5472b18 commit 69104f1

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

client/src/components/Barplot.jsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import * as d3 from "d3";
44
const MARGIN = { top: 16, right: 48, bottom: 8, left: 160 };
55
const MIN_WIDTH = 220;
66
const MIN_HEIGHT = 240;
7+
const MAX_BANDWIDTH = 20;
8+
const BAND_PADDING = 0.1;
79

810
/**
911
* React wrapper around the original D3 barplot from client/js/main.js (barplot_new).
@@ -63,19 +65,23 @@ export default function Barplot({ data, onTickClick, disabled }) {
6365
.attr("width", outerW)
6466
.attr("height", outerH);
6567

68+
const idealRange = (MAX_BANDWIDTH * plotData.length) / (1 - BAND_PADDING);
69+
const rangeHeight = Math.min(height, idealRange);
70+
const yOffset = Math.max(0, (height - rangeHeight) / 2);
71+
6672
const svg = d3
6773
.select(svgEl)
6874
.append("g")
69-
.attr("transform", `translate(${MARGIN.left},${MARGIN.top})`)
75+
.attr("transform", `translate(${MARGIN.left},${MARGIN.top + yOffset})`)
7076
.attr("fill", "white");
7177

7278
const xMax = d3.max(plotData, (d) => d.prob) || 1;
7379
const xScale = d3.scaleLinear().domain([0, xMax]).range([0, width]);
7480
const yScale = d3
7581
.scaleBand()
7682
.domain(plotData.map((d) => d.text))
77-
.range([0, height])
78-
.padding(0.1);
83+
.range([0, rangeHeight])
84+
.padding(BAND_PADDING);
7985

8086
const yAxis = svg.append("g").call(d3.axisLeft(yScale));
8187
const tickFontSize = Math.min(15, Math.max(5, yScale.bandwidth() * 0.9));

0 commit comments

Comments
 (0)