diff --git a/src/transforms/bin.js b/src/transforms/bin.js index a33e9642d5..ea84b234ba 100644 --- a/src/transforms/bin.js +++ b/src/transforms/bin.js @@ -67,9 +67,13 @@ export function bin(outputs = {fill: "count"}, options = {}) { } function maybeDenseInterval(bin, k, options = {}) { - return options?.interval == null - ? options - : bin({[k]: options?.reduce === undefined ? reduceFirst : options.reduce, filter: null}, 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}1`] != null) outputs[`${k}1`] = reduce; + if (options[`${k}2`] != null) outputs[`${k}2`] = reduce; + return bin(outputs, options); } export function maybeDenseIntervalX(options = {}) { diff --git a/test/output/aaplInterval.svg b/test/output/aaplInterval.svg new file mode 100644 index 0000000000..608f36adc7 --- /dev/null +++ b/test/output/aaplInterval.svg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + 56 + 58 + 60 + 62 + 64 + 66 + 68 + 70 + 72 + + + + + + + + + Jun2013 + Jul + Aug + Sep + + + + + \ No newline at end of file diff --git a/test/plots/aapl-interval.ts b/test/plots/aapl-interval.ts new file mode 100644 index 0000000000..bc66b29275 --- /dev/null +++ b/test/plots/aapl-interval.ts @@ -0,0 +1,7 @@ +import * as Plot from "@observablehq/plot"; +import * as d3 from "d3"; + +export async function aaplInterval() { + const aapl = await d3.csv("data/aapl.csv", d3.autoType); + return Plot.areaY(aapl.slice(0, 81), {x: "Date", y1: "Low", y2: "High", interval: "day", curve: "step"}).plot(); +} diff --git a/test/plots/index.ts b/test/plots/index.ts index f54ad0948a..7660b3f473 100644 --- a/test/plots/index.ts +++ b/test/plots/index.ts @@ -4,6 +4,7 @@ export * from "./aapl-change-volume.js"; export * from "./aapl-close-untyped.js"; export * from "./aapl-close.js"; export * from "./aapl-fancy-axis.js"; +export * from "./aapl-interval.js"; export * from "./aapl-monthly.js"; export * from "./aapl-volume-rect.js"; export * from "./aapl-volume.js";