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
- Create a
PlotDialog with PlotType.CURVE and add a curve
- Add
YRangeCursorTool to the manager
- Activate the Y-range cursor tool
- Drag the top horizontal cursor below the bottom cursor
- 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 < y < %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 < y < %g", lambda ymin, ymax: (min(ymin, ymax), max(ymin, ymax))),
("∆y=%g", lambda ymin, ymax: abs(ymax - ymin)),
)
Describe the bug
The default
LABELFUNCSofYRangeCursorTooldisplayy0 < y < y1and∆y = y1 - y0without sorting the values. When the user drags the cursors so thaty0 > y1, the inequality becomes mathematically incorrect and∆ybecomes negative, which has no meaning for a range width.To Reproduce
PlotDialogwithPlotType.CURVEand add a curveYRangeCursorToolto the managery0 < y < y1is displayed withy0 > y1, and∆yis negativeExpected behavior
The annotation should always display values in sorted order:
min(y0, y1) < y < max(y0, y1), and∆yshould 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 theYRangeCursorToolclass definition:The lambdas assume ymin < ymax, but YRangeSelection does not enforce this ordering. The fix should sort the values: