Skip to content

Commit 15741e2

Browse files
authored
Merge pull request #34 from NGO-Algorithm-Audit/feature/update-violin-chart
Feature/update violin chart
2 parents 004ea92 + b3536f3 commit 15741e2

File tree

5 files changed

+184
-93
lines changed

5 files changed

+184
-93
lines changed

src/components/DistributionReport.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export const DistributionReport = (
129129
const charts = columnNames.map((column, index) => {
130130
const dataType = dataTypes[column];
131131
return columnNames.map((column2, index2) => {
132-
if (column === column2 || index >= index2) {
132+
if (column === column2 || index <= index2) {
133133
return null;
134134
}
135135
const dataType2 = dataTypes[column2];
@@ -195,11 +195,26 @@ export const DistributionReport = (
195195
return (
196196
<div key={column + column2}>
197197
<GroupBarChart
198+
yAxisLabel={column}
198199
data={histogramData}
199200
title={`${column} vs ${column2}`}
200201
/>
201202
</div>
202203
);
204+
} else if (
205+
dataType === 'float' &&
206+
dataType2 === 'category'
207+
) {
208+
return (
209+
<ViolinChart
210+
key={column + column2}
211+
categoricalColumn={column2}
212+
numericColumn={column}
213+
realData={realData}
214+
syntheticData={syntheticData}
215+
comparison={false}
216+
/>
217+
);
203218
}
204219
});
205220
});
@@ -237,6 +252,7 @@ export const DistributionReport = (
237252
numericColumn={column}
238253
realData={realData}
239254
syntheticData={syntheticData}
255+
comparison={true}
240256
/>
241257
);
242258
}

src/components/componentMapper.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export default function ComponentMapper({
152152
<ErrorBoundary key={index}>
153153
<GroupBarChart
154154
data={histogramData}
155+
yAxisLabel={t('distribution.frequency')}
155156
title={resultItem.title ?? ''}
156157
/>
157158
</ErrorBoundary>

src/components/graphs/GroupBarChart.tsx

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,27 @@ interface Data extends DataLabel {
77
}
88

99
interface GroupBarChartProps {
10+
yAxisLabel: string;
1011
title: string;
1112
data: Data[];
1213
}
1314

14-
const margin = { top: 10, right: 10, bottom: 40, left: 50 };
15+
const margin = { top: 30, right: 50, bottom: 40, left: 80 };
1516
const height = 300 - margin.top - margin.bottom;
1617
const barWidth = 0.05 * window.innerWidth < 40 ? 40 : 0.05 * window.innerWidth;
1718
const barGap = 5;
1819

19-
const GroupBarChart = ({ title, data }: GroupBarChartProps) => {
20+
const GroupBarChart = ({ title, data, yAxisLabel }: GroupBarChartProps) => {
2021
const svgRef = useRef<SVGSVGElement>(null);
2122
const containerRef = useRef<HTMLDivElement>(null);
2223
const [containerWidth, setContainerWidth] = useState(800); // Default width
24+
25+
//const legendWidth = 140;
26+
// const plotWidth =
27+
// containerWidth -
28+
// margin.left -
29+
// margin.right ;
30+
2331
const fx = useMemo(
2432
() =>
2533
d3
@@ -82,6 +90,7 @@ const GroupBarChart = ({ title, data }: GroupBarChartProps) => {
8290
.text(
8391
"@import url('https://fonts.googleapis.com/css2?family=Avenir:wght@600');"
8492
);
93+
8594
// Append x-axis
8695
const xAxis = svg
8796
.append('g')
@@ -143,14 +152,24 @@ const GroupBarChart = ({ title, data }: GroupBarChartProps) => {
143152
`translate(${Math.max(containerWidth, data.length * barWidth) - margin.left - margin.right + 20}, 0)`
144153
);
145154

146-
// Append title to the legend
147-
legend
148-
.append('text')
149-
.attr('x', 0)
150-
.attr('y', 0)
155+
// Append title to the svg
156+
svg.append('text')
157+
.attr('x', (containerWidth - margin.left - margin.right) / 2)
158+
.attr('y', -10)
159+
.attr('text-anchor', 'middle')
160+
.style('font-size', '12px')
151161
.style('font-weight', 'bold')
152162
.text(title);
153163

164+
// Add y-axis label
165+
svg.append('text')
166+
.attr('transform', 'rotate(-90)')
167+
.attr('y', -50)
168+
.attr('x', -height / 2)
169+
.attr('text-anchor', 'middle')
170+
.attr('font-size', '12px')
171+
.text(yAxisLabel);
172+
154173
// Append legend color boxes and text labels
155174
const legendItems = legend
156175
.selectAll('.legend-item')

src/components/graphs/GroupedBarChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface GroupedBarChartProps {
1111
data: Data[];
1212
}
1313

14-
const margin = { top: 20, right: 250, bottom: 40, left: 50 };
14+
const margin = { top: 20, right: 250, bottom: 40, left: 80 };
1515
const height = 300 - margin.top - margin.bottom;
1616
const maxBuckets = 10; // Maximum number of buckets per group
1717

0 commit comments

Comments
 (0)