Line-D3.svelte component
Generates an SVG line shape using the line
function from d3-shape.
Param | Default | Required | Description |
---|---|---|---|
stroke string |
'#ab00d6' |
The shape's fill color. This is technically optional because it comes with a default value but you'll likely want to replace it with your own color. | |
curve CurveFactory |
curveLinear |
An optional D3 interpolation function. See d3-shape for options. Pass this function in uncalled, i.e. without the open-close parentheses. |
<!--
@component
Generates an SVG line shape using the `line` function from [d3-shape](https://github.com/d3/d3-shape).
-->
<script>
import { getContext } from 'svelte';
import { line, curveLinear } from 'd3-shape';
const { data, xGet, yGet } = getContext('LayerCake');
/** @typedef {import('d3-shape').CurveFactory} CurveFactory */
/**
* @typedef {Object} Props
* @property {string} [stroke='#ab00d6'] - The shape's fill color. This is technically optional because it comes with a default value but you'll likely want to replace it with your own color.
* @property {CurveFactory} [curve=curveLinear] - An optional D3 interpolation function. See [d3-shape](https://github.com/d3/d3-shape#curves) for options. Pass this function in uncalled, i.e. without the open-close parentheses.
*/
/** @type {Props} */
let { stroke = '#ab00d6', curve = curveLinear } = $props();
let path = $derived(line().x($xGet).y($yGet).curve(curve));
// .defined($y)
</script>
<path class="path-line" d={path($data)} {stroke}></path>
<style>
.path-line {
fill: none;
stroke-linejoin: round;
stroke-linecap: round;
stroke-width: 2;
}
</style>