Layer Cake

A graphics framework for Svelte

README

Layer Cake  


a framework for mostly-reusable graphics with svelte


🍰 API docs

Svelte versions


Works Svelte 3 and Svelte 4

Install


  1. ```sh
  2. npm install --save layercake
  3. ```

Example


  1. ```svelte
  2. <script>
  3.   // The library provides a main wrapper component
  4.   // and a bunch empty layout components...
  5.   import { LayerCake, Svg, Html, Canvas } from 'layercake';

  6.   // ...that you fill with your own chart components,
  7.   // that live inside your project and which you
  8.   // can copy and paste from here as starting points.
  9.   import AxisX from './components/AxisX.svelte';
  10.   import AxisY from './components/AxisY.svelte';
  11.   import Line from './components/Line.svelte';
  12.   import Scatter from './components/Scatter.svelte';
  13.   import Labels from './components/Labels.svelte';

  14.   const data = [{ x: 0, y: 1 }, { x: 1, y: 2 }, { x: 2, y: 3 }];
  15. </script>

  16. <style>
  17.   .chart-container {
  18.     width: 100%;
  19.     height: 500px;
  20.   }
  21. </style>

  22. <div class="chart-container">
  23.   <LayerCake
  24.     x='x'
  25.     y='y'
  26.     {data}
  27.   >
  28.     <Svg>
  29.       <AxisX/>
  30.       <AxisY/>
  31.       <Line color='#f0c'/>
  32.     </Svg>

  33.     <Canvas>
  34.       <Scatter color='#0fc'/>
  35.     </Canvas>

  36.     <Html>
  37.       <Labels/>
  38.     </Html>
  39.   </LayerCake>
  40. </div>
  41. ```

License


MIT