Archived

Documentation for Layer Cake v10, before Svelte 5 runes. Current docs at layercake.graphics

Menu

Line.svelte component

Generates an SVG line shape.

Param Default Required Description
stroke string '#ab00d6'
no
The line's stroke color.

Used in these examples:

SSR Examples:

<!--
  @component
  Generates an SVG line shape.
 -->
<script>
  import { getLayerCakeContext } from 'layercake';

  const k = getLayerCakeContext();

  /**
   * @typedef {Object} Props
   * @property {string} [stroke='#ab00d6'] - The line's stroke color.
   */

  /** @type {Props} */
  let { stroke = '#ab00d6' } = $props();

  let path = $derived(
    'M' +
      k.data
        .map(d => {
          return k.xGet(d) + ',' + k.yGet(d);
        })
        .join('L')
  );
</script>

<path class="path-line" d={path} {stroke}></path>

<style>
  .path-line {
    fill: none;
    stroke-linejoin: round;
    stroke-linecap: round;
    stroke-width: 2px;
  }
</style>