diff --git a/components/PieChart.module.css b/components/PieChart.module.css index 699ab34..15e569a 100644 --- a/components/PieChart.module.css +++ b/components/PieChart.module.css @@ -1,18 +1,28 @@ -.path { +.piePath { fill: #354265; } -.text { - display: none; - fill: white; - font-weight: 800; +.labelPath { + fill: var(--primary-background); } -.group:hover>.path { +.pieText, +.labelText { + fill: white; + font-size: 20px; + font-weight: 800; + font-family: "Inconsolata", "sans-serif"; +} + +.pieText { + display: none; +} + +.group:hover>.piePath { fill: #EF839D; filter: drop-shadow(0px 0px 6px #CC5773); } -.group:hover>.text { +.group:hover>.pieText { display: inline } \ No newline at end of file diff --git a/components/PieChart.tsx b/components/PieChart.tsx index 0034c70..91225d5 100644 --- a/components/PieChart.tsx +++ b/components/PieChart.tsx @@ -1,4 +1,5 @@ import { Group } from "@visx/group"; +import { Arc } from "@visx/shape"; import Pie, { ProvidedProps } from "@visx/shape/lib/shapes/Pie"; import React, { useState } from "react"; @@ -7,13 +8,7 @@ import styles from "./PieChart.module.css"; interface PieChartProps { data: PieChartData[]; width: number; - height: number; - margin: { - top: number; - bottom: number; - left: number; - right: number; - }; + textPadding: number; className?: string; } @@ -22,19 +17,31 @@ interface PieChartData { value: number; } -export function PieChart(props: PieChartProps) { +export function PieChart({ width, textPadding, ...props }: PieChartProps) { + const pieWidth = width * 0.5 - textPadding; return ( - - + + d.value} - outerRadius={100} - cornerRadius={5} - padAngle={0.1} + cornerRadius={10} + padAngle={0.075} + padRadius={width * 0.7} + innerRadius={width * 0.03} + outerRadius={pieWidth} > - {(pie) => } + {(pie) => } + + d.value} + innerRadius={pieWidth} + outerRadius={width * 0.5} + > + {(pie) => } @@ -42,23 +49,34 @@ export function PieChart(props: PieChartProps) { } // path, arcs, pie -type PieSliceProps = ProvidedProps; +type PieSlicesProps = ProvidedProps & { + isLabel: boolean; +}; -export function PieSlice(props: PieSliceProps) { - return props.arcs.map((arc) => { - const [centroidX, centroidY] = props.path.centroid(arc); - const pathArc = props.path(arc); +export function PieSlices({ isLabel, ...props }: PieSlicesProps) { + return ( + <> + {props.arcs.map((arc) => { + const [centroidX, centroidY] = props.path.centroid(arc); + const pathArc = props.path(arc); - return ( - - - {`${arc.data.value}%`} - - ); - }); + return ( + + + + {isLabel ? `${arc.data.category}` : `${arc.data.value}%`} + + + ); + })} + + ); } diff --git a/pages/playground.tsx b/pages/playground.tsx index 28a222d..e2b7201 100644 --- a/pages/playground.tsx +++ b/pages/playground.tsx @@ -8,12 +8,9 @@ export default function Home() { <>

Playground

Show off your components here!

- +
+ +
); }