Skip to content

Commit de190fa

Browse files
docs(charts): Update pie chart size/dimension docs
The size prop no longer controls container dimensions — it constrains the maximum pie diameter. Width and height now control the container. Updated JSDoc, API reference, stories argTypes, and the docs MDX to reflect the new behavior and remove the broken Responsiveness story reference. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent e40ad90 commit de190fa

File tree

4 files changed

+58
-39
lines changed

4 files changed

+58
-39
lines changed

projects/js-packages/charts/src/charts/pie-chart/stories/index.api.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ Main component for rendering pie and donut charts.
1313
| Prop | Type | Default | Description |
1414
| ---- | ---- | ------- | ----------- |
1515
| `data` | `DataPointPercentage[]` | - | **Required.** Array of data objects with label, value, and percentage |
16-
| `size` | `number` | - | Diameter of the chart in pixels (omit for responsive behavior) |
16+
| `width` | `number` | - | Width of the chart container in pixels. When omitted, fills parent width |
17+
| `height` | `number` | - | Height of the chart container in pixels. When omitted, fills parent height |
18+
| `size` | `number` | - | Maximum diameter of the pie in pixels. The pie shrinks if the container is smaller. When omitted, fills available space |
19+
| `gap` | `GapSize` | `'md'` | Gap between chart elements (SVG, legend, children). Uses WordPress design system tokens |
1720
| `thickness` | `number` | `1` | Thickness of the pie chart segments (0-1). Values less than 1 create donut charts |
1821
| `padding` | `number` | `20` | Padding around the chart in pixels |
1922
| `gapScale` | `number` | `0` | Scale of gaps between segments (0-1) |

projects/js-packages/charts/src/charts/pie-chart/stories/index.docs.mdx

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ The simplest pie chart requires only a `data` prop with percentage-based data:
4141
<Source
4242
language="jsx"
4343
code={ `<PieChart
44-
size={ 400 }
4544
data={[
4645
{ label: 'MacOS', value: 30000, valueDisplay: '30K', percentage: 23 },
4746
{ label: 'Linux', value: 22000, valueDisplay: '22K', percentage: 17 },
@@ -53,16 +52,18 @@ The simplest pie chart requires only a `data` prop with percentage-based data:
5352
### Required Props
5453

5554
- **`data`**: Array of `DataPointPercentage` objects containing label, value, and percentage
56-
- **`size`**: Diameter of the chart in pixels (when not using responsive mode)
5755

5856
### Optional Props
5957

58+
- **`size`**: Maximum diameter of the pie in pixels. The pie shrinks if the container is smaller. When omitted, the pie fills available space.
59+
- **`width`** / **`height`**: Explicit container dimensions in pixels. When omitted, the chart fills its parent.
6060
- **`padding`** (default: `20`): Padding around the chart in pixels
6161
- **`withTooltips`** (default: `false`): Enables interactive tooltips on hover
6262
- **`showLegend`** (default: `false`): Shows a legend for the chart data
6363
- **`thickness`** (default: `1`): Thickness of the pie chart segments (0-1). Values less than 1 create donut charts
6464
- **`gapScale`** (default: `0`): Scale of gaps between segments (0-1)
6565
- **`cornerScale`** (default: `0`): Scale of corner rounding for segments (0-1)
66+
- **`gap`** (default: `'md'`): Gap between chart elements (SVG, legend, children). Uses WordPress design system tokens.
6667
- **`children`**: Optional React node to render inside the chart center (useful for donut charts)
6768

6869
For detailed prop information, compound components, and type definitions, see the [Pie Chart API Reference](./?path=/docs/js-packages-charts-library-charts-pie-chart-api-reference--docs).
@@ -80,24 +81,24 @@ The composition API allows you to add custom SVG and HTML elements to your chart
8081
<Source
8182
language="jsx"
8283
code={ `<PieChart data={ data } size={ 400 }>
83-
{/* HTML elements rendered outside the SVG */}
84-
<PieChart.HTML>
85-
<h3>Chart Title</h3>
86-
</PieChart.HTML>
87-
88-
{/* SVG elements rendered inside the chart */}
89-
<PieChart.SVG>
90-
<text x={ 0 } y={ 0 } textAnchor="middle">
91-
Center Text
92-
</text>
93-
</PieChart.SVG>
94-
95-
{/* More HTML elements */}
96-
<PieChart.HTML>
97-
<PieChart.Legend position="bottom" />
98-
<p>Additional information</p>
99-
</PieChart.HTML>
100-
</PieChart>` }
84+
{/* HTML elements rendered outside the SVG */}
85+
<PieChart.HTML>
86+
<h3>Chart Title</h3>
87+
</PieChart.HTML>
88+
89+
{/* SVG elements rendered inside the chart */}
90+
<PieChart.SVG>
91+
<text x={ 0 } y={ 0 } textAnchor="middle">
92+
Center Text
93+
</text>
94+
</PieChart.SVG>
95+
96+
{/* More HTML elements */}
97+
<PieChart.HTML>
98+
<PieChart.Legend position="bottom" />
99+
<p>Additional information</p>
100+
</PieChart.HTML>
101+
</PieChart>` }
101102
/>
102103

