From 4773bb9dc08f48536cfb79a31e74a90ba1c6b0ac Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Wed, 20 Mar 2024 16:56:52 -0700 Subject: [PATCH] fix crash during reindex --- src/options.js | 2 +- test/output/mixedFacets.svg | 148 ++++++++++++++++++++++++++++++++++++ test/plots/index.ts | 1 + test/plots/mixed-facets.ts | 20 +++++ 4 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 test/output/mixedFacets.svg create mode 100644 test/plots/mixed-facets.ts diff --git a/src/options.js b/src/options.js index 8ffa10afcb..387daa94fb 100644 --- a/src/options.js +++ b/src/options.js @@ -25,7 +25,7 @@ export function valueof(data, value, type) { } function maybeTake(values, index) { - return index ? take(values, index) : values; + return values != null && index ? take(values, index) : values; } function maybeTypedMap(data, f, type) { diff --git a/test/output/mixedFacets.svg b/test/output/mixedFacets.svg new file mode 100644 index 0000000000..78d9af4406 --- /dev/null +++ b/test/output/mixedFacets.svg @@ -0,0 +1,148 @@ + + + + + a + + + b + + + + name + + + + 2024Jan + + + Feb + + + + + + 0 + 2 + 4 + 6 + 8 + + + 0 + 2 + 4 + 6 + 8 + + + + ↑ value + + + + + a + b + + + a + b + + + + name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/plots/index.ts b/test/plots/index.ts index 0a3ee3eb0d..7da1e050cc 100644 --- a/test/plots/index.ts +++ b/test/plots/index.ts @@ -164,6 +164,7 @@ export * from "./metro-unemployment-ridgeline.js"; export * from "./metro-unemployment-slope.js"; export * from "./metro-unemployment-stroke.js"; export * from "./metro-unemployment.js"; +export * from "./mixed-facets.js"; export * from "./moby-dick-faceted.js"; export * from "./moby-dick-letter-frequency.js"; export * from "./moby-dick-letter-pairs.js"; diff --git a/test/plots/mixed-facets.ts b/test/plots/mixed-facets.ts new file mode 100644 index 0000000000..6f8243c995 --- /dev/null +++ b/test/plots/mixed-facets.ts @@ -0,0 +1,20 @@ +import * as Plot from "@observablehq/plot"; + +export async function mixedFacets() { + const data = [ + {date: new Date("2024-01-01"), name: "a", value: 1}, + {date: new Date("2024-01-01"), name: "b", value: 2}, + {date: new Date("2024-01-01"), name: "a", value: 2}, + {date: new Date("2024-02-01"), name: "b", value: 3}, + {date: new Date("2024-02-01"), name: "a", value: 5}, + {date: new Date("2024-02-01"), name: "b", value: 2}, + {date: new Date("2024-02-01"), name: "a", value: 3} + ]; + return Plot.plot({ + marks: [ + Plot.barY(data, {x: "name", y: "value", fill: "name", fx: "date", fy: "name"}), + Plot.barY(data, {x: "name", y: "value", fx: "date", stroke: "currentColor"}), + Plot.ruleY([0]) + ] + }); +}