Skip to content

Commit 99397d9

Browse files
authored
better error message for missing stack value (#1798)
* better error message for missing channel * linked pointer example * shorten error message
1 parent b7a0be4 commit 99397d9

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

src/transforms/stack.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ function mergeOptions(options) {
7575
const lengthy = {length: true};
7676

7777
function stack(x, y = one, kx, ky, {offset, order, reverse}, options) {
78+
if (y === null) throw new Error(`stack requires ${ky}`);
7879
const z = maybeZ(options);
7980
const [X, setX] = maybeColumn(x);
8081
const [Y1, setY1] = column(y);
Lines changed: 70 additions & 0 deletions
Loading

test/plots/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ export * from "./penguin-species-island-sex.js";
208208
export * from "./penguin-species-island.js";
209209
export * from "./penguin-species.js";
210210
export * from "./penguin-voronoi-1d.js";
211+
export * from "./pointer-linked.js";
211212
export * from "./pointer.js";
212213
export * from "./polylinear.js";
213214
export * from "./population-by-latitude.js";

test/plots/pointer-linked.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as Plot from "@observablehq/plot";
2+
import * as d3 from "d3";
3+
4+
export async function pointerLinkedRectInterval() {
5+
const a = d3.range(10).map((i) => ({series: "A", time: i, value: 15 + i - 0.3 * (i * i)}));
6+
const b = d3.range(12).map((i) => ({series: "B", time: i, value: 12 * i - i * i}));
7+
const round = {floor: (x) => Math.floor(x) - 0.5, offset: (x) => x + 1};
8+
const series = [...a, ...b];
9+
return Plot.plot({
10+
marks: [
11+
Plot.rect(series, Plot.pointerX({x: "time", interval: round, fillOpacity: 0.1})),
12+
Plot.lineY(series, {stroke: "series", x: "time", y: "value", marker: true, curve: "natural"}),
13+
Plot.arrow(series, Plot.pointerX(Plot.groupX({y1: "min", y2: "max"}, {x: "time", y: "value", inset: 10})))
14+
]
15+
});
16+
}

0 commit comments

Comments
 (0)