Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit d2d3a06

Browse files
authored
feat(gui): quality view for automatically generated annotations (#811)
* feat(gui): improve contract of charts in dark mode * feat(gui): quality view for annotations * feat(gui): treat changed annotations still as autogenerated * style: fix lint error * style: apply automatic fixes of linters Co-authored-by: lars-reimann <[email protected]>
1 parent 117682b commit d2d3a06

File tree

10 files changed

+257
-637
lines changed

10 files changed

+257
-637
lines changed

api-editor/gui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"serve": "vite preview",
99
"test": "jest src",
1010
"test-with-coverage": "jest src --coverage",
11-
"gen:theme-typings": "chakra-cli tokens src/theme/index.ts -- out src/theme/index.d.ts",
11+
"gen:theme-typings": "chakra-cli tokens src/theme/index.ts",
1212
"postinstall": "npm run gen:theme-typings"
1313
},
1414
"prettier": "@lars-reimann/prettier-config",

api-editor/gui/src/features/annotations/annotationSlice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ const removeAnnotation = (state: AnnotationSlice, parent: { [key: string]: Annot
977977

978978
const isAutogenerated = (annotation: Annotation) => {
979979
const authors = annotation.authors ?? [];
980-
return authors.length === 1 && authors[0] === '$autogen$';
980+
return authors.includes('$autogen$');
981981
};
982982

983983
const updateQueue = function (state: AnnotationSlice) {

api-editor/gui/src/features/packageData/selectionView/ParameterView.tsx

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Box, Heading, Stack, Text as ChakraText } from '@chakra-ui/react';
1+
import { Box, Heading, Stack, Text as ChakraText, useColorModeValue } from '@chakra-ui/react';
22
import React from 'react';
33
import { PythonParameter } from '../model/PythonParameter';
44
import { ParameterNode } from './ParameterNode';
@@ -54,15 +54,22 @@ export const ParameterView: React.FC<ParameterViewProps> = function ({ pythonPar
5454
Most Common Values
5555
</Heading>
5656
<Box w="30vw" maxWidth="640px">
57-
{createBarChart(parameterUsages)}
57+
<CustomBarChart parameterUsages={parameterUsages} />
5858
</Box>
5959
</Stack>
6060
)}
6161
</Stack>
6262
);
6363
};
6464

