Skip to content

YRangeCursorTool: default LABELFUNCS show incorrect inequality and negative ∆y when cursors are inverted #55

@dappham-CODRA

Description

@dappham-CODRA

Describe the bug

The default LABELFUNCS of YRangeCursorTool display y0 < y < y1 and ∆y = y1 - y0 without sorting the values. When the user drags the cursors so that y0 > y1, the inequality becomes mathematically incorrect and ∆y becomes negative, which has no meaning for a range width.

To Reproduce

  1. Create a PlotDialog with PlotType.CURVE and add a curve
  2. Add YRangeCursorTool to the manager
  3. Activate the Y-range cursor tool
  4. Drag the top horizontal cursor below the bottom cursor
  5. 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 drag order.

Screenshots

N/A

Additional context

The issue is in plotpy/tools/curve.py, in the YRangeCursorTool class definition:

LABELFUNCS: tuple[tuple[str, Callable[..., Any]], ...] = (
    ("%g &lt; y &lt; %g", lambda ymin, ymax: (ymin, ymax)),
    ("∆y=%g", lambda ymin, ymax: ymax - ymin),
)

The lambdas assume ymin < ymax, but YRangeSelection does not enforce this ordering. The fix should sort the values:

LABELFUNCS: tuple[tuple[str, Callable[..., Any]], ...] = (
    ("%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

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions