// Expert guide for LayerChart, a Svelte component library for building diverse data visualizations (Cartesian, radial, hierarchical, geo, graph) with unopinionated building blocks, motion primitives, and advanced interactions.
| name | layerchart |
| description | Expert guide for LayerChart, a Svelte component library for building diverse data visualizations (Cartesian, radial, hierarchical, geo, graph) with unopinionated building blocks, motion primitives, and advanced interactions. |
| license | MIT |
LayerChart is a comprehensive Svelte visualization framework built on Layer Cake, providing composable components for creating responsive, interactive charts across multiple visualization types.
LayerChart operates on a component-based, data-driven philosophy. The library provides three primary categories of components:
Data-Driven Components render visual marks directly from data (Area, Bars, Spline, Pie, Sunburst, Treemap, Sankey, etc.). These components automatically handle scale transformations through LayerCake's context.
Motion-Enabled SVG Primitives (Rect, Circle, Arc, Group, Line, Path) provide low-level drawing utilities with built-in Svelte transition support for animated data updates.
Utility Components handle legends, tooltips, pan/zoom interactions, annotations, and layout operations (hierarchy, geo projections).
Use LayerChart's data transformation utilities before passing to visualizations:
stack() - converts wide-format data into stacked series with baseline/top valuesbin() - groups data into histogram bins with x0/x1 boundsgroupLonger() - pivots wide-format to long-format (one row per value)flatten() - flattens nested arrays one level, with optional accessorcalcExtents() - calculates min/max across multiple fields, skipping nullsAll LayerChart visualizations sit within a LayerCake wrapper that establishes scales and context. Child components access scales via Svelte's context API.
<LayerCake x="date" y="value" data={data} padding={{...}}>
<Svg>
<Area />
<Line />
<AxisX />
</Svg>
<Canvas>
<Points /> <!-- High-performance canvas rendering -->
</Canvas>
<Html>
<Tooltip />
</Html>
</LayerCake>
LayerChart automatically handles responsive layouts via padding configuration and container dimensions. Components reactively update when data or scales change.
Bar Charts: Use Bars component with x as categorical field. Stack with BarStack or group with BarGroup for multi-series.
Time Series: Configure xScale={scaleTime()} with temporal data. Use AxisX with tickFormat for readable date labels.
Geographic Visualizations: Select appropriate projection (Mercator for web maps, Azimuthal for polar), use GeoPath for boundaries, Choropleth for value mapping.
High-Volume Data: Render marks via Canvas instead of SVG for 5000+ points. Layer SVG axes/legends with Canvas for hybrid rendering.
Stacked/Grouped Series: Use stack() utility to transform data, then render via AreaStack/BarStack components.
All primitive components support standard SVG/Canvas attributes (stroke, fill, opacity, strokeWidth). Use Svelte's reactive statements for conditional styling based on interaction state or data values.
Gradient fills, patterns, and clipping available via ClipPath, RectClipPath, CircleClipPath components with SVG <defs>.