From 5fa920dbc704b50415d499e5b12105b01d944457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Thu, 1 Apr 2021 19:15:08 +0200 Subject: [PATCH 1/2] function mark ``` Plot.plot({ marks: [ () => svg`Hello, function mark` ] }) ``` closes #182 --- src/plot.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/plot.js b/src/plot.js index 2665465c66..e77b332745 100644 --- a/src/plot.js +++ b/src/plot.js @@ -15,7 +15,11 @@ 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(mark => typeof mark === "function" ? { + initialize: () => ({ index: [], channels: [] }), + render: mark + } : mark); // A Map from Mark instance to an object of named channel values. const markChannels = new Map(); From 2dca478bf1e353e016653b44ef22fff2257ff4bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Thu, 1 Apr 2021 19:21:52 +0200 Subject: [PATCH 2/2] render mark ``` Plot.plot({ marks: [ { render: () => svg`Hello, function mark` } ] }) ``` closes #182 --- src/plot.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/plot.js b/src/plot.js index e77b332745..20a72eaa13 100644 --- a/src/plot.js +++ b/src/plot.js @@ -15,11 +15,12 @@ export function plot(options = {}) { } // Flatten any nested marks. - const marks = options.marks === undefined ? [] : options.marks.flat(Infinity) - .map(mark => typeof mark === "function" ? { - initialize: () => ({ index: [], channels: [] }), - render: mark - } : mark); + const marks = options.marks === undefined ? [] : options.marks.flat(Infinity); + for (const mark of marks) { + if (mark.initialize === undefined) { + mark.initialize = () => ({ index: [], channels: [] }); + } + } // A Map from Mark instance to an object of named channel values. const markChannels = new Map();