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

Enable pure JS linking of the view, selection, and hover state #82

Open
flekschas opened this issue Jul 17, 2023 · 2 comments
Open

Enable pure JS linking of the view, selection, and hover state #82

flekschas opened this issue Jul 17, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@flekschas
Copy link
Owner

When exporting a notebook to HTML via the following snippet, the resulting HTML file properly renders the scatter plot instance and data but the view, selection, and hover linking do not work as they currently require a Python kernel. However, this is not necessary. By using jslink() we can ensure that the linking works with and without a Python kernel. Therefore, we should switch jslink() over observe().

jupyter nbconvert --execute --to html notebooks/get-started.ipynb
@flekschas
Copy link
Owner Author

Having had a quick look, using jslink over observe is tricky as regl-scatterplot strictly relies on the data indices (incrementing integers) while jscatter also supports selections via a Pandas index. To link two scatters by via Pandas indices, the selection relies on querying the Pandas DataFrame by its indices and then getting the data indices.

Say we have the following setup.

import jscatter
import pandas as pd

df_one = pd.DataFrame({
    'id': ['a', 'b', 'c'],
    'x': [1, 2, 3],
    'y': [1, 2, 3],
})
df_two = pd.DataFrame({
    'id': ['b', 'c', 'a'],
    'x': [1, 2, 3],
    'y': [1, 2, 3],
})

config = {
    'x': 'x',
    'y': 'y',
    'color_by': 'id',
    'size': 20,
    'legend': True
}

scatter_one = jscatter.Scatter(data=df_one, **config)
scatter_two = jscatter.Scatter(data=df_two, **config)

jscatter.link([scatter_one, scatter_two], match_by='id')

Simply linking the selection won't work because a in the first scatter has the index 0 but in the second scatter it has index 2. Without access to the dataframe, I'm not sure how to get around this. The only alternative that comes to mind here requires a big refactor where the ID mapping is exposed to the JS kernel to allow client-side only ID matching.

Any thoughts @manzt?

@manzt
Copy link
Collaborator

manzt commented May 12, 2024

The only alternative that comes to mind here requires a big refactor where the ID mapping is exposed to the JS kernel to allow client-side only ID matching.

Yeah, I'm not sure I can think of a workaround either unfortunately. jslink is super nice if you can get away with it, but usually limited. I wonder if there are some cases where the indexes are the the same (e.g., same data but different columns) and in that case jscatter.link could try for jslink?

Maybe that's too convoluted, or not even possible. I'm just wondering if there is a common case that could be supported with jslink (i.e. a jscatter.jslink), throwing an error if it's not possible.

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