Skip to content

ignore null marks #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion src/facet.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Facet extends Mark {
],
transform
);
this.marks = marks;
this.marks = marks.filter(d => !!d);
// 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
2 changes: 2 additions & 0 deletions src/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function plot(options = {}) {
// Initialize the marks’ channels, indexing them by mark and scale as needed.
// Also apply any scale transforms.
for (const mark of marks) {
if (!mark) continue;
if (markChannels.has(mark)) throw new Error("duplicate mark");
const named = Object.create(null);
const {index, channels} = mark.initialize();
Expand Down Expand Up @@ -93,6 +94,7 @@ export function plot(options = {}) {
.text(`.plot text { white-space: pre; }`);

for (const mark of marks) {
if (!mark) continue;
const channels = markChannels.get(mark);
const index = markIndex.get(mark);
const node = mark.render(index, scales, channels, dimensions, axes);
Expand Down
23 changes: 23 additions & 0 deletions test/marks/empty-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as Plot from "@observablehq/plot";
import {JSDOM} from "jsdom";
import tape from "tape-await";

tape("empty marks are ignored", test => {
global.document = new JSDOM("").window.document;
test.equal(
Plot.plot({ marks: [undefined, 0, null, Plot.dotX([0])] }).innerHTML,
Plot.plot({ marks: [Plot.dotX([0])] }).innerHTML
);
const data = [1,2,3];
test.equal(
Plot.plot({
facet: { data, y: d => d },
marks: [ false, Plot.dotX(data) ]
}).innerHTML,
Plot.plot({
facet: { data, y: d => d },
marks: [ Plot.dotX(data) ]
}).innerHTML
);
delete global.document;
});