Skip to content

Commit 548376c

Browse files
committed
Bar Chart changes according to teams workrate
1 parent 395d852 commit 548376c

File tree

1 file changed

+66
-60
lines changed

1 file changed

+66
-60
lines changed

src/Chart/BarChart.tsx

Lines changed: 66 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import {
99
Tooltip,
1010
Legend,
1111
} from 'chart.js';
12+
import { useQuery } from '@apollo/client';
13+
import { GET_ALL_TEAMS } from '../queries/team.queries';
14+
import { FETCH_ALL_RATINGS } from '../queries/ratings.queries';
1215

1316
ChartJS.register(
1417
CategoryScale,
@@ -23,77 +26,80 @@ interface Props {}
2326

2427
// eslint-disable-next-line react/function-component-definition
2528
const BarChart: React.FC<Props> = () => {
26-
const data = {
27-
labels: [
28-
'01',
29-
'02',
30-
'03',
31-
'04',
32-
'05',
33-
'06',
34-
'07',
35-
'08',
36-
'09',
37-
'10',
38-
'11',
39-
'12',
40-
],
29+
const orgToken = localStorage.getItem('orgToken');
30+
const { data, loading, error } = useQuery(GET_ALL_TEAMS, {
31+
variables: {
32+
orgToken,
33+
},
34+
fetchPolicy: 'network-only',
35+
});
36+
37+
const {
38+
data: ratingsData,
39+
loading: ratingsLoading,
40+
error: ratingsError,
41+
} = useQuery(FETCH_ALL_RATINGS, {
42+
variables: {
43+
orgToken,
44+
},
45+
fetchPolicy: 'network-only',
46+
});
47+
48+
if (loading) return <p>Loading...</p>;
49+
if (error) return <p>Error: {error.message}</p>;
50+
51+
if (ratingsLoading) return <p>Loading ratings...</p>;
52+
if (ratingsError) return <p>Error loading ratings: {ratingsError.message}</p>;
53+
54+
const teamNames = data?.getAllTeams?.map(
55+
(team: { name: string }) => team.name,
56+
);
57+
const ratingsArray = ratingsData?.fetchAllRatings || [];
58+
59+
const professionalismData = ratingsArray.map(
60+
(rating: { professional_Skills: string }) =>
61+
parseFloat(rating.professional_Skills),
62+
);
63+
const qualityData = ratingsArray.map((rating: { quality: string }) =>
64+
parseFloat(rating.quality),
65+
);
66+
const quantityData = ratingsArray.map((rating: { quantity: string }) =>
67+
parseFloat(rating.quantity),
68+
);
69+
if (!teamNames || teamNames.length === 0) {
70+
return <p>No team data available.</p>;
71+
}
72+
73+
const datas = {
74+
labels: teamNames,
4175
datasets: [
4276
{
43-
label: 'Nova',
44-
data: [12, 19, 3, 5, 2, 3, 12, 14, 5, 7, 9, 11],
77+
label: 'Professionalism',
78+
data: professionalismData,
4579
backgroundColor: '#5A6ACF',
46-
borderRadius: 0,
47-
barThickness: 8,
80+
borderRadius: 20,
81+
barThickness: 14,
4882
},
4983
{
50-
label: 'Fighters',
51-
data: [10, 15, 5, 8, 6, 9, 13, 9, 6, 8, 7, 10],
52-
backgroundColor: '#D1D5DB',
53-
borderRadius: 0,
54-
barThickness: 8,
55-
},
56-
],
57-
};
58-
59-
const options = {
60-
responsive: true,
61-
maintainAspectRatio: false,
62-
plugins: {
63-
legend: {
64-
position: 'bottom' as const,
65-
labels: {
66-
color: '#D1D5DB',
67-
},
68-
},
69-
tooltip: {
70-
enabled: true,
84+
label: 'Quality',
85+
data: qualityData,
86+
backgroundColor: '#fcffa4',
87+
borderRadius: 20,
88+
barThickness: 14,
7189
},
72-
},
73-
scales: {
74-
x: {
75-
grid: {
76-
display: false,
77-
},
78-
ticks: {
79-
color: '#737B8B',
80-
},
81-
},
82-
y: {
83-
grid: {
84-
borderDash: [5, 5],
85-
color: '#ffffff',
86-
},
87-
ticks: {
88-
color: '#ffffff',
89-
},
90+
{
91+
label: 'Quantity',
92+
data: quantityData,
93+
backgroundColor: '#9f5233',
94+
borderRadius: 20,
95+
barThickness: 14,
9096
},
91-
},
97+
],
9298
};
9399

94100
return (
95101
<div className="w-full h-[300px]">
96-
<Bar data={data} options={options} className="-ml-8" />
102+
<Bar data={datas} options={{ responsive: true }} className="-ml-2" />
97103
</div>
98104
);
99105
};

0 commit comments

Comments
 (0)