diff --git a/src/transforms/stack.js b/src/transforms/stack.js index 7c92fc0d82..25d676fe2f 100644 --- a/src/transforms/stack.js +++ b/src/transforms/stack.js @@ -75,6 +75,7 @@ function mergeOptions(options) { const lengthy = {length: true}; function stack(x, y = one, kx, ky, {offset, order, reverse}, options) { + if (y === null) throw new Error(`stack requires ${ky}`); const z = maybeZ(options); const [X, setX] = maybeColumn(x); const [Y1, setY1] = column(y); diff --git a/test/output/pointerLinkedRectInterval.svg b/test/output/pointerLinkedRectInterval.svg new file mode 100644 index 0000000000..1c6cbaaed5 --- /dev/null +++ b/test/output/pointerLinkedRectInterval.svg @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + 0 + 5 + 10 + 15 + 20 + 25 + 30 + 35 + + + ↑ value + + + + + + + + + + + 0 + 2 + 4 + 6 + 8 + 10 + + + time → + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/plots/index.ts b/test/plots/index.ts index df3e1abf18..65c6cfb5c6 100644 --- a/test/plots/index.ts +++ b/test/plots/index.ts @@ -208,6 +208,7 @@ export * from "./penguin-species-island-sex.js"; export * from "./penguin-species-island.js"; export * from "./penguin-species.js"; export * from "./penguin-voronoi-1d.js"; +export * from "./pointer-linked.js"; export * from "./pointer.js"; export * from "./polylinear.js"; export * from "./population-by-latitude.js"; diff --git a/test/plots/pointer-linked.ts b/test/plots/pointer-linked.ts new file mode 100644 index 0000000000..b5852fcba7 --- /dev/null +++ b/test/plots/pointer-linked.ts @@ -0,0 +1,16 @@ +import * as Plot from "@observablehq/plot"; +import * as d3 from "d3"; + +export async function pointerLinkedRectInterval() { + const a = d3.range(10).map((i) => ({series: "A", time: i, value: 15 + i - 0.3 * (i * i)})); + const b = d3.range(12).map((i) => ({series: "B", time: i, value: 12 * i - i * i})); + const round = {floor: (x) => Math.floor(x) - 0.5, offset: (x) => x + 1}; + const series = [...a, ...b]; + return Plot.plot({ + marks: [ + Plot.rect(series, Plot.pointerX({x: "time", interval: round, fillOpacity: 0.1})), + Plot.lineY(series, {stroke: "series", x: "time", y: "value", marker: true, curve: "natural"}), + Plot.arrow(series, Plot.pointerX(Plot.groupX({y1: "min", y2: "max"}, {x: "time", y: "value", inset: 10}))) + ] + }); +}