Skip to content

Commit 7653011

Browse files
committed
legend in violinplot now doesn't overlap the violinplots
1 parent 00f5c22 commit 7653011

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/components/graphs/ViolinChart.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const ViolinChart = ({
2424
const { t } = useTranslation();
2525

2626
useEffect(() => {
27-
const plotWidth = containerWidth - margin.left - margin.right;
2827
const plotHeight = height - margin.top - margin.bottom;
2928

3029
// Get unique categories
@@ -62,6 +61,11 @@ const ViolinChart = ({
6261
.append('g')
6362
.attr('transform', `translate(${margin.left},${margin.top})`);
6463

64+
// Reserve space for legend (120px width + 20px padding)
65+
const legendWidth = 140;
66+
const plotWidth =
67+
containerWidth - margin.left - margin.right - legendWidth;
68+
6569
// Create scales
6670
const xScale = d3
6771
.scaleBand()
@@ -237,11 +241,13 @@ const ViolinChart = ({
237241
.attr('font-size', '12px')
238242
.text(numericColumn);
239243

240-
// Add legend
244+
// Add legend at fixed position relative to plot area
241245
const legend = svg
242246
.append('g')
243247
.attr('class', 'legend')
244-
.attr('transform', `translate(${plotWidth - 120}, 30)`);
248+
.attr('transform', `translate(${plotWidth + 20}, 30)`);
249+
250+
// No need to adjust SVG width since we reserved space for legend
245251

246252
// Add background rectangle for legend
247253
legend

0 commit comments

Comments
 (0)