|
| 1 | +import type { Meta, StoryObj } from '@storybook/react'; |
| 2 | + |
| 3 | +import { DonutChart } from '@/ui/chart'; |
| 4 | +import { ThemeAwareDecorator } from '../../../.storybook/decorators'; |
| 5 | + |
| 6 | +/** |
| 7 | + * A donut chart component built on top of Recharts primitives. |
| 8 | + * Supports configurable inner/outer radius, tooltip, and legend. |
| 9 | + */ |
| 10 | +const meta: Meta<typeof DonutChart> = { |
| 11 | + title: 'ui/Charts/DonutChart', |
| 12 | + component: DonutChart, |
| 13 | + tags: ['autodocs'], |
| 14 | + parameters: { |
| 15 | + layout: 'centered', |
| 16 | + }, |
| 17 | + args: { |
| 18 | + className: 'h-[250px] min-w-[300px]', |
| 19 | + innerRadius: 60, |
| 20 | + outerRadius: 90, |
| 21 | + showTooltip: true, |
| 22 | + showLegend: true, |
| 23 | + }, |
| 24 | + decorators: [ThemeAwareDecorator], |
| 25 | +} satisfies Meta<typeof DonutChart>; |
| 26 | + |
| 27 | +export default meta; |
| 28 | + |
| 29 | +type Story = StoryObj<typeof meta>; |
| 30 | + |
| 31 | +const categoryData = [ |
| 32 | + { name: 'compute', value: 400 }, |
| 33 | + { name: 'storage', value: 300 }, |
| 34 | + { name: 'network', value: 200 }, |
| 35 | + { name: 'database', value: 100 }, |
| 36 | +]; |
| 37 | + |
| 38 | +const categoryConfig = { |
| 39 | + compute: { |
| 40 | + label: 'Compute', |
| 41 | + theme: { light: '#3b82f6', dark: '#60a5fa' }, |
| 42 | + }, |
| 43 | + storage: { |
| 44 | + label: 'Storage', |
| 45 | + theme: { light: '#10b981', dark: '#34d399' }, |
| 46 | + }, |
| 47 | + network: { |
| 48 | + label: 'Network', |
| 49 | + theme: { light: '#f59e0b', dark: '#fbbf24' }, |
| 50 | + }, |
| 51 | + database: { |
| 52 | + label: 'Database', |
| 53 | + theme: { light: '#ef4444', dark: '#f87171' }, |
| 54 | + }, |
| 55 | +}; |
| 56 | + |
| 57 | +/** |
| 58 | + * A simple donut chart with a single data series. |
| 59 | + */ |
| 60 | +export const Default: Story = { |
| 61 | + args: { |
| 62 | + data: categoryData, |
| 63 | + config: categoryConfig, |
| 64 | + }, |
| 65 | +}; |
| 66 | + |
| 67 | +/** |
| 68 | + * Donut chart with a larger inner radius, creating a thinner ring. |
| 69 | + */ |
| 70 | +export const ThinRing: Story = { |
| 71 | + args: { |
| 72 | + data: categoryData, |
| 73 | + config: categoryConfig, |
| 74 | + innerRadius: 75, |
| 75 | + outerRadius: 90, |
| 76 | + }, |
| 77 | +}; |
| 78 | + |
| 79 | +/** |
| 80 | + * Donut chart with a smaller inner radius, creating a thicker ring. |
| 81 | + */ |
| 82 | +export const ThickRing: Story = { |
| 83 | + args: { |
| 84 | + data: categoryData, |
| 85 | + config: categoryConfig, |
| 86 | + innerRadius: 40, |
| 87 | + outerRadius: 90, |
| 88 | + }, |
| 89 | +}; |
| 90 | + |
| 91 | +/** |
| 92 | + * Donut chart with all category values set to zero, showing an empty state. |
| 93 | + */ |
| 94 | +export const EmptyState: Story = { |
| 95 | + args: { |
| 96 | + data: [ |
| 97 | + { name: 'compute', value: 0 }, |
| 98 | + { name: 'storage', value: 0 }, |
| 99 | + { name: 'network', value: 0 }, |
| 100 | + { name: 'database', value: 0 }, |
| 101 | + ], |
| 102 | + config: categoryConfig, |
| 103 | + }, |
| 104 | +}; |
| 105 | + |
| 106 | +/** |
| 107 | + * Donut chart with mixed values — legend labels are hidden for zero-value slices. |
| 108 | + */ |
| 109 | +export const PartialEmpty: Story = { |
| 110 | + args: { |
| 111 | + data: [ |
| 112 | + { name: 'compute', value: 400 }, |
| 113 | + { name: 'storage', value: 0 }, |
| 114 | + { name: 'network', value: 200 }, |
| 115 | + { name: 'database', value: 0 }, |
| 116 | + ], |
| 117 | + config: categoryConfig, |
| 118 | + className: 'h-[300px] min-w-[400px]', |
| 119 | + }, |
| 120 | +}; |
| 121 | + |
| 122 | +/** |
| 123 | + * Donut chart combining all features: radial legend, custom radii. |
| 124 | + */ |
| 125 | +export const AllFeatures: Story = { |
| 126 | + args: { |
| 127 | + data: categoryData, |
| 128 | + config: categoryConfig, |
| 129 | + showLegend: true, |
| 130 | + innerRadius: 60, |
| 131 | + outerRadius: 90, |
| 132 | + className: 'h-[300px] min-w-[400px]', |
| 133 | + }, |
| 134 | +}; |
0 commit comments