Skip to content

Commit

Permalink
computer outer, inner, and thickness props
Browse files Browse the repository at this point in the history
  • Loading branch information
retrofox committed Jan 13, 2025
1 parent 0c0818b commit c31fe74
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions projects/js-packages/charts/src/components/pie-chart/pie-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ interface PieChartProps extends OmitBaseChartProps {
* Add padding to the chart
*/
padding?: number;

/**
* Thickness of the pie chart. A value between 0 and 1
*/
thickness?: number;
}

/**
Expand All @@ -40,8 +45,8 @@ interface PieChartProps extends OmitBaseChartProps {
const PieChart = ( {
data,
size = 500, //TODO: replace when making the components responsive
thickness = 1,
withTooltips = false,
innerRadius = 0,
className,
showLegend,
legendOrientation,
Expand All @@ -67,6 +72,9 @@ const PieChart = ( {
index,
} ) );

const outerRadius = radius - padding;
const innerRadius = outerRadius * ( 1 - thickness );

const accessors = {
value: ( d: DataPointPercentage ) => d.value,
// Use the color property from the data object as a last resort. The theme provides colours by default.
Expand All @@ -88,7 +96,7 @@ const PieChart = ( {
<Pie< DataPointPercentage & { index: number } >
data={ dataWithIndex }
pieValue={ accessors.value }
outerRadius={ radius - padding }
outerRadius={ outerRadius }
innerRadius={ innerRadius }
>
{ pie => {
Expand Down

0 comments on commit c31fe74

Please sign in to comment.