Skip to main content

Scatter Plot Widget Roadmap

ScatterPlotWidget Development Roadmap

This document tracks remaining development tasks for the Scatter Plot Widget. For documentation of completed features and current architecture, see the main developer documentation.

Not yet implemented: Stale key handling (Phase 6.3).


Phase 7: External Feature Coloring (Widget Integration)

Status: Complete. All widget integration steps finished.

Goal: Color scatter points by an external data source (e.g., velocity colored by acceleration, points colored by whether they fall inside a DigitalIntervalSeries interval).

Completed Infrastructure

The shared CorePlotting/FeatureColor/ library is fully implemented and tested (24 test cases, 74 assertions). See the FeatureColor module docs for the full API reference. Key components:

  • FeatureColorSourceDescriptor — serializable pointer to a DataManager key + optional column
  • resolveFeatureColors() — per-point float lookup via ATS, TensorData (TFI hash join / ordinal positional), or DIS containment
  • checkFeatureColorCompatibility() — validates key existence, column existence, row-type compatibility
  • applyFeatureColorsToScene() — mutates RenderableGlyphBatch::colors[] via ContinuousMapping (colormap) or ThresholdMapping (binary)
  • computeEffectiveColorRange() — Auto/Manual/Symmetric vmin/vmax from resolved values
  • PlotSourceRowType — shared enum (replaces the earlier ScatterSourceRowType)

Rendering Pipeline

Feature coloring is a post-buildScatterPoints() color override inserted before group colors:

buildScatterPoints()          → ScatterPointData with time_indices
    → addGlyphs()             → uniform color from GlyphStyleData
    → applyFeatureColorsToScene()  → per-point color override (NEW)
    → applyGroupColorsToScene()    → group colors override feature colors
    → uploadScene()

No changes needed to SceneBuilder, GlyphRenderer, or shaders. Color priority (highest wins): navigate highlight > selected > group > feature > default glyph style.

Remaining Implementation Steps

Step Component Location Description
7.1 ScatterColorConfigData ScatterPlotWidget/Core/ ✅ Done
7.2 Properties panel UI ScatterPlotWidget/UI/ ✅ Done
7.3 Rendering integration ScatterPlotWidget/Rendering/ ✅ Done
7.4 Tooltip extension ScatterPlotWidget/Rendering/ ✅ Done
7.5 Unit tests tests/ScatterPlotWidget/ ✅ Done

7.1 ScatterColorConfigData

Create ScatterPlotWidget/Core/ScatterColorConfig.hpp:

struct ScatterColorConfigData {
    std::string color_mode = "fixed";              ///< "fixed" or "by_feature"

    std::optional<FeatureColorSourceDescriptor> color_source;

    std::string mapping_mode = "continuous";        ///< "continuous" or "threshold"

    // Continuous mode
    std::string colormap_preset = "viridis";
    ColorRangeConfig color_range;

    // Threshold mode
    double threshold = 0.5;
    std::string above_color = "#FF4444";
    std::string below_color = "#3388FF";
    float above_alpha = 0.9f;
    float below_alpha = 0.9f;
};

Add ScatterColorConfigData color_config to ScatterPlotStateData.

Add to ScatterPlotState: colorConfigChanged() signal, colorConfig() getter, setColorConfig() setter. Connect the signal to _scene_dirty = true in ScatterPlotOpenGLWidget::setState().

7.2 Properties Panel: “Point Coloring” Section

Add a collapsible Section to ScatterPlotPropertiesWidget between “Glyph Options” and “Selection Mode”:

