Skip to content

Commit 5e6341d

Browse files
Filmbostock
andauthored
[] is an empty facet (#1216)
* [] is an empty facet closes #1212 alternative to #1215 * consistent filtering Co-authored-by: Mike Bostock <[email protected]>
1 parent eb31eb3 commit 5e6341d

File tree

8 files changed

+68
-14
lines changed

8 files changed

+68
-14
lines changed

src/plot.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ export function plot(options = {}) {
303303
if (facets) {
304304
const fi = facetPosition.get(key);
305305
facet = facets[fi] ?? facets[0];
306-
if (!facet) continue;
307306
facet = mark.filter(facet, channels, values);
307+
if (!facet.length) continue;
308308
facet.fi = fi;
309309
}
310310
const node = mark.render(facet, scales, values, subdimensions, context);
@@ -316,8 +316,8 @@ export function plot(options = {}) {
316316
let facet = null;
317317
if (facets) {
318318
facet = facets[0];
319-
if (!facet) continue;
320319
facet = mark.filter(facet, channels, values);
320+
if (!facet.length) continue;
321321
}
322322
const node = mark.render(facet, scales, values, dimensions, context);
323323
if (node != null) svg.appendChild(node);
@@ -655,8 +655,8 @@ function maybeMarkFacet(mark, topFacetState, options) {
655655
// Facet filter, by mark; for now only the "eq" filter is provided.
656656
function filterFacets(facets, {channels: {fx, fy}, groups}) {
657657
return fx && fy
658-
? facets.map(({x, y}) => groups.get(x)?.get(y))
658+
? facets.map(({x, y}) => groups.get(x)?.get(y) ?? [])
659659
: fx
660-
? facets.map(({x}) => groups.get(x))
661-
: facets.map(({y}) => groups.get(y));
660+
? facets.map(({x}) => groups.get(x) ?? [])
661+
: facets.map(({y}) => groups.get(y) ?? []);
662662
}

test/output/athletesSample.svg

Lines changed: 1 addition & 3 deletions
Loading

test/output/athletesSportWeight.svg

Lines changed: 1 addition & 3 deletions
Loading

test/output/emptyFacet.svg

Lines changed: 47 additions & 0 deletions
Loading

test/output/projectionFitAntarctica.svg

Lines changed: 0 additions & 2 deletions
Loading

test/output/shorthandBoxX.svg

Lines changed: 0 additions & 1 deletion
Loading

test/plots/empty-facet.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as Plot from "@observablehq/plot";
2+
3+
export default async function () {
4+
const data = [
5+
{PERIOD: 1, VALUE: 3, TYPE: "c"},
6+
{PERIOD: 2, VALUE: 4, TYPE: "c"}
7+
];
8+
return Plot.plot({
9+
facet: {data, x: "TYPE"},
10+
fx: {domain: ["a", "b"]},
11+
marks: [Plot.barY(data, {x: "PERIOD", y: "VALUE"})]
12+
});
13+
}

test/plots/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export {default as downloads} from "./downloads.js";
6464
export {default as downloadsOrdinal} from "./downloads-ordinal.js";
6565
export {default as driving} from "./driving.js";
6666
export {default as empty} from "./empty.js";
67+
export {default as emptyFacet} from "./empty-facet.js";
6768
export {default as emptyLegend} from "./empty-legend.js";
6869
export {default as emptyX} from "./empty-x.js";
6970
export {default as energyProduction} from "./energy-production.js";

0 commit comments

Comments
 (0)