AutoscaleChart
neon-ui/autoscale-chartFreeComponent
Autoscaling compute units over time against the min/max bounds, with a scrubable readout.
Install it
npx shadcn@latest add https://ui.neon.com/r/autoscale-chart.jsonSource
1"use client";23import { useId } from "react";4import type { ComponentProps } from "react";5import {6 Area,7 AreaChart,8 ReferenceArea,9 ReferenceLine,10 XAxis,11 YAxis,12} from "recharts";1314import type { ChartConfig } from "@/components/ui/chart";15import {16 ChartContainer,17 ChartTooltip,18 ChartTooltipContent,19} from "@/components/ui/chart";20import { Skeleton } from "@/components/ui/skeleton";21import { cn } from "@/lib/utils";2223export interface AutoscalePoint {24 /** Short time label, e.g. "12:00". */25 label: string;26 /** Compute units in use at this moment. */27 cu: number;28}2930const HEADROOM = 1.08;31const NICE_STEPS = [1, 2, 2.5, 5, 10] as const;3233/**34 * Rounds the top of the scale to a readable number. Left at peak x 1.0835 * the axis reads 4.32, which is a number nobody asked for.36 */37const niceCeiling = (peak: number) => {38 const raw = peak * HEADROOM;3940 if (raw <= 0) {41 return 1;42 }4344 const magnitude = 10 ** Math.floor(Math.log10(raw));45 const normalized = raw / magnitude;46 const step = NICE_STEPS.find((candidate) => normalized <= candidate) ?? 10;4748 return step * magnitude;49};5051const formatCu = (cu: number) => {52 const rounded = Math.round(cu * 100) / 100;5354 return Number.isInteger(rounded) ? String(rounded) : rounded.toFixed(2);55};5657export type AutoscaleChartProps = Omit<ComponentProps<"div">, "children"> & {58 /** Compute-unit readings over time, oldest first. */59 data: AutoscalePoint[];60 /** Autoscale lower bound (CU); the compute never scales below it. */61 min: number;62 /** Autoscale upper bound (CU); the compute never scales above it. */63 max: number;64 /** Panel heading. */65 title?: string;66 isLoading?: boolean;67};6869/* ─────────────────────────────────────────────────────────70 * AUTOSCALE STORYBOARD71 *72 * envelope the band between min and max is drawn first,73 * so the reading is always seen against the74 * room it has to move in75 * bounds dashed lines with mono labels at both edges;76 * a ceiling you can't see is a ceiling you'll77 * hit without knowing78 * scrub Recharts' accessibility layer gives the plot79 * focus and arrow keys; the tooltip names the80 * moment and its CU81// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from neon-ui
All 77 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ActivityFeedactivity-feed | neon-ui | Components | Free | 2 deps | |
| AgentChatagent-chat | neon-ui | Components | Free | 6 deps | |
| AnimatedWashanimated-wash | neon-ui | Components | Free | no deps · 2 files | |
| ApiKeyListapi-key-list | neon-ui | Components | Free | 2 deps | |
| AppCardapp-card | neon-ui | Components | Free | 2 deps | |
| AppCreatorapp-creator | neon-ui | Components | Free | 2 deps | |
| AuthFormauth-form | neon-ui | Components | Free | no deps | |
| Badgebadge | neon-ui | Components | Free | 2 deps |
