Skip to content

Commit a1fd53f

Browse files
author
Oussama
committed
fix: align gender chart annotations
1 parent 7d223d2 commit a1fd53f

2 files changed

Lines changed: 42 additions & 11 deletions

File tree

website/src/lib/charts/LineChart.svelte

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,20 @@
1616
$: range = $filters.decadeRange;
1717
$: x = scaleLinear().domain([1860, 2020]).range([0, innerWidth]);
1818
$: y = scaleLinear().domain([0, 0.6]).range([innerHeight, 0]);
19+
$: pointByDecade = new Map(data.map((d) => [d.decade, d]));
1920
$: pathD = line()
2021
.x((d) => x(d.decade))
2122
.y((d) => y(d.femaleShare))(data);
2223
$: areaD = `${pathD || ''} L ${x(data.at(-1)?.decade ?? 2020)} ${innerHeight} L ${x(data[0]?.decade ?? 1860)} ${innerHeight} Z`;
24+
$: plottedAnnotations = annotations.map(positionAnnotation).filter(Boolean);
25+
26+
function positionAnnotation(note) {
27+
if (Number.isFinite(note.x) && Number.isFinite(note.y)) return note;
28+
const point = pointByDecade.get(note.decade);
29+
const share = Number.isFinite(note.femaleShare) ? note.femaleShare : point?.femaleShare;
30+
if (!Number.isFinite(note.decade) || !Number.isFinite(share)) return null;
31+
return { ...note, x: x(note.decade), y: y(share) };
32+
}
2333
2434
function showTooltip(event, d) {
2535
window.dispatchEvent(
@@ -59,6 +69,9 @@
5969
/>
6070
<path class="area" d={areaD} />
6171
<path class="series draw" d={pathD} />
72+
{#each plottedAnnotations as note}
73+
<Annotation {...note} />
74+
{/each}
6275
{#each data as d}
6376
<circle
6477
cx={x(d.decade)}
@@ -76,9 +89,6 @@
7689
{/each}
7790
<text class="axis-title y" x={-innerHeight / 2} y="-42">female-credited share</text>
7891
<text class="axis-title x" x={innerWidth / 2} y={innerHeight + 46}>artwork decade</text>
79-
{#each annotations as note}
80-
<Annotation {...note} />
81-
{/each}
8292
</g>
8393
</svg>
8494
<table class="sr-only">

website/src/lib/scenes/Scene3Gender.svelte

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,38 @@
2525
let lineData = $derived(toLineData(lineRows));
2626
let latest = $derived([...lineData].reverse().find((d) => d.n > 0) ?? { femaleShare: 0, decade: 2020, n: 0 });
2727
let annotations = $derived([
28-
{ x: 210, y: 80, dx: -110, dy: -35, value: '1910s', label: 'brief opening in the early collection.', width: 180 },
29-
{ x: 300, y: 108, dx: -80, dy: 58, value: '1930s', label: 'another spike, then a long plateau.', width: 185 },
30-
{ x: 535, y: 170, dx: 48, dy: -72, value: '1980s', label: 'sustained rise begins.', width: 165 },
3128
{
32-
x: 685,
33-
y: 112,
34-
dx: -150,
35-
dy: -82,
29+
decade: 1910,
30+
dx: -118,
31+
dy: -105,
32+
value: '1910s',
33+
label: 'brief opening in the early collection.',
34+
width: 185,
35+
},
36+
{
37+
decade: 1930,
38+
dx: -76,
39+
dy: -78,
40+
value: '1930s',
41+
label: 'another spike, then a long plateau.',
42+
width: 190,
43+
},
44+
{
45+
decade: 1990,
46+
dx: 42,
47+
dy: 82,
48+
value: '1980s',
49+
label: 'sustained rise begins.',
50+
width: 160,
51+
},
52+
{
53+
decade: latest.decade,
54+
dx: -134,
55+
dy: -76,
3656
value: `${(latest.femaleShare * 100).toFixed(0)}%`,
3757
label: `in the ${latest.decade}s.`,
38-
width: 150,
58+
width: 140,
59+
emphasis: 'strong',
3960
},
4061
]);
4162

0 commit comments

Comments
 (0)