2023-02-10 13:10:02 +00:00
|
|
|
import React from "react";
|
|
|
|
|
2023-06-19 07:29:57 +00:00
|
|
|
// ui
|
|
|
|
import { LineGraph } from "components/ui";
|
|
|
|
// helpers
|
2023-06-23 05:39:34 +00:00
|
|
|
import { getDatesInRange, renderShortNumericDateFormat } from "helpers/date-time.helper";
|
2023-02-10 13:10:02 +00:00
|
|
|
//types
|
2023-06-20 11:02:02 +00:00
|
|
|
import { TCompletionChartDistribution } from "types";
|
2023-02-10 13:10:02 +00:00
|
|
|
|
|
|
|
type Props = {
|
2023-06-20 11:02:02 +00:00
|
|
|
distribution: TCompletionChartDistribution;
|
|
|
|
startDate: string | Date;
|
|
|
|
endDate: string | Date;
|
|
|
|
totalIssues: number;
|
2023-02-10 13:10:02 +00:00
|
|
|
};
|
|
|
|
|
2023-06-19 07:29:57 +00:00
|
|
|
const styleById = {
|
|
|
|
ideal: {
|
|
|
|
strokeDasharray: "6, 3",
|
|
|
|
strokeWidth: 1,
|
|
|
|
},
|
|
|
|
default: {
|
|
|
|
strokeWidth: 1,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const DashedLine = ({ series, lineGenerator, xScale, yScale }: any) =>
|
|
|
|
series.map(({ id, data, color }: any) => (
|
|
|
|
<path
|
|
|
|
key={id}
|
|
|
|
d={lineGenerator(
|
|
|
|
data.map((d: any) => ({
|
|
|
|
x: xScale(d.data.x),
|
|
|
|
y: yScale(d.data.y),
|
|
|
|
}))
|
|
|
|
)}
|
|
|
|
fill="none"
|
|
|
|
stroke={color ?? "#ddd"}
|
|
|
|
style={styleById[id as keyof typeof styleById] || styleById.default}
|
|
|
|
/>
|
|
|
|
));
|
|
|
|
|
2023-06-20 11:02:02 +00:00
|
|
|
const ProgressChart: React.FC<Props> = ({ distribution, startDate, endDate, totalIssues }) => {
|
|
|
|
const chartData = Object.keys(distribution).map((key) => ({
|
|
|
|
currentDate: renderShortNumericDateFormat(key),
|
|
|
|
pending: distribution[key],
|
|
|
|
}));
|
2023-06-19 07:29:57 +00:00
|
|
|
|
2023-06-23 05:39:34 +00:00
|
|
|
const generateXAxisTickValues = () => {
|
|
|
|
const dates = getDatesInRange(startDate, endDate);
|
|
|
|
|
|
|
|
const maxDates = 4;
|
|
|
|
const totalDates = dates.length;
|
|
|
|
|
2023-06-27 12:38:37 +00:00
|
|
|
if (totalDates <= maxDates) return dates.map((d) => renderShortNumericDateFormat(d));
|
2023-06-23 05:39:34 +00:00
|
|
|
else {
|
|
|
|
const interval = Math.ceil(totalDates / maxDates);
|
|
|
|
const limitedDates = [];
|
|
|
|
|
2023-11-08 15:01:46 +00:00
|
|
|
for (let i = 0; i < totalDates; i += interval) limitedDates.push(renderShortNumericDateFormat(dates[i]));
|
2023-06-23 05:39:34 +00:00
|
|
|
|
|
|
|
if (!limitedDates.includes(renderShortNumericDateFormat(dates[totalDates - 1])))
|
|
|
|
limitedDates.push(renderShortNumericDateFormat(dates[totalDates - 1]));
|
|
|
|
|
|
|
|
return limitedDates;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-10 13:10:02 +00:00
|
|
|
return (
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="flex w-full items-center justify-center">
|
2023-06-19 07:29:57 +00:00
|
|
|
<LineGraph
|
|
|
|
animate
|
|
|
|
curve="monotoneX"
|
|
|
|
height="160px"
|
2023-06-20 11:02:02 +00:00
|
|
|
width="100%"
|
2023-06-19 07:29:57 +00:00
|
|
|
enableGridY={false}
|
|
|
|
lineWidth={1}
|
|
|
|
margin={{ top: 30, right: 30, bottom: 30, left: 30 }}
|
|
|
|
data={[
|
|
|
|
{
|
|
|
|
id: "pending",
|
|
|
|
color: "#3F76FF",
|
|
|
|
data: chartData.map((item, index) => ({
|
|
|
|
index,
|
|
|
|
x: item.currentDate,
|
|
|
|
y: item.pending,
|
|
|
|
color: "#3F76FF",
|
|
|
|
})),
|
|
|
|
enableArea: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "ideal",
|
|
|
|
color: "#a9bbd0",
|
|
|
|
fill: "transparent",
|
2023-06-23 19:05:00 +00:00
|
|
|
data:
|
|
|
|
chartData.length > 0
|
|
|
|
? [
|
|
|
|
{
|
|
|
|
x: chartData[0].currentDate,
|
|
|
|
y: totalIssues,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
x: chartData[chartData.length - 1].currentDate,
|
|
|
|
y: 0,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
: [],
|
2023-06-19 07:29:57 +00:00
|
|
|
},
|
|
|
|
]}
|
|
|
|
layers={["grid", "markers", "areas", DashedLine, "slices", "points", "axes", "legends"]}
|
|
|
|
axisBottom={{
|
2023-06-23 05:39:34 +00:00
|
|
|
tickValues: generateXAxisTickValues(),
|
2023-06-19 07:29:57 +00:00
|
|
|
}}
|
|
|
|
enablePoints={false}
|
|
|
|
enableArea
|
|
|
|
colors={(datum) => datum.color ?? "#3F76FF"}
|
2023-06-20 11:02:02 +00:00
|
|
|
customYAxisTickValues={[0, totalIssues]}
|
2023-06-19 07:29:57 +00:00
|
|
|
gridXValues={chartData.map((item, index) => (index % 2 === 0 ? item.currentDate : ""))}
|
2023-06-26 08:56:38 +00:00
|
|
|
enableSlices="x"
|
|
|
|
sliceTooltip={(datum) => (
|
2023-07-17 10:58:23 +00:00
|
|
|
<div className="rounded-md border border-custom-border-200 bg-custom-background-80 p-2 text-xs">
|
2023-06-26 08:56:38 +00:00
|
|
|
{datum.slice.points[0].data.yFormatted}
|
2023-07-10 07:17:00 +00:00
|
|
|
<span className="text-custom-text-200"> issues pending on </span>
|
2023-06-26 08:56:38 +00:00
|
|
|
{datum.slice.points[0].data.xFormatted}
|
|
|
|
</div>
|
|
|
|
)}
|
2023-06-19 07:29:57 +00:00
|
|
|
theme={{
|
2023-06-20 11:02:02 +00:00
|
|
|
background: "transparent",
|
2023-06-19 07:29:57 +00:00
|
|
|
axis: {
|
|
|
|
domain: {
|
|
|
|
line: {
|
|
|
|
stroke: "rgb(var(--color-border))",
|
|
|
|
strokeWidth: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-03-07 08:13:09 +00:00
|
|
|
}}
|
2023-06-19 07:29:57 +00:00
|
|
|
/>
|
2023-02-10 13:10:02 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ProgressChart;
|