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

connect points by straight lines #130

Open
abast opened this issue May 30, 2024 · 6 comments
Open

connect points by straight lines #130

abast opened this issue May 30, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@abast
Copy link

abast commented May 30, 2024

The example in the docs connects lines by curved lines:

data = '''0	0.13	0.27	A	2
1	0.87	0.93	A	1
2	0.10	0.25	B	2
3	0.03	0.90	A	3
4	0.19	0.78	B	1'''
data = [d.split('	') for d in data.split('\n')]
df = pd.DataFrame(data).set_index(0)
df.columns = ['x','y','group','order']
df['x'] = df.x.astype(float)
df['y'] = df.y.astype(float)
df['order'] = df.order.astype(float)

scatter = Scatter(data = df, x = 'x', y = 'y', width = 320, height = 320)
scatter.connect(by='group')

scatter.show()
image

Would it be possible to connect points with straight lines instead? How exactly are the lines computed?

@flekschas
Copy link
Owner

Right now all lines are spline interpolated as that works well across many use cases. Unfortunately you can't control the "curviness" or even render straight lines. Technically that would of course be possible but we would need to implement that feature for regl-scatterplot first. I don't have the bandwidth for working on this at the moment but if you have time, please go ahead and take a stab at it. I don't think it would be a hard lift to enable straight lines as all we really need is to skip the spline interpolation step when creating the line segments.

@abast
Copy link
Author

abast commented Jun 3, 2024

Can you point me to the code that deals with plotting the lines?

@flekschas
Copy link
Owner

It should be fairly straight forward. All we gotta do is have an option to skip createSplineCurve in https://github.com/flekschas/regl-scatterplot/blob/master/src/index.js#L2014 and instead pass newPoints directly into https://github.com/flekschas/regl-scatterplot/blob/master/src/index.js#L2020. The only extra bit we need is a function that groups newPoints such that each set of connected points is a flat list of 2D point coordinates. E.g., we need to separately call groupPoints() from https://github.com/flekschas/regl-scatterplot/blob/master/src/spline-curve-worker.js#L205-L231.

@flekschas flekschas added the enhancement New feature or request label Jun 4, 2024
@flekschas
Copy link
Owner

I just realized, there's an easy workaround to achieve straight lines:

scatter.options({ 'pointConnectionTolerance': 1 })

By increasing the tolerance, fewer to literally no interpolated points are added. E.g:

With a tolerance of 1 / 5000

Screenshot 2024-06-04 at 9 41 01 PM

With a tolerance of 1

Screenshot 2024-06-04 at 9 40 27 PM

This isn't the very best solution but at least it should get you there without any code changes.

@abast
Copy link
Author

abast commented Jun 5, 2024

That's great, thanks for this workaround and for having another look at it!

@flekschas
Copy link
Owner

FYI, there are a few glitches related to connected scatterplots I recently found and fixed in #125. I'm hoping to cut a new release with the fixes soon 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
2 participants