From 661715584004bd270c450afb8eacd874302fe4f2 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Wed, 15 Feb 2023 15:22:06 -0800 Subject: [PATCH 1/2] auto bin options --- src/marks/auto.js | 18 ++++---- test/output/autoLineMeanThresholds.svg | 58 ++++++++++++++++++++++++++ test/plots/autoplot.js | 5 +++ 3 files changed, 72 insertions(+), 9 deletions(-) create mode 100644 test/output/autoLineMeanThresholds.svg diff --git a/src/marks/auto.js b/src/marks/auto.js index 8a2c9c9875..d86560b70d 100644 --- a/src/marks/auto.js +++ b/src/marks/auto.js @@ -29,16 +29,12 @@ export function auto(data, {x, y, color, size, fx, fy, mark} = {}) { if (isOptions(fx)) ({value: fx} = makeOptions(fx)); if (isOptions(fy)) ({value: fy} = makeOptions(fy)); - const {value: xValue} = x; - const {value: yValue} = y; - const {value: sizeValue} = size; - const {value: colorValue, color: colorColor} = color; + let {value: xValue, reduce: xReduce, ...xOptions} = x; + let {value: yValue, reduce: yReduce, ...yOptions} = y; + let {value: sizeValue, reduce: sizeReduce} = size; + let {value: colorValue, color: colorColor, reduce: colorReduce} = color; // Determine the default reducer, if any. - let {reduce: xReduce} = x; - let {reduce: yReduce} = y; - let {reduce: sizeReduce} = size; - let {reduce: colorReduce} = color; if (xReduce === undefined) xReduce = yReduce == null && xValue == null && sizeValue == null && yValue != null ? "count" : null; if (yReduce === undefined) @@ -175,7 +171,11 @@ export function auto(data, {x, y, color, size, fx, fy, mark} = {}) { transform = isOrdinal(y) ? groupY : binY; } } - if (transform) options = transform(transformOptions, options); + if (transform) { + if (transform === bin || transform === binX) options.x = {value: x, ...xOptions}; + if (transform === bin || transform === binY) options.y = {value: y, ...yOptions}; + options = transform(transformOptions, options); + } // If zero-ness is not specified, default based on whether the resolved mark // type will include a zero baseline. diff --git a/test/output/autoLineMeanThresholds.svg b/test/output/autoLineMeanThresholds.svg new file mode 100644 index 0000000000..91e9bc938d --- /dev/null +++ b/test/output/autoLineMeanThresholds.svg @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + 8 + 10 + 12 + 14 + 16 + 18 + 20 + 22 + 24 + 26 + 28 + + + ↑ temp_max + + + + + + + + 2013 + 2014 + 2015 + + + + + \ No newline at end of file diff --git a/test/plots/autoplot.js b/test/plots/autoplot.js index 58895d931e..4754cfa8a8 100644 --- a/test/plots/autoplot.js +++ b/test/plots/autoplot.js @@ -212,6 +212,11 @@ export async function autoLineMeanColor() { return Plot.auto(athletes, {x: "date_of_birth", y: {value: "height", reduce: "mean"}, color: "sex"}).plot(); } +export async function autoLineMeanThresholds() { + const weather = await d3.csv("data/seattle-weather.csv", d3.autoType); + return Plot.auto(weather, {x: {value: "date", thresholds: d3.utcMonth}, y: {value: "temp_max", reduce: "mean"}}).plot(); +} + export async function autoLineFacet() { const industries = await d3.csv("data/bls-industry-unemployment.csv", d3.autoType); return Plot.auto(industries, {x: "date", y: "unemployed", fy: "industry"}).plot(); From 32afce7a055b04c371a554eebc63083d31cc1df8 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Wed, 15 Feb 2023 15:29:49 -0800 Subject: [PATCH 2/2] pRetTieR --- test/plots/autoplot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/plots/autoplot.js b/test/plots/autoplot.js index 4754cfa8a8..71dbd741a8 100644 --- a/test/plots/autoplot.js +++ b/test/plots/autoplot.js @@ -214,7 +214,7 @@ export async function autoLineMeanColor() { export async function autoLineMeanThresholds() { const weather = await d3.csv("data/seattle-weather.csv", d3.autoType); - return Plot.auto(weather, {x: {value: "date", thresholds: d3.utcMonth}, y: {value: "temp_max", reduce: "mean"}}).plot(); + return Plot.auto(weather, {x: {value: "date", thresholds: "month"}, y: {value: "temp_max", reduce: "mean"}}).plot(); } export async function autoLineFacet() {