Skip to content

Commit f7358d9

Browse files
fix(charts): Fix donut story color mapping and clean up stories
Blanking labels with `label: ''` broke pie chart color indexing — `findIndex` by label always returned 0, so all segments got the same color. Use original data with `showLabels: false` instead. Also removes redundant Doughnut/WithTooltipsDoughnut stories, simplifies composition and interactive legend examples, and switches ErrorStates from `size` to `height`. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent a312472 commit f7358d9

File tree

1 file changed

+47
-134
lines changed

1 file changed

+47
-134
lines changed

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

Lines changed: 47 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,8 @@ type Story = StoryObj< StoryArgs >;
9090
export const Default: Story = {
9191
args: {
9292
...sharedThemeArgs,
93-
size: 400,
9493
containerWidth: '432px',
9594
containerHeight: '432px',
96-
resize: 'none',
9795
thickness: 0.5,
9896
gapScale: 0.03,
9997
cornerScale: 0.03,
@@ -124,12 +122,12 @@ export const ErrorStates: Story = {
124122
<div style={ { display: 'grid', gap: '2rem', gridTemplateColumns: 'repeat(2, 1fr)' } }>
125123
<div>
126124
<h3>Empty Data</h3>
127-
<PieChart size={ 300 } thickness={ 0.6 } data={ [] } />
125+
<PieChart height={ 300 } thickness={ 0.6 } data={ [] } />
128126
</div>
129127
<div>
130128
<h3>Single Value</h3>
131129
<PieChart
132-
size={ 300 }
130+
height={ 300 }
133131
thickness={ 0.6 }
134132
data={ [ { label: 'Single', value: 100, percentage: 100 } ] }
135133
/>
@@ -159,50 +157,6 @@ export const Thin: Story = {
159157
},
160158
};
161159

162-
export const Doughnut: Story = {
163-
args: {
164-
...Default.args,
165-
thickness: 0.5,
166-
gapScale: 0.03,
167-
cornerScale: 0.03,
168-
size: 600,
169-
containerWidth: '632px',
170-
containerHeight: '632px',
171-
children: (
172-
<Group>
173-
<Text textAnchor="middle" verticalAnchor="middle" fontSize={ 24 } y={ -16 }>
174-
🍩 Doughnut
175-
</Text>
176-
<Text textAnchor="middle" verticalAnchor="middle" fill="#008A20" fontSize={ 18 } y={ 16 }>
177-
Three donuts for the price of one!
178-
</Text>
179-
</Group>
180-
),
181-
},
182-
parameters: {
183-
docs: {
184-
description: {
185-
story: 'Doughnut chart variant with the thickness set to 0.5 (50%).',
186-
},
187-
},
188-
},
189-
};
190-
191-
export const WithTooltipsDoughnut: Story = {
192-
args: {
193-
...Default.args,
194-
thickness: 0.5,
195-
withTooltips: true,
196-
},
197-
parameters: {
198-
docs: {
199-
description: {
200-
story: 'Doughnut chart with interactive tooltips that appear on hover.',
201-
},
202-
},
203-
},
204-
};
205-
206160
export const Animation: Story = {
207161
args: {
208162
...Default.args,
@@ -220,69 +174,32 @@ export const WithLegend: Story = {
220174

221175
export const WithCompositionLegend: Story = {
222176
render: args => (
223-
<div
224-
style={ {
225-
display: 'grid',
226-
gap: '2rem',
227-
gridTemplateColumns: 'repeat(2, 1fr)',
228-
alignItems: 'center',
229-
} }
177+
<PieChart
178+
size={ 300 }
179+
data={ args.data }
180+
thickness={ 0.5 }
181+
legendValueDisplay={ args.legendValueDisplay }
230182
>
231-
<div>
232-
<h3>Traditional Props-based</h3>
233-
<PieChart
234-
size={ 300 }
235-
data={ args.data }
236-
thickness={ 0.5 }
237-
showLegend={ true }
238-
legendPosition={ args.legendPosition || 'bottom' }
239-
legendOrientation={ args.legendOrientation || 'horizontal' }
240-
legendAlignment={ args.legendAlignment || 'center' }
241-
legendMaxWidth={ args.legendMaxWidth }
242-
legendTextOverflow={ args.legendTextOverflow || 'wrap' }
243-
legendValueDisplay={ args.legendValueDisplay }
244-
>
245-
<Group>
246-
<Text textAnchor="middle" verticalAnchor="middle" fontSize={ 16 } y={ -8 }>
247-
User Stats
248-
</Text>
249-
<Text textAnchor="middle" verticalAnchor="middle" fontSize={ 14 } y={ 12 } fill="#666">
250-
100K Total
251-
</Text>
252-
</Group>
253-
</PieChart>
254-
</div>
255-
<div>
256-
<h3>Composition API</h3>
257-
<PieChart
258-
size={ 300 }
259-
data={ args.data }
260-
thickness={ 0.5 }
261-
legendValueDisplay={ args.legendValueDisplay }
262-
>
263-
<Group>
264-
<Text textAnchor="middle" verticalAnchor="middle" fontSize={ 16 } y={ -8 }>
265-
User Stats
266-
</Text>
267-
<Text textAnchor="middle" verticalAnchor="middle" fontSize={ 14 } y={ 12 } fill="#666">
268-
100K Total
269-
</Text>
270-
</Group>
271-
<PieChart.Legend
272-
position={ args.legendPosition || 'bottom' }
273-
orientation={ args.legendOrientation || 'horizontal' }
274-
alignment={ args.legendAlignment || 'center' }
275-
maxWidth={ args.legendMaxWidth }
276-
textOverflow={ args.legendTextOverflow || 'wrap' }
277-
/>
278-
</PieChart>
279-
</div>
280-
</div>
183+
<Group>
184+
<Text textAnchor="middle" verticalAnchor="middle" fontSize={ 16 } y={ -8 }>
185+
User Stats
186+
</Text>
187+
<Text textAnchor="middle" verticalAnchor="middle" fontSize={ 14 } y={ 12 } fill="#666">
188+
100K Total
189+
</Text>
190+
</Group>
191+
<PieChart.Legend
192+
position={ args.legendPosition || 'bottom' }
193+
orientation={ args.legendOrientation || 'horizontal' }
194+
alignment={ args.legendAlignment || 'center' }
195+
maxWidth={ args.legendMaxWidth }
196+
textOverflow={ args.legendTextOverflow || 'wrap' }
197+
/>
198+
</PieChart>
281199
),
282200
args: {
283201
data,
284202
thickness: 0.5,
285-
containerHeight: '500px',
286203
},
287204
argTypes: {
288205
legendInteractive: {
@@ -302,40 +219,35 @@ export const WithCompositionLegend: Story = {
302219
export const InteractiveLegend: Story = {
303220
render: args => (
304221
<GlobalChartsProvider>
305-
<div style={ { padding: '20px' } }>
306-
<h3>Interactive Donut Chart</h3>
307-
<p style={ { marginBottom: '20px', color: '#666' } }>
222+
<PieChartUnresponsive
223+
chartId="interactive-donut-chart"
224+
size={ args.size }
225+
data={ args.data }
226+
thickness={ 0.5 }
227+
showLegend={ true }
228+
legendInteractive={ true }
229+
legendPosition={ args.legendPosition || 'bottom' }
230+
legendOrientation={ args.legendOrientation || 'horizontal' }
231+
legendAlignment={ args.legendAlignment || 'center' }
232+
legendValueDisplay={ args.legendValueDisplay }
233+
>
234+
<Group>
235+
<Text textAnchor="middle" verticalAnchor="middle" fontSize={ 16 } y={ -8 }>
236+
User Stats
237+
</Text>
238+
<Text textAnchor="middle" verticalAnchor="middle" fontSize={ 14 } y={ 12 } fill="#666">
239+
100K Total
240+
</Text>
241+
</Group>
242+
<p style={ { color: '#666' } }>
308243
Click legend items to show/hide segments. The total value updates dynamically.
309244
</p>
310-
<PieChartUnresponsive
311-
chartId="interactive-donut-chart"
312-
size={ args.size || 400 }
313-
data={ args.data }
314-
thickness={ 0.5 }
315-
showLegend={ true }
316-
legendInteractive={ true }
317-
legendPosition={ args.legendPosition || 'bottom' }
318-
legendOrientation={ args.legendOrientation || 'horizontal' }
319-
legendAlignment={ args.legendAlignment || 'center' }
320-
legendValueDisplay={ args.legendValueDisplay }
321-
>
322-
<Group>
323-
<Text textAnchor="middle" verticalAnchor="middle" fontSize={ 16 } y={ -8 }>
324-
User Stats
325-
</Text>
326-
<Text textAnchor="middle" verticalAnchor="middle" fontSize={ 14 } y={ 12 } fill="#666">
327-
100K Total
328-
</Text>
329-
</Group>
330-
</PieChartUnresponsive>
331-
</div>
245+
</PieChartUnresponsive>
332246
</GlobalChartsProvider>
333247
),
334248
args: {
335249
data,
336-
size: 400,
337250
thickness: 0.5,
338-
containerHeight: '600px',
339251
},
340252
parameters: {
341253
docs: {
@@ -455,7 +367,8 @@ export const CustomLegend: Story = {
455367
),
456368
args: {
457369
...Default.args,
458-
data: customerRevenueData.map( segment => ( { ...segment, label: '' } ) ),
370+
data: customerRevenueData,
371+
showLabels: false,
459372
thickness: 0.3,
460373
cornerScale: 0.03,
461374
gapScale: 0.01,

0 commit comments

Comments
 (0)