GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Get nearest graphics by kushalkolar · Pull Request #519 · fastplotlib/fastplotlib

Conversation

@kushalkolar

@kushalkolar kushalkolar commented Jun 17, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
kushalkolar added 3 commits June 17, 2024 00:22
@kushalkolar
bugfix
56a22c1
@kushalkolar
center works, need to figure out what's wrong with edge
39ce0af
@kushalkolar
allow passing graphic collection to subset
d1cc1ca
@kushalkolar

kushalkolar commented Jun 17, 2024

Copy link
Copy Markdown
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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@clewis7

clewis7 commented Jun 17, 2024

Copy link
Copy Markdown
Member

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...

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kushalkolar

kushalkolar commented Jun 17, 2024

Copy link
Copy Markdown
Member Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kushalkolar added 6 commits June 17, 2024 23:20
@kushalkolar
Merge branch 'main' of https://github.com/fastplotlib/fastplotlib
12a3990
@kushalkolar
allow passing graphic collection to subset
fee3d8d
@kushalkolar
move get_nearest_graphics to utils
5db9d3e
@kushalkolar
move stuff
5aef21d
@kushalkolar
test for get nearest
440d9f8
@kushalkolar
Merge branch 'get-nearest' of https://github.com/fastplotlib/fastplotlib
3a79eb7
 into get-nearest
@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 added 2 commits June 18, 2024 00:12
@kushalkolar
black
7b41a1e
@kushalkolar
more black
196972b
@kushalkolar

kushalkolar commented Jun 18, 2024

Copy link
Copy Markdown
Member Author

@clewis7 ready for review!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

clewis7
clewis7 reviewed Jun 18, 2024
View reviewed changes
Comment thread fastplotlib/utils/_plot_helpers.py
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")

@clewis7 clewis7 Jun 18, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@kushalkolar kushalkolar Jun 18, 2024

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

clewis7 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
clewis7
clewis7 reviewed Jun 18, 2024
View reviewed changes

@clewis7 clewis7 left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

See question...

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
clewis7
clewis7 approved these changes Jun 18, 2024
View reviewed changes
@kushalkolar
kushalkolar merged commit a07636c into main Jun 18, 2024
@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

Reviewers

@clewis7 clewis7 clewis7 approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Plot area nearest graphics method

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@kushalkolar @clewis7
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.