Skip to main content
Create new
Introduction
Reactivity
Props
Logic
Events
Bindings
Lifecycle
Stores
Motion
Transitions
Animations
Easing
SVG
Actions
Classes
Component composition
Context API
Special elements
Module context
Debugging
7GUIs
Miscellaneous
App.svelte
AxisX.svelte
AxisY.svelte
BarStacked.svelte
fruitOrdinal.js
<script>
import { LayerCake, Svg, flatten, stack } from 'layercake';

import { scaleBand, scaleOrdinal } from 'd3-scale';
import { format } from 'd3-format';

import BarStacked from './BarStacked.svelte';
import AxisX from './AxisX.svelte';
import AxisY from './AxisY.svelte';

// In your local project, you will more likely be loading this as a csv and converting it to json using @rollup/plugin-dsv
import data from './fruitOrdinal.js';

const xKey = [0, 1];
const yKey = 'year';
const zKey = 'key';

const seriesNames = Object.keys(data[0]).filter(d => d !== yKey);
const seriesColors = ['#00bbff', '#8bcef6', '#c4e2ed', '#f7f6e3'];

/* --------------------------------------------
* Cast data
*/
data.forEach(d => {
seriesNames.forEach(name => {
d[name] = +d[name];
});
});

const formatLabelX = d => format(`~s`)(d);

const stackedData = stack(data, seriesNames);
</script>

<style>
/*
loading Svelte compiler...
/* Select a component to see its compiled code */
result = svelte.compile(source, {
generate: ,
});
/* Select a component to see its compiled code */