forked from rael346/nucarpool
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
459 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import React from "react"; | ||
import { Bar } from "react-chartjs-2"; | ||
import { | ||
Chart as ChartJS, | ||
CategoryScale, | ||
LinearScale, | ||
BarElement, | ||
Title, | ||
Tooltip, | ||
Legend, | ||
ChartData, | ||
ChartOptions, | ||
} from "chart.js"; | ||
|
||
ChartJS.register( | ||
CategoryScale, | ||
LinearScale, | ||
BarElement, | ||
Title, | ||
Tooltip, | ||
Legend | ||
); | ||
|
||
import { TempUser } from "../../utils/types"; | ||
|
||
interface BarChartOnboardingProps { | ||
users: TempUser[]; | ||
} | ||
|
||
function BarChartUserCounts({ users }: BarChartOnboardingProps) { | ||
const activeUsers = users.filter((user) => user.status === "ACTIVE"); | ||
|
||
const drivers = activeUsers.filter((user) => user.role === "DRIVER"); | ||
|
||
const riders = activeUsers.filter((user) => user.role === "RIDER"); | ||
const riderDayCount = [0, 0, 0, 0, 0, 0, 0]; | ||
const driverDayCount = [0, 0, 0, 0, 0, 0, 0]; | ||
|
||
riders.forEach((rider) => { | ||
rider.daysWorking.split(",").forEach((day, index) => { | ||
if (day === "1") { | ||
riderDayCount[index] += 1; | ||
} | ||
}); | ||
}); | ||
drivers.forEach((driver) => { | ||
driver.daysWorking.split(",").forEach((day, index) => { | ||
if (day === "1") { | ||
driverDayCount[index] += 1; | ||
} | ||
}); | ||
}); | ||
|
||
const labels = ["Su", "M", "Tu", "W", "Th", "F", "S"]; | ||
|
||
const barData: ChartData<"bar"> = { | ||
labels, | ||
|
||
datasets: [ | ||
{ | ||
label: "Riders", | ||
data: riderDayCount, | ||
backgroundColor: "#DA7D25", | ||
}, | ||
{ | ||
label: "Drivers", | ||
data: driverDayCount, | ||
backgroundColor: "#C8102E", | ||
}, | ||
], | ||
}; | ||
|
||
const barOptions: ChartOptions<"bar"> = { | ||
responsive: true, | ||
maintainAspectRatio: false, | ||
plugins: { | ||
legend: { | ||
display: true, | ||
}, | ||
title: { | ||
display: true, | ||
text: "Days Carpooling Frequency", | ||
font: { | ||
family: "Montserrat", | ||
size: 18, | ||
style: "normal", | ||
weight: "bold", | ||
}, | ||
color: "#000000", | ||
}, | ||
}, | ||
scales: { | ||
x: { | ||
stacked: true, | ||
ticks: { | ||
font: { | ||
family: "Montserrat", | ||
size: 16, | ||
style: "normal", | ||
weight: "bold", | ||
}, | ||
}, | ||
}, | ||
y: { | ||
stacked: true, | ||
beginAtZero: true, | ||
title: { | ||
display: true, | ||
text: "Number of Users", | ||
font: { | ||
family: "Montserrat", | ||
size: 16, | ||
style: "normal", | ||
weight: "bold", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
return ( | ||
<div className="relative w-full "> | ||
<div className=" flex h-[500px] flex-col"> | ||
<Bar data={barData} options={barOptions} /> | ||
<span className="w-full text-center font-lato text-sm text-gray-400"> | ||
All bars currently only include active users aside from | ||
"Inactive" | ||
</span> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default BarChartUserCounts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
interface DisplayBoxProps { | ||
data: { | ||
data: number | string; | ||
label: string; | ||
}[]; | ||
title: string; | ||
} | ||
const DisplayBox = ({ data, title }: DisplayBoxProps) => { | ||
return ( | ||
<div className="flex flex-col justify-center space-y-2 rounded-lg border border-black p-6 font-montserrat drop-shadow-2xl "> | ||
<div className="text-center text-2xl font-bold">{title}</div> | ||
<div className="grid grid-flow-col items-center gap-1 divide-x text-center"> | ||
{data.map((data, index) => { | ||
return ( | ||
<div | ||
key={index} | ||
className="flex h-full w-full flex-col p-2 text-base" | ||
> | ||
<strong>{data.label}: </strong> | ||
{data.data} | ||
</div> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default DisplayBox; |
Oops, something went wrong.