Skip to content

Commit 93e13a9

Browse files
authored
Merge pull request #27 from NGO-Algorithm-Audit/feature/show-labels-next-to-y-scale-axis
Feature/show labels next to y scale axis
2 parents 8dbdf09 + 77995b9 commit 93e13a9

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

src/components/graphs/CountBarChart.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface CountBarChartProps {
88
}
99

1010
const margin = { top: 30, right: 50, bottom: 60, left: 50 }; // Increased bottom margin for rotated labels
11-
const height = 300 - margin.top - margin.bottom;
11+
const height = 380 - margin.top - margin.bottom;
1212

1313
const CountBarChart = ({ column, realData }: CountBarChartProps) => {
1414
const svgRef = useRef<SVGSVGElement>(null);
@@ -108,18 +108,27 @@ const CountBarChart = ({ column, realData }: CountBarChartProps) => {
108108
svg.append('g').call(
109109
d3
110110
.axisLeft(yScale)
111-
.ticks(5) // Reduce number of ticks
111+
.ticks(5)
112112
.tickFormat(d => formatTick(d as number))
113113
);
114114

115+
// Add y-axis label
116+
svg.append('text')
117+
.attr('transform', 'rotate(-90)')
118+
.attr('y', -40) // Adjust position from left edge
119+
.attr('x', -plotHeight / 2) // Center vertically
120+
.attr('text-anchor', 'middle')
121+
.attr('font-size', '12px')
122+
.text(t('distribution.frequency'));
123+
115124
// Add title
116125
svg.append('text')
117126
.attr('x', plotWidth / 2)
118127
.attr('y', -10)
119128
.attr('text-anchor', 'middle')
120129
.style('font-size', '12px')
121130
.style('font-weight', 'bold')
122-
.text(`${t('distribution.distributionFor')} ${column}`);
131+
.text(`${t('distribution.countFor')} ${column}`);
123132
}, [containerWidth, column, realData]);
124133

125134
useEffect(() => {

src/components/graphs/DistributionBarChart.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ interface DistributionBarChartProps {
99
syntheticData: (string | number)[];
1010
}
1111

12-
const margin = { top: 30, right: 50, bottom: 60, left: 50 }; // Increased bottom margin for rotated labels
13-
const height = 300 - margin.top - margin.bottom;
12+
const margin = { top: 30, right: 50, bottom: 60, left: 80 }; // Increased bottom margin for rotated labels
13+
const height = 380 - margin.top - margin.bottom;
1414

1515
const DistributionBarChart = ({
1616
column,
@@ -166,6 +166,15 @@ const DistributionBarChart = ({
166166
.style('font-weight', 'bold')
167167
.text(`${t('distribution.distributionFor')} ${column}`);
168168

169+
// Add y-axis label
170+
svg.append('text')
171+
.attr('transform', 'rotate(-90)')
172+
.attr('y', -50) // Adjust position from left edge
173+
.attr('x', -plotHeight / 2) // Center vertically
174+
.attr('text-anchor', 'middle')
175+
.attr('font-size', '12px')
176+
.text(t('distribution.percentage'));
177+
169178
// Add legend
170179
const legend = svg
171180
.append('g')

src/locales/en.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@
144144
},
145145
"distribution": {
146146
"distributionFor": "Distribution for",
147+
"countFor": "Distribution for",
148+
"frequency": "Frequency",
147149
"syntheticData": "Synthetic data",
148-
"realData": "Real data"
150+
"realData": "Real data",
151+
"percentage": "Percentage of dataset"
149152
}
150153
}

src/locales/nl.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@
143143
},
144144
"distribution": {
145145
"distributionFor": "Distributie voor",
146+
"countFor": "Distributie voor",
147+
"frequency": "Frequentie",
146148
"syntheticData": "Synthetische data",
147-
"realData": "Echte data"
149+
"realData": "Echte data",
150+
"percentage": "Percentage van dataset"
148151
}
149152
}

0 commit comments

Comments
 (0)