Skip to content

Get nearest graphics #519

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

Merged
merged 11 commits into from
Jun 18, 2024
Merged

Get nearest graphics #519

merged 11 commits into from
Jun 18, 2024

Conversation

kushalkolar
Copy link
Member

@kushalkolar kushalkolar commented Jun 17, 2024

closes #514

WIP, need to finish edge method

from itertools import product
import numpy as np
import fastplotlib as fpl


def make_circle(center, radius: float, n_points: int = 75) -> np.ndarray:
    theta = np.linspace(0, 2 * np.pi, n_points)
    xs = radius * np.sin(theta)
    ys = radius * np.cos(theta)

    return np.column_stack([xs, ys]) + center


spatial_dims = (100, 100)

circles = list()
for center in product(range(0, spatial_dims[0], 15), range(0, spatial_dims[1], 15)):
    circles.append(make_circle(center, 5, n_points=75))

fig = fpl.Figure()

lines = fig[0, 0].add_line_collection(circles, colors="r", thickness=5)


def highlight_nearest(ev):
    lines.colors = "r"
    
    xy = fig[0, 0].map_screen_to_world(ev)[:-1]
    nearest = fig[0, 0].get_nearest_graphics(xy, method="center", subset=lines)
    
    nearest[0].colors = "w"

fig.renderer.add_event_handler(highlight_nearest, "pointer_move")

fig.show()
get_nearest-2024-06-17_00.35.24.mp4

@kushalkolar
Copy link
Member Author

@clewis7 @apasarkar what about just skipping the edge method, using the bbox is actually useless for many real use cases like this where there is lots of overlap 🙃

image

@clewis7
Copy link
Member

clewis7 commented Jun 17, 2024

This looks amazing!! I am okay with skipping edge. When I think about doing something like clicking a contour I would be clicking near the center...

@kushalkolar
Copy link
Member Author

I think I'm going to make this a function in fastplotlib.utils

@kushalkolar kushalkolar marked this pull request as ready for review June 18, 2024 04:10
@kushalkolar kushalkolar requested a review from clewis7 as a code owner June 18, 2024 04:10
@kushalkolar
Copy link
Member Author

@clewis7 ready for review!

Comment on lines +36 to +37
if not all(isinstance(g, Graphic) for g in graphics):
raise TypeError("all elements of `graphics` must be Graphic objects")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there also be a check for if all the graphics are in the same subplot? Or would that not make a difference?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We leave that to the user, so it's just a very simple function unaware of plot areas

Copy link
Member

@clewis7 clewis7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See question...

@kushalkolar kushalkolar merged commit a07636c into main Jun 18, 2024
10 checks passed
@kushalkolar kushalkolar deleted the get-nearest branch June 18, 2024 23:13
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

Successfully merging this pull request may close these issues.

Plot area nearest graphics method
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy