← 返回首页
Selection vector improve by apasarkar · Pull Request #1061 · fastplotlib/fastplotlib · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

Selection vector improve#1061

Draft
apasarkar wants to merge 6 commits into
ndwidgetfrom
selection_vector_improve
Draft

Selection vector improve#1061
apasarkar wants to merge 6 commits into
ndwidgetfrom
selection_vector_improve

Conversation

Copy link
Copy Markdown
Collaborator

Addresses #1047.

Concrete changes:

  • Includes logic to block re-entrance when selections are changed
  • Includes more compact code for adding selectors to make things more declarative. Now the user just provides the selector + a global index --> local index mapping. This mapping is given by a 1D array (or a dictionary). The inverse mapping and event handler logic is dealt with internally within SelectionVector.
  • Fills in missing functionality: clear selectables, remove, remove_selector

apasarkar marked this pull request as draft June 11, 2026 05:16

@selection.setter
def selection(self, value: Iterable[int] | dict[Literal["rows", "cols", "pixels"], list]) -> None:
def selection(self, value: Iterable[int] | dict[Literal["rows", "cols", "pixels"], list] | None) -> None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

value can also be Iterable[int | None]

import numpy as np
from ._protocols import SelectorProtocol, MultiSelectorProtocol

from fastplotlib.graphics.features._base import GraphicFeatureEvent

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

relative import

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

deleting for now because SelectionVector just works with VisibilitySelector + HighlightSelector (+ subclasses)

# selector -> (map, map_inv)
self._selectors: dict[
SelectorProtocol | MultiSelectorProtocol, tuple[Callable, Callable]
SelectorProtocol | MultiSelectorProtocol, tuple[Callable, Callable, list]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

list[Callable] for the handlers

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

code comment above when type signature is large

self._block_reentrance = True
if isinstance(new, Integral):
new = [new]
self._selection = [i for i in new]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

this doesn't do anything, can just be self._selection = new

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

@kushalkolar thought about this -- this does something. if the input is any iterable other than a list, it makes the input a list.

self._selection = [i for i in new]
# iterate through each selector that operates in its own "local" space
for selector_local, (map_, map_inv, handler) in self._selectors.items():
cumulated_output = []

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

call it local_indices

for value in new:
curr_indices = map_(value)
cumulated_output.append(curr_indices)
# indices_local = map_(new)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

get rid of stale code

if not isinstance(selector, MultiSelectorProtocol):
continue

index_local = map_([index])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

this should be a scalar now and not a vector

),
):
"""
User specifies (1) the selector and (2) The master --> local index mapping. This

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

they can also specify a mapping Callable directly

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

2 participants

Footer

© 2026 GitHub, Inc.