103104
### Benefits of Composition API
@@ -128,27 +129,31 @@ Enable interactive tooltips that display data information on hover:
128129

129130
### Responsive Behavior
130131

131-
The Pie Chart component supports responsive sizing by omitting the `size` prop:
132-
133-
<Canvas of={ PieChartStories.Responsiveness } />
132+
By default, charts **fill their parent container's dimensions**. The parent must have an explicit height:
134133

135134
<Source
136135
language="jsx"
137-
code={ `// Responsive - fills parent container
138-
<PieChart
139-
data={ data }
140-
maxWidth={ 600 }
141-
aspectRatio={ 1 }
142-
/>
136+
code={ `// Fill parent container (default) - parent needs explicit height
137+
<div style={{ width: '100%', height: '400px' }}>
138+
<PieChart data={data} />
139+
</div>
143140
144-
// Fixed size
145-
<PieChart
146-
size={ 400 }
147-
data={ data }
148-
/>` }
141+
// Fixed dimensions
142+
<PieChart data={data} width={400} height={400} />` }
143+
/>
144+
145+
Use the `size` prop to constrain the maximum pie diameter. The pie will shrink if the container is smaller, but won't grow beyond this value:
146+
147+
<Canvas of={ PieChartStories.WithSize } />
149148

149+
<Source
150+
language="jsx"
151+
code={ `// Constrained pie diameter (container still fills parent)
152+
<PieChart data={data} size={200} />` }
150153
/>
151154

155+
For more details on responsive behavior, see the [Responsive Design section](./?path=/docs/js-packages-charts-library-introduction--docs#responsive-design) in the introduction.
156+
152157
### Data Validation and Error Handling
153158

154159
The component includes built-in data validation with helpful error states:

projects/js-packages/charts/src/charts/pie-chart/stories/index.stories.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ const meta: Meta< StoryArgs > = {
3535
step: 10,
3636
default: 400,
3737
},
38-
description: 'Diameter of the pie chart in pixels',
38+
description:
39+
'Maximum diameter of the pie in pixels. The pie shrinks if the container is smaller. When omitted, fills available space.',
3940
table: { category: 'Dimensions' },
4041
},
4142
thickness: {
@@ -137,6 +138,14 @@ export const WithSize: Story = {
137138
},
138139
};
139140

141+
export const FixedDimensions: Story = {
142+
args: {
143+
...Default.args,
144+
width: 300,
145+
height: 300,
146+
},
147+
};
148+
140149
export const Animation: Story = {
141150
args: {
142151
...Default.args,

projects/js-packages/charts/src/types.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,15 +364,17 @@ export type BaseChartProps< T = DataPoint | DataPointDate | LeaderboardEntry > =
364364
*/
365365
className?: string;
366366
/**
367-
* Width of the chart in pixels
367+
* Width of the chart container in pixels. When omitted, the chart fills its parent's width.
368368
*/
369369
width?: number;
370370
/**
371-
* Height of the chart in pixels
371+
* Height of the chart container in pixels. When omitted, the chart fills its parent's height.
372372
*/
373373
height?: number;
374374
/**
375-
* Size of the chart in pixels for pie and donut charts
375+
* Maximum diameter of the pie in pixels (pie and donut charts only).
376+
* The pie will shrink if the container is smaller than this value.
377+
* When omitted, the pie fills the available space.
376378
*/
377379
size?: number;
378380
/**

0 commit comments

Comments
 (0)