Skip to content

FastSense: add AutoFitY — auto-scale the Y axis to the data visible in the current X window #362

Description

@HanSur94

Problem / motivation

When you zoom into an X (time) window on a FastSense plot, the Y axis never rescales — it stays at the full-dataset range. A small feature riding on a large-amplitude signal therefore renders as a flat line once you zoom in, and the user has to fiddle with ylim manually to see any detail.

This is verified in code:

  • At render, FastSense pins Y to the full data range: set(obj.hAxes,'YLim',[yLimLow,yLimHigh]) (libs/FastSense/FastSense.m:1497) followed by set(obj.hAxes,'YLimMode','manual') (:1500), cached as FullYLim (:1504) for the Home button (:3970).
  • The primary zoom/pan listener onXLimChanged (registered at :1533) re-downsamples for the new X view but never touches Y.

Auto-fit-Y-on-zoom is the single most-requested time-series interaction after zoom itself — every oscilloscope / trace viewer has it. For a MATLAB sensor engineer scanning a long recording, it turns "zoom in → flat line" into "zoom in → see the detail."

Tracker checked (autoscale, YLimMode, AutoY, fit y visible): no existing issue. (#300 secondary y-axis and #263/#285 fixed limits are the opposite — they pin limits; this fits to the view.)

Proposed feature

An opt-in 'AutoFitY' name-value option on FastSense. When enabled, every time the visible X window changes (zoom/pan), the Y axis is rescaled to the min/max of the data currently visible in that window (with a small headroom pad). Default false preserves today's exact behavior.

Rough sketch

  • Lib/class: libs/FastSense/FastSense.m only.
  • Public API: FastSense(..., 'AutoFitY', true) (default false), parsed via the existing parseOpts mechanism. Optionally a runtime setAutoFitY(tf) setter mirroring the other set* toggles.
  • Mechanism: in onXLimChanged (the existing zoom/pan hook), when AutoFitY is on, scan the displayed lines' YData over the current XLim and set YLim to [min max] plus a small pad. MinMax downsampling already preserves per-window extremes, so the displayed YData min/max is the true visible extent — no extra data pass.
  • Home button: decide whether Home re-fits or restores FullYLim (flagged as a product micro-decision below).
  • Guard: if the visible window is empty / all-NaN, leave YLim unchanged.

Value

A genuine new end-user capability (not builder convenience): see detail on zoom instead of a flat line, with zero manual ylim calls. Later forwardable to FastSenseWidget via the established forward-an-option pattern (cf. #290 / #298 / #301).

Constraints check

  • Toolbox-free: yes — plain axes YLim manipulation.
  • Backward-compatible: yes — opt-in, default false preserves current manual-full-range behavior; FastSense config is not serialized, so no dashboard/JSON round-trip impact.
  • Pure MATLAB/Octave: yes.
  • Existing contract: stays within the FastSense render/update lifecycle; piggybacks on the existing onXLimChanged listener.

Effort estimate

S–M — one parseOpts default + a small refit block in onXLimChanged + Home-button interaction + empty/all-NaN guard, all in FastSense.m. One focused test: zoom into a sub-window of a spiky-vs-flat signal and assert YLim tightened to the visible extent; assert AutoFitY=false leaves it at FullYLim.

Open product micro-decisions for triage: the Y headroom pad fraction, and whether the Home button re-fits or restores the full range.


AI-proposed via /feature-scout — needs a human product decision before implementation.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions