Skip to content

Callout: new plot type#3650

Merged
swharden merged 29 commits intoScottPlot:mainfrom
NicolasLairNET:#3420
Apr 14, 2024
Merged

Callout: new plot type#3650
swharden merged 29 commits intoScottPlot:mainfrom
NicolasLairNET:#3420

Conversation

@NicolasLairNET
Copy link
Contributor

@NicolasLairNET NicolasLairNET commented Apr 11, 2024

This pull request add new Plot named LabelPlot which allows to create a Label draggable with a link an element

LabelPlot.mp4

See issue #3420 for more context.

using ScottPlot;
using ScottPlot.Plottables;

namespace Sandbox.WinForms;

public partial class Form1 : Form
{
    LabelPlot? labelBeingDragged = null;
    public Form1()
    {
        InitializeComponent();

        formsPlot1.Plot.Axes.SetLimits(-1, 10, -1, 1);
        var label = formsPlot1.Plot.Add.LabelPlot(
            "A beautiful draggable label\nCan be link with an element", 
            3, 
            0, 
            3, 
            0);

        label.Label.BorderColor = Colors.Blue;
        label.Label.BackColor = Colors.Blue.WithAlpha(.5);
        label.Label.Padding = 5;

        label.LineStyle = new LineStyle()
        {
            Color = label.Label.BorderColor,
            Width = label.Label.BorderWidth,
        };

        formsPlot1.MouseDown += FormsPlot1_MouseDown;
        formsPlot1.MouseUp += FormsPlot1_MouseUp;
        formsPlot1.MouseMove += FormsPlot1_MouseMove;
    }

    private void FormsPlot1_MouseMove(object? sender, MouseEventArgs e)
    {
        if (labelBeingDragged is null) return;
        labelBeingDragged.Move(e.X, e.Y);
        formsPlot1.Refresh();
    }

    private void FormsPlot1_MouseUp(object? sender, MouseEventArgs e)
    {
        labelBeingDragged = null;
        formsPlot1.Interaction.Enable();
        formsPlot1.Refresh();
    }

    private void FormsPlot1_MouseDown(object? sender, MouseEventArgs e)
    {
        LabelPlot? labelUnderMouse = GetLabelUnderMouse(e.X, e.Y);
        if (labelUnderMouse is not null)
        {
            labelBeingDragged = labelUnderMouse;
            labelBeingDragged.StartMove(e.X, e.Y);
            formsPlot1.Interaction.Disable();
        }
    }

    private LabelPlot? GetLabelUnderMouse(float x, float y)
    {
        foreach (LabelPlot label in formsPlot1.Plot.GetPlottables<LabelPlot>())
        {
            if (label.IsUnderMouse(x, y)) return label;
        }

        return null;
    }
}

@NicolasLairNET NicolasLairNET changed the title #3420 Add draggable LabelPlot Apr 11, 2024
@NicolasLairNET

This comment was marked as outdated.

@swharden

This comment was marked as outdated.

@drphobos

This comment was marked as outdated.

@NicolasLairNET

This comment was marked as outdated.

@BrianAtZetica BrianAtZetica mentioned this pull request Apr 13, 2024
@swharden
Copy link
Member

Looks like you figured out the build checks! I'm going to take over and make a few refinements then merge this in.

I'll rename this plot type to "callout". I found something similar as a Powerpoint shape and they call it a callout, and I like the idea of keeping the plottable name distinct from the primitive name.

image

Thanks again for this great new features! I'm excited to have it in the next release 🚀

@NicolasLairNET
Copy link
Contributor Author

NicolasLairNET commented Apr 13, 2024

Thanks @swharden. The new name is perfect, I'm French and I couldn't find a good name in english for this new plot 😀.

@swharden swharden changed the title Add draggable LabelPlot Callout: new plot type Apr 13, 2024
@swharden
Copy link
Member

@swharden
Copy link
Member

I also lost an hour working on #3657 to make that curve to demonstrate this new plot type 😆

When it's done it's going to look great! 🚀

image

introduced earlier in this PR, resolves ScottPlot#3661
@swharden
Copy link
Member

This is looking fantastic! Merging now 🚀 🚀 🚀

callout

@swharden swharden merged commit bb43272 into ScottPlot:main Apr 14, 2024
@NicolasLairNET NicolasLairNET deleted the #3420 branch January 13, 2025 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants