Skip to content

Commit

Permalink
[WEB-1235] chore: module and cycle sidebar graph improvement (#4650)
Browse files Browse the repository at this point in the history
* chore: module and cycle sidebar graph improvement

* chore: code refactor
  • Loading branch information
anmolsinghbhatia authored May 31, 2024
1 parent 9143e5a commit fc4ba5a
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions web/components/core/sidebar/progress-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,18 @@ const ProgressChart: React.FC<Props> = ({ distribution, startDate, endDate, tota
dates = eachDayOfInterval({ start, end });
}

const maxDates = 4;
const totalDates = dates.length;
if (dates.length === 0) return [];

if (totalDates <= maxDates) return dates.map((d) => renderFormattedDateWithoutYear(d));
else {
const interval = Math.ceil(totalDates / maxDates);
const limitedDates = [];
const formattedDates = dates.map((d) => renderFormattedDateWithoutYear(d));
const firstDate = formattedDates[0];
const lastDate = formattedDates[formattedDates.length - 1];

for (let i = 0; i < totalDates; i += interval) limitedDates.push(renderFormattedDateWithoutYear(dates[i]));
if (formattedDates.length <= 2) return [firstDate, lastDate];

if (!limitedDates.includes(renderFormattedDateWithoutYear(dates[totalDates - 1])))
limitedDates.push(renderFormattedDateWithoutYear(dates[totalDates - 1]));
const middleDateIndex = Math.floor(formattedDates.length / 2);
const middleDate = formattedDates[middleDateIndex];

return limitedDates;
}
return [firstDate, middleDate, lastDate];
};

return (
Expand Down

0 comments on commit fc4ba5a

Please sign in to comment.