diff --git a/src/transforms/bin.js b/src/transforms/bin.js index 02321a3345..5962d84fe7 100644 --- a/src/transforms/bin.js +++ b/src/transforms/bin.js @@ -71,7 +71,7 @@ function maybeDenseInterval(bin, k, options = {}) { if (options?.interval == null) return options; const {reduce = reduceFirst} = options; const outputs = {filter: null}; - if (options[k] != null) outputs[k] = reduce; + if (options[k] !== null) outputs[k] = reduce; if (options[`${k}1`] != null) outputs[`${k}1`] = reduce; if (options[`${k}2`] != null) outputs[`${k}2`] = reduce; return bin(outputs, options); diff --git a/test/output/denseIntervalAreaX.svg b/test/output/denseIntervalAreaX.svg new file mode 100644 index 0000000000..7dc2c7ccb1 --- /dev/null +++ b/test/output/denseIntervalAreaX.svg @@ -0,0 +1,64 @@ + + + + + −3.5 + −3.0 + −2.5 + −2.0 + −1.5 + −1.0 + −0.5 + 0.0 + 0.5 + 1.0 + 1.5 + 2.0 + 2.5 + 3.0 + + + + 0 + 100 + 200 + + + Frequency → + + + + + \ No newline at end of file diff --git a/test/output/denseIntervalAreaY.svg b/test/output/denseIntervalAreaY.svg new file mode 100644 index 0000000000..dc3d752c73 --- /dev/null +++ b/test/output/denseIntervalAreaY.svg @@ -0,0 +1,64 @@ + + + + + 0 + 2 + 4 + 6 + 8 + 10 + 12 + 14 + 16 + 18 + 20 + 22 + + + ↑ Frequency + + + + 2014 + 2015 + 2016 + 2017 + 2018 + + + + + \ No newline at end of file diff --git a/test/output/denseIntervalLineX.svg b/test/output/denseIntervalLineX.svg new file mode 100644 index 0000000000..9238917254 --- /dev/null +++ b/test/output/denseIntervalLineX.svg @@ -0,0 +1,64 @@ + + + + + −3.5 + −3.0 + −2.5 + −2.0 + −1.5 + −1.0 + −0.5 + 0.0 + 0.5 + 1.0 + 1.5 + 2.0 + 2.5 + 3.0 + + + + 0 + 100 + 200 + + + Frequency → + + + + + \ No newline at end of file diff --git a/test/output/denseIntervalLineY.svg b/test/output/denseIntervalLineY.svg new file mode 100644 index 0000000000..6a09fb2bc8 --- /dev/null +++ b/test/output/denseIntervalLineY.svg @@ -0,0 +1,70 @@ + + + + + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + + + ↑ Frequency + + + + 2014 + 2015 + 2016 + 2017 + 2018 + + + + + \ No newline at end of file diff --git a/test/plots/dense-interval.ts b/test/plots/dense-interval.ts new file mode 100644 index 0000000000..196376f9a9 --- /dev/null +++ b/test/plots/dense-interval.ts @@ -0,0 +1,40 @@ +import * as Plot from "@observablehq/plot"; +import * as d3 from "d3"; + +export async function denseIntervalAreaY() { + const aapl = await d3.csv("data/aapl.csv", d3.autoType); + return Plot.plot({ + marks: [Plot.areaY(aapl, {x: "Date", reduce: "count", interval: "month"})] + }); +} + +export async function denseIntervalLineY() { + const aapl = await d3.csv("data/aapl.csv", d3.autoType); + return Plot.plot({ + marks: [Plot.lineY(aapl, {x: "Date", reduce: "count", interval: "month"})] + }); +} + +export async function denseIntervalAreaX() { + return Plot.areaX( + {length: 1000}, + { + y: d3.randomNormal.source(d3.randomLcg(42))(), + reduce: "count", + interval: 0.5, + curve: "basis" + } + ).plot({width: 200}); +} + +export async function denseIntervalLineX() { + return Plot.lineX( + {length: 1000}, + { + y: d3.randomNormal.source(d3.randomLcg(42))(), + reduce: "count", + interval: 0.5, + curve: "basis" + } + ).plot({width: 200}); +} diff --git a/test/plots/index.ts b/test/plots/index.ts index f54398dca7..996f68f03f 100644 --- a/test/plots/index.ts +++ b/test/plots/index.ts @@ -48,6 +48,7 @@ export * from "./boxplot.js"; export * from "./caltrain-direction.js"; export * from "./caltrain.js"; export * from "./cars-dodge.js"; +export * from "./dense-interval.js"; export * from "./cars-hexbin.js"; export * from "./cars-jitter.js"; export * from "./cars-mpg.js";