import type { Meta, StoryObj } from '@storybook/react'; import { useMemo } from 'react'; import { Area, AreaChart, Bar, BarChart, CartesianGrid, Label, Line, LineChart, Pie, PieChart, XAxis, } from 'recharts'; import { type ChartConfig, ChartContainer, ChartTooltip, ChartTooltipContent, } from '@konobangu/design-system/components/ui/chart'; const multiSeriesData = [ { month: 'January', desktop: 186, mobile: 80 }, { month: 'February', desktop: 305, mobile: 200 }, { month: 'March', desktop: 237, mobile: 120 }, { month: 'April', desktop: 73, mobile: 190 }, { month: 'May', desktop: 209, mobile: 130 }, { month: 'June', desktop: 214, mobile: 140 }, ]; const multiSeriesConfig = { desktop: { label: 'Desktop', color: 'hsl(var(--chart-1))', }, mobile: { label: 'Mobile', color: 'hsl(var(--chart-2))', }, } satisfies ChartConfig; const singleSeriesData = [ { browser: 'chrome', visitors: 275, fill: 'var(--color-chrome)' }, { browser: 'safari', visitors: 200, fill: 'var(--color-safari)' }, { browser: 'other', visitors: 190, fill: 'var(--color-other)' }, ]; const singleSeriesConfig = { visitors: { label: 'Visitors', }, chrome: { label: 'Chrome', color: 'hsl(var(--chart-1))', }, safari: { label: 'Safari', color: 'hsl(var(--chart-2))', }, other: { label: 'Other', color: 'hsl(var(--chart-5))', }, } satisfies ChartConfig; /** * Beautiful charts. Built using Recharts. Copy and paste into your apps. */ const meta = { title: 'ui/Chart', component: ChartContainer, tags: ['autodocs'], argTypes: {}, args: { children:
, }, } satisfies Meta; export default meta; type Story = StoryObj; /** * Combine multiple Area components to create a stacked area chart. */ export const StackedAreaChart: Story = { args: { config: multiSeriesConfig, }, render: (args) => ( value.slice(0, 3)} /> } /> ), }; /** * Combine multiple Bar components to create a stacked bar chart. */ export const StackedBarChart: Story = { args: { config: multiSeriesConfig, }, render: (args) => ( value.slice(0, 3)} /> } /> ), }; /** * Combine multiple Line components to create a single line chart. */ export const MultiLineChart: Story = { args: { config: multiSeriesConfig, }, render: (args) => ( value.slice(0, 3)} /> } /> ), }; /** * Combine Pie and Label components to create a doughnut chart. */ export const DoughnutChart: Story = { args: { config: singleSeriesConfig, }, render: (args) => { const totalVisitors = useMemo(() => { return singleSeriesData.reduce((acc, curr) => acc + curr.visitors, 0); }, []); return ( } /> ); }, };