Skip to content
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

Behavior at jump discontinuities #133

Open
hazelnb opened this issue Jan 17, 2024 · 5 comments
Open

Behavior at jump discontinuities #133

hazelnb opened this issue Jan 17, 2024 · 5 comments

Comments

@hazelnb
Copy link

hazelnb commented Jan 17, 2024

Consider the plot <Plot.OfX y={(x: number) => math.mod(x, 1)}/>. This of course has a number of jump discontinuities, but by default mafs joins discontinuities with a vertical line. Personally, I find this behavior unexpected and undesirable and would like to at least have the option to configure the discontinutiy behavior. Something like Mathematica's Exclusions and ExclusionsStyle seem appropriate for the existing Mafs API. I.e., the user provides Plot.OfX with a parameter which tells it where the discontinuities are and how they should be drawn.

To my mind, this should either be:

  1. an array of x values of discontinuities
  2. a function (x: number): boolean

I think the "jump" style that I'm hoping for can be accomplished by modifying the onPoint callback in sampleParametric to output an M command rather than an L command if the t value of the point is a discontiuity.

Let me know what you think! I love the library, and I'm using it to make companion interactive visualizations for my dissertation :)

@stevenpetryk
Copy link
Owner

Totally agreed. I think the function approach might be required for cases where there are infinite discontinuities, but instead of accepting a number and returning a boolean, it should accept a range and return a list (with the option to pass a static list, no function).

Mafs could use those values and:

  • Evaluate continuity (or the user can explicitly specify)
  • Ensure additional points are plotted near these important points (whether continuous or not)

In other words, a way to indicate important regions to plot.

@stevenpetryk
Copy link
Owner

Agreed also on the approach for jump discontinuities.

For holes, the best approach would probably just be a two <circle>s: one to mask off the function, and one to show the classic circular outline.

This means adding a mask to some functions which may have an effect on perf, but I doubt it.

@stevenpetryk
Copy link
Owner

stevenpetryk commented Jan 18, 2024

Got a nice API for holes I think (not jumps yet, because the sample function scares me after not working with it for over a year).

CleanShot 2024-01-18 at 13 14 11@2x

I think this could be a bit more automated (like, in this case, it might be more convenient to pass in x = -0.5 and let Mafs figure out that it's NaN). However, I'm worried about imprecise computer math making that infeasible.

@stevenpetryk
Copy link
Owner

stevenpetryk commented Jan 18, 2024

CleanShot 2024-01-18 at 13 20 24@2x

I think JavaScript's stupidity IEEE-754's limitations will prevent a lot of ergonomics here. But I'm okay with devs having to do the math to tell Mafs where to display these indicators.

@hazelnb
Copy link
Author

hazelnb commented Jan 23, 2024

Wow thanks for starting working on this so quickly, this looks great! I think your modifications for the "jump" api make sense, and if you're open to doing code review I would be happy to take a crack at implementing it.

As a mathematician, I swear Javascript makes some truly odd choices for built in operators that have caused some surprising and sneaky bugs for my viz. I have certainly not come to expect ergonomics haha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants