diff --git a/src/facet.js b/src/facet.js
index 3f48d37ce1..9473026e02 100644
--- a/src/facet.js
+++ b/src/facet.js
@@ -1,6 +1,6 @@
import {cross, difference, groups, InternMap} from "d3";
import {create} from "d3";
-import {Mark, first, second} from "./mark.js";
+import {Mark, first, second, markify} from "./mark.js";
import {applyScales} from "./scales.js";
import {filterStyles} from "./style.js";
@@ -21,7 +21,7 @@ class Facet extends Mark {
],
options
);
- this.marks = marks.flat(Infinity);
+ this.marks = marks.flat(Infinity).map(markify);
// The following fields are set by initialize:
this.marksChannels = undefined; // array of mark channels
this.marksIndex = undefined; // array of mark indexes (for non-faceted marks)
diff --git a/src/mark.js b/src/mark.js
index 45cd137353..1a9ad193b7 100644
--- a/src/mark.js
+++ b/src/mark.js
@@ -271,3 +271,17 @@ export function isTemporal(values) {
return value instanceof Date;
}
}
+
+export function markify(mark) {
+ return mark instanceof Mark ? mark : new Render(mark);
+}
+
+class Render extends Mark {
+ constructor(render) {
+ super();
+ if (render == null) return;
+ if (typeof render !== "function") throw new TypeError("invalid mark");
+ this.render = render;
+ }
+ render() {}
+}
diff --git a/src/plot.js b/src/plot.js
index 777cd76a81..e2d526853f 100644
--- a/src/plot.js
+++ b/src/plot.js
@@ -1,6 +1,7 @@
import {create} from "d3";
import {Axes, autoAxisTicks, autoAxisLabels} from "./axes.js";
import {facets} from "./facet.js";
+import {markify} from "./mark.js";
import {Scales, autoScaleRange, applyScales} from "./scales.js";
import {filterStyles, offset} from "./style.js";
@@ -15,7 +16,7 @@ export function plot(options = {}) {
}
// Flatten any nested marks.
- const marks = options.marks === undefined ? [] : options.marks.flat(Infinity);
+ const marks = options.marks === undefined ? [] : options.marks.flat(Infinity).map(markify);
// A Map from Mark instance to an object of named channel values.
const markChannels = new Map();
diff --git a/test/output/empty.svg b/test/output/empty.svg
index 0cc4729c0a..8f790da6ef 100644
--- a/test/output/empty.svg
+++ b/test/output/empty.svg
@@ -92,4 +92,5 @@
+
\ No newline at end of file
diff --git a/test/plots/empty.js b/test/plots/empty.js
index 12d68afdf6..6c7a8e4a2c 100644
--- a/test/plots/empty.js
+++ b/test/plots/empty.js
@@ -1,4 +1,5 @@
import * as Plot from "@observablehq/plot";
+import {svg} from "htl";
export default async function() {
return Plot.plot({
@@ -11,7 +12,12 @@ export default async function() {
domain: [0, 1]
},
marks: [
- Plot.frame()
+ Plot.frame(),
+ undefined,
+ null,
+ () => null,
+ () => undefined,
+ () => svg``
]
});
}