How Layer Cake works (Core Concepts)
mainLayer Cake is a "headless" graphics framework for Svelte. Unlike high-level charting libraries, it does not provide pre-built charts (like scatter or bar charts). Instead, it provides the coordinate system, scales, and empty containers (layout components) to help you build your own custom layers.
Key Mental Models:
- Custom Layers: All chart elements (axes, plots, annotations) are components you create within your own project. Layer Cake only provides the infrastructure.
- Data Extents: Layer Cake uses a flat array of objects to measure data extents. If your data is complex (e.g., multi-series), pass a flat array to the
flatDataprop so accessors can calculate scale extents correctly. - Scale Logic:
- For categorical scales (
scaleBand,scalePoint,scaleOrdinal), Layer Cake uses the unique values in your data as the extent. - For continuous scales (e.g.,
scaleLinear), it uses the[min, max]values. - Y-Scale Inversion: For non-categorical y-scales, Layer Cake defaults the range to
[height, 0]to match the DOM coordinate system, making drawing easier.
- For categorical scales (