Spaces:
Sleeping
Sleeping
Commit
·
3c0668b
1
Parent(s):
b9be5eb
resolved dashboard error
Browse files- backend/main.py +6 -6
- frontend/src/components/Dashboard.tsx +21 -21
backend/main.py
CHANGED
@@ -589,12 +589,12 @@ def get_stats(request: Request):
|
|
589 |
country_counts = country["count"].to_list()
|
590 |
|
591 |
return {
|
592 |
-
"
|
593 |
-
"
|
594 |
-
"
|
595 |
-
"
|
596 |
-
"
|
597 |
-
"
|
598 |
}
|
599 |
|
600 |
@app.get("/api/project/{project_id}/organizations")
|
|
|
589 |
country_counts = country["count"].to_list()
|
590 |
|
591 |
return {
|
592 |
+
"ppy": {"labels": years, "values": year_counts},
|
593 |
+
"psd": {"labels": size_labels, "values": size_counts},
|
594 |
+
"frs": {"labels": scheme_labels, "values": scheme_values},
|
595 |
+
"top10": {"labels": topic_labels, "values": topic_values},
|
596 |
+
"frb": {"labels": fr_labels, "values": fr_counts},
|
597 |
+
"ppc": {"labels": country_labels, "values": country_counts},
|
598 |
}
|
599 |
|
600 |
@app.get("/api/project/{project_id}/organizations")
|
frontend/src/components/Dashboard.tsx
CHANGED
@@ -50,13 +50,13 @@ interface ChartDataShape { labels: string[]; values: number[]; }
|
|
50 |
interface Stats { [key: string]: ChartDataShape; }
|
51 |
|
52 |
// define the six charts and their component types
|
53 |
-
const chartOrder: { key: string; type: ChartType }[] = [
|
54 |
-
{ key: "Projects per Year", type: "line" },
|
55 |
-
{ key: "Project-Size Distribution", type: "bar" },
|
56 |
-
{ key: "Co-funding Ratio by Scheme", type: "bar" },
|
57 |
-
{ key: "Top 10 Topics (€ M)", type: "bar" },
|
58 |
-
{ key: "Funding Range Breakdown", type: "pie" },
|
59 |
-
{ key: "Projects per Country", type: "doughnut" },
|
60 |
];
|
61 |
|
62 |
const FILTER_LABELS: Record<keyof FilterState, string> = {
|
@@ -215,16 +215,16 @@ const Dashboard: React.FC<DashboardProps> = ({
|
|
215 |
</Flex>
|
216 |
)}
|
217 |
<SimpleGrid columns={{ base:1, md:2, lg:3 }} spacing={6}>
|
218 |
-
{chartOrder.map(({
|
219 |
const raw = statsData[key]!;
|
220 |
-
|
221 |
// ---- properly typed Chart.js data & options ----
|
222 |
if (type === "bar") {
|
223 |
const data: ChartData<"bar", number[], string> = {
|
224 |
labels: raw.labels,
|
225 |
datasets: [
|
226 |
{
|
227 |
-
label:
|
228 |
data: raw.values,
|
229 |
backgroundColor: "#003399",
|
230 |
borderColor: "#FFCC00",
|
@@ -240,12 +240,12 @@ const Dashboard: React.FC<DashboardProps> = ({
|
|
240 |
},
|
241 |
title: {
|
242 |
display: true,
|
243 |
-
text:
|
244 |
},
|
245 |
},
|
246 |
};
|
247 |
return (
|
248 |
-
<Box key={
|
249 |
<Bar data={data} options={options} />
|
250 |
</Box>
|
251 |
);
|
@@ -255,7 +255,7 @@ const Dashboard: React.FC<DashboardProps> = ({
|
|
255 |
labels: raw.labels,
|
256 |
datasets: [
|
257 |
{
|
258 |
-
label:
|
259 |
data: raw.values,
|
260 |
backgroundColor: "#003399",
|
261 |
borderColor: "#FFCC00",
|
@@ -271,12 +271,12 @@ const Dashboard: React.FC<DashboardProps> = ({
|
|
271 |
},
|
272 |
title: {
|
273 |
display: true,
|
274 |
-
text:
|
275 |
},
|
276 |
},
|
277 |
};
|
278 |
return (
|
279 |
-
<Box key={
|
280 |
<Line data={data} options={options} />
|
281 |
</Box>
|
282 |
);
|
@@ -286,7 +286,7 @@ const Dashboard: React.FC<DashboardProps> = ({
|
|
286 |
labels: raw.labels,
|
287 |
datasets: [
|
288 |
{
|
289 |
-
label:
|
290 |
data: raw.values,
|
291 |
backgroundColor: "#003399",
|
292 |
borderColor: "#FFCC00",
|
@@ -302,12 +302,12 @@ const Dashboard: React.FC<DashboardProps> = ({
|
|
302 |
},
|
303 |
title: {
|
304 |
display: true,
|
305 |
-
text:
|
306 |
},
|
307 |
},
|
308 |
};
|
309 |
return (
|
310 |
-
<Box key={
|
311 |
<Pie data={data} options={options} />
|
312 |
</Box>
|
313 |
);
|
@@ -317,7 +317,7 @@ const Dashboard: React.FC<DashboardProps> = ({
|
|
317 |
labels: raw.labels,
|
318 |
datasets: [
|
319 |
{
|
320 |
-
label:
|
321 |
data: raw.values,
|
322 |
backgroundColor: "#003399",
|
323 |
borderColor: "#FFCC00",
|
@@ -333,12 +333,12 @@ const Dashboard: React.FC<DashboardProps> = ({
|
|
333 |
},
|
334 |
title: {
|
335 |
display: true,
|
336 |
-
text:
|
337 |
},
|
338 |
},
|
339 |
};
|
340 |
return (
|
341 |
-
<Box key={
|
342 |
<Doughnut data={data} options={options} />
|
343 |
</Box>
|
344 |
);
|
|
|
50 |
interface Stats { [key: string]: ChartDataShape; }
|
51 |
|
52 |
// define the six charts and their component types
|
53 |
+
const chartOrder: { key:string; name: string; type: ChartType }[] = [
|
54 |
+
{ key: "ppy", name: "Projects per Year", type: "line" },
|
55 |
+
{ key: "psd",name: "Project-Size Distribution", type: "bar" },
|
56 |
+
{ key: "frs",name: "Co-funding Ratio by Scheme", type: "bar" },
|
57 |
+
{ key: "top10",name: "Top 10 Topics (€ M)", type: "bar" },
|
58 |
+
{ key: "frb",name: "Funding Range Breakdown", type: "pie" },
|
59 |
+
{ key: "ppc",name: "Projects per Country", type: "doughnut" },
|
60 |
];
|
61 |
|
62 |
const FILTER_LABELS: Record<keyof FilterState, string> = {
|
|
|
215 |
</Flex>
|
216 |
)}
|
217 |
<SimpleGrid columns={{ base:1, md:2, lg:3 }} spacing={6}>
|
218 |
+
{chartOrder.map(({key,name, type }) => {
|
219 |
const raw = statsData[key]!;
|
220 |
+
if (!raw) return null;
|
221 |
// ---- properly typed Chart.js data & options ----
|
222 |
if (type === "bar") {
|
223 |
const data: ChartData<"bar", number[], string> = {
|
224 |
labels: raw.labels,
|
225 |
datasets: [
|
226 |
{
|
227 |
+
label: name,
|
228 |
data: raw.values,
|
229 |
backgroundColor: "#003399",
|
230 |
borderColor: "#FFCC00",
|
|
|
240 |
},
|
241 |
title: {
|
242 |
display: true,
|
243 |
+
text: name,
|
244 |
},
|
245 |
},
|
246 |
};
|
247 |
return (
|
248 |
+
<Box key={name} bg="white" borderRadius="md" p={4}>
|
249 |
<Bar data={data} options={options} />
|
250 |
</Box>
|
251 |
);
|
|
|
255 |
labels: raw.labels,
|
256 |
datasets: [
|
257 |
{
|
258 |
+
label: name,
|
259 |
data: raw.values,
|
260 |
backgroundColor: "#003399",
|
261 |
borderColor: "#FFCC00",
|
|
|
271 |
},
|
272 |
title: {
|
273 |
display: true,
|
274 |
+
text: name,
|
275 |
},
|
276 |
},
|
277 |
};
|
278 |
return (
|
279 |
+
<Box key={name} bg="white" borderRadius="md" p={4}>
|
280 |
<Line data={data} options={options} />
|
281 |
</Box>
|
282 |
);
|
|
|
286 |
labels: raw.labels,
|
287 |
datasets: [
|
288 |
{
|
289 |
+
label: name,
|
290 |
data: raw.values,
|
291 |
backgroundColor: "#003399",
|
292 |
borderColor: "#FFCC00",
|
|
|
302 |
},
|
303 |
title: {
|
304 |
display: true,
|
305 |
+
text: name,
|
306 |
},
|
307 |
},
|
308 |
};
|
309 |
return (
|
310 |
+
<Box key={name} bg="white" borderRadius="md" p={4}>
|
311 |
<Pie data={data} options={options} />
|
312 |
</Box>
|
313 |
);
|
|
|
317 |
labels: raw.labels,
|
318 |
datasets: [
|
319 |
{
|
320 |
+
label: name,
|
321 |
data: raw.values,
|
322 |
backgroundColor: "#003399",
|
323 |
borderColor: "#FFCC00",
|
|
|
333 |
},
|
334 |
title: {
|
335 |
display: true,
|
336 |
+
text: name,
|
337 |
},
|
338 |
},
|
339 |
};
|
340 |
return (
|
341 |
+
<Box key={name} bg="white" borderRadius="md" p={4}>
|
342 |
<Doughnut data={data} options={options} />
|
343 |
</Box>
|
344 |
);
|