From d514313f00fc17e30ea26ac54750678b94aa5fb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Tue, 19 Nov 2024 17:25:39 +0100 Subject: [PATCH 1/4] A channel of explicit symbols does not show in the tip nor has a legend closes #2237 --- src/marks/tip.js | 4 +- test/output/explicitSymbol.svg | 378 +++++++++++++++++++++++++++++++++ test/plots/explicit-symbol.ts | 15 ++ test/plots/index.ts | 1 + 4 files changed, 396 insertions(+), 2 deletions(-) create mode 100644 test/output/explicitSymbol.svg create mode 100644 test/plots/explicit-symbol.ts diff --git a/src/marks/tip.js b/src/marks/tip.js index bfb9d04cb2..20cb75ebf0 100644 --- a/src/marks/tip.js +++ b/src/marks/tip.js @@ -347,8 +347,8 @@ function getSourceChannels(channels, scales) { if ((key === "x" || key === "y") && channels.geometry) continue; // ignore x & y on geo const source = getSource(channels, key); if (source) { - // Ignore color channels if the values are all literal colors. - if (source.scale == null && source.defaultScale === "color") continue; + // Ignore color/symbol channels if the values are all literal colors/symbols. + if (source.scale == null && ["color", "symbol"].includes(source.defaultScale)) continue; sources[key] = source; } } diff --git a/test/output/explicitSymbol.svg b/test/output/explicitSymbol.svg new file mode 100644 index 0000000000..f8364cb5be --- /dev/null +++ b/test/output/explicitSymbol.svg @@ -0,0 +1,378 @@ + + + + + 35 + 40 + 45 + 50 + 55 + + + culmen_length_mm → + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/plots/explicit-symbol.ts b/test/plots/explicit-symbol.ts new file mode 100644 index 0000000000..a3674b73b7 --- /dev/null +++ b/test/plots/explicit-symbol.ts @@ -0,0 +1,15 @@ +import * as Plot from "@observablehq/plot"; +import * as d3 from "d3"; + +// A channel of explicit symbols does not show in the tip nor has a legend. +export async function explicitSymbol() { + const penguins = await d3.csv("data/penguins.csv", d3.autoType); + return Plot.dot( + penguins, + Plot.dodgeY({ + x: "culmen_length_mm", + symbol: (d) => (d.sex === "FEMALE" ? "square" : "star"), + tip: true + }) + ).plot({height: 220, symbol: {legend: true}}); +} diff --git a/test/plots/index.ts b/test/plots/index.ts index f54398dca7..6db12dcd86 100644 --- a/test/plots/index.ts +++ b/test/plots/index.ts @@ -89,6 +89,7 @@ export * from "./empty-x.js"; export * from "./empty.js"; export * from "./energy-production.js"; export * from "./error-bar.js"; +export * from "./explicit-symbol.js"; export * from "./facet-reindex.js"; export * from "./faithful-density-1d.js"; export * from "./faithful-density.js"; From 20b8179b0814f16232341741f1aec8170befc201 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Sat, 23 Nov 2024 08:05:58 -0800 Subject: [PATCH 2/4] generalize test --- src/marks/tip.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/marks/tip.js b/src/marks/tip.js index 20cb75ebf0..8277a79215 100644 --- a/src/marks/tip.js +++ b/src/marks/tip.js @@ -347,8 +347,8 @@ function getSourceChannels(channels, scales) { if ((key === "x" || key === "y") && channels.geometry) continue; // ignore x & y on geo const source = getSource(channels, key); if (source) { - // Ignore color/symbol channels if the values are all literal colors/symbols. - if (source.scale == null && ["color", "symbol"].includes(source.defaultScale)) continue; + // Ignore (e.g., color) channels if the values are all literal. + if (source.scale == null && source.defaultScale) continue; sources[key] = source; } } From 49da12a8c1335e18cb1f651f16acac2fbcfce3b8 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Sat, 23 Nov 2024 08:07:29 -0800 Subject: [PATCH 3/4] prettier --- test/plots/explicit-symbol.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/test/plots/explicit-symbol.ts b/test/plots/explicit-symbol.ts index a3674b73b7..71d2d69a73 100644 --- a/test/plots/explicit-symbol.ts +++ b/test/plots/explicit-symbol.ts @@ -4,12 +4,19 @@ import * as d3 from "d3"; // A channel of explicit symbols does not show in the tip nor has a legend. export async function explicitSymbol() { const penguins = await d3.csv("data/penguins.csv", d3.autoType); - return Plot.dot( - penguins, - Plot.dodgeY({ - x: "culmen_length_mm", - symbol: (d) => (d.sex === "FEMALE" ? "square" : "star"), - tip: true - }) - ).plot({height: 220, symbol: {legend: true}}); + return Plot.plot({ + height: 220, + symbol: {legend: true}, + marks: [ + Plot.dot( + penguins, + Plot.dodgeY({ + x: "culmen_length_mm", + symbol: (d) => (d.sex === "FEMALE" ? "square" : "star"), + fill: "sex", + tip: true + }) + ) + ] + }); } From 76733dea308afbef0c14220a75435a220610f5d6 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Sat, 23 Nov 2024 09:46:28 -0800 Subject: [PATCH 4/4] oops, fix test --- test/plots/explicit-symbol.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/plots/explicit-symbol.ts b/test/plots/explicit-symbol.ts index 71d2d69a73..446a864aad 100644 --- a/test/plots/explicit-symbol.ts +++ b/test/plots/explicit-symbol.ts @@ -13,7 +13,6 @@ export async function explicitSymbol() { Plot.dodgeY({ x: "culmen_length_mm", symbol: (d) => (d.sex === "FEMALE" ? "square" : "star"), - fill: "sex", tip: true }) )