diff --git a/apps/palette/web/src/components/projects/ColorBreakdown.tsx b/apps/palette/web/src/components/projects/ColorBreakdown.tsx index ef22ab89..fdd46a53 100644 --- a/apps/palette/web/src/components/projects/ColorBreakdown.tsx +++ b/apps/palette/web/src/components/projects/ColorBreakdown.tsx @@ -2,10 +2,9 @@ import { hooks } from '@/hooks.js'; import { Project, ProjectColorsItem } from '@palette.biscuits/verdant'; // @ts-ignore import { Color } from '@dynamize/color-utilities'; -import { Tabs } from '@a-type/ui/components/tabs'; import { useColorSelection } from './hooks.js'; -import { H3 } from '@a-type/ui/components/typography'; import { clsx } from '@a-type/ui'; +import { useBoundsCssVars } from '@a-type/ui/hooks'; export interface ColorBreakdownProps { project: Project; @@ -54,41 +53,26 @@ function ColorBreakdownVisuals({ const hsl = convertible.hsl; return ( - -
-

Color mix

- - RYB - CMY - -
- - - - - - +
+
- +
); } @@ -106,11 +90,10 @@ function PieChart({ segments, className, }: { - segments: { color: string; percent: number }[]; + segments: { color: string; percent: number; label: string }[]; className?: string; }) { let total = 0; - console.log(segments); const gradient = `conic-gradient(${segments .map(({ color, percent }, i) => { const steps = []; @@ -123,13 +106,44 @@ function PieChart({ }) .flat() .join(', ')})`; - console.log(gradient); + + let totalAngle = 0; + const segmentLabelRadians = segments.map(({ percent }) => { + const angle = (percent / 100) * Math.PI * 2; + const angleCenter = totalAngle + angle / 2 - Math.PI / 2; + totalAngle += angle; + return angleCenter; + }); + + const rootRef = useBoundsCssVars(); + return (
+ className={clsx('rounded-full aspect-1 w-full relative', className)} + > +
+ {/* Render percentage values in the correct positions */} + {segments.map(({ label, percent }, i) => { + const x = Math.cos(segmentLabelRadians[i]); + const y = Math.sin(segmentLabelRadians[i]); + + return ( + + {label} {percent.toFixed(0)}% + + ); + })} +
+
); }