65-
const createBarChart = function (parameterUsages: Map<string, number>): React.ReactElement {
65+
interface CustomBarChartProps {
66+
parameterUsages: Map<string, number>;
67+
}
68+
69+
const CustomBarChart: React.FC<CustomBarChartProps> = function ({ parameterUsages }) {
70+
const gridColor = useColorModeValue('#BBB', '#555');
71+
const textColor = useColorModeValue('#000', '#FFF');
72+
6673
const options = {
6774
indexAxis: 'y' as const,
6875
elements: {
@@ -82,6 +89,24 @@ const createBarChart = function (parameterUsages: Map<string, number>): React.Re
8289
intersect: false,
8390
},
8491
},
92+
scales: {
93+
x: {
94+
grid: {
95+
color: gridColor,
96+
},
97+
ticks: {
98+
color: textColor,
99+
},
100+
},
101+
y: {
102+
grid: {
103+
color: gridColor,
104+
},
105+
ticks: {
106+
color: textColor,
107+
},
108+
},
109+
},
85110
};
86111

87112
const sortedParameterUsages = new Map([...parameterUsages.entries()].sort((a, b) => b[1] - a[1]));

api-editor/gui/src/features/statistics/ApiSizeStatistics.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { Box, Flex, Heading } from '@chakra-ui/react';
33
import { useAppSelector } from '../../app/hooks';
44
import { selectRawPythonPackage } from '../packageData/apiSlice';
55
import { selectUsages } from '../usages/usageSlice';
6-
import { createBarChart } from './ChartWrappers';
76
import { PythonPackage } from '../packageData/model/PythonPackage';
87
import { UsageCountStore } from '../usages/model/UsageCountStore';
8+
import { CustomBarChart } from './ChartWrappers';
99

1010
export const ApiSizeStatistics = function () {
1111
const rawPythonPackage = useAppSelector(selectRawPythonPackage);
@@ -15,15 +15,15 @@ export const ApiSizeStatistics = function () {
1515

1616
const classLabels = ['full', 'public', 'used'];
1717
const classValues = getClassValues(rawPythonPackage, usages, usedThreshold);
18-
const classBarChart = createBarChart(classLabels, classValues, 'Classes');
18+
const classBarChart = <CustomBarChart labels={classLabels} values={classValues} title="Classes" />;
1919

2020
const functionLabels = ['full', 'public', 'used'];
2121
const functionValues = getFunctionValues(rawPythonPackage, usages, usedThreshold);
22-
const functionBarChart = createBarChart(functionLabels, functionValues, 'Functions');
22+
const functionBarChart = <CustomBarChart labels={functionLabels} values={functionValues} title="Functions" />;
2323

2424
const parameterLabels = ['full', 'public', 'used', 'useful'];
2525
const parameterValues = getParameterValues(rawPythonPackage, usages, usedThreshold);
26-
const parameterBarChart = createBarChart(parameterLabels, parameterValues, 'Parameters');
26+
const parameterBarChart = <CustomBarChart labels={parameterLabels} values={parameterValues} title={'Parameters'} />;
2727

2828
return (
2929
<>

api-editor/gui/src/features/statistics/ApiSizeVsUsefulnessStatistics.tsx

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,43 @@ import { Box, Flex, Heading } from '@chakra-ui/react';
33
import { useAppSelector } from '../../app/hooks';
44
import { selectRawPythonPackage } from '../packageData/apiSlice';
55
import { selectUsages } from '../usages/usageSlice';
6-
import { createLineChart } from './ChartWrappers';
6+
import { CustomLineChart } from './ChartWrappers';
77

88
export const ApiSizeVsUsefulnessStatistics = function () {
99
const rawPythonPackage = useAppSelector(selectRawPythonPackage);
1010
const usages = useAppSelector(selectUsages);
1111

1212
const thresholds = [...Array(26).keys()];
1313
thresholds.shift();
14-
const classLineChart = createLineChart(
15-
usages,
16-
rawPythonPackage,
17-
thresholds,
18-
usages.getNumberOfUsedPublicClasses,
19-
'Classes',
20-
'Minimum usefulness',
14+
const classLineChart = (
15+
<CustomLineChart
16+
usages={usages}
17+
pythonPackage={rawPythonPackage}
18+
labels={thresholds}
19+
getValue={usages.getNumberOfUsedPublicClasses}
20+
title={'Classes'}
21+
xAxisLabel={'Minimum usefulness'}
22+
/>
2123
);
22-
const functionLineChart = createLineChart(
23-
usages,
24-
rawPythonPackage,
25-
thresholds,
26-
usages.getNumberOfUsedPublicFunctions,
27-
'Functions',
28-
'Minimum usefulness',
24+
const functionLineChart = (
25+
<CustomLineChart
26+
usages={usages}
27+
pythonPackage={rawPythonPackage}
28+
labels={thresholds}
29+
getValue={usages.getNumberOfUsedPublicFunctions}
30+
title={'Functions'}
31+
xAxisLabel={'Minimum usefulness'}
32+
/>
2933
);
30-
const parameterLineChart = createLineChart(
31-
usages,
32-
rawPythonPackage,
33-
thresholds,
34-
usages.getNumberOfUsefulPublicParameters,
35-
'Parameters',
36-
'Minimum usefulness',
34+
const parameterLineChart = (
35+
<CustomLineChart
36+
usages={usages}
37+
pythonPackage={rawPythonPackage}
38+
labels={thresholds}
39+
getValue={usages.getNumberOfUsefulPublicParameters}
40+
title={'Parameters'}
41+
xAxisLabel={'Minimum usefulness'}
42+
/>
3743
);
3844

3945
return (

api-editor/gui/src/features/statistics/ChartWrappers.tsx

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { UsageCountStore } from '../usages/model/UsageCountStore';
22
import { PythonPackage } from '../packageData/model/PythonPackage';
3-
import React, { ReactElement } from 'react';
3+
import React from 'react';
44
import { Bar, Line } from 'react-chartjs-2';
55
import {
66
ArcElement,
@@ -13,10 +13,20 @@ import {
1313
Title,
1414
Tooltip,
1515
} from 'chart.js';
16+
import { useColorModeValue } from '@chakra-ui/react';
1617

1718
ChartJS.register(ArcElement, CategoryScale, PointElement, LineElement, LinearScale, BarElement, Title, Tooltip);
1819

19-
export const createBarChart = function (labels: string[], values: number[], title: string): ReactElement {
20+
interface CustomBarChartProps {
21+
labels: string[];
22+
values: number[];
23+
title: string;
24+
}
25+
26+
export const CustomBarChart: React.FC<CustomBarChartProps> = function ({ labels, values, title }) {
27+
const gridColor = useColorModeValue('#BBB', '#555');
28+
const textColor = useColorModeValue('#000', '#FFF');
29+
2030
const options = {
2131
indexAxis: 'y' as const,
2232
elements: {
@@ -32,6 +42,7 @@ export const createBarChart = function (labels: string[], values: number[], titl
3242
title: {
3343
display: true,
3444
text: title,
45+
color: textColor,
3546
},
3647
tooltip: {
3748
interaction: {
@@ -40,6 +51,24 @@ export const createBarChart = function (labels: string[], values: number[], titl
4051
intersect: false,
4152
},
4253
},
54+
scales: {
55+
x: {
56+
grid: {
57+
color: gridColor,
58+
},
59+
ticks: {
60+
color: textColor,
61+
},
62+
},
63+
y: {
64+
grid: {
65+
color: gridColor,
66+
},
67+
ticks: {
68+
color: textColor,
69+
},
70+
},
71+
},
4372
};
4473

4574
const dataValues = new Map();
@@ -61,14 +90,26 @@ export const createBarChart = function (labels: string[], values: number[], titl
6190
return <Bar options={options} data={data} />;
6291
};
6392

64-
export const createLineChart = function (
65-
usages: UsageCountStore,
66-
pythonPackage: PythonPackage,
67-
labels: number[],
68-
getValue: Function,
69-
title: string,
70-
xAxisLabel: string,
71-
): ReactElement {
93+
interface CustomLineChartProps {
94+
usages: UsageCountStore;
95+
pythonPackage: PythonPackage;
96+
labels: number[];
97+
getValue: Function;
98+
title: string;
99+
xAxisLabel: string;
100+
}
101+
102+
export const CustomLineChart: React.FC<CustomLineChartProps> = function ({
103+
usages,
104+
pythonPackage,
105+
labels,
106+
getValue,
107+
title,
108+
xAxisLabel,
109+
}) {
110+
const gridColor = useColorModeValue('#BBB', '#555');
111+
const textColor = useColorModeValue('#000', '#FFF');
112+
72113
const options = {
73114
responsive: true,
74115
plugins: {
@@ -78,13 +119,29 @@ export const createLineChart = function (
78119
title: {
79120
display: true,
80121
text: title,
122+
color: textColor,
81123
},
82124
},
83125
scales: {
84126
x: {
85127
title: {
86128
display: true,
87129
text: xAxisLabel,
130+
color: textColor,
131+
},
132+
grid: {
133+
color: gridColor,
134+
},
135+
ticks: {
136+
color: textColor,
137+
},
138+
},
139+
y: {
140+
grid: {
141+
color: gridColor,
142+
},
143+
ticks: {
144+
color: textColor,
88145
},
89146
},
90147
},

api-editor/gui/src/features/statistics/ProgressStatistics.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { Box, Heading, HStack } from '@chakra-ui/react';
2+
import { Box, Heading, HStack, useColorModeValue } from '@chakra-ui/react';
33
import { useAppSelector } from '../../app/hooks';
44
import { selectMatchedNodes } from '../packageData/apiSlice';
55
import { selectAllAnnotationsOnTargets, selectAnnotationStore } from '../annotations/annotationSlice';
@@ -10,19 +10,27 @@ import { ArcElement, Chart as ChartJS, Title, Tooltip } from 'chart.js';
1010
ChartJS.register(ArcElement, Title, Tooltip);
1111

1212
export const ProgressStatistics = function () {
13+
const completeOrCorrectBg = useColorModeValue('#38a169', '#68d391');
14+
const completeOrCorrectBorder = useColorModeValue('#2f855a', '#99e6b3');
15+
16+
const uncheckedBg = useColorModeValue('#CCC', '#888');
17+
const uncheckedBorder = useColorModeValue('#AAA', '#AAA');
18+
19+
const textColor = useColorModeValue('#000', '#FFF');
20+
1321
// Completion Progress
1422
const completed = useAppSelector(selectAnnotationStore).completes;
1523
const matchedNodes = useAppSelector(selectMatchedNodes);
1624
const numberOfMatchedNodes = matchedNodes.length;
1725
const numberOfCompleteMatchedNodes = matchedNodes.filter((it) => it.id in completed).length;
1826

1927
const completionData = {
20-
labels: ['Complete', 'Incomplete?'],
28+
labels: ['Complete', 'Unchecked'],
2129
datasets: [
2230
{
2331
data: [numberOfCompleteMatchedNodes, numberOfMatchedNodes - numberOfCompleteMatchedNodes],
24-
backgroundColor: ['rgba(164,255,99,0.2)', 'rgba(162,162,162,0.2)'],
25-
borderColor: ['rgba(92,154,45,0.2)', 'rgba(115,115,115,0.2)'],
32+
backgroundColor: [completeOrCorrectBg, uncheckedBg],
33+
borderColor: [completeOrCorrectBorder, uncheckedBorder],
2634
borderWidth: 1,
2735
},
2836
],
@@ -33,6 +41,7 @@ export const ProgressStatistics = function () {
3341
title: {
3442
display: true,
3543
text: 'Completion Progress',
44+
color: textColor,
3645
},
3746
},
3847
};
@@ -43,12 +52,12 @@ export const ProgressStatistics = function () {
4352
const numberOfReviewedAnnotations = allAnnotations.filter((it) => (it.reviewers?.length ?? 0) > 0).length;
4453

4554
const correctnessData = {
46-
labels: ['Correct', 'Incorrect?'],
55+
labels: ['Correct', 'Unchecked'],
4756
datasets: [
4857
{
4958
data: [numberOfReviewedAnnotations, numberOfAnnotations - numberOfReviewedAnnotations],
50-
backgroundColor: ['rgba(164,255,99,0.2)', 'rgba(162,162,162,0.2)'],
51-
borderColor: ['rgba(92,154,45,0.2)', 'rgba(115,115,115,0.2)'],
59+
backgroundColor: [completeOrCorrectBg, uncheckedBg],
60+
borderColor: [completeOrCorrectBorder, uncheckedBorder],
5261
borderWidth: 1,
5362
},
5463
],
@@ -59,6 +68,7 @@ export const ProgressStatistics = function () {
5968
title: {
6069
display: true,
6170
text: 'Review Progress',
71+
color: textColor,
6272
},
6373
},
6474
};

0 commit comments

Comments
 (0)