chartAreaAxes
A Charts block/component from shadcn/ui — clean-room reimplemented for Domphy (see methodology). Call chartAreaAxes() with no arguments for a working demo, or edit the code below live.
Implementation notes
Two-series overlapping area chart with a real sparse y-axis (splitNumber, no axis line/tick, floating labels) and horizontal-only gridlines (yAxis.splitLine on, xAxis.splitLine off) via @domphy/chart's native AxisOption/GridOption support — no approximation needed for the axes themselves. Same mount-reveal approximation caveat as chartAreaDefault.
Status: partial · Reference: shadcn/ui original
// shadcn/ui "chart-area" (axes recipe) — clean-room reimplementation.
//
// The same two-series area chart as the gradient/legend recipes, but with a
// visible y-axis (a sparse handful of value labels) alongside the x-axis
// month labels, plus faint horizontal-only background gridlines. Neither
// axis draws a heavy line or tick marks — just floating text labels near the
// plot edges.
//
// Implemented purely from the block's public functional/visual spec — no
// upstream shadcn/ui source was viewed or copied.
import type { DomphyElement } from "@domphy/core";
import type { ChartOption } from "@domphy/chart";
import type { ThemeColor } from "@domphy/theme";
import {
CHART_AREA_SERIES_PALETTE,
CHART_AREA_TWO_SERIES_DATA,
CHART_AREA_X_AXIS_BARE,
chartAreaFrame,
chartAxisTooltipFormatter,
chartCardShell,
type ChartAreaTwoSeriesPoint,
} from "./chart-area-shared.js";
export interface ChartAreaAxesSeries {
key: "desktop" | "mobile";
label: string;
color: ThemeColor;
}
export interface ChartAreaAxesProps {
data?: ChartAreaTwoSeriesPoint[];
series?: ChartAreaAxesSeries[];
/** Number of y-axis ticks to show. Defaults to a sparse 3. */
yAxisTickCount?: number;
title?: string;
description?: string;
height?: number;
}
const DEFAULT_SERIES: ChartAreaAxesSeries[] = [
{ key: "desktop", label: "Desktop", color: CHART_AREA_SERIES_PALETTE[0] },
{ key: "mobile", label: "Mobile", color: CHART_AREA_SERIES_PALETTE[1] },
];
/**
* shadcn/ui "chart-area" axes recipe — a two-series area chart with a
* sparse y-axis and horizontal-only gridlines. Call with no arguments for a
* working demo.
*/
function chartAreaAxes(props: ChartAreaAxesProps = {}): DomphyElement<"div"> {
const {
data = CHART_AREA_TWO_SERIES_DATA,
series = DEFAULT_SERIES,
yAxisTickCount = 3,
title = "Area Chart - Axes",
description = "Showing total visitors for the last 6 months",
height = 64,
} = props;
const categories = data.map((point) => point.month);
const option: ChartOption = {
tooltip: {
trigger: "axis",
formatter: chartAxisTooltipFormatter(categories),
},
xAxis: { ...CHART_AREA_X_AXIS_BARE, data: categories },
yAxis: {
type: "value",
splitNumber: yAxisTickCount,
axisLine: { show: false },
axisTick: { show: false },
// Horizontal-only gridlines — the x-axis above keeps its splitLine off.
splitLine: { show: true },
},
grid: { left: 40, right: 8, top: 12, bottom: 24, containLabel: false },
series: series.map((s) => ({
type: "line",
name: s.label,
smooth: true,
showSymbol: false,
color: s.color,
lineStyle: { width: 2 },
areaStyle: { opacity: 0.4 },
data: data.map((point) => point[s.key]),
})),
};
return chartCardShell({
title,
description,
content: { div: [chartAreaFrame(option, height)] },
});
}
export { chartAreaAxes };