Skip to content

Commit

Permalink
the denseInterval option for k must also reduce k1 and k2 if present (#…
Browse files Browse the repository at this point in the history
…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]>
  • Loading branch information
Fil and mbostock authored Aug 24, 2023
1 parent e3e794e commit 1ff36a3
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/transforms/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) {
Expand Down
53 changes: 53 additions & 0 deletions test/output/aaplInterval.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions test/plots/aapl-interval.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as Plot from "@observablehq/plot";
import * as d3 from "d3";

export async function aaplInterval() {
const aapl = await d3.csv<any>("data/aapl.csv", d3.autoType);
return Plot.areaY(aapl.slice(0, 81), {x: "Date", y1: "Low", y2: "High", interval: "day", curve: "step"}).plot();
}
1 change: 1 addition & 0 deletions test/plots/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 1ff36a3

Please sign in to comment.