Skip to content

YRangeCursorTool: annotation shows incorrect inequality and negative ∆y when y0 > y1 #306

@dappham-CODRA

Description

@dappham-CODRA

Describe the bug

The YRangeCursorTool annotation label displays y0 < y < y1 and ∆y = y1 - y0. Unlike XRangeSelection where x values are always ordered (x0 < x1), the Y range cursor allows the user to place cursors in any order, meaning y0 can be greater than y1. This results in a mathematically incorrect inequality (y0 < y < y1 with y0 > y1) and a negative ∆y, which has no physical meaning for a range width.

To Reproduce

  1. Open DataLab with a signal
  2. Activate the Y range cursor tool (YRangeCursorTool) from the plot toolbar
  3. Drag the top horizontal cursor below the bottom cursor so that the first Y value is greater than the second
  4. Observe the annotation label: y0 < y < y1 is displayed with y0 > y1, and ∆y is negative

Expected behavior

The annotation should always display values in sorted order: min(y0, y1) < y < max(y0, y1), and ∆y should always be the absolute range width (positive value), regardless of cursor placement order.

Image

Installation information

  • DataLab installation type: Python package (development)

Additional context

The issue is located in datalab/gui/docks.py, in CurveStatsToolFunctions.set_labelfuncs() (line ~95):

else:  # YRangeCursorTool
    labelfuncs = (
        ("%g &lt; y &lt; %g", lambda ymin, ymax: (ymin, ymax)),
        ("∆y=%g", lambda ymin, ymax: ymax - ymin),
    )

The lambdas assume ymin < ymax, but this is not guaranteed by YRangeCursorTool. The fix should sort the values:

("%g &lt; y &lt; %g", lambda ymin, ymax: (min(ymin, ymax), max(ymin, ymax))),
("∆y=%g", lambda ymin, ymax: abs(ymax - ymin)),

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions