Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/facet.js
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions src/mark.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
}
3 changes: 2 additions & 1 deletion src/plot.js
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions test/output/empty.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion test/plots/empty.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as Plot from "@observablehq/plot";
import {svg} from "htl";

export default async function() {
return Plot.plot({
Expand All @@ -11,7 +12,12 @@ export default async function() {
domain: [0, 1]
},
marks: [
Plot.frame()
Plot.frame(),
undefined,
null,
() => null,
() => undefined,
() => svg`<circle cx=50% cy=50% r=5 fill=green>`
]
});
}