-
Notifications
You must be signed in to change notification settings - Fork 205
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
Feature : custom user functions for the plot plugin interpreter. #335
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 89d4eb9:
|
if (imported !== undefined) { | ||
math.import(imported, {}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it problematic to import multiple times? In that case, could we check if the expressions has already been imported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is, at first I tried to create one global instance and to call import inside the getSymbols function but it fails because of dupplication.
This is very cool! I don't see the clunkyness as a big problem 🤔 What would happen if the user tried to import the same expression twice? If it fails silently, we can just leave that to the user - assuming they'd read docs |
Co-authored-by: Gianmarco <[email protected]>
Hi @gsimone and thanks for you review. Yes as mentionned above multiple imports on the same symbols fails (the plot also fails to render properly). I guess if we want to avoid recreating an instance we can check symbols on a map / set but it seems overkill. Also we might want to discuss the proper keyword to use for this, Cheers. |
Maybe we could think of an alternate api where we // imagine using it in a setup file
|
Good idea that might be worth a try. Looking into it I'm not sure how to go about it though, do you have an idea for the actual implementation ? It seems the advantage of the current implementation is to be able to extend plots individually, for example by giving previous functions / symbols to the next plot (à la graphtoy). So maybe we can go with both ideas : a default |
Hey everyone,
So I'm interested into adding custom functions - like
smoothstep
- to the plot plugin using the import function of the underlying mathjs library.Here is a proof of concept implementation which allow the user to provide an
imported
attribute to the plot function accepting a dictionnary of functions.For example :
The idea is to define the functions in a general dictionnary once and pass it to a plot wrapper for the whole app, as each plot will instanciate mathjs before evaluation to import its custom functions (a bit of a caveat I suppose).
Here's a simplified clojurescript version of what I'm using for example :
So it might become cumbersome for larger functions dictionnaries.