2023-06-19 07:29:57 +00:00
|
|
|
// ui
|
|
|
|
import { PieGraph } from "components/ui";
|
|
|
|
// helpers
|
|
|
|
import { capitalizeFirstLetter } from "helpers/string.helper";
|
2023-03-15 20:06:21 +00:00
|
|
|
// types
|
2023-03-23 10:24:59 +00:00
|
|
|
import { IUserStateDistribution } from "types";
|
2023-03-15 20:06:21 +00:00
|
|
|
// constants
|
|
|
|
import { STATE_GROUP_COLORS } from "constants/state";
|
|
|
|
|
|
|
|
type Props = {
|
2023-03-23 10:24:59 +00:00
|
|
|
groupedIssues: IUserStateDistribution[] | undefined;
|
2023-03-15 20:06:21 +00:00
|
|
|
};
|
|
|
|
|
2023-06-19 07:29:57 +00:00
|
|
|
export const IssuesPieChart: React.FC<Props> = ({ groupedIssues }) => (
|
|
|
|
<div>
|
|
|
|
<h3 className="mb-2 font-semibold">Issues by States</h3>
|
2023-07-17 10:58:23 +00:00
|
|
|
<div className="rounded-[10px] border border-custom-border-200 bg-custom-background-100 p-4">
|
2023-07-17 09:18:43 +00:00
|
|
|
<div className="grid grid-cols-1 sm:grid-cols-4">
|
|
|
|
<div className="sm:col-span-3">
|
|
|
|
<PieGraph
|
|
|
|
data={
|
2023-06-19 07:29:57 +00:00
|
|
|
groupedIssues?.map((cell) => ({
|
|
|
|
id: cell.state_group,
|
2023-07-17 09:18:43 +00:00
|
|
|
label: cell.state_group,
|
2023-06-19 07:29:57 +00:00
|
|
|
value: cell.state_count,
|
|
|
|
color: STATE_GROUP_COLORS[cell.state_group.toLowerCase()],
|
2023-07-17 09:18:43 +00:00
|
|
|
})) ?? []
|
|
|
|
}
|
|
|
|
height="320px"
|
|
|
|
innerRadius={0.6}
|
|
|
|
cornerRadius={5}
|
|
|
|
padAngle={2}
|
|
|
|
enableArcLabels
|
|
|
|
arcLabelsTextColor="#000000"
|
|
|
|
enableArcLinkLabels={false}
|
|
|
|
activeInnerRadiusOffset={5}
|
|
|
|
colors={(datum) => datum.data.color}
|
|
|
|
tooltip={(datum) => (
|
2023-07-17 10:58:23 +00:00
|
|
|
<div className="flex items-center gap-2 rounded-md border border-custom-border-200 bg-custom-background-80 p-2 text-xs">
|
2023-07-17 09:18:43 +00:00
|
|
|
<span className="text-custom-text-200 capitalize">{datum.datum.label} issues:</span>{" "}
|
|
|
|
{datum.datum.value}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
margin={{
|
|
|
|
top: 32,
|
|
|
|
right: 0,
|
|
|
|
bottom: 32,
|
|
|
|
left: 0,
|
|
|
|
}}
|
|
|
|
theme={{
|
|
|
|
background: "transparent",
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="flex sm:block items-center gap-3 flex-wrap justify-center sm:space-y-2 sm:self-end sm:justify-self-end sm:px-8 sm:pb-8">
|
|
|
|
{groupedIssues?.map((cell) => (
|
|
|
|
<div key={cell.state_group} className="flex items-center gap-2">
|
|
|
|
<div
|
|
|
|
className="h-2 w-2"
|
|
|
|
style={{ backgroundColor: STATE_GROUP_COLORS[cell.state_group] }}
|
|
|
|
/>
|
|
|
|
<div className="capitalize text-custom-text-200 text-xs">
|
|
|
|
{cell.state_group}- {cell.state_count}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-03-15 20:06:21 +00:00
|
|
|
</div>
|
2023-06-19 07:29:57 +00:00
|
|
|
</div>
|
|
|
|
);
|