Skip to content

Commit 5674bd2

Browse files
authored
auto chose rect (#1563)
* auto chose rect * nullish checks
1 parent 1f79087 commit 5674bd2

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/marks/auto.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {cell} from "./cell.js";
99
import {dot} from "./dot.js";
1010
import {frame} from "./frame.js";
1111
import {line, lineX, lineY} from "./line.js";
12-
import {rectX, rectY} from "./rect.js";
12+
import {rect, rectX, rectY} from "./rect.js";
1313
import {ruleX, ruleY} from "./rule.js";
1414

1515
export function autoSpec(data, options) {
@@ -91,10 +91,10 @@ export function autoSpec(data, options) {
9191
break;
9292
case "line":
9393
markImpl =
94-
(X && Y) || xReduce || yReduce // same logic as area (see below), but default to line
95-
? yZero || yReduce || (X && isMonotonic(X))
94+
(X && Y) || xReduce != null || yReduce != null // same logic as area (see below), but default to line
95+
? yZero || yReduce != null || (X && isMonotonic(X))
9696
? lineY
97-
: xZero || xReduce || (Y && isMonotonic(Y))
97+
: xZero || xReduce != null || (Y && isMonotonic(Y))
9898
? lineX
9999
: line
100100
: X // 1d line by index
@@ -104,7 +104,7 @@ export function autoSpec(data, options) {
104104
if (isHighCardinality(C)) Z = null; // TODO only if z not set by user
105105
break;
106106
case "area":
107-
markImpl = !(yZero || yReduce) && (xZero || xReduce || (Y && isMonotonic(Y))) ? areaX : areaY; // favor areaY if unsure
107+
markImpl = !(yZero || yReduce != null) && (xZero || xReduce != null || (Y && isMonotonic(Y))) ? areaX : areaY; // favor areaY if unsure
108108
colorMode = "fill";
109109
if (isHighCardinality(C)) Z = null; // TODO only if z not set by user
110110
break;
@@ -127,7 +127,11 @@ export function autoSpec(data, options) {
127127
? barY
128128
: isOrdinalReduced(yReduce, Y)
129129
? barX
130-
: rectY;
130+
: xReduce != null
131+
? rectX
132+
: yReduce != null
133+
? rectY
134+
: rect;
131135
colorMode = "fill";
132136
break;
133137
default:
@@ -350,6 +354,7 @@ const impls = {
350354
ruleY,
351355
barX,
352356
barY,
357+
rect,
353358
rectX,
354359
rectY,
355360
cell,

test/marks/auto-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ it("Plot.autoSpec makes a faceted heatmap", () => {
227227
color: {value: null, reduce: "count"},
228228
size: {value: null, reduce: null},
229229
mark: "bar",
230-
markImpl: "rectY",
230+
markImpl: "rect",
231231
markOptions: {
232232
fx: undefined,
233233
fy: "f",

0 commit comments

Comments
 (0)