This seems great - thanks!
Have you considered exposing just a function that computes *just* the points? For example, plot_points(Math.sin,-10,10) could return just a list of x/ pairs, as opposed to a graph. I ask because there are a lot of folks here at Observable with plenty of expertise in generating graphics with various tools. For many, computation of the points is the crux of the matter and it would be nice to have complete control over the graphics.
Evaluating a function with some values doesn't require a library and this can be done with JavaScript like this: https://codesandbox.io/s/interesting-ives-h422m?file=/src/index.js, the idea is to first generate the evaluation values (values between -10 and 10 in your example) and providing them to the evaluation function.
Right - it's easy to map a function over a list of points. I'm recommending that you expose the function that computes a good list of points over which to sample the function yielding a good graph, rather than just use evenly spaced points.
I actually whipped up my own here:
https://observablehq.com/@mcmcclur/adaptive-plotter
Thus, I could import the build_samples function from that notebook and use it, for example here:
https://observablehq.com/@mcmcclur/pluck
I wrote the build_samples function fairly hastily, though. I'm sure yours is much better. I'm using yours in this, as yet unpublished notebook, for example:
https://observablehq.com/d/6cdf570add5ba9d3
I hope my recommendation is more clear.
Thanks for the suggestion, computing the points is as you've seen a little bit more complicated than mapping over a list of evenly spaced points and joining them with line segments, some functions like 1/x have asymptotes, the library uses interval arithmetic instead to deal with this problem, I'll think of a format to expose the points to plot like an array of arrays where each subarray represents a part of the plot.