Skip to content

Incorrect Comparison of X Coordinate for Vertical Drag Limits in DragTo Method of Text.cs #4587

@claire0821

Description

@claire0821

Issue: (Describe the bug here)
In the DragTo method of Text.cs, there is an issue with the way the vertical drag limits (DragYLimitMin and DragYLimitMax) are being applied. The conditionals for checking coordinateX should be comparing coordinateY instead, as the drag limits for the X and Y coordinates are being mistakenly mixed.
ScottPlot Version: (What NuGet package are you using?)
ScottPlot 4
Code Sample: See http://scottplot.net/faq/repro/ for tips about creating reproducible code samples

public void DragTo(double coordinateX, double coordinateY, bool fixedSize)
{
    if (!DragEnabled)
        return;

    Coordinate original = new(coordinateX, coordinateY);
    Coordinate snapped = DragSnap.Snap(original);
    coordinateX = snapped.X;
    coordinateY = snapped.Y;

    if (coordinateX < DragXLimitMin) coordinateX = DragXLimitMin;
    if (coordinateX > DragXLimitMax) coordinateX = DragXLimitMax;
    if (coordinateX < DragYLimitMin) coordinateY = DragYLimitMin;
    if (coordinateX > DragYLimitMax) coordinateY = DragYLimitMax;
    X = coordinateX + DeltaCX;
    Y = coordinateY + DeltaCY;
    Dragged(this, EventArgs.Empty);
}

Change the following lines in the DragTo method:

if (coordinateX < DragYLimitMin) coordinateY = DragYLimitMin;
if (coordinateX > DragYLimitMax) coordinateY = DragYLimitMax;

To

if (coordinateY < DragYLimitMin) coordinateY = DragYLimitMin;
if (coordinateY > DragYLimitMax) coordinateY = DragYLimitMax;

I came across a small issue in the DragTo method of Text.cs. It seems that the code is using coordinateX to check the vertical drag limits (DragYLimitMin and DragYLimitMax), but I believe it should actually be using coordinateY instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions