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>
|
|
|
|
<div className="rounded-[10px] border border-brand-base bg-brand-base p-4">
|
|
|
|
<PieGraph
|
|
|
|
data={
|
|
|
|
groupedIssues?.map((cell) => ({
|
|
|
|
id: cell.state_group,
|
|
|
|
label: cell.state_group,
|
|
|
|
value: cell.state_count,
|
|
|
|
color: STATE_GROUP_COLORS[cell.state_group.toLowerCase()],
|
|
|
|
})) ?? []
|
|
|
|
}
|
|
|
|
height="320px"
|
2023-06-28 13:38:33 +00:00
|
|
|
innerRadius={0.6}
|
|
|
|
cornerRadius={5}
|
|
|
|
padAngle={2}
|
|
|
|
enableArcLabels
|
|
|
|
arcLabelsTextColor="#000000"
|
|
|
|
enableArcLinkLabels={false}
|
2023-06-19 07:29:57 +00:00
|
|
|
legends={[
|
|
|
|
{
|
|
|
|
anchor: "right",
|
|
|
|
direction: "column",
|
|
|
|
justify: false,
|
|
|
|
translateX: 0,
|
|
|
|
translateY: 56,
|
|
|
|
itemsSpacing: 10,
|
|
|
|
itemWidth: 100,
|
|
|
|
itemHeight: 18,
|
|
|
|
itemTextColor: "rgb(var(--color-text-secondary))",
|
|
|
|
itemDirection: "left-to-right",
|
|
|
|
itemOpacity: 1,
|
|
|
|
symbolSize: 12,
|
|
|
|
symbolShape: "square",
|
|
|
|
data:
|
|
|
|
groupedIssues?.map((cell) => ({
|
|
|
|
id: cell.state_group,
|
|
|
|
label: capitalizeFirstLetter(cell.state_group),
|
|
|
|
value: cell.state_count,
|
|
|
|
color: STATE_GROUP_COLORS[cell.state_group.toLowerCase()],
|
|
|
|
})) ?? [],
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
activeInnerRadiusOffset={5}
|
|
|
|
colors={(datum) => datum.data.color}
|
2023-06-28 13:38:33 +00:00
|
|
|
tooltip={(datum) => (
|
|
|
|
<div className="flex items-center gap-2 rounded-md border border-brand-base bg-brand-surface-2 p-2 text-xs">
|
|
|
|
<span className="text-brand-secondary capitalize">{datum.datum.label} issues:</span>{" "}
|
|
|
|
{datum.datum.value}
|
|
|
|
</div>
|
|
|
|
)}
|
2023-06-19 07:29:57 +00:00
|
|
|
theme={{
|
2023-06-28 13:38:33 +00:00
|
|
|
background: "transparent",
|
2023-06-19 07:29:57 +00:00
|
|
|
}}
|
|
|
|
/>
|
2023-03-15 20:06:21 +00:00
|
|
|
</div>
|
2023-06-19 07:29:57 +00:00
|
|
|
</div>
|
|
|
|
);
|