From 9a34a1bdfbf31672041ff1d01d728cbb175d459d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Fri, 2 Jun 2023 07:42:58 +0200 Subject: [PATCH] =?UTF-8?q?The=20intent=20of=20this=20=E2=80=9Chigh=20card?= =?UTF-8?q?inality=E2=80=9D=20warning=20(as=20specified=20[here](https://g?= =?UTF-8?q?ithub.com/observablehq/plot/pull/761#issuecomment-1043121845))?= =?UTF-8?q?=20is=20the=20following:=20when=20a=20mark=20only=C2=B9=20makes?= =?UTF-8?q?=20sense=20with=20grouping=E2=80=94currently=20area,=20line,=20?= =?UTF-8?q?linearRegression=20and=20density=E2=80=94,=20we=20want=20to=20w?= =?UTF-8?q?arn=20when=20the=20number=20of=20groups=20(G.size)=20is=20highe?= =?UTF-8?q?r=20than=20the=20smallest=20possible=20number=20of=20=5Fmeaning?= =?UTF-8?q?ful=5F=20groups,=20which=20is=20I.length=20>>=201=20(obtained?= =?UTF-8?q?=20when=20the=20groups=20are=20pairs).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/style.js | 2 +- test/output/pairsArea.svg | 26 ++++++++++++++++++++++++++ test/plots/index.ts | 1 + test/plots/pairs.ts | 6 ++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 test/output/pairsArea.svg create mode 100644 test/plots/pairs.ts diff --git a/src/style.js b/src/style.js index d77bd0f1b8..c239fa56ab 100644 --- a/src/style.js +++ b/src/style.js @@ -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.` ); diff --git a/test/output/pairsArea.svg b/test/output/pairsArea.svg new file mode 100644 index 0000000000..33fb1b772a --- /dev/null +++ b/test/output/pairsArea.svg @@ -0,0 +1,26 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/plots/index.ts b/test/plots/index.ts index b6886b388d..64f185bdd9 100644 --- a/test/plots/index.ts +++ b/test/plots/index.ts @@ -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"; diff --git a/test/plots/pairs.ts b/test/plots/pairs.ts new file mode 100644 index 0000000000..ffa6ba9ebe --- /dev/null +++ b/test/plots/pairs.ts @@ -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}); +}