From 381341bbb72ee5e5a949e65401fe72687b02cb99 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Wed, 1 Nov 2023 15:17:50 -0700 Subject: [PATCH] prefilter data --- test/plots/find.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/plots/find.ts b/test/plots/find.ts index 0855458d22..cd9bb77c6f 100644 --- a/test/plots/find.ts +++ b/test/plots/find.ts @@ -2,23 +2,26 @@ import * as Plot from "@observablehq/plot"; import * as d3 from "d3"; export async function findArrow() { - const ilc = await d3.csv("data/ilc_lvps08.csv", d3.autoType); const ages = ["Y16-19", "Y20-24", "Y25-29"]; + const sexes = ["M", "F"]; + const ilc = await d3.csv("data/ilc_lvps08.csv", (d) => + d.geo === "EL" && sexes.includes(d.sex) && ages.includes(d.age) ? d3.autoType(d) : null + ); return Plot.plot({ x: {tickFormat: "", label: null, inset: 10}, y: {grid: true, label: "Greek youth living with parents (%, ↑more male, ↓more female)"}, - color: {legend: true, domain: ages}, + color: {legend: true}, marks: [ Plot.ruleY([0, 100]), Plot.lineY(ilc, { - filter: (d) => d.geo === "EL" && d.sex === "F", + filter: (d) => d.sex === "F", x: "TIME_PERIOD", y: "OBS_VALUE", stroke: "age", strokeOpacity: 0.2 }), Plot.lineY(ilc, { - filter: (d) => d.geo === "EL" && d.sex === "M", + filter: (d) => d.sex === "M", x: "TIME_PERIOD", y: "OBS_VALUE", stroke: "age" @@ -31,7 +34,6 @@ export async function findArrow() { y2: Plot.find((d) => d.sex === "M") }, { - filter: (d) => d.geo === "EL", x: "TIME_PERIOD", y: "OBS_VALUE", stroke: "age",