flekschas / regl-scatterplot

Scalable WebGL-based scatter plot library build with Regl
https://flekschas.github.io/regl-scatterplot/
MIT License
184 stars 21 forks source link

Troubles with Connecting Points #171

Closed OreFoX18 closed 3 months ago

OreFoX18 commented 3 months ago

I've been trying to implement the feature of connecting points in my own dataset locally and kept encountering this error:
regl-scatterplot.esm.js:6949 Uncaught TypeError: Cannot read properties of undefined (reading 'points')

Later on, I tried running simplified example on Observable Notebook (https://observablehq.com/d/b42c6936f266a4c5) and still got the similar issue.

Could you please help me out, I'm running out of ideas.

Thank you in advance!

Haris

flekschas commented 3 months ago

Here is a working version: https://observablehq.com/d/bcacc006eb3c217a

Generally, next time start with a working version and do one step at a time. There were several issues in your notebook. (e.g., the colors were specified incorrectly. the y positions were out of bounds. the notebook error was TypeError: searchIndex is undefined and not TypeError: Cannot read properties of undefined (reading 'points')).

The root cause of the issue is a bug in regl-scatterplot caused by scatterplot.set({ showPointConnections: true }) before any points were drawn. I'll fix that right away.

flekschas commented 3 months ago

The fix will go out with the next version. Thanks for reporting the issue!

OreFoX18 commented 3 months ago

Dear Fritz,

Thank you for your swift assistance! Your guidance has been immensely helpful, and I truly appreciate your support.

I successfully implemented your suggestions into my dataset, and now the connections between points are visible. However, I've encountered a slight deviation from my intended outcome.

Shortly, in my dataset I've got around 42000 points which were ordered in clusters. Each cluster has one cluster representative and several or more cluster members. All the points are nicely positioned in 2D space using an algorithm. However, I have a particular requirement: I need to display connections exclusively between cluster members and their corresponding cluster representatives, omitting connections between cluster members themselves. I'm aware that one could specify the 6th value to change the order of how points are connected, but would that be helpful in my case where I want more connection lines to stem from one central point (cluster representative)?

For example: There are 10 points in one cluster (1 clust_rep + 9 clust_memb). The connections would be 1 -> 2, 1 -> 3, 1 -> 4, 1 ->5 etc.

I greatly value your expertise and look forward to your further insights.

Warm regards,

Haris

flekschas commented 3 months ago

That's unfortunately not supported out of the box. But since you only have 42K points, there's a workaround that should visually look identical: for each cluster member to cluster representative connection, duplication the representative point. Then for each member_i <> repr_i pair, choose a unique ID as the 5th element. This isn't elegant but at least it should work :)