Skip to content

Commit 1ff36a3

Browse files
Filmbostock
andauthored
the denseInterval option for k must also reduce k1 and k2 if present (#1828)
* the denseInterval option for k must also reduce k1 and k2 if present closes #1784 * Update src/transforms/bin.js * conditional reduce of k, too * prettier --------- Co-authored-by: Mike Bostock <[email protected]>
1 parent e3e794e commit 1ff36a3

File tree

4 files changed

+68
-3
lines changed

4 files changed

+68
-3
lines changed

src/transforms/bin.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,13 @@ export function bin(outputs = {fill: "count"}, options = {}) {
6767
}
6868

6969
function maybeDenseInterval(bin, k, options = {}) {
70-
return options?.interval == null
71-
? options
72-
: bin({[k]: options?.reduce === undefined ? reduceFirst : options.reduce, filter: null}, options);
70+
if (options?.interval == null) return options;
71+
const {reduce = reduceFirst} = options;
72+
const outputs = {filter: null};
73+
if (options[k] != null) outputs[k] = reduce;
74+
if (options[`${k}1`] != null) outputs[`${k}1`] = reduce;
75+
if (options[`${k}2`] != null) outputs[`${k}2`] = reduce;
76+
return bin(outputs, options);
7377
}
7478

7579
export function maybeDenseIntervalX(options = {}) {

test/output/aaplInterval.svg

Lines changed: 53 additions & 0 deletions
Loading

test/plots/aapl-interval.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as Plot from "@observablehq/plot";
2+
import * as d3 from "d3";
3+
4+
export async function aaplInterval() {
5+
const aapl = await d3.csv<any>("data/aapl.csv", d3.autoType);
6+
return Plot.areaY(aapl.slice(0, 81), {x: "Date", y1: "Low", y2: "High", interval: "day", curve: "step"}).plot();
7+
}

test/plots/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export * from "./aapl-change-volume.js";
44
export * from "./aapl-close-untyped.js";
55
export * from "./aapl-close.js";
66
export * from "./aapl-fancy-axis.js";
7+
export * from "./aapl-interval.js";
78
export * from "./aapl-monthly.js";
89
export * from "./aapl-volume-rect.js";
910
export * from "./aapl-volume.js";

0 commit comments

Comments
 (0)