Skip to main content

DataViewer Ordering Abstractions Implementation Roadmap

Purpose

This roadmap defines a focused refactor that separates ordering concerns for DataViewer stacked lanes.

It introduces a reusable ordering model that decouples:

  1. metadata ingestion (for example, spike-sorter channel positions)
  2. sortable value derivation
  3. ordering policy resolution
  4. layout request assembly

This roadmap is intended to be completed before Phase 4b in mixed lanes and scaling work.

Relationship to Mixed-Lanes Roadmap

This document is a prerequisite for interactive lane drag-and-drop (Phase 4b) in:

  • docs/developer/ui/Plots/DataViewerWidget/mixed_lanes_and_scaling_implementation_roadmap.md

Rationale:

  • Phase 4b requires a stable source of truth for lane ordering.
  • Current ordering behavior still mixes policy and ingestion concerns.
  • A clean ordering abstraction reduces coupling and makes drag/drop persistence rules clearer.

Scope

In scope:

  • Introduce ordering-domain abstractions for stackable lane series.
  • Separate ingestion from sorting policy.
  • Add policy composition with deterministic precedence.
  • Add a persisted constraints model in DataViewer state.
  • Keep current behavior parity before enabling new constraint types.

Out of scope:

  • UI for authoring all rule types (JSON/state API first).
  • Full-canvas series reordering semantics.
  • Phase 4b drag/drop interaction implementation itself.

Locked Decisions

  1. Constraint scope (first release): stackable series only.
  2. Persistence model: ordering rules and constraints are serialized in DataViewerState.
  3. Conflict policy: explicit lane_order wins; constraints apply to unresolved relative ordering.

Success Criteria

  1. OpenGLWidget no longer owns ordering policy details.
  2. Spike-sorter support is one provider in a generic sortable-ranking model.
  3. Ordering remains deterministic under mixed explicit, relational, and fallback rules.
  4. Existing Phase 4 behavior remains unchanged after extraction.
  5. The resulting abstraction directly supports Phase 4b state updates.

High-Level Delivery Order

  1. Phase A: Baseline behavior lock
  2. Phase B: Ordering domain model extraction
  3. Phase C: Ingestion and ranking separation
  4. Phase D: Policy resolver introduction
  5. Phase E: Relational constraints model (stackable-only)
  6. Phase F: UI and renderer decoupling follow-through
  7. Phase G: Verification matrix and hardening

Phase A: Baseline Behavior Lock

Goal

Create a stable regression harness before refactoring ordering internals.

Tasks

Acceptance Criteria


Phase B: Ordering Domain Model Extraction

Goal

Introduce a normalized ordering input model independent of file format details.

Tasks

Acceptance Criteria


Phase C: Ingestion and Ranking Separation

Goal

Separate spike-sorter file parsing from ordering-policy execution.

Tasks

Acceptance Criteria


Phase D: Policy Resolver Introduction

Goal

Centralize ordering precedence logic in a dedicated resolver.

Resolver precedence

  1. explicit lane_order
  2. relational constraints (when present)
  3. fallback sortable provider ranks
  4. deterministic tie-break (series type precedence then stable key)

Tasks

Acceptance Criteria


Phase E: Relational Constraints Model (Stackable-Only)

Goal

Add persisted relative-order constraints to support richer semantics.

Example target use case

  • Place DigitalEventSeries 2 and 3 above AnalogTimeSeries channel 7.

Tasks

Acceptance Criteria


Phase F: UI and Renderer Decoupling Follow-Through

Goal

Ensure ownership and signal flow align with EditorState architecture.

Tasks

  • The seriesLaneOverrideChanged signal already triggers layout invalidation and repaint, so no manual dirty-flag management is needed in the new load/clear methods.

    New channels loaded after the config is applied land below all explicitly-ordered channels (no lane_order override → nullopt → after explicit series in resolver precedence). This is the intended behavior; re-running load rewrites all overrides from scratch.

  • [N/A] F3 – Replace spike_sorter_configs in LayoutRequestBuildContext with a SortableRankProvider. Superseded by F2: by converting positions to lane_order overrides at load time, LayoutRequestBuildContext never needs a spike-sorter-specific field at all. The SortableRankProvider type alias remains available for future rank providers.

  • [N/A] F4 – Wire SortableRankProvider through applyOrderingRules. Superseded by F2: the spike-sorter fallback path in applyOrderingRules is removed entirely; spike-sorter ordering flows through the existing explicit lane_order path.

Acceptance Criteria


Phase G: Verification Matrix and Hardening

Goal

Provide robust confidence for Phase 4b and future ordering features.

Verification matrix

  1. Explicit lane_order only
  2. Fallback ranking only
  3. Constraints only
  4. Explicit plus constraints
  5. Constraints plus fallback
  6. Explicit plus constraints plus fallback
  7. Shared-lane overlays with mixed series types

Tasks

Acceptance Criteria


Suggested PR Slicing

  1. PR 1: Baseline tests and ordering domain scaffolding
  2. PR 2: Spike-sorter parser/rank split
  3. PR 3: Policy resolver extraction
  4. PR 4: Relational constraints persistence and solver
  5. PR 5: Integration cleanup and docs

Definition of Done

The ordering-abstractions roadmap is complete when:

  • all phase acceptance criteria are met
  • ordering policy is modular and ingestion-agnostic
  • deterministic tests cover precedence and conflicts
  • mixed-lanes Phase 4 behavior remains intact
  • the codebase is ready to begin Phase 4b interactive drag/drop work