Skip to content

Commit

Permalink
fix: set percentage max 100
Browse files Browse the repository at this point in the history
  • Loading branch information
yougyung committed Sep 6, 2024
1 parent 351c0a8 commit a606dca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
12 changes: 5 additions & 7 deletions app/ui/view/molecule/pie-chart/pie-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@ export interface PieChartProp {
}

function PieChart({ percentage }: PieChartProp) {
const filterdPercentage = percentage > 100 ? 100 : percentage;

const isDesktop = useMediaQuery('(min-width: 767px)');

return (
<div
className={cn(
'relative aspect-square rounded-full w-[6.5rem] h-[6.5rem]',
filterdPercentage > 0 && 'piechart',
filterdPercentage === 100 ? 'bg-light-blue-1 complete' : 'bg-etc-pink',
percentage > 0 && 'piechart',
percentage === 100 ? 'bg-light-blue-1 complete' : 'bg-etc-pink',
'md:w-[9rem] md:h-[9rem]',
)}
style={{
'--percentage': filterdPercentage,
'--percentage': percentage,
'--startRadius': isDesktop ? '1.5rem' : '1.1rem',
'--endRadius': isDesktop ? '0.74rem' : '0.50rem',
'--pieSize': isDesktop ? '9rem' : '6.5rem',
Expand All @@ -30,11 +28,11 @@ function PieChart({ percentage }: PieChartProp) {
<div
className={cn(
'absolute rounded-full bg-white text-base font-bold w-[4.5rem] h-[4.5rem] top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 flex justify-center items-center',
filterdPercentage === 100 ? 'text-light-blue-6' : 'text-etc-red',
percentage === 100 ? 'text-light-blue-6' : 'text-etc-red',
'md:w-[6rem] md:h-[6rem] md:text-xl ',
)}
>
{filterdPercentage}%
{percentage}%
</div>
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion app/utils/chart.util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const getPercentage = (numerator: number, denominator: number) => {
return Number(((numerator / denominator) * 100).toFixed(0));
const percentage = Number(((numerator / denominator) * 100).toFixed(0));
return percentage > 100 ? 100 : percentage;
};

0 comments on commit a606dca

Please sign in to comment.