Svelte x D3

A collection of data visualisations built with Svelte and D3

Github repo

Chart

A responsive chart wrapper that can be filled with other elements

My height is 100px and my width is 100px

Code

Chart

<script lang="ts">
	import { setContext } from 'svelte';
	import { writable } from 'svelte/store';
	import Group from './Group.svelte';

	export let dimensions = {
		width: 100,
		height: 100,
		margins: {
			top: 0,
			right: 0,
			bottom: 0,
			left: 0
		},
		innerWidth: 0,
		innerHeight: 0
	};

	let currentDimensions = writable(dimensions);

	$: {
		currentDimensions.set(dimensions);
	}

	setContext('Chart', {
		dimensions: currentDimensions
	});
</script>

<svg class="Chart" width={dimensions.width} height={dimensions.height}>
	<Group left={dimensions.margins.left} top={dimensions.margins.top}>
		<slot />
	</Group>
</svg>