Skip to content

Commit af4d93a

Browse files
authored
auto bin options (#1277)
* auto bin options * pRetTieR
1 parent cca578a commit af4d93a

File tree

3 files changed

+72
-9
lines changed

3 files changed

+72
-9
lines changed

src/marks/auto.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,12 @@ export function auto(data, {x, y, color, size, fx, fy, mark} = {}) {
2929
if (isOptions(fx)) ({value: fx} = makeOptions(fx));
3030
if (isOptions(fy)) ({value: fy} = makeOptions(fy));
3131

32-
const {value: xValue} = x;
33-
const {value: yValue} = y;
34-
const {value: sizeValue} = size;
35-
const {value: colorValue, color: colorColor} = color;
32+
let {value: xValue, reduce: xReduce, ...xOptions} = x;
33+
let {value: yValue, reduce: yReduce, ...yOptions} = y;
34+
let {value: sizeValue, reduce: sizeReduce} = size;
35+
let {value: colorValue, color: colorColor, reduce: colorReduce} = color;
3636

3737
// Determine the default reducer, if any.
38-
let {reduce: xReduce} = x;
39-
let {reduce: yReduce} = y;
40-
let {reduce: sizeReduce} = size;
41-
let {reduce: colorReduce} = color;
4238
if (xReduce === undefined)
4339
xReduce = yReduce == null && xValue == null && sizeValue == null && yValue != null ? "count" : null;
4440
if (yReduce === undefined)
@@ -175,7 +171,11 @@ export function auto(data, {x, y, color, size, fx, fy, mark} = {}) {
175171
transform = isOrdinal(y) ? groupY : binY;
176172
}
177173
}
178-
if (transform) options = transform(transformOptions, options);
174+
if (transform) {
175+
if (transform === bin || transform === binX) options.x = {value: x, ...xOptions};
176+
if (transform === bin || transform === binY) options.y = {value: y, ...yOptions};
177+
options = transform(transformOptions, options);
178+
}
179179

180180
// If zero-ness is not specified, default based on whether the resolved mark
181181
// type will include a zero baseline.
Lines changed: 58 additions & 0 deletions
Loading

test/plots/autoplot.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ export async function autoLineMeanColor() {
212212
return Plot.auto(athletes, {x: "date_of_birth", y: {value: "height", reduce: "mean"}, color: "sex"}).plot();
213213
}
214214

215+
export async function autoLineMeanThresholds() {
216+
const weather = await d3.csv("data/seattle-weather.csv", d3.autoType);
217+
return Plot.auto(weather, {x: {value: "date", thresholds: "month"}, y: {value: "temp_max", reduce: "mean"}}).plot();
218+
}
219+
215220
export async function autoLineFacet() {
216221
const industries = await d3.csv("data/bls-industry-unemployment.csv", d3.autoType);
217222
return Plot.auto(industries, {x: "date", y: "unemployed", fy: "industry"}).plot();

0 commit comments

Comments
 (0)