Skip to content

Commit 292253f

Browse files
committed
new content feature: accordion component
1 parent 73a0afe commit 292253f

File tree

5 files changed

+214
-19
lines changed

5 files changed

+214
-19
lines changed

package-lock.json

Lines changed: 111 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"dependencies": {
1717
"@heroicons/react": "^2.1.5",
1818
"@hookform/resolvers": "^3.9.0",
19+
"@radix-ui/react-accordion": "^1.2.1",
1920
"@radix-ui/react-checkbox": "^1.1.2",
2021
"@radix-ui/react-dialog": "^1.1.2",
2122
"@radix-ui/react-icons": "^1.3.0",

src/assets/bias-detection-python-code.tsx

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -230,42 +230,47 @@ def run():
230230
231231
if dataType == 'numeric':
232232
diff_df = diffDataframe(df, features, type='Numerical')
233+
234+
overview = "";
235+
233236
for feat in features:
234237
diff = diff_df.loc[feat,"Difference"].round(2)
235238
236239
if diff < 0:
237-
setResult(json.dumps(
238-
{'type': 'text', 'data': f'{abs(diff)} less {feat} than in the rest of the dataset.'}
239-
))
240+
overview += f'{abs(diff)} less {feat} than in the rest of the dataset. '
241+
240242
elif diff > 0:
241-
setResult(json.dumps(
242-
{'type': 'text', 'data': f'{diff} more {feat} than in the rest of the dataset.'}
243-
))
243+
overview += f'{diff} more {feat} than in the rest of the dataset. '
244+
244245
elif diff == 0:
245-
setResult(json.dumps(
246-
{'type': 'text', 'data': f'equal {feat} as in the rest of the dataset.'}
247-
))
246+
overview += f'equal {feat} as in the rest of the dataset. '
247+
248+
overview += '''
249+
'''
250+
251+
setResult(json.dumps(
252+
{'type': 'accordion', 'title': 'Open details to view feature comparisons to the rest of the dataset','content': overview}
253+
))
248254
else:
249255
diff_df = diffDataframe(df, features, type='Categorical')
256+
overview = "";
250257
for feat in features:
251258
values = df[feat].unique().tolist()
252259
for value in values:
253260
diff = diff_df.loc[value,"Difference"].round(2)
254261
255262
if (isinstance(diff, float)):
256263
if diff < 0:
257-
setResult(json.dumps(
258-
{'type': 'text', 'data': f'{abs(diff)} less {value} than in the rest of the dataset.'}
259-
))
264+
overview += f'{abs(diff)} less {value} than in the rest of the dataset. '
260265
elif diff > 0:
261-
setResult(json.dumps(
262-
{'type': 'text', 'data': f'{diff} more {value} than in the rest of the dataset.'}
263-
))
266+
overview += f'{diff} more {value} than in the rest of the dataset. '
264267
elif diff == 0:
265-
setResult(json.dumps(
266-
{'type': 'text', 'data': f'equal {value} as in the rest of the dataset.'}
267-
))
268-
268+
overview += f'equal {value} as in the rest of the dataset. '
269+
overview += '''
270+
'''
271+
setResult(json.dumps(
272+
{'type': 'accordion', 'title': 'Open details to view feature comparisons to the rest of the dataset','content': overview}
273+
))
269274
270275
if dataType == 'numeric':
271276
for col in full_df.columns:

src/components/componentMapper.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import Markdown from 'react-markdown';
66
import { getLabel } from './graphs/get-label';
77
import { CSVData } from './bias-detection-interfaces/csv-data';
88
import { Fragment } from 'react/jsx-runtime';
9+
import {
10+
Accordion,
11+
AccordionContent,
12+
AccordionItem,
13+
AccordionTrigger,
14+
} from './ui/accordion';
915

1016
const createArrayFromPythonDictionary = (dict: Record<string, number>) => {
1117
const resultArray = [];
@@ -71,6 +77,21 @@ export default function ComponentMapper({
7177
{resultItem.data}
7278
</h5>
7379
);
80+
case 'accordion':
81+
return (
82+
<Accordion key={index} type="single" collapsible>
83+
<AccordionItem value="item-1">
84+
<AccordionTrigger>
85+
{resultItem.title}
86+
</AccordionTrigger>
87+
<AccordionContent>
88+
<Markdown className="mt-2 text-gray-800 markdown">
89+
{resultItem.content}
90+
</Markdown>
91+
</AccordionContent>
92+
</AccordionItem>
93+
</Accordion>
94+
);
7495
case 'histogram': {
7596
const histogramData = JSON.parse(resultItem.data)?.map(
7697
(x: Record<string, number>, index: number) => {

src/components/ui/accordion.tsx

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
'use client';
2+
3+
import * as React from 'react';
4+
import * as AccordionPrimitive from '@radix-ui/react-accordion';
5+
import { ChevronDown } from 'lucide-react';
6+
7+
import { cn } from '@/lib/utils';
8+
9+
const Accordion = AccordionPrimitive.Root;
10+
11+
const AccordionItem = React.forwardRef<
12+
React.ElementRef<typeof AccordionPrimitive.Item>,
13+
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item>
14+
>(({ className, ...props }, ref) => (
15+
<AccordionPrimitive.Item
16+
ref={ref}
17+
className={cn('border-b', className)}
18+
{...props}
19+
/>
20+
));
21+
AccordionItem.displayName = 'AccordionItem';
22+
23+
const AccordionTrigger = React.forwardRef<
24+
React.ElementRef<typeof AccordionPrimitive.Trigger>,
25+
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger>
26+
>(({ className, children, ...props }, ref) => (
27+
<AccordionPrimitive.Header className="flex">
28+
<AccordionPrimitive.Trigger
29+
ref={ref}
30+
className={cn(
31+
'flex flex-1 items-center justify-between pb-4 text-md font-semibold transition-all hover:underline text-left [&[data-state=open]>svg]:rotate-180',
32+
className
33+
)}
34+
{...props}
35+
>
36+
{children}
37+
<ChevronDown className="h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-200" />
38+
</AccordionPrimitive.Trigger>
39+
</AccordionPrimitive.Header>
40+
));
41+
AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName;
42+
43+
const AccordionContent = React.forwardRef<
44+
React.ElementRef<typeof AccordionPrimitive.Content>,
45+
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content>
46+
>(({ className, children, ...props }, ref) => (
47+
<AccordionPrimitive.Content
48+
ref={ref}
49+
className="overflow-hidden text-sm data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down"
50+
{...props}
51+
>
52+
<div className={cn('pb-4 pt-0', className)}>{children}</div>
53+
</AccordionPrimitive.Content>
54+
));
55+
AccordionContent.displayName = AccordionPrimitive.Content.displayName;
56+
57+
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent };

0 commit comments

Comments
 (0)