Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 79 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"vite": "^6.3.6"
},
"dependencies": {
"@onsvisual/svelte-components": "^1.0.21",
"@tailwindcss/vite": "^4.1.6",
"@types/d3": "^7.4.3",
"csv-parser": "^3.2.0",
Expand Down
27 changes: 18 additions & 9 deletions src/components/Barchart.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<script>
import { scaleLinear } from 'd3-scale';
import { format } from 'd3-format';
import { getContext } from 'svelte';
// import { getContext } from 'svelte';

// 1. Basic Setup: Get the data

let { data = $bindable() } = $props();
const selected = getContext('selected');
let { data = $bindable(), selected, peaks } = $props();
const [peak1='peak1', peak2='peak2'] = peaks;

// const selected = getContext('selected');

// 2. Dimensions, Margins & Scales

Expand Down Expand Up @@ -48,7 +50,7 @@
// We will do this in the html markup
</script>

<div class="barchart flex-1" bind:clientWidth={width}>
<div class="barchart flex-1 bg-white/60" bind:clientWidth={width}>
<svg {width} {height}>

<!-- Design y axis -->
Expand All @@ -74,9 +76,10 @@
</g>

<!-- 4. Design the bars -->
<g class="bars {selected()}">
<g class="bars {selected}">
{#each data as d, i}
<rect
class={d.year == peak1 || d.year == peak2 ? "highlight-bar" : "all"}
x={xScale(i) + 2}
y={yScale(d.victims)}
width={barWidth * 0.9}
Expand All @@ -100,17 +103,23 @@
color: --color-slate-800;
}

.bars.missingOrDeceased rect {
.bars.missingOrDeceased rect.all {
fill: var(--color-red-900);
stroke: none;
opacity: .8;
}
.bars.missingOrDeceased rect.highlight-bar {
fill: var(--color-red-950);
opacity: 1;
}

.bars.deceased rect {
.bars.deceased rect.all {
fill: var(--color-stone-800);
stroke: none;
opacity: .8;
}
.bars.deceased rect.highlight-bar {
fill: var(--color-stone-900);
opacity: 1;
}


.tick {
Expand Down
Loading