|
1 | 1 | import {ascending, InternSet} from "d3";
|
2 | 2 | import {marks} from "../mark.js";
|
3 |
| -import {isColor, isObject, isOptions, isOrdinal, labelof, valueof} from "../options.js"; |
| 3 | +import {isColor, isNumeric, isObject, isOptions, isOrdinal, labelof, valueof} from "../options.js"; |
4 | 4 | import {bin, binX, binY} from "../transforms/bin.js";
|
5 | 5 | import {group, groupX, groupY} from "../transforms/group.js";
|
6 | 6 | import {areaX, areaY} from "./area.js";
|
@@ -113,27 +113,32 @@ export function autoSpec(data, options) {
|
113 | 113 | colorMode = "stroke";
|
114 | 114 | break;
|
115 | 115 | case "bar":
|
116 |
| - markImpl = yZero |
117 |
| - ? isOrdinalReduced(xReduce, X) |
118 |
| - ? barY |
119 |
| - : rectY |
120 |
| - : xZero |
121 |
| - ? isOrdinalReduced(yReduce, Y) |
122 |
| - ? barX |
123 |
| - : rectX |
124 |
| - : isOrdinalReduced(xReduce, X) && isOrdinalReduced(yReduce, Y) |
125 |
| - ? cell |
126 |
| - : isOrdinalReduced(xReduce, X) |
127 |
| - ? barY |
128 |
| - : isOrdinalReduced(yReduce, Y) |
129 |
| - ? barX |
130 |
| - : xReduce != null |
131 |
| - ? rectX |
132 |
| - : yReduce != null |
133 |
| - ? rectY |
134 |
| - : colorReduce != null |
135 |
| - ? rect |
136 |
| - : cell; |
| 116 | + markImpl = |
| 117 | + xReduce != null // bin or group on y |
| 118 | + ? isOrdinal(Y) |
| 119 | + ? isSelectReducer(xReduce) && X && isOrdinal(X) |
| 120 | + ? cell |
| 121 | + : barX |
| 122 | + : rectX |
| 123 | + : yReduce != null // bin or group on x |
| 124 | + ? isOrdinal(X) |
| 125 | + ? isSelectReducer(yReduce) && Y && isOrdinal(Y) |
| 126 | + ? cell |
| 127 | + : barY |
| 128 | + : rectY |
| 129 | + : colorReduce != null || sizeReduce != null // bin or group on both x and y |
| 130 | + ? X && isOrdinal(X) && Y && isOrdinal(Y) |
| 131 | + ? cell |
| 132 | + : X && isOrdinal(X) |
| 133 | + ? barY |
| 134 | + : Y && isOrdinal(Y) |
| 135 | + ? barX |
| 136 | + : rect |
| 137 | + : X && isNumeric(X) && !(Y && isNumeric(Y)) |
| 138 | + ? barX // if y is temporal, treat as ordinal |
| 139 | + : Y && isNumeric(Y) && !(X && isNumeric(X)) |
| 140 | + ? barY // if x is temporal, treat as ordinal |
| 141 | + : cell; |
137 | 142 | colorMode = "fill";
|
138 | 143 | break;
|
139 | 144 | default:
|
@@ -300,12 +305,6 @@ function isSelectReducer(reduce) {
|
300 | 305 | return /^(?:first|last|mode)$/i.test(reduce);
|
301 | 306 | }
|
302 | 307 |
|
303 |
| -// We can’t infer the type of a custom reducer without invoking it, so |
304 |
| -// assume most reducers produce quantitative values. |
305 |
| -function isOrdinalReduced(reduce, value) { |
306 |
| - return (reduce != null && !isSelectReducer(reduce)) || !value ? false : isOrdinal(value); |
307 |
| -} |
308 |
| - |
309 | 308 | // https://github.com/observablehq/plot/blob/818562649280e155136f730fc496e0b3d15ae464/src/transforms/group.js#L236
|
310 | 309 | function isReducer(reduce) {
|
311 | 310 | if (reduce == null) return false;
|
|
0 commit comments