Extending Observable Plot with D3 in Observable Framework #1981
-
Hello, I’m working with Observable Plot (not in the notebook, but within the Observable Framework) and want to create complex plots. This includes e.g. highlighting shapes and using a split legend for charts. However, I’ve encountered limitations with Observable Plot, so I’ve switched to D3. But is rather cumbersome to produce simple charts and I’m interested in additions.
Thanks in advance for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Yes! You can create a custom mark by specifying a function:
the returned element must be a SVGElement; for a scatterplot, is typically a
The variables
In that case The documentation is still in flux, see https://github.com/observablehq/plot/pull/1811/files |
Beta Was this translation helpful? Give feedback.
-
For the first example, here's a working version: Plot.plot({
marks: [
Plot.lineY(
[
{ x: 1, y: 2 },
{ x: 2, y: 3 },
{ x: 3, y: 0 }
],
{ x: "x", y: "y" }
),
(_index, scales, _values, dimensions, context) => {
const g = d3.create("svg:g");
g.append("circle")
.attr("cx", 100)
.attr("cy", 50)
.attr("r", 50)
.attr("fill", "red");
return g.node();
}
]
}) I fixed the second example; it is supposed to log the arguments and display a text, which explains why you're only seeing a text :) Here's a third example where I'm using the last argument "next" to have Plot generate the line chart, then I can animate it with D3:
|
Beta Was this translation helpful? Give feedback.
For the first example, here's a working version:
I fixed the second example; it is supposed to log the arguments and display a text, which explains why you're only seeing a text :)
Here's a third example where I'm using the last argument "next" to have Plot generate the line chart, …