1- import { InternSet } from "d3" ;
1+ import { ascending , InternSet } from "d3" ;
22import { isOrdinal , labelof , valueof , isOptions , isColor } from "../options.js" ;
33import { area , areaX , areaY } from "./area.js" ;
44import { dot } from "./dot.js" ;
@@ -11,7 +11,6 @@ import {frame} from "./frame.js";
1111import { bin , binX , binY } from "../transforms/bin.js" ;
1212import { group , groupX , groupY } from "../transforms/group.js" ;
1313import { marks } from "../mark.js" ;
14- import { ascending } from "d3" ;
1514
1615/** @jsdoc auto */
1716export 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} = {}) {
4544 if ( yReduce === undefined )
4645 yReduce = xReduce == null && yValue == null && sizeValue == null && xValue != null ? "count" : null ;
4746
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 ;
5049
5150 // TODO The line mark will need z?
5251 // 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} = {}) {
9897 mark =
9998 sizeValue != null || sizeReduce != null
10099 ? "dot"
101- : xReduce != null || yReduce != null || colorReduce != null
100+ : xZero || yZero || colorReduce != null // histogram or heatmap
102101 ? "bar"
103102 : x && y
104- ? isContinuous ( x ) && isContinuous ( y ) && ( isMonotonic ( x ) || isMonotonic ( y ) )
103+ ? isContinuous ( x ) && isContinuous ( y ) && ( xReduce != null || yReduce != null || isMonotonic ( x ) || isMonotonic ( y ) )
105104 ? "line"
106- : ( isContinuous ( x ) && xZero ) || ( isContinuous ( y ) && yZero )
107- ? "bar"
108105 : "dot"
109- : x
110- ? "rule"
111- : y
106+ : x || y
112107 ? "rule"
113108 : null ;
114109 }
@@ -239,6 +234,10 @@ function makeOptions(value) {
239234 return isReducer ( value ) ? { reduce : value } : { value} ;
240235}
241236
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+
242241// https://github.com/observablehq/plot/blob/818562649280e155136f730fc496e0b3d15ae464/src/transforms/group.js#L236
243242function isReducer ( reduce ) {
244243 if ( typeof reduce ?. reduce === "function" ) return true ;
0 commit comments