-
-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathJobAnalyticsGraph.jsx
More file actions
130 lines (121 loc) · 2.92 KB
/
JobAnalyticsGraph.jsx
File metadata and controls
130 lines (121 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import React, { useMemo } from "react";
import PropTypes from "prop-types";
import { Bar } from "react-chartjs-2";
import {
Chart as ChartJS,
CategoryScale,
LinearScale,
BarElement,
Title,
Tooltip,
Legend,
} from "chart.js";
import ChartDataLabels from "chartjs-plugin-datalabels";
import styles from "./JobAnalyticsPage.module.css";
ChartJS.register(
CategoryScale,
LinearScale,
BarElement,
Title,
Tooltip,
Legend,
ChartDataLabels
);
export default function JobAnalyticsGraph({ data, darkMode }) {
const normalizedData = useMemo(() => {
if (!Array.isArray(data)) return [];
return data
.map((d) => ({
role: d.role,
applications:
typeof d.applications === "number"
? d.applications
: typeof d.count === "number"
? d.count
: 0,
}))
.filter((d) => d.role && d.applications > 0);
}, [data]);
if (normalizedData.length === 0) {
return <p>No data available</p>;
}
const chartData = {
labels: normalizedData.map((d) => d.role),
datasets: [
{
label: "Applications",
data: normalizedData.map((d) => d.applications),
backgroundColor: darkMode
? "#3A506B"
: "rgba(54, 162, 235, 0.7)",
},
],
};
const chartOptions = {
indexAxis: "y",
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: { display: false },
title: {
display: true,
text: "Most Competitive Roles",
color: darkMode ? "#E0E0E0" : "#111111",
font: { size: 18, weight: "bold" },
},
datalabels: {
color: darkMode ? "#E0E0E0" : "#111111",
anchor: "end",
align: "left",
offset: -5,
formatter: (value) => value.toLocaleString(),
font: { weight: "bold" },
},
},
scales: {
x: {
title: {
display: true,
text: "Number of Applications",
color: darkMode ? "#E0E0E0" : "#111111",
font: { weight: "bold", size: 14 },
},
ticks: {
color: darkMode ? "#E0E0E0" : "#111111",
},
grid: { color: darkMode ? "#333" : "#ddd" },
},
y: {
title: {
display: true,
text: "Role",
color: darkMode ? "#E0E0E0" : "#111111",
font: { weight: "bold", size: 14 },
},
ticks: {
color: darkMode ? "#E0E0E0" : "#111111",
},
grid: { color: darkMode ? "#333" : "#ddd" },
},
},
};
return (
<div className={styles.graphContainer}>
<Bar data={chartData} options={chartOptions} />
</div>
);
}
JobAnalyticsGraph.propTypes = {
data: PropTypes.arrayOf(
PropTypes.shape({
role: PropTypes.string,
applications: PropTypes.number,
count: PropTypes.number,
})
),
darkMode: PropTypes.bool,
};
JobAnalyticsGraph.defaultProps = {
data: [],
darkMode: false,
};