┌─ Point Coloring ─────────────────────────────┐
│  Color Mode:  [ Fixed ▾ ]                    │  ← "Fixed" / "By Feature"
│                                               │
│  ── (visible only when "By Feature") ──       │
│  Data Key:    [ velocity ▾ ]                  │  ← DM keys (ATS, TensorData, DIS)
│  Column:      [ col_0 ▾ ]                     │  ← TensorData only; hidden for ATS/DIS
│  Status:      ✓ Compatible (ATS→ATS join)     │  ← checkFeatureColorCompatibility() result
│                                               │
│  Mapping:     [ Continuous ▾ ]                │  ← "Continuous" / "Threshold"
│                                               │
│  ── Continuous mode ─────────────────────     │
│  [ColormapControls widget]                    │  ← Reuse existing ColormapControls
│                                               │
│  ── Threshold mode ──────────────────────     │
│  Threshold:   [ 0.500    ]                    │
│  Above color: [■ #FF4444 ]                    │  ← QColorDialog
│  Below color: [■ #3388FF ]                    │  ← QColorDialog
└───────────────────────────────────────────────┘

Behaviors:

  • Data Key combo lists all DM keys of type ATS, TensorData, or DIS
  • Column combo shown only for TensorData keys; hidden otherwise
  • Selecting a DigitalIntervalSeries key auto-switches to Threshold mode (threshold=0.5)
  • Compatibility label updates dynamically on key/column change

7.3 Rendering Integration

In ScatterPlotOpenGLWidget::rebuildScene(), after builder.build() and before applyGroupColorsToScene():

auto const & cc = _state->colorConfig();
if (cc.color_mode == "by_feature" && cc.color_source.has_value()) {
    auto const feature_values = resolveFeatureColors(
        *_data_manager, *cc.color_source,
        _scatter_data.time_indices, _scatter_data.time_frame);

    FeatureColorMapping mapping;
    if (cc.mapping_mode == "threshold") {
        mapping = ThresholdMapping{
            static_cast<float>(cc.threshold),
            hexColorToVec4(cc.above_color, cc.above_alpha),
            hexColorToVec4(cc.below_color, cc.below_alpha)};
    } else {
        auto const range = computeEffectiveColorRange(feature_values, cc.color_range);
        if (range.has_value()) {
            auto const preset = colormapPresetFromString(cc.colormap_preset);
            mapping = ContinuousMapping{preset, range->first, range->second};
        }
    }

    applyFeatureColorsToScene(*_scene, feature_values, mapping, point_count);
}

applyGroupColorsToScene();  // Group colors override feature colors

Cache feature_values as a member for tooltip access (step 7.4).

7.4 Tooltip Extension

When feature coloring is active, append the feature value to the hover tooltip:

X: 1.234  Y: 5.678
TFI: 42
Color: 0.891 (velocity)           ← continuous mode
X: 1.234  Y: 5.678
TFI: 42
Color: 25.3 (velocity) [above]    ← threshold mode

Extend the PlotTooltipManager text provider to query the cached feature_values vector.


Design Decisions

  1. Post-build color override: Feature colors mutate RenderableGlyphBatch::colors[] after addGlyphs(), matching the existing applyGroupColorsToScene() pattern. No SceneBuilder or GlyphRenderer changes needed.

  2. Threshold mode as generalized binary coloring: A single threshold mapping handles DIS (0/1 at threshold=0.5), binary classifier output, and continuous cutoffs (e.g., “velocity > 20”). It is a peer of continuous colormap mode, not a special case.

  3. Shared CorePlotting/FeatureColor/ library: Resolution and rendering logic is shared with EventPlotWidget (Phase 5) and LinePlotWidget (Phase 3). Each widget provides its own time_indices and integrates the color config into its EditorState.


Other Remaining Work

Item Description
Phase 6.3 Stale key handling for color source (clear color_source when DM key is deleted)

Phase 8: SVG Export — Complete

Status: Complete. End-to-end export (state background color, exportToSVG(), properties button, handleExportSVG(), registration wiring) is implemented; manual validation in the running app has been performed. Uses PlottingSVG (same stack as EventPlotWidget and DataViewer_Widget).

Goal: Export the current scatter plot view to SVG for publication-quality figures.

Step Description Status
8.1 background_color in state + OpenGL clear from state Done
8.2 exportToSVG() on ScatterPlotOpenGLWidget Done
8.3 Export button + exportSVGRequested in properties Done
8.4 handleExportSVG() on ScatterPlotWidget Done
8.5 Wire signals in ScatterPlotWidgetRegistration Done
8.6 Manual validation Done

Verified: Project build; scatter plot ctest targets; interactive export exercised in the app (8.6 checklist below).

Architecture Assessment

The ScatterPlotWidget rendering pipeline is the most compatible of all remaining widgets:

  • It already caches a RenderableScene as _scene (std::unique_ptr<CorePlotting::RenderableScene>)
  • The scene contains RenderableGlyphBatch entries (circles, squares, crosses for scatter points) and optionally a RenderablePolyLineBatch (reference line). Both are fully supported by SVGGlyphRenderer and SVGPolyLineRenderer.
  • Feature colors and group colors are pre-applied to RenderableGlyphBatch::colors[] during rebuildScene(), so the SVG renderer sees the final per-point colors with no additional work.

Background color: ScatterPlotStateData includes background_color (default #1A1A1A, serializable). ScatterPlotOpenGLWidget uses updateBackgroundColor() (CoreUtilities::hexToRGB) in initializeGL() and paintGL(), and listens for backgroundColorChanged(). A properties-panel color control (like EventPlot) is optional and not required for SVG export.

Step 8.1: Add background_color to ScatterPlotStateData — Complete

Implemented in:

  • src/WhiskerToolbox/Plots/ScatterPlotWidget/Core/ScatterPlotState.hpp — on ScatterPlotStateData: std::string background_color = "#1A1A1A"; on ScatterPlotState: getBackgroundColor() / setBackgroundColor() and backgroundColorChanged(QString) signal
  • src/WhiskerToolbox/Plots/ScatterPlotWidget/Core/ScatterPlotState.cpp — setter implementation
  • src/WhiskerToolbox/Plots/ScatterPlotWidget/Rendering/ScatterPlotOpenGLWidget.cpp — updateBackgroundColor(), called from initializeGL() and paintGL(); connection to backgroundColorChanged in setState()

Verify: Project build; scatter plot tests pass.

Step 8.2: Add exportToSVG() to ScatterPlotOpenGLWidget — Complete

Follows the EventPlotOpenGLWidget pattern. The scatter plot caches _scene as std::unique_ptr<RenderableScene>; live view/projection matrices are copied onto the scene before export (the OpenGL path passes matrices into SceneRenderer::render(), so the CPU scene would otherwise keep identity defaults).

Declaration: [[nodiscard]] QString exportToSVG(); (non-const — mutates scene matrices for export).

Implementation (reference):

QString ScatterPlotOpenGLWidget::exportToSVG() {
    if (!_scene) {
        return {};
    }
    if (_scene->glyph_batches.empty() && _scene->poly_line_batches.empty() &&
        _scene->rectangle_batches.empty()) {
        return {};
    }

    _scene->view_matrix = _view_matrix;
    _scene->projection_matrix = _projection_matrix;

    PlottingSVG::SVGSceneRenderer renderer;
    renderer.setScene(*_scene);
    renderer.setCanvasSize(_widget_width, _widget_height);

    if (_state) {
        renderer.setBackgroundColor(_state->getBackgroundColor().toStdString());
    }

    return QString::fromStdString(renderer.render());
}

Implemented in: - Rendering/ScatterPlotOpenGLWidget.hpp / .cpp — exportToSVG(), #include <QString>, PlottingSVG/SVGSceneRenderer.hpp - CMakeLists.txt — target_link_libraries(ScatterPlotWidget PRIVATE PlottingSVG)

Verify: Project build; scatter plot tests pass.

Step 8.3: Add exportSVGRequested signal to ScatterPlotPropertiesWidget — Complete

Collapsible Export section with Export SVG… button (QSizePolicy::Expanding width), inserted before the bottom spacer; clicked connected to exportSVGRequested().

Implemented in: UI/ScatterPlotPropertiesWidget.hpp (signal + _createExportUI()), UI/ScatterPlotPropertiesWidget.cpp.

Verify: Project build; button visible in properties; scatter plot tests pass.

Step 8.4: Add handleExportSVG() to ScatterPlotWidget — Complete

Same pattern as EventPlotWidget::handleExportSVG(): AppFileDialog::getSaveFileName (id export_scatter_plot_svg), _opengl_widget->exportToSVG(), QMessageBox on empty scene / I/O failure / success.

Implemented in: - UI/ScatterPlotWidget.hpp — public slots: void handleExportSVG(); - UI/ScatterPlotWidget.cpp — implementation; includes StateManagement/AppFileDialog.hpp, QFile, QMessageBox, QTextStream - CMakeLists.txt — target_link_libraries(ScatterPlotWidget PRIVATE WhiskerToolbox::StateManagement)

Verify: Project build; scatter plot tests pass.

Step 8.5: Wire signals in ScatterPlotWidgetRegistration — Complete

In create_editor_custom, after props->setPlotWidget(view):

QObject::connect(props, &ScatterPlotPropertiesWidget::exportSVGRequested,
                 view, &ScatterPlotWidget::handleExportSVG);

Implemented in: ScatterPlotWidgetRegistration.cpp. Also removed an unused registry capture from the create_view lambda (was triggering -Wunused-lambda-capture).

Verify: Project build; scatter plot tests pass; in the app, Export SVG… opens the save dialog and produces SVG when the plot has geometry.

Step 8.6: Manual validation — Complete

Checklist used for sign-off (spot-check as needed for regressions):

  1. Load a dataset with scatter-compatible data (e.g., TensorData or paired AnalogTimeSeries)
  2. Open a ScatterPlotWidget, configure X/Y data sources
  3. Test with:
    • Default uniform glyph coloring (circles)
    • Feature coloring (continuous colormap mode)
    • Feature coloring (threshold mode)
    • Group coloring (color-by-group)
    • Reference line enabled
    • Point selection (polygon selection or single-click)
  4. Click “Export SVG” in the properties panel
  5. Open the resulting SVG in a web browser and/or Inkscape
  6. Verify:
    • Glyph positions match on-screen points
    • Per-point colors (feature/group) are correct
    • Selected points have highlight color
    • Reference line rendered as <polyline> (if enabled)
    • Background color is correct
    • Zoom/pan state is reflected

Design Notes

  • No PlottingSVG extensions needed: RenderableGlyphBatch (circles, squares, crosses, ticks) and RenderablePolyLineBatch (reference line) are both fully supported.
  • Selection highlights included: Selected and navigated-highlight glyphs are separate GlyphBatch entries in the scene with their own colors/sizes, so they export automatically.
  • Polygon selection overlay NOT exported: The PolygonInteractionController preview is rendered via PreviewRenderer (not part of the RenderableScene), so the in-progress polygon outline will not appear in the SVG. This is desirable — the polygon is transient interaction state, not a data visualization element.

See Also