Skip to content

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

@apasarkar

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

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.

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.

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.

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.

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.

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.

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

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.

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.

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.

they can also specify a mapping Callable directly

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