1
- import { InternSet } from "d3" ;
1
+ import { ascending , InternSet } from "d3" ;
2
2
import { isOrdinal , labelof , valueof , isOptions , isColor } from "../options.js" ;
3
3
import { area , areaX , areaY } from "./area.js" ;
4
4
import { dot } from "./dot.js" ;
@@ -11,7 +11,6 @@ import {frame} from "./frame.js";
11
11
import { bin , binX , binY } from "../transforms/bin.js" ;
12
12
import { group , groupX , groupY } from "../transforms/group.js" ;
13
13
import { marks } from "../mark.js" ;
14
- import { ascending } from "d3" ;
15
14
16
15
/** @jsdoc auto */
17
16
export function auto ( data , { x, y, color, size, fx, fy, mark} = { } ) {
@@ -45,8 +44,8 @@ export function auto(data, {x, y, color, size, fx, fy, mark} = {}) {
45
44
if ( yReduce === undefined )
46
45
yReduce = xReduce == null && yValue == null && sizeValue == null && xValue != null ? "count" : null ;
47
46
48
- let { zero : xZero } = x ;
49
- let { zero : yZero } = y ;
47
+ let { zero : xZero = isZeroReducer ( xReduce ) ? true : undefined } = x ;
48
+ let { zero : yZero = isZeroReducer ( yReduce ) ? true : undefined } = y ;
50
49
51
50
// TODO The line mark will need z?
52
51
// TODO Limit and sort for bar charts (e.g. alphabet)?
@@ -98,17 +97,13 @@ export function auto(data, {x, y, color, size, fx, fy, mark} = {}) {
98
97
mark =
99
98
sizeValue != null || sizeReduce != null
100
99
? "dot"
101
- : xReduce != null || yReduce != null || colorReduce != null
100
+ : xZero || yZero || colorReduce != null // histogram or heatmap
102
101
? "bar"
103
102
: x && y
104
- ? isContinuous ( x ) && isContinuous ( y ) && ( isMonotonic ( x ) || isMonotonic ( y ) )
103
+ ? isContinuous ( x ) && isContinuous ( y ) && ( xReduce != null || yReduce != null || isMonotonic ( x ) || isMonotonic ( y ) )
105
104
? "line"
106
- : ( isContinuous ( x ) && xZero ) || ( isContinuous ( y ) && yZero )
107
- ? "bar"
108
105
: "dot"
109
- : x
110
- ? "rule"
111
- : y
106
+ : x || y
112
107
? "rule"
113
108
: null ;
114
109
}
@@ -239,6 +234,10 @@ function makeOptions(value) {
239
234
return isReducer ( value ) ? { reduce : value } : { value} ;
240
235
}
241
236
237
+ function isZeroReducer ( reduce ) {
238
+ return / ^ (?: d i s t i n c t | c o u n t | s u m | p r o p o r t i o n ) $ / i. test ( reduce ) ;
239
+ }
240
+
242
241
// https://github.com/observablehq/plot/blob/818562649280e155136f730fc496e0b3d15ae464/src/transforms/group.js#L236
243
242
function isReducer ( reduce ) {
244
243
if ( typeof reduce ?. reduce === "function" ) return true ;
0 commit comments