8000 Refactor `mda_folder.selectionField` · Issue #111 · BCDA-APS/mdaviz · GitHub
[go: up one dir, main page]

Skip to content

Refactor mda_folder.selectionField #111

Open

Description

@rodolakis
    def selectionField(self):
        """
        Retrieves the current field selection for plotting.
        - Returns a dictionary with selected positioner and detectors indices.
        - Format: {'X': positioner_index, 'Y': [detector_indices]}.
        - Returns None if no selection is made.
        """
        return self._selection_field

    def setSelectionField(self, new_selection=None):
        """
        Updates the current field selection for plotting.
        - Accepts a dictionary specifying new selection of positioner and detectors.
        - Resets to None if given an empty dictionary.
        - Format for new_selection: {'X': positioner_index, 'Y': [detector_indices]}.
        """
        # TODO - how to enfore selectionField structure? Turn it into a class!
        # what if new_selectionvdoes not have X or Y key, or any of those key return
        # a None value? or is {}?
        self._selection_field = new_selection if new_selection != {} else None

Activity

  1. added
    enhancement
    on Apr 4, 2024
  2. added this to the v1.0 milestone on Apr 4, 2024
  3. self-assigned this
    on Apr 4, 2024
  4. moved this to Complicated in mdavizon Apr 4, 2024
  5. modified the milestones: v1.0, v1.1, v2.0 on Apr 12, 2024
  6. moved this from Complicated to v1.1 in mdavizon Jun 12, 2024
  7. rodolakis commented on Jul 24, 2025

    @rodolakis
    CollaboratorAuthor

    Current State:

    • self.selections (in MDAFileTableModel): {1: 'X', 2: 'Y', 4: 'Y', 4: 'I0'} - row-based format
    • self.selectionField() (in MDA_MVC): {'Y': [2, 3], 'X': 1, 'I0': 4} - column-based format
    • ftm2mda() and mda2ftm(): Convert between these two formats

    Problems with Current Approach:

    • Complexity: Two different data structures for the same information
    • Maintenance Burden: Every change requires updating both formats and conversion functions
    • Inconsistency: The multiple selection feature breaks the assumption that each row has exactly one selection

    Option 1: Unify to Single Format (Recommended)

    • Choose one format and stick with it throughout
    • Column-based format ({'Y': [2, 3], 'X': 1, 'I0': 4}) seems more natural because:
      • It directly represents what we want to plot (X, Y, I0 selections)
      • It's easier to extend (adding "Un" is just another key)
      • It's more intuitive for the plotting logic
    • Pros: Cleaner, more maintainable, easier to extend

    Option 2: Create a Selection Manager Class

    • Encapsulate selection logic in a dedicated class
    • Handle both formats internally
    • Pros: Clean interface, encapsulates complexity
    • Cons: More code, might be overkill
  8. changed the title [-]Make `mda_folder.selectionField` a class[/-] [+]Refactor `mda_folder.selectionField`[/+] on Jul 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

  • Status
    Upgrades

Relationships

None yet

Development

No branches or pull requests

Issue actions

0