Skip to content

Commit 9a34a1b

Browse files
committed
The intent of this “high cardinality” warning (as specified [here](#761 (comment))) is the following: when a mark only¹ makes sense with grouping—currently area, line, linearRegression and density—, we want to warn when the number of groups (G.size) is higher than the smallest possible number of _meaningful_ groups, which is I.length >> 1 (obtained when the groups are pairs).
However when there is an odd number of elements, having 1 element that falls out is to be expected and should not invalidate the chart. Closes #1667 ¹ It's not a hard rule: the areaY mark with a stroke, the lineY mark with a marker, and the density mark tolerate single points. But these are not the default usage.
1 parent df3a3ad commit 9a34a1b

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

src/style.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ function groupAesthetics(
252252

253253
export function groupZ(I, Z, z) {
254254
const G = group(I, (i) => Z[i]);
255-
if (z === undefined && G.size > I.length >> 1) {
255+
if (z === undefined && G.size > (1 + I.length) >> 1) {
256256
warn(
257257
`Warning: the implicit z channel has high cardinality. This may occur when the fill or stroke channel is associated with quantitative data rather than ordinal or categorical data. You can suppress this warning by setting the z option explicitly; if this data represents a single series, set z to null.`
258258
);

test/output/pairsArea.svg

Lines changed: 26 additions & 0 deletions
Loading

test/plots/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ export * from "./music-revenue.js";
168168
export * from "./npm-versions.js";
169169
export * from "./opacity.js";
170170
export * from "./ordinal-bar.js";
171+
export * from "./pairs.js";
171172
export * from "./penguin-annotated.js";
172173
export * from "./penguin-culmen-array.js";
173174
export * from "./penguin-culmen-delaunay-mesh.js";

test/plots/pairs.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as Plot from "@observablehq/plot";
2+
import * as d3 from "d3";
3+
4+
export async function pairsArea() {
5+
return Plot.areaY({length: 15}, {y: d3.randomLcg(42), stroke: (d, i) => i >> 1}).plot({axis: null, height: 140});
6+
}

0 commit comments

Comments
 (0)