@platned/ui 0.10.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -98
- package/dist/blocks-charts.cjs +459 -0
- package/dist/blocks-charts.cjs.map +1 -0
- package/dist/blocks-charts.d.cts +64 -0
- package/dist/blocks-charts.d.ts +64 -0
- package/dist/blocks-charts.js +440 -0
- package/dist/blocks-charts.js.map +1 -0
- package/dist/blocks.cjs +8007 -0
- package/dist/blocks.cjs.map +1 -0
- package/dist/blocks.d.cts +3082 -0
- package/dist/blocks.d.ts +3082 -0
- package/dist/blocks.js +8223 -0
- package/dist/blocks.js.map +1 -0
- package/dist/chart.cjs +226 -0
- package/dist/chart.cjs.map +1 -0
- package/dist/chart.d.ts +66 -0
- package/dist/chart.js +183 -0
- package/dist/chart.js.map +1 -0
- package/dist/chunk-2L5XAYNK.js +11 -0
- package/dist/chunk-2L5XAYNK.js.map +1 -0
- package/dist/chunk-327NSKZW.js +3176 -0
- package/dist/chunk-327NSKZW.js.map +1 -0
- package/dist/chunk-GJJWRZ4B.js +200 -0
- package/dist/chunk-GJJWRZ4B.js.map +1 -0
- package/dist/chunk-WGCAQEZ4.js +178 -0
- package/dist/chunk-WGCAQEZ4.js.map +1 -0
- package/dist/code-block-BgEiLXpO.d.ts +111 -0
- package/dist/code-block-highlight.cjs +489 -0
- package/dist/code-block-highlight.cjs.map +1 -0
- package/dist/code-block-highlight.d.ts +28 -0
- package/dist/code-block-highlight.js +120 -0
- package/dist/code-block-highlight.js.map +1 -0
- package/dist/data-table-Dec6t8NO.d.ts +729 -0
- package/dist/data-table.cjs +3506 -2219
- package/dist/data-table.cjs.map +1 -1
- package/dist/data-table.d.ts +2 -1
- package/dist/data-table.js +1396 -246
- package/dist/data-table.js.map +1 -1
- package/dist/index.cjs +8934 -11994
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2524 -5312
- package/dist/index.js +4678 -9574
- package/dist/index.js.map +1 -1
- package/dist/map.cjs +432 -0
- package/dist/map.cjs.map +1 -0
- package/dist/map.d.cts +294 -0
- package/dist/map.d.ts +294 -0
- package/dist/map.js +422 -0
- package/dist/map.js.map +1 -0
- package/dist/theme.css +1897 -0
- package/package.json +65 -24
- package/dist/chunk-OVIRTNT4.js +0 -2787
- package/dist/chunk-OVIRTNT4.js.map +0 -1
- package/dist/data-table-JX-vnL0F.d.ts +0 -464
- package/dist/sidebar.cjs +0 -108
- package/dist/sidebar.cjs.map +0 -1
- package/dist/sidebar.d.cts +0 -257
- package/dist/sidebar.d.ts +0 -257
- package/dist/sidebar.js +0 -70
- package/dist/sidebar.js.map +0 -1
- package/dist/styles.css +0 -1
- package/dist/tokens.css +0 -1
- package/tailwind-preset.cjs +0 -446
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/blocks/charts.tsx","../src/blocks/stat-chart.tsx","../src/components/charts/chart.tsx","../src/lib/cn.ts","../src/blocks/card-chart.tsx"],"sourcesContent":["/**\n * Every Recharts drawing the blocks use, built as one file of its own (`blocks-charts`). Blocks load\n * it with `import('./charts')` on first use, so `blocks.js` never imports Recharts and an app that\n * draws no chart does not install it (tsup plugin `blocksChartsAsFile`).\n */\nexport { default as StatChart } from './stat-chart';\nexport { CardChart } from './card-chart';\n","import { useId } from 'react';\nimport { Area, AreaChart, Bar, BarChart, Cell, Line, LineChart, Pie, PieChart, YAxis } from 'recharts';\n\nimport { ChartContainer, ChartTooltip, ChartTooltipContent, type ChartConfig } from '../components/charts/chart';\n\n/**\n * The small charts inside stat cards, on Recharts. Loaded on demand by `StatCards` (its own\n * built file, `blocks-charts`), so an app that shows no chart in a card does not need Recharts.\n */\n\nexport interface StatChartPoint {\n label: string;\n value: number;\n}\n\nexport interface StatChartProps {\n kind: 'area' | 'line' | 'bar' | 'donut';\n points: StatChartPoint[];\n /** The series name in the tooltip. */\n name: string;\n /** Segment colours for a donut, as CSS colours (`var(--chart-1)`). */\n colors?: string[];\n /** Formats a value in the tooltip. */\n formatValue?: (value: number) => string;\n /** Text inside the donut. */\n centerLabel?: string;\n /** `lg`: a taller trend, for a feature card. */\n size?: 'default' | 'lg';\n}\n\nexport default function StatChart({\n kind,\n points,\n name,\n colors = [],\n formatValue,\n centerLabel,\n size = 'default',\n}: StatChartProps) {\n const gradient = useId().replace(/:/g, '');\n const config: ChartConfig = { value: { label: name, color: 'var(--chart-1)' } };\n const tooltip = (\n <ChartTooltip\n cursor={false}\n content={\n <ChartTooltipContent\n hideIndicator={kind !== 'donut'}\n formatter={(value, _name, item) => (\n <span className=\"flex w-full justify-between gap-3\">\n <span className=\"text-muted-foreground\">{String(item.payload?.label ?? '')}</span>\n <span className=\"font-medium tabular-nums\">\n {formatValue ? formatValue(Number(value)) : String(value)}\n </span>\n </span>\n )}\n hideLabel\n />\n }\n />\n );\n\n if (kind === 'donut') {\n return (\n <ChartContainer config={config} className=\"aspect-square h-24 w-24\">\n <PieChart>\n {tooltip}\n <Pie data={points} dataKey=\"value\" nameKey=\"label\" innerRadius={30} outerRadius={44} strokeWidth={2}>\n {points.map((point, index) => (\n <Cell key={point.label} fill={colors[index] ?? `var(--chart-${(index % 5) + 1})`} />\n ))}\n </Pie>\n {centerLabel && (\n <text\n x=\"50%\"\n y=\"50%\"\n textAnchor=\"middle\"\n dominantBaseline=\"middle\"\n className=\"fill-foreground text-sm font-semibold\"\n >\n {centerLabel}\n </text>\n )}\n </PieChart>\n </ChartContainer>\n );\n }\n\n const margin = { top: 4, right: 0, bottom: 0, left: 0 };\n return (\n <ChartContainer config={config} className={size === 'lg' ? 'aspect-auto h-28 w-full' : 'aspect-auto h-16 w-full'}>\n {kind === 'bar' ? (\n <BarChart data={points} margin={margin}>\n {tooltip}\n <YAxis hide domain={[0, 'auto']} />\n <Bar dataKey=\"value\" fill=\"var(--color-value)\" fillOpacity={0.85} radius={3} maxBarSize={14} />\n </BarChart>\n ) : kind === 'line' ? (\n <LineChart data={points} margin={margin}>\n {tooltip}\n <YAxis hide domain={['dataMin', 'dataMax']} />\n <Line dataKey=\"value\" type=\"monotone\" stroke=\"var(--color-value)\" strokeWidth={2} dot={false} />\n </LineChart>\n ) : (\n <AreaChart data={points} margin={margin}>\n <defs>\n <linearGradient id={gradient} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n <stop offset=\"5%\" stopColor=\"var(--color-value)\" stopOpacity={0.4} />\n <stop offset=\"95%\" stopColor=\"var(--color-value)\" stopOpacity={0.05} />\n </linearGradient>\n </defs>\n {tooltip}\n <YAxis hide domain={['dataMin', 'dataMax']} />\n <Area\n baseValue=\"dataMin\"\n dataKey=\"value\"\n type=\"monotone\"\n stroke=\"var(--color-value)\"\n strokeWidth={2}\n fill={`url(#${gradient})`}\n />\n </AreaChart>\n )}\n </ChartContainer>\n );\n}\n","import {\n createContext,\n useContext,\n useId,\n useMemo,\n type ComponentProps,\n type ComponentType,\n type CSSProperties,\n type ReactNode,\n} from 'react';\nimport * as RechartsPrimitive from 'recharts';\nimport type { TooltipValueType } from 'recharts';\nimport { cn } from '../../lib/cn';\n\n/**\n * Chart: beautiful charts, built using Recharts.\n *\n * `ChartContainer` takes a `ChartConfig` (each series' label, colour or per-theme colours, and\n * icon) and renders a responsive Recharts container; compose the chart inside it with Recharts' own\n * parts (`BarChart`, `Bar`, `XAxis`…). Each configured colour becomes `--color-<key>` on the\n * container, so a series is coloured with `fill=\"var(--color-desktop)\"`. `ChartTooltipContent` and\n * `ChartLegendContent` read labels and colours from the config.\n *\n * Published as `@platned/ui/chart`, because `recharts` is an optional peer dependency.\n */\n\n// Format: { THEME_NAME: CSS_SELECTOR }\nconst THEMES = { light: '', dark: '.dark' } as const;\n\nconst INITIAL_DIMENSION = { width: 320, height: 200 } as const;\ntype TooltipNameType = number | string;\n\nexport type ChartConfig = Record<\n string,\n {\n label?: ReactNode;\n icon?: ComponentType;\n } & ({ color?: string; theme?: never } | { color?: never; theme: Record<keyof typeof THEMES, string> })\n>;\n\ntype ChartContextProps = {\n config: ChartConfig;\n};\n\nconst ChartContext = createContext<ChartContextProps | null>(null);\n\nexport function useChart() {\n const context = useContext(ChartContext);\n if (!context) throw new Error('useChart must be used within a <ChartContainer />');\n return context;\n}\n\nexport type ChartContainerProps = ComponentProps<'div'> & {\n config: ChartConfig;\n children: ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>['children'];\n initialDimension?: { width: number; height: number };\n};\n\nexport function ChartContainer({\n id,\n className,\n children,\n config,\n initialDimension = INITIAL_DIMENSION,\n ...props\n}: ChartContainerProps) {\n const uniqueId = useId();\n const chartId = `chart-${id ?? uniqueId.replace(/:/g, '')}`;\n\n return (\n <ChartContext.Provider value={{ config }}>\n <div\n data-slot=\"chart\"\n data-chart={chartId}\n className={cn(\n \"flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden\",\n className,\n )}\n {...props}\n >\n <ChartStyle id={chartId} config={config} />\n <RechartsPrimitive.ResponsiveContainer initialDimension={initialDimension}>{children}</RechartsPrimitive.ResponsiveContainer>\n </div>\n </ChartContext.Provider>\n );\n}\n\n/** Writes each configured colour as `--color-<key>` on the chart, per theme. */\nexport function ChartStyle({ id, config }: { id: string; config: ChartConfig }) {\n const colorConfig = Object.entries(config).filter(([, item]) => item.theme ?? item.color);\n if (!colorConfig.length) return null;\n\n return (\n <style\n dangerouslySetInnerHTML={{\n __html: Object.entries(THEMES)\n .map(\n ([theme, prefix]) => `\n${prefix} [data-chart=${id}] {\n${colorConfig\n .map(([key, itemConfig]) => {\n const color = itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ?? itemConfig.color;\n return color ? ` --color-${key}: ${color};` : null;\n })\n .join('\\n')}\n}\n`,\n )\n .join('\\n'),\n }}\n />\n );\n}\n\nexport const ChartTooltip = RechartsPrimitive.Tooltip;\n\nexport type ChartTooltipContentProps = ComponentProps<typeof RechartsPrimitive.Tooltip> &\n ComponentProps<'div'> & {\n hideLabel?: boolean;\n hideIndicator?: boolean;\n indicator?: 'line' | 'dot' | 'dashed';\n nameKey?: string;\n labelKey?: string;\n } & Omit<RechartsPrimitive.DefaultTooltipContentProps<TooltipValueType, TooltipNameType>, 'accessibilityLayer'>;\n\nexport function ChartTooltipContent({\n active,\n payload,\n className,\n indicator = 'dot',\n hideLabel = false,\n hideIndicator = false,\n label,\n labelFormatter,\n labelClassName,\n formatter,\n color,\n nameKey,\n labelKey,\n}: ChartTooltipContentProps) {\n const { config } = useChart();\n\n const tooltipLabel = useMemo(() => {\n if (hideLabel || !payload?.length) return null;\n const [item] = payload;\n const key = `${labelKey ?? item?.dataKey ?? item?.name ?? 'value'}`;\n const itemConfig = getPayloadConfigFromPayload(config, item, key);\n const value = !labelKey && typeof label === 'string' ? (config[label]?.label ?? label) : itemConfig?.label;\n if (labelFormatter) {\n return <div className={cn('font-medium', labelClassName)}>{labelFormatter(value, payload)}</div>;\n }\n if (!value) return null;\n return <div className={cn('font-medium', labelClassName)}>{value}</div>;\n }, [label, labelFormatter, payload, hideLabel, labelClassName, config, labelKey]);\n\n if (!active || !payload?.length) return null;\n\n const nestLabel = payload.length === 1 && indicator !== 'dot';\n\n return (\n <div\n className={cn(\n 'grid min-w-32 items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl',\n className,\n )}\n >\n {!nestLabel ? tooltipLabel : null}\n <div className=\"grid gap-1.5\">\n {payload\n .filter((item) => item.type !== 'none')\n .map((item, index) => {\n const key = `${nameKey ?? item.name ?? item.dataKey ?? 'value'}`;\n const itemConfig = getPayloadConfigFromPayload(config, item, key);\n const indicatorColor = color ?? item.payload?.fill ?? item.color;\n\n return (\n <div\n key={index}\n className={cn(\n 'flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground',\n indicator === 'dot' && 'items-center',\n )}\n >\n {formatter && item?.value !== undefined && item.name ? (\n formatter(item.value, item.name, item, index, item.payload)\n ) : (\n <>\n {itemConfig?.icon ? (\n <itemConfig.icon />\n ) : (\n !hideIndicator && (\n <div\n className={cn('shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)', {\n 'h-2.5 w-2.5': indicator === 'dot',\n 'w-1': indicator === 'line',\n 'w-0 border-[1.5px] border-dashed bg-transparent': indicator === 'dashed',\n 'my-0.5': nestLabel && indicator === 'dashed',\n })}\n style={{ '--color-bg': indicatorColor, '--color-border': indicatorColor } as CSSProperties}\n />\n )\n )}\n <div className={cn('flex flex-1 justify-between leading-none', nestLabel ? 'items-end' : 'items-center')}>\n <div className=\"grid gap-1.5\">\n {nestLabel ? tooltipLabel : null}\n <span className=\"text-muted-foreground\">{itemConfig?.label ?? item.name}</span>\n </div>\n {item.value != null && (\n <span className=\"font-mono font-medium text-foreground tabular-nums\">\n {typeof item.value === 'number' ? item.value.toLocaleString() : String(item.value)}\n </span>\n )}\n </div>\n </>\n )}\n </div>\n );\n })}\n </div>\n </div>\n );\n}\n\nexport const ChartLegend = RechartsPrimitive.Legend;\n\nexport type ChartLegendContentProps = ComponentProps<'div'> & {\n hideIcon?: boolean;\n nameKey?: string;\n} & RechartsPrimitive.DefaultLegendContentProps;\n\nexport function ChartLegendContent({ className, hideIcon = false, payload, verticalAlign = 'bottom', nameKey }: ChartLegendContentProps) {\n const { config } = useChart();\n if (!payload?.length) return null;\n\n return (\n <div className={cn('flex items-center justify-center gap-4', verticalAlign === 'top' ? 'pb-3' : 'pt-3', className)}>\n {payload\n .filter((item) => item.type !== 'none')\n .map((item, index) => {\n const key = `${nameKey ?? item.dataKey ?? 'value'}`;\n const itemConfig = getPayloadConfigFromPayload(config, item, key);\n return (\n <div key={index} className=\"flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground\">\n {itemConfig?.icon && !hideIcon ? (\n <itemConfig.icon />\n ) : (\n <div className=\"h-2 w-2 shrink-0 rounded-[2px]\" style={{ backgroundColor: item.color }} />\n )}\n {itemConfig?.label}\n </div>\n );\n })}\n </div>\n );\n}\n\nfunction getPayloadConfigFromPayload(config: ChartConfig, payload: unknown, key: string) {\n if (typeof payload !== 'object' || payload === null) return undefined;\n\n const payloadPayload =\n 'payload' in payload && typeof payload.payload === 'object' && payload.payload !== null ? payload.payload : undefined;\n\n let configLabelKey: string = key;\n\n if (key in payload && typeof payload[key as keyof typeof payload] === 'string') {\n configLabelKey = payload[key as keyof typeof payload] as string;\n } else if (payloadPayload && key in payloadPayload && typeof payloadPayload[key as keyof typeof payloadPayload] === 'string') {\n configLabelKey = payloadPayload[key as keyof typeof payloadPayload] as string;\n }\n\n return configLabelKey in config ? config[configLabelKey] : config[key];\n}\n","import { type ClassValue, clsx } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\n/**\n * `clsx` + `tailwind-merge`.\n *\n * The type scale is Tailwind's stock one (0.11), so `tailwind-merge` recognises every size as a\n * size. Until 0.11 the preset had word-named sizes (`text-body-sm`), which twMerge filed under\n * colour and dropped when a colour followed; the build now rejects any custom `fontSize` key\n * in the preset so that cannot come back.\n *\n * Use this instead of bare `clsx` in any component whose `className` prop is meant to\n * *override* a base utility — the composable `Card*` and `Dialog*` parts, and anything\n * else built to be reshaped by its caller.\n *\n * Why it is necessary: `clsx` only concatenates. When two conflicting Tailwind\n * utilities both end up in the attribute, the winner is decided by *stylesheet order*,\n * not attribute order. Tailwind emits `flex-row` before `flex-col` and `gap-3` before\n * `gap-4`, so under plain `clsx`:\n *\n * <Part className=\"flex-row gap-3\" /> // base is 'flex flex-col gap-4'\n *\n * silently stays a column with a 4-unit gap. `twMerge` drops the losing class instead,\n * so the caller's intent wins.\n *\n * Everywhere else in the library `className` is purely additive, and plain `clsx`\n * remains correct — and cheaper. Do not sweep it out of those files.\n */\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n","import { useId } from 'react';\nimport {\n Area,\n AreaChart,\n Bar,\n BarChart,\n CartesianGrid,\n Cell,\n Label,\n Line,\n LineChart,\n Pie,\n PieChart,\n XAxis,\n YAxis,\n} from 'recharts';\n\nimport {\n ChartContainer,\n ChartLegend,\n ChartLegendContent,\n ChartTooltip,\n ChartTooltipContent,\n type ChartConfig,\n} from '../components/charts/chart';\nimport { cn } from '../lib/cn';\n\n/**\n * The chart inside a `ChartCard`, on Recharts. Loaded on demand from the `blocks-charts` file, like\n * the stat cards' small charts, so an app that never draws one does not need Recharts.\n *\n * It takes data already shaped by `ChartCard`: rows keyed `x` plus one key per series (`s0`, `s1`…),\n * or, for a donut or pie, one row per segment.\n */\n\nexport interface CardChartSeries {\n /** The row key of the series' values. */\n key: string;\n label: string;\n /** A CSS colour. */\n color: string;\n}\n\nexport interface CardChartProps {\n kind: 'area' | 'line' | 'bar' | 'donut' | 'pie';\n /** Cartesian: `{ x, s0, s1… }`. Donut and pie: `{ x: label, value }` per segment. */\n rows: Record<string, string | number | null>[];\n series: CardChartSeries[];\n stacked?: boolean;\n /** Bars run left to right. */\n horizontal?: boolean;\n curve?: 'smooth' | 'linear' | 'step';\n legend?: boolean;\n /** Show the value axis. */\n valueAxis?: boolean;\n formatValue?: (value: number) => string;\n /** The number and its label in the middle of a donut. (A donut's legend is drawn by the card.) */\n center?: { value: string; label?: string };\n /** Take the container's height instead of a fixed one. */\n fill?: boolean;\n}\n\nconst CURVE = { smooth: 'monotone', linear: 'linear', step: 'step' } as const;\n\nexport function CardChart({\n kind,\n rows,\n series,\n stacked = false,\n horizontal = false,\n curve = 'smooth',\n legend = false,\n valueAxis = false,\n formatValue,\n center,\n fill = false,\n}: CardChartProps) {\n const gradient = useId().replace(/:/g, '');\n const config: ChartConfig = Object.fromEntries(series.map((s) => [s.key, { label: s.label, color: s.color }]));\n const format = (value: unknown) => (formatValue && typeof value === 'number' ? formatValue(value) : String(value));\n const size = fill ? 'aspect-auto h-full min-h-40 w-full' : 'aspect-auto h-60 w-full';\n\n if (kind === 'donut' || kind === 'pie') {\n return (\n <ChartContainer\n config={config}\n className={cn('mx-auto aspect-square', fill ? 'h-full max-h-full min-h-40' : 'max-h-60')}\n >\n <PieChart>\n <ChartTooltip\n cursor={false}\n content={<ChartTooltipContent hideLabel nameKey=\"key\" formatter={tooltipRow(format, config)} />}\n />\n <Pie\n data={rows}\n dataKey=\"value\"\n nameKey=\"key\"\n innerRadius={kind === 'donut' ? '58%' : 0}\n outerRadius=\"88%\"\n strokeWidth={2}\n stroke=\"var(--card)\"\n >\n {rows.map((row, index) => (\n <Cell key={String(row.key)} fill={series[index]?.color} />\n ))}\n {kind === 'donut' && center && (\n <Label\n content={({ viewBox }) => {\n if (!viewBox || !('cx' in viewBox) || !('cy' in viewBox)) return null;\n const cx = Number(viewBox.cx);\n const cy = Number(viewBox.cy);\n return (\n <text x={cx} y={cy} textAnchor=\"middle\" dominantBaseline=\"middle\">\n <tspan x={cx} y={center.label ? cy - 6 : cy} className=\"fill-foreground text-2xl font-semibold\">\n {center.value}\n </tspan>\n {center.label && (\n <tspan x={cx} y={cy + 16} className=\"fill-muted-foreground text-xs\">\n {center.label}\n </tspan>\n )}\n </text>\n );\n }}\n />\n )}\n </Pie>\n </PieChart>\n </ChartContainer>\n );\n }\n\n const tooltip = (\n <ChartTooltip\n cursor={kind === 'bar'}\n content={<ChartTooltipContent indicator={kind === 'bar' ? 'dot' : 'line'} formatter={tooltipRow(format, config)} />}\n />\n );\n // Room for the longest category name beside horizontal bars (about 7px a character at 12px).\n const labelWidth = Math.min(160, Math.max(48, 12 + 7 * Math.max(0, ...rows.map((row) => String(row.x ?? '').length))));\n const legendNode = legend ? <ChartLegend content={<ChartLegendContent />} className=\"flex-wrap\" /> : null;\n const categoryAxis = horizontal ? (\n <YAxis dataKey=\"x\" type=\"category\" tickLine={false} axisLine={false} tickMargin={8} width={labelWidth} />\n ) : (\n <XAxis dataKey=\"x\" tickLine={false} axisLine={false} tickMargin={8} minTickGap={16} interval=\"preserveStartEnd\" />\n );\n const numberAxis = horizontal ? (\n <XAxis type=\"number\" hide={!valueAxis} tickLine={false} axisLine={false} tickFormatter={format} />\n ) : (\n <YAxis hide={!valueAxis} tickLine={false} axisLine={false} tickMargin={4} width={valueAxis ? 48 : 0} tickFormatter={format} />\n );\n const margin = { top: 8, right: 8, bottom: 0, left: valueAxis || horizontal ? 0 : 8 };\n\n if (kind === 'bar') {\n return (\n <ChartContainer config={config} className={size}>\n <BarChart data={rows} layout={horizontal ? 'vertical' : 'horizontal'} margin={margin} accessibilityLayer>\n <CartesianGrid vertical={horizontal} horizontal={!horizontal} />\n {categoryAxis}\n {numberAxis}\n {tooltip}\n {series.map((s, index) => (\n <Bar\n key={s.key}\n dataKey={s.key}\n fill={`var(--color-${s.key})`}\n stackId={stacked ? 'stack' : undefined}\n radius={stacked ? (index === series.length - 1 ? (horizontal ? [0, 4, 4, 0] : [4, 4, 0, 0]) : 0) : 4}\n maxBarSize={40}\n />\n ))}\n {legendNode}\n </BarChart>\n </ChartContainer>\n );\n }\n\n if (kind === 'line') {\n return (\n <ChartContainer config={config} className={size}>\n <LineChart data={rows} margin={margin} accessibilityLayer>\n <CartesianGrid vertical={false} />\n {categoryAxis}\n {numberAxis}\n {tooltip}\n {series.map((s) => (\n <Line\n key={s.key}\n dataKey={s.key}\n type={CURVE[curve]}\n stroke={`var(--color-${s.key})`}\n strokeWidth={2}\n dot={false}\n connectNulls\n />\n ))}\n {legendNode}\n </LineChart>\n </ChartContainer>\n );\n }\n\n return (\n <ChartContainer config={config} className={size}>\n <AreaChart data={rows} margin={margin} accessibilityLayer>\n <defs>\n {series.map((s) => (\n <linearGradient key={s.key} id={`${gradient}-${s.key}`} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n <stop offset=\"5%\" stopColor={`var(--color-${s.key})`} stopOpacity={0.6} />\n <stop offset=\"95%\" stopColor={`var(--color-${s.key})`} stopOpacity={0.05} />\n </linearGradient>\n ))}\n </defs>\n <CartesianGrid vertical={false} />\n {categoryAxis}\n {numberAxis}\n {tooltip}\n {series.map((s) => (\n <Area\n key={s.key}\n dataKey={s.key}\n type={CURVE[curve]}\n stroke={`var(--color-${s.key})`}\n strokeWidth={2}\n fill={`url(#${gradient}-${s.key})`}\n stackId={stacked ? 'stack' : undefined}\n connectNulls\n />\n ))}\n {legendNode}\n </AreaChart>\n </ChartContainer>\n );\n}\n\n/** A tooltip row: the series' colour, its name and the formatted value. */\nfunction tooltipRow(format: (value: unknown) => string, config: ChartConfig) {\n return (value: unknown, name: unknown, item: { color?: string; payload?: { fill?: string } }) => (\n <span className=\"flex w-full items-center gap-2\">\n <span\n aria-hidden\n className=\"size-2.5 shrink-0 rounded-[2px]\"\n style={{ background: item.color ?? item.payload?.fill }}\n />\n <span className=\"text-muted-foreground\">{config[String(name)]?.label ?? String(name)}</span>\n <span className=\"ms-auto font-medium text-foreground tabular-nums\">{format(value)}</span>\n </span>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAAsB;AACtB,sBAA4F;;;ACD5F,mBASO;AACP,wBAAmC;;;ACVnC,kBAAsC;AACtC,4BAAwB;AA2BjB,SAAS,MAAM,QAAsB;AAC1C,aAAO,mCAAQ,kBAAK,MAAM,CAAC;AAC7B;;;ADyCM;AA5CN,IAAM,SAAS,EAAE,OAAO,IAAI,MAAM,QAAQ;AAE1C,IAAM,oBAAoB,EAAE,OAAO,KAAK,QAAQ,IAAI;AAepD,IAAM,mBAAe,4BAAwC,IAAI;AAE1D,SA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AAG,KAAI,IAAG,KAAI,IAAG,KAC9E;AAAA,mDAAC,UAAK,QAAO,MAAK,WAAW,eAAe,EAAE,GAAG,KAAK,aAAa,KAAK;AAAA,MACxE,6CAAC,UAAK,QAAO,OAAM,WAAW,eAAe,EAAE,GAAG,KAAK,aAAa,MAAM;AAAA,SAFvD,EAAE,GAGvB,CACD,GACH;AAAA,IACA,6CAAC,kCAAc,UAAU,OAAO;AAAA,IAC/B;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO,IAAI,CAAC,MACX;AAAA,MAAC;AAAA;AAAA,QAEC,SAAS,EAAE;AAAA,QACX,MAAM,MAAM,KAAK;AAAA,QACjB,QAAQ,eAAe,EAAE,GAAG;AAAA,QAC5B,aAAa;AAAA,QACb,MAAM,QAAQ,QAAQ,IAAI,EAAE,GAAG;AAAA,QAC/B,SAAS,UAAU,UAAU;AAAA,QAC7B,cAAY;AAAA;AAAA,MAPP,EAAE;AAAA,IAQT,CACD;AAAA,IACA;AAAA,KACH,GACF;AAEJ;AAGA,SAAS,WAAW,QAAoC,QAAqB;AAC3E,SAAO,CAAC,OAAgB,MAAe,SACrC,8CAAC,UAAK,WAAU,kCACd;AAAA;AAAA,MAAC;AAAA;AAAA,QACC,eAAW;AAAA,QACX,WAAU;AAAA,QACV,OAAO,EAAE,YAAY,KAAK,SAAS,KAAK,SAAS,KAAK;AAAA;AAAA,IACxD;AAAA,IACA,6CAAC,UAAK,WAAU,yBAAyB,iBAAO,OAAO,IAAI,CAAC,GAAG,SAAS,OAAO,IAAI,GAAE;AAAA,IACrF,6CAAC,UAAK,WAAU,oDAAoD,iBAAO,KAAK,GAAE;AAAA,KACpF;AAEJ;","names":["import_react","import_jsx_runtime","import_react","import_recharts","import_jsx_runtime"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The small charts inside stat cards, on Recharts. Loaded on demand by `StatCards` (its own
|
|
5
|
+
* built file, `blocks-charts`), so an app that shows no chart in a card does not need Recharts.
|
|
6
|
+
*/
|
|
7
|
+
interface StatChartPoint {
|
|
8
|
+
label: string;
|
|
9
|
+
value: number;
|
|
10
|
+
}
|
|
11
|
+
interface StatChartProps {
|
|
12
|
+
kind: 'area' | 'line' | 'bar' | 'donut';
|
|
13
|
+
points: StatChartPoint[];
|
|
14
|
+
/** The series name in the tooltip. */
|
|
15
|
+
name: string;
|
|
16
|
+
/** Segment colours for a donut, as CSS colours (`var(--chart-1)`). */
|
|
17
|
+
colors?: string[];
|
|
18
|
+
/** Formats a value in the tooltip. */
|
|
19
|
+
formatValue?: (value: number) => string;
|
|
20
|
+
/** Text inside the donut. */
|
|
21
|
+
centerLabel?: string;
|
|
22
|
+
/** `lg`: a taller trend, for a feature card. */
|
|
23
|
+
size?: 'default' | 'lg';
|
|
24
|
+
}
|
|
25
|
+
declare function StatChart({ kind, points, name, colors, formatValue, centerLabel, size, }: StatChartProps): react.JSX.Element;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The chart inside a `ChartCard`, on Recharts. Loaded on demand from the `blocks-charts` file, like
|
|
29
|
+
* the stat cards' small charts, so an app that never draws one does not need Recharts.
|
|
30
|
+
*
|
|
31
|
+
* It takes data already shaped by `ChartCard`: rows keyed `x` plus one key per series (`s0`, `s1`…),
|
|
32
|
+
* or, for a donut or pie, one row per segment.
|
|
33
|
+
*/
|
|
34
|
+
interface CardChartSeries {
|
|
35
|
+
/** The row key of the series' values. */
|
|
36
|
+
key: string;
|
|
37
|
+
label: string;
|
|
38
|
+
/** A CSS colour. */
|
|
39
|
+
color: string;
|
|
40
|
+
}
|
|
41
|
+
interface CardChartProps {
|
|
42
|
+
kind: 'area' | 'line' | 'bar' | 'donut' | 'pie';
|
|
43
|
+
/** Cartesian: `{ x, s0, s1… }`. Donut and pie: `{ x: label, value }` per segment. */
|
|
44
|
+
rows: Record<string, string | number | null>[];
|
|
45
|
+
series: CardChartSeries[];
|
|
46
|
+
stacked?: boolean;
|
|
47
|
+
/** Bars run left to right. */
|
|
48
|
+
horizontal?: boolean;
|
|
49
|
+
curve?: 'smooth' | 'linear' | 'step';
|
|
50
|
+
legend?: boolean;
|
|
51
|
+
/** Show the value axis. */
|
|
52
|
+
valueAxis?: boolean;
|
|
53
|
+
formatValue?: (value: number) => string;
|
|
54
|
+
/** The number and its label in the middle of a donut. (A donut's legend is drawn by the card.) */
|
|
55
|
+
center?: {
|
|
56
|
+
value: string;
|
|
57
|
+
label?: string;
|
|
58
|
+
};
|
|
59
|
+
/** Take the container's height instead of a fixed one. */
|
|
60
|
+
fill?: boolean;
|
|
61
|
+
}
|
|
62
|
+
declare function CardChart({ kind, rows, series, stacked, horizontal, curve, legend, valueAxis, formatValue, center, fill, }: CardChartProps): react.JSX.Element;
|
|
63
|
+
|
|
64
|
+
export { CardChart, StatChart };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The small charts inside stat cards, on Recharts. Loaded on demand by `StatCards` (its own
|
|
5
|
+
* built file, `blocks-charts`), so an app that shows no chart in a card does not need Recharts.
|
|
6
|
+
*/
|
|
7
|
+
interface StatChartPoint {
|
|
8
|
+
label: string;
|
|
9
|
+
value: number;
|
|
10
|
+
}
|
|
11
|
+
interface StatChartProps {
|
|
12
|
+
kind: 'area' | 'line' | 'bar' | 'donut';
|
|
13
|
+
points: StatChartPoint[];
|
|
14
|
+
/** The series name in the tooltip. */
|
|
15
|
+
name: string;
|
|
16
|
+
/** Segment colours for a donut, as CSS colours (`var(--chart-1)`). */
|
|
17
|
+
colors?: string[];
|
|
18
|
+
/** Formats a value in the tooltip. */
|
|
19
|
+
formatValue?: (value: number) => string;
|
|
20
|
+
/** Text inside the donut. */
|
|
21
|
+
centerLabel?: string;
|
|
22
|
+
/** `lg`: a taller trend, for a feature card. */
|
|
23
|
+
size?: 'default' | 'lg';
|
|
24
|
+
}
|
|
25
|
+
declare function StatChart({ kind, points, name, colors, formatValue, centerLabel, size, }: StatChartProps): react.JSX.Element;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The chart inside a `ChartCard`, on Recharts. Loaded on demand from the `blocks-charts` file, like
|
|
29
|
+
* the stat cards' small charts, so an app that never draws one does not need Recharts.
|
|
30
|
+
*
|
|
31
|
+
* It takes data already shaped by `ChartCard`: rows keyed `x` plus one key per series (`s0`, `s1`…),
|
|
32
|
+
* or, for a donut or pie, one row per segment.
|
|
33
|
+
*/
|
|
34
|
+
interface CardChartSeries {
|
|
35
|
+
/** The row key of the series' values. */
|
|
36
|
+
key: string;
|
|
37
|
+
label: string;
|
|
38
|
+
/** A CSS colour. */
|
|
39
|
+
color: string;
|
|
40
|
+
}
|
|
41
|
+
interface CardChartProps {
|
|
42
|
+
kind: 'area' | 'line' | 'bar' | 'donut' | 'pie';
|
|
43
|
+
/** Cartesian: `{ x, s0, s1… }`. Donut and pie: `{ x: label, value }` per segment. */
|
|
44
|
+
rows: Record<string, string | number | null>[];
|
|
45
|
+
series: CardChartSeries[];
|
|
46
|
+
stacked?: boolean;
|
|
47
|
+
/** Bars run left to right. */
|
|
48
|
+
horizontal?: boolean;
|
|
49
|
+
curve?: 'smooth' | 'linear' | 'step';
|
|
50
|
+
legend?: boolean;
|
|
51
|
+
/** Show the value axis. */
|
|
52
|
+
valueAxis?: boolean;
|
|
53
|
+
formatValue?: (value: number) => string;
|
|
54
|
+
/** The number and its label in the middle of a donut. (A donut's legend is drawn by the card.) */
|
|
55
|
+
center?: {
|
|
56
|
+
value: string;
|
|
57
|
+
label?: string;
|
|
58
|
+
};
|
|
59
|
+
/** Take the container's height instead of a fixed one. */
|
|
60
|
+
fill?: boolean;
|
|
61
|
+
}
|
|
62
|
+
declare function CardChart({ kind, rows, series, stacked, horizontal, curve, legend, valueAxis, formatValue, center, fill, }: CardChartProps): react.JSX.Element;
|
|
63
|
+
|
|
64
|
+
export { CardChart, StatChart };
|
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
// src/blocks/stat-chart.tsx
|
|
2
|
+
import { useId as useId2 } from "react";
|
|
3
|
+
import { Area, AreaChart, Bar, BarChart, Cell, Line, LineChart, Pie, PieChart, YAxis } from "recharts";
|
|
4
|
+
|
|
5
|
+
// src/components/charts/chart.tsx
|
|
6
|
+
import {
|
|
7
|
+
createContext,
|
|
8
|
+
useContext,
|
|
9
|
+
useId,
|
|
10
|
+
useMemo
|
|
11
|
+
} from "react";
|
|
12
|
+
import * as RechartsPrimitive from "recharts";
|
|
13
|
+
|
|
14
|
+
// src/lib/cn.ts
|
|
15
|
+
import { clsx } from "clsx";
|
|
16
|
+
import { twMerge } from "tailwind-merge";
|
|
17
|
+
function cn(...inputs) {
|
|
18
|
+
return twMerge(clsx(inputs));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/components/charts/chart.tsx
|
|
22
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
23
|
+
var THEMES = { light: "", dark: ".dark" };
|
|
24
|
+
var INITIAL_DIMENSION = { width: 320, height: 200 };
|
|
25
|
+
var ChartContext = createContext(null);
|
|
26
|
+
function useChart() {
|
|
27
|
+
const context = useContext(ChartContext);
|
|
28
|
+
if (!context) throw new Error("useChart must be used within a <ChartContainer />");
|
|
29
|
+
return context;
|
|
30
|
+
}
|
|
31
|
+
function ChartContainer({
|
|
32
|
+
id,
|
|
33
|
+
className,
|
|
34
|
+
children,
|
|
35
|
+
config,
|
|
36
|
+
initialDimension = INITIAL_DIMENSION,
|
|
37
|
+
...props
|
|
38
|
+
}) {
|
|
39
|
+
const uniqueId = useId();
|
|
40
|
+
const chartId = `chart-${id ?? uniqueId.replace(/:/g, "")}`;
|
|
41
|
+
return /* @__PURE__ */ jsx(ChartContext.Provider, { value: { config }, children: /* @__PURE__ */ jsxs(
|
|
42
|
+
"div",
|
|
43
|
+
{
|
|
44
|
+
"data-slot": "chart",
|
|
45
|
+
"data-chart": chartId,
|
|
46
|
+
className: cn(
|
|
47
|
+
"flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden",
|
|
48
|
+
className
|
|
49
|
+
),
|
|
50
|
+
...props,
|
|
51
|
+
children: [
|
|
52
|
+
/* @__PURE__ */ jsx(ChartStyle, { id: chartId, config }),
|
|
53
|
+
/* @__PURE__ */ jsx(RechartsPrimitive.ResponsiveContainer, { initialDimension, children })
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
) });
|
|
57
|
+
}
|
|
58
|
+
function ChartStyle({ id, config }) {
|
|
59
|
+
const colorConfig = Object.entries(config).filter(([, item]) => item.theme ?? item.color);
|
|
60
|
+
if (!colorConfig.length) return null;
|
|
61
|
+
return /* @__PURE__ */ jsx(
|
|
62
|
+
"style",
|
|
63
|
+
{
|
|
64
|
+
dangerouslySetInnerHTML: {
|
|
65
|
+
__html: Object.entries(THEMES).map(
|
|
66
|
+
([theme, prefix]) => `
|
|
67
|
+
${prefix} [data-chart=${id}] {
|
|
68
|
+
${colorConfig.map(([key, itemConfig]) => {
|
|
69
|
+
const color = itemConfig.theme?.[theme] ?? itemConfig.color;
|
|
70
|
+
return color ? ` --color-${key}: ${color};` : null;
|
|
71
|
+
}).join("\n")}
|
|
72
|
+
}
|
|
73
|
+
`
|
|
74
|
+
).join("\n")
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
var ChartTooltip = RechartsPrimitive.Tooltip;
|
|
80
|
+
function ChartTooltipContent({
|
|
81
|
+
active,
|
|
82
|
+
payload,
|
|
83
|
+
className,
|
|
84
|
+
indicator = "dot",
|
|
85
|
+
hideLabel = false,
|
|
86
|
+
hideIndicator = false,
|
|
87
|
+
label,
|
|
88
|
+
labelFormatter,
|
|
89
|
+
labelClassName,
|
|
90
|
+
formatter,
|
|
91
|
+
color,
|
|
92
|
+
nameKey,
|
|
93
|
+
labelKey
|
|
94
|
+
}) {
|
|
95
|
+
const { config } = useChart();
|
|
96
|
+
const tooltipLabel = useMemo(() => {
|
|
97
|
+
if (hideLabel || !payload?.length) return null;
|
|
98
|
+
const [item] = payload;
|
|
99
|
+
const key = `${labelKey ?? item?.dataKey ?? item?.name ?? "value"}`;
|
|
100
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
101
|
+
const value = !labelKey && typeof label === "string" ? config[label]?.label ?? label : itemConfig?.label;
|
|
102
|
+
if (labelFormatter) {
|
|
103
|
+
return /* @__PURE__ */ jsx("div", { className: cn("font-medium", labelClassName), children: labelFormatter(value, payload) });
|
|
104
|
+
}
|
|
105
|
+
if (!value) return null;
|
|
106
|
+
return /* @__PURE__ */ jsx("div", { className: cn("font-medium", labelClassName), children: value });
|
|
107
|
+
}, [label, labelFormatter, payload, hideLabel, labelClassName, config, labelKey]);
|
|
108
|
+
if (!active || !payload?.length) return null;
|
|
109
|
+
const nestLabel = payload.length === 1 && indicator !== "dot";
|
|
110
|
+
return /* @__PURE__ */ jsxs(
|
|
111
|
+
"div",
|
|
112
|
+
{
|
|
113
|
+
className: cn(
|
|
114
|
+
"grid min-w-32 items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl",
|
|
115
|
+
className
|
|
116
|
+
),
|
|
117
|
+
children: [
|
|
118
|
+
!nestLabel ? tooltipLabel : null,
|
|
119
|
+
/* @__PURE__ */ jsx("div", { className: "grid gap-1.5", children: payload.filter((item) => item.type !== "none").map((item, index) => {
|
|
120
|
+
const key = `${nameKey ?? item.name ?? item.dataKey ?? "value"}`;
|
|
121
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
122
|
+
const indicatorColor = color ?? item.payload?.fill ?? item.color;
|
|
123
|
+
return /* @__PURE__ */ jsx(
|
|
124
|
+
"div",
|
|
125
|
+
{
|
|
126
|
+
className: cn(
|
|
127
|
+
"flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground",
|
|
128
|
+
indicator === "dot" && "items-center"
|
|
129
|
+
),
|
|
130
|
+
children: formatter && item?.value !== void 0 && item.name ? formatter(item.value, item.name, item, index, item.payload) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
131
|
+
itemConfig?.icon ? /* @__PURE__ */ jsx(itemConfig.icon, {}) : !hideIndicator && /* @__PURE__ */ jsx(
|
|
132
|
+
"div",
|
|
133
|
+
{
|
|
134
|
+
className: cn("shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)", {
|
|
135
|
+
"h-2.5 w-2.5": indicator === "dot",
|
|
136
|
+
"w-1": indicator === "line",
|
|
137
|
+
"w-0 border-[1.5px] border-dashed bg-transparent": indicator === "dashed",
|
|
138
|
+
"my-0.5": nestLabel && indicator === "dashed"
|
|
139
|
+
}),
|
|
140
|
+
style: { "--color-bg": indicatorColor, "--color-border": indicatorColor }
|
|
141
|
+
}
|
|
142
|
+
),
|
|
143
|
+
/* @__PURE__ */ jsxs("div", { className: cn("flex flex-1 justify-between leading-none", nestLabel ? "items-end" : "items-center"), children: [
|
|
144
|
+
/* @__PURE__ */ jsxs("div", { className: "grid gap-1.5", children: [
|
|
145
|
+
nestLabel ? tooltipLabel : null,
|
|
146
|
+
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: itemConfig?.label ?? item.name })
|
|
147
|
+
] }),
|
|
148
|
+
item.value != null && /* @__PURE__ */ jsx("span", { className: "font-mono font-medium text-foreground tabular-nums", children: typeof item.value === "number" ? item.value.toLocaleString() : String(item.value) })
|
|
149
|
+
] })
|
|
150
|
+
] })
|
|
151
|
+
},
|
|
152
|
+
index
|
|
153
|
+
);
|
|
154
|
+
}) })
|
|
155
|
+
]
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
var ChartLegend = RechartsPrimitive.Legend;
|
|
160
|
+
function ChartLegendContent({ className, hideIcon = false, payload, verticalAlign = "bottom", nameKey }) {
|
|
161
|
+
const { config } = useChart();
|
|
162
|
+
if (!payload?.length) return null;
|
|
163
|
+
return /* @__PURE__ */ jsx("div", { className: cn("flex items-center justify-center gap-4", verticalAlign === "top" ? "pb-3" : "pt-3", className), children: payload.filter((item) => item.type !== "none").map((item, index) => {
|
|
164
|
+
const key = `${nameKey ?? item.dataKey ?? "value"}`;
|
|
165
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
166
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground", children: [
|
|
167
|
+
itemConfig?.icon && !hideIcon ? /* @__PURE__ */ jsx(itemConfig.icon, {}) : /* @__PURE__ */ jsx("div", { className: "h-2 w-2 shrink-0 rounded-[2px]", style: { backgroundColor: item.color } }),
|
|
168
|
+
itemConfig?.label
|
|
169
|
+
] }, index);
|
|
170
|
+
}) });
|
|
171
|
+
}
|
|
172
|
+
function getPayloadConfigFromPayload(config, payload, key) {
|
|
173
|
+
if (typeof payload !== "object" || payload === null) return void 0;
|
|
174
|
+
const payloadPayload = "payload" in payload && typeof payload.payload === "object" && payload.payload !== null ? payload.payload : void 0;
|
|
175
|
+
let configLabelKey = key;
|
|
176
|
+
if (key in payload && typeof payload[key] === "string") {
|
|
177
|
+
configLabelKey = payload[key];
|
|
178
|
+
} else if (payloadPayload && key in payloadPayload && typeof payloadPayload[key] === "string") {
|
|
179
|
+
configLabelKey = payloadPayload[key];
|
|
180
|
+
}
|
|
181
|
+
return configLabelKey in config ? config[configLabelKey] : config[key];
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// src/blocks/stat-chart.tsx
|
|
185
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
186
|
+
function StatChart({
|
|
187
|
+
kind,
|
|
188
|
+
points,
|
|
189
|
+
name,
|
|
190
|
+
colors = [],
|
|
191
|
+
formatValue,
|
|
192
|
+
centerLabel,
|
|
193
|
+
size = "default"
|
|
194
|
+
}) {
|
|
195
|
+
const gradient = useId2().replace(/:/g, "");
|
|
196
|
+
const config = { value: { label: name, color: "var(--chart-1)" } };
|
|
197
|
+
const tooltip = /* @__PURE__ */ jsx2(
|
|
198
|
+
ChartTooltip,
|
|
199
|
+
{
|
|
200
|
+
cursor: false,
|
|
201
|
+
content: /* @__PURE__ */ jsx2(
|
|
202
|
+
ChartTooltipContent,
|
|
203
|
+
{
|
|
204
|
+
hideIndicator: kind !== "donut",
|
|
205
|
+
formatter: (value, _name, item) => /* @__PURE__ */ jsxs2("span", { className: "flex w-full justify-between gap-3", children: [
|
|
206
|
+
/* @__PURE__ */ jsx2("span", { className: "text-muted-foreground", children: String(item.payload?.label ?? "") }),
|
|
207
|
+
/* @__PURE__ */ jsx2("span", { className: "font-medium tabular-nums", children: formatValue ? formatValue(Number(value)) : String(value) })
|
|
208
|
+
] }),
|
|
209
|
+
hideLabel: true
|
|
210
|
+
}
|
|
211
|
+
)
|
|
212
|
+
}
|
|
213
|
+
);
|
|
214
|
+
if (kind === "donut") {
|
|
215
|
+
return /* @__PURE__ */ jsx2(ChartContainer, { config, className: "aspect-square h-24 w-24", children: /* @__PURE__ */ jsxs2(PieChart, { children: [
|
|
216
|
+
tooltip,
|
|
217
|
+
/* @__PURE__ */ jsx2(Pie, { data: points, dataKey: "value", nameKey: "label", innerRadius: 30, outerRadius: 44, strokeWidth: 2, children: points.map((point, index) => /* @__PURE__ */ jsx2(Cell, { fill: colors[index] ?? `var(--chart-${index % 5 + 1})` }, point.label)) }),
|
|
218
|
+
centerLabel && /* @__PURE__ */ jsx2(
|
|
219
|
+
"text",
|
|
220
|
+
{
|
|
221
|
+
x: "50%",
|
|
222
|
+
y: "50%",
|
|
223
|
+
textAnchor: "middle",
|
|
224
|
+
dominantBaseline: "middle",
|
|
225
|
+
className: "fill-foreground text-sm font-semibold",
|
|
226
|
+
children: centerLabel
|
|
227
|
+
}
|
|
228
|
+
)
|
|
229
|
+
] }) });
|
|
230
|
+
}
|
|
231
|
+
const margin = { top: 4, right: 0, bottom: 0, left: 0 };
|
|
232
|
+
return /* @__PURE__ */ jsx2(ChartContainer, { config, className: size === "lg" ? "aspect-auto h-28 w-full" : "aspect-auto h-16 w-full", children: kind === "bar" ? /* @__PURE__ */ jsxs2(BarChart, { data: points, margin, children: [
|
|
233
|
+
tooltip,
|
|
234
|
+
/* @__PURE__ */ jsx2(YAxis, { hide: true, domain: [0, "auto"] }),
|
|
235
|
+
/* @__PURE__ */ jsx2(Bar, { dataKey: "value", fill: "var(--color-value)", fillOpacity: 0.85, radius: 3, maxBarSize: 14 })
|
|
236
|
+
] }) : kind === "line" ? /* @__PURE__ */ jsxs2(LineChart, { data: points, margin, children: [
|
|
237
|
+
tooltip,
|
|
238
|
+
/* @__PURE__ */ jsx2(YAxis, { hide: true, domain: ["dataMin", "dataMax"] }),
|
|
239
|
+
/* @__PURE__ */ jsx2(Line, { dataKey: "value", type: "monotone", stroke: "var(--color-value)", strokeWidth: 2, dot: false })
|
|
240
|
+
] }) : /* @__PURE__ */ jsxs2(AreaChart, { data: points, margin, children: [
|
|
241
|
+
/* @__PURE__ */ jsx2("defs", { children: /* @__PURE__ */ jsxs2("linearGradient", { id: gradient, x1: "0", y1: "0", x2: "0", y2: "1", children: [
|
|
242
|
+
/* @__PURE__ */ jsx2("stop", { offset: "5%", stopColor: "var(--color-value)", stopOpacity: 0.4 }),
|
|
243
|
+
/* @__PURE__ */ jsx2("stop", { offset: "95%", stopColor: "var(--color-value)", stopOpacity: 0.05 })
|
|
244
|
+
] }) }),
|
|
245
|
+
tooltip,
|
|
246
|
+
/* @__PURE__ */ jsx2(YAxis, { hide: true, domain: ["dataMin", "dataMax"] }),
|
|
247
|
+
/* @__PURE__ */ jsx2(
|
|
248
|
+
Area,
|
|
249
|
+
{
|
|
250
|
+
baseValue: "dataMin",
|
|
251
|
+
dataKey: "value",
|
|
252
|
+
type: "monotone",
|
|
253
|
+
stroke: "var(--color-value)",
|
|
254
|
+
strokeWidth: 2,
|
|
255
|
+
fill: `url(#${gradient})`
|
|
256
|
+
}
|
|
257
|
+
)
|
|
258
|
+
] }) });
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// src/blocks/card-chart.tsx
|
|
262
|
+
import { useId as useId3 } from "react";
|
|
263
|
+
import {
|
|
264
|
+
Area as Area2,
|
|
265
|
+
AreaChart as AreaChart2,
|
|
266
|
+
Bar as Bar2,
|
|
267
|
+
BarChart as BarChart2,
|
|
268
|
+
CartesianGrid,
|
|
269
|
+
Cell as Cell2,
|
|
270
|
+
Label,
|
|
271
|
+
Line as Line2,
|
|
272
|
+
LineChart as LineChart2,
|
|
273
|
+
Pie as Pie2,
|
|
274
|
+
PieChart as PieChart2,
|
|
275
|
+
XAxis,
|
|
276
|
+
YAxis as YAxis2
|
|
277
|
+
} from "recharts";
|
|
278
|
+
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
279
|
+
var CURVE = { smooth: "monotone", linear: "linear", step: "step" };
|
|
280
|
+
function CardChart({
|
|
281
|
+
kind,
|
|
282
|
+
rows,
|
|
283
|
+
series,
|
|
284
|
+
stacked = false,
|
|
285
|
+
horizontal = false,
|
|
286
|
+
curve = "smooth",
|
|
287
|
+
legend = false,
|
|
288
|
+
valueAxis = false,
|
|
289
|
+
formatValue,
|
|
290
|
+
center,
|
|
291
|
+
fill = false
|
|
292
|
+
}) {
|
|
293
|
+
const gradient = useId3().replace(/:/g, "");
|
|
294
|
+
const config = Object.fromEntries(series.map((s) => [s.key, { label: s.label, color: s.color }]));
|
|
295
|
+
const format = (value) => formatValue && typeof value === "number" ? formatValue(value) : String(value);
|
|
296
|
+
const size = fill ? "aspect-auto h-full min-h-40 w-full" : "aspect-auto h-60 w-full";
|
|
297
|
+
if (kind === "donut" || kind === "pie") {
|
|
298
|
+
return /* @__PURE__ */ jsx3(
|
|
299
|
+
ChartContainer,
|
|
300
|
+
{
|
|
301
|
+
config,
|
|
302
|
+
className: cn("mx-auto aspect-square", fill ? "h-full max-h-full min-h-40" : "max-h-60"),
|
|
303
|
+
children: /* @__PURE__ */ jsxs3(PieChart2, { children: [
|
|
304
|
+
/* @__PURE__ */ jsx3(
|
|
305
|
+
ChartTooltip,
|
|
306
|
+
{
|
|
307
|
+
cursor: false,
|
|
308
|
+
content: /* @__PURE__ */ jsx3(ChartTooltipContent, { hideLabel: true, nameKey: "key", formatter: tooltipRow(format, config) })
|
|
309
|
+
}
|
|
310
|
+
),
|
|
311
|
+
/* @__PURE__ */ jsxs3(
|
|
312
|
+
Pie2,
|
|
313
|
+
{
|
|
314
|
+
data: rows,
|
|
315
|
+
dataKey: "value",
|
|
316
|
+
nameKey: "key",
|
|
317
|
+
innerRadius: kind === "donut" ? "58%" : 0,
|
|
318
|
+
outerRadius: "88%",
|
|
319
|
+
strokeWidth: 2,
|
|
320
|
+
stroke: "var(--card)",
|
|
321
|
+
children: [
|
|
322
|
+
rows.map((row, index) => /* @__PURE__ */ jsx3(Cell2, { fill: series[index]?.color }, String(row.key))),
|
|
323
|
+
kind === "donut" && center && /* @__PURE__ */ jsx3(
|
|
324
|
+
Label,
|
|
325
|
+
{
|
|
326
|
+
content: ({ viewBox }) => {
|
|
327
|
+
if (!viewBox || !("cx" in viewBox) || !("cy" in viewBox)) return null;
|
|
328
|
+
const cx = Number(viewBox.cx);
|
|
329
|
+
const cy = Number(viewBox.cy);
|
|
330
|
+
return /* @__PURE__ */ jsxs3("text", { x: cx, y: cy, textAnchor: "middle", dominantBaseline: "middle", children: [
|
|
331
|
+
/* @__PURE__ */ jsx3("tspan", { x: cx, y: center.label ? cy - 6 : cy, className: "fill-foreground text-2xl font-semibold", children: center.value }),
|
|
332
|
+
center.label && /* @__PURE__ */ jsx3("tspan", { x: cx, y: cy + 16, className: "fill-muted-foreground text-xs", children: center.label })
|
|
333
|
+
] });
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
)
|
|
337
|
+
]
|
|
338
|
+
}
|
|
339
|
+
)
|
|
340
|
+
] })
|
|
341
|
+
}
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
const tooltip = /* @__PURE__ */ jsx3(
|
|
345
|
+
ChartTooltip,
|
|
346
|
+
{
|
|
347
|
+
cursor: kind === "bar",
|
|
348
|
+
content: /* @__PURE__ */ jsx3(ChartTooltipContent, { indicator: kind === "bar" ? "dot" : "line", formatter: tooltipRow(format, config) })
|
|
349
|
+
}
|
|
350
|
+
);
|
|
351
|
+
const labelWidth = Math.min(160, Math.max(48, 12 + 7 * Math.max(0, ...rows.map((row) => String(row.x ?? "").length))));
|
|
352
|
+
const legendNode = legend ? /* @__PURE__ */ jsx3(ChartLegend, { content: /* @__PURE__ */ jsx3(ChartLegendContent, {}), className: "flex-wrap" }) : null;
|
|
353
|
+
const categoryAxis = horizontal ? /* @__PURE__ */ jsx3(YAxis2, { dataKey: "x", type: "category", tickLine: false, axisLine: false, tickMargin: 8, width: labelWidth }) : /* @__PURE__ */ jsx3(XAxis, { dataKey: "x", tickLine: false, axisLine: false, tickMargin: 8, minTickGap: 16, interval: "preserveStartEnd" });
|
|
354
|
+
const numberAxis = horizontal ? /* @__PURE__ */ jsx3(XAxis, { type: "number", hide: !valueAxis, tickLine: false, axisLine: false, tickFormatter: format }) : /* @__PURE__ */ jsx3(YAxis2, { hide: !valueAxis, tickLine: false, axisLine: false, tickMargin: 4, width: valueAxis ? 48 : 0, tickFormatter: format });
|
|
355
|
+
const margin = { top: 8, right: 8, bottom: 0, left: valueAxis || horizontal ? 0 : 8 };
|
|
356
|
+
if (kind === "bar") {
|
|
357
|
+
return /* @__PURE__ */ jsx3(ChartContainer, { config, className: size, children: /* @__PURE__ */ jsxs3(BarChart2, { data: rows, layout: horizontal ? "vertical" : "horizontal", margin, accessibilityLayer: true, children: [
|
|
358
|
+
/* @__PURE__ */ jsx3(CartesianGrid, { vertical: horizontal, horizontal: !horizontal }),
|
|
359
|
+
categoryAxis,
|
|
360
|
+
numberAxis,
|
|
361
|
+
tooltip,
|
|
362
|
+
series.map((s, index) => /* @__PURE__ */ jsx3(
|
|
363
|
+
Bar2,
|
|
364
|
+
{
|
|
365
|
+
dataKey: s.key,
|
|
366
|
+
fill: `var(--color-${s.key})`,
|
|
367
|
+
stackId: stacked ? "stack" : void 0,
|
|
368
|
+
radius: stacked ? index === series.length - 1 ? horizontal ? [0, 4, 4, 0] : [4, 4, 0, 0] : 0 : 4,
|
|
369
|
+
maxBarSize: 40
|
|
370
|
+
},
|
|
371
|
+
s.key
|
|
372
|
+
)),
|
|
373
|
+
legendNode
|
|
374
|
+
] }) });
|
|
375
|
+
}
|
|
376
|
+
if (kind === "line") {
|
|
377
|
+
return /* @__PURE__ */ jsx3(ChartContainer, { config, className: size, children: /* @__PURE__ */ jsxs3(LineChart2, { data: rows, margin, accessibilityLayer: true, children: [
|
|
378
|
+
/* @__PURE__ */ jsx3(CartesianGrid, { vertical: false }),
|
|
379
|
+
categoryAxis,
|
|
380
|
+
numberAxis,
|
|
381
|
+
tooltip,
|
|
382
|
+
series.map((s) => /* @__PURE__ */ jsx3(
|
|
383
|
+
Line2,
|
|
384
|
+
{
|
|
385
|
+
dataKey: s.key,
|
|
386
|
+
type: CURVE[curve],
|
|
387
|
+
stroke: `var(--color-${s.key})`,
|
|
388
|
+
strokeWidth: 2,
|
|
389
|
+
dot: false,
|
|
390
|
+
connectNulls: true
|
|
391
|
+
},
|
|
392
|
+
s.key
|
|
393
|
+
)),
|
|
394
|
+
legendNode
|
|
395
|
+
] }) });
|
|
396
|
+
}
|
|
397
|
+
return /* @__PURE__ */ jsx3(ChartContainer, { config, className: size, children: /* @__PURE__ */ jsxs3(AreaChart2, { data: rows, margin, accessibilityLayer: true, children: [
|
|
398
|
+
/* @__PURE__ */ jsx3("defs", { children: series.map((s) => /* @__PURE__ */ jsxs3("linearGradient", { id: `${gradient}-${s.key}`, x1: "0", y1: "0", x2: "0", y2: "1", children: [
|
|
399
|
+
/* @__PURE__ */ jsx3("stop", { offset: "5%", stopColor: `var(--color-${s.key})`, stopOpacity: 0.6 }),
|
|
400
|
+
/* @__PURE__ */ jsx3("stop", { offset: "95%", stopColor: `var(--color-${s.key})`, stopOpacity: 0.05 })
|
|
401
|
+
] }, s.key)) }),
|
|
402
|
+
/* @__PURE__ */ jsx3(CartesianGrid, { vertical: false }),
|
|
403
|
+
categoryAxis,
|
|
404
|
+
numberAxis,
|
|
405
|
+
tooltip,
|
|
406
|
+
series.map((s) => /* @__PURE__ */ jsx3(
|
|
407
|
+
Area2,
|
|
408
|
+
{
|
|
409
|
+
dataKey: s.key,
|
|
410
|
+
type: CURVE[curve],
|
|
411
|
+
stroke: `var(--color-${s.key})`,
|
|
412
|
+
strokeWidth: 2,
|
|
413
|
+
fill: `url(#${gradient}-${s.key})`,
|
|
414
|
+
stackId: stacked ? "stack" : void 0,
|
|
415
|
+
connectNulls: true
|
|
416
|
+
},
|
|
417
|
+
s.key
|
|
418
|
+
)),
|
|
419
|
+
legendNode
|
|
420
|
+
] }) });
|
|
421
|
+
}
|
|
422
|
+
function tooltipRow(format, config) {
|
|
423
|
+
return (value, name, item) => /* @__PURE__ */ jsxs3("span", { className: "flex w-full items-center gap-2", children: [
|
|
424
|
+
/* @__PURE__ */ jsx3(
|
|
425
|
+
"span",
|
|
426
|
+
{
|
|
427
|
+
"aria-hidden": true,
|
|
428
|
+
className: "size-2.5 shrink-0 rounded-[2px]",
|
|
429
|
+
style: { background: item.color ?? item.payload?.fill }
|
|
430
|
+
}
|
|
431
|
+
),
|
|
432
|
+
/* @__PURE__ */ jsx3("span", { className: "text-muted-foreground", children: config[String(name)]?.label ?? String(name) }),
|
|
433
|
+
/* @__PURE__ */ jsx3("span", { className: "ms-auto font-medium text-foreground tabular-nums", children: format(value) })
|
|
434
|
+
] });
|
|
435
|
+
}
|
|
436
|
+
export {
|
|
437
|
+
CardChart,
|
|
438
|
+
StatChart
|
|
439
|
+
};
|
|
440
|
+
//# sourceMappingURL=blocks-charts.js.map
|