LayerCake is a lightweight, opinionated graphics framework designed for building highly customizable and reusable data visualizations with Svelte. It emphasizes a clear separation between the data layering, scaling, and rendering logic, allowing developers to bring their own Svelte components for charts and annotations. The current stable version is 10.0.2, with major versions released somewhat frequently to align with Svelte's evolution (e.g., Svelte 5 'Runes' support in v9/v10). Key differentiators include its Svelte-native component approach, making it highly composable and performant within a Svelte application, and its flexibility in rendering to SVG, HTML, or Canvas elements without dictating visual styles.
npm install layercakeVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to set up a basic LayerCake chart using `LayerCake` as the primary wrapper, and rendering different chart elements to `Svg`, `Canvas`, and `Html` containers. It also shows how to define accessor functions for data properties.
Review your `Svg` component usage. The `innerElement` binding is no longer available. Most use cases for this binding might be achievable through direct DOM manipulation within Svelte or by rethinking the component structure.
Consult the v9.0.0 changelog. Ensure your Svelte setup supports Runes, and update any custom components that interact with layout or domain sorting. If using Svelte 3 or 4, stick to LayerCake v8.4.4 or older.
If you require unsorted ordinal domains in v8.0.0, you will need to upgrade to v8.1.0 or newer and use the new option to disable sorting. For earlier versions, review the changelog for `sorted` prop usage.
If targeting Svelte 5, use LayerCake v9.0.0 or higher. If you need Svelte 3 or 4 compatibility, explicitly install `layercake@8.4.4`. Consult the `layercake-prerunes` documentation archive for Svelte 3/4 examples.
Familiarize yourself with Svelte's context and slot prop mechanisms. The LayerCake examples and guide extensively demonstrate their usage for passing scales, dimensions, and data down the component tree.
Downgrade LayerCake to `8.4.4` to maintain compatibility with Svelte 3/4: `npm install layercake@8.4.4`.
Ensure your custom component is nested within a LayerCake layout component (`<Svg>`, `<Html>`, `<Canvas>`) and that you are correctly receiving context values via `getContext` or using `let:xScale` on the slot if it's exposed that way, as shown in the LayerCake examples.
Prefer ESM `import { ... } from 'layercake';` syntax. If you are forced to use CommonJS, ensure your build setup correctly handles ESM imports (e.g., Babel or Webpack configured with `esm` support or consider dynamic `import('layercake')`).