Skip to content

Commit

Permalink
The intent of this “high cardinality” warning (as specified [here](#7…
Browse files Browse the repository at this point in the history
…61 (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.
  • Loading branch information
Fil committed Jun 2, 2023
1 parent df3a3ad commit 9a34a1b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ function groupAesthetics(

export function groupZ(I, Z, z) {
const G = group(I, (i) => Z[i]);
if (z === undefined && G.size > I.length >> 1) {
if (z === undefined && G.size > (1 + I.length) >> 1) {
warn(
`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.`
);
Expand Down
26 changes: 26 additions & 0 deletions test/output/pairsArea.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/plots/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export * from "./music-revenue.js";
export * from "./npm-versions.js";
export * from "./opacity.js";
export * from "./ordinal-bar.js";
export * from "./pairs.js";
export * from "./penguin-annotated.js";
export * from "./penguin-culmen-array.js";
export * from "./penguin-culmen-delaunay-mesh.js";
Expand Down
6 changes: 6 additions & 0 deletions test/plots/pairs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as Plot from "@observablehq/plot";
import * as d3 from "d3";

export async function pairsArea() {
return Plot.areaY({length: 15}, {y: d3.randomLcg(42), stroke: (d, i) => i >> 1}).plot({axis: null, height: 140});
}

0 comments on commit 9a34a1b

Please sign in to comment.