Skip to content

Ellipse and Circle Plots#2437

Merged
swharden merged 15 commits intoScottPlot:mainfrom
bukkideme:main
Mar 4, 2023
Merged

Ellipse and Circle Plots#2437
swharden merged 15 commits intoScottPlot:mainfrom
bukkideme:main

Conversation

@bukkideme
Copy link
Contributor

@bukkideme bukkideme commented Mar 1, 2023

Hi!

This is where I managed to get so far :)
To be honest, the pixel/coordinate transformations got me confused a bit. Also, I am not sure how to lock the created circle to coordinate positions, so when i zoom in/out (with AxisScaleLock(true)), the circle size should follow it dynamically (this should be also optional i guess?).
Maybe you can give me some help in this? :)
Otherwise it does draw a circle at least :)
Thanks!

formsPlot1.Plot.AddCirclePlot(0, 0, 150);
//formsPlot1.Plot.SetAxisLimits(-150, 150, -150, 150);            
formsPlot1.Plot.AxisScaleLock(true);
formsPlot1.Plot.Render();
formsPlot1.Refresh();

image

@bukkideme
Copy link
Contributor Author

bukkideme commented Mar 2, 2023

Hmm, I am not really good at this :)
I should first better understand the pixel/coordinate calculations inside ScottPlot :)

This attempt works fine if XY= 0,0 , otherwise wrong width/height :)

public void Render(PlotDimensions dims, System.Drawing.Bitmap bmp, bool lowQuality = false)
{
    // Use ScottPlot's GDI helper functions to create System.Drawing objects
    using var gfx = ScottPlot.Drawing.GDI.Graphics(bmp, dims, lowQuality);
    using var pen = ScottPlot.Drawing.GDI.Pen(Color, LineWidth, LineStyle);

    // Use 'dims' methods to convert between axis coordinates and pixel positions            
    float xPixel = dims.GetPixelX(X - Radius);
    float yPixel = dims.GetPixelY(Y - Radius);
    
    // Render data by drawing on the Graphics object
    gfx.DrawEllipse(pen, xPixel, yPixel, dims.GetPixelX(Radius * 2) - dims.GetPixelX(X), dims.GetPixelY(Radius * 2) - dims.GetPixelY(Y));
    //gfx.DrawEllipse(pen, xPixel, yPixel, dims.GetPixelX(Radius * 2), dims.GetPixelY(Radius * 2));
}

@swharden
Copy link
Member

swharden commented Mar 4, 2023

Hi @bukkideme, thanks so much for getting this started!

I'll start working on this now and make some commits to this branch and possibly merge it in. I recommend not making additional commits while I'm working on it to avoid merge conflicts. Hopefully the changes I implement from here will help answer your questions!

Even though the code in its present state isn't working perfectly, getting this PR started was still a big help, so thanks! I'll follow-up with a message shortly to indicate my progress.

@swharden swharden changed the title Implementing CirclePlot - not finished CirclePlot Mar 4, 2023
@swharden swharden linked an issue Mar 4, 2023 that may be closed by this pull request
@bukkideme
Copy link
Contributor Author

Thanks very much for continue the implementation, i will certainly learn from the commits you will make! I do not commit new things from now then!

@swharden
Copy link
Member

swharden commented Mar 4, 2023

See 6364e92

I had to convert Radius from coordinate units to pixel units before the ellipse was drawn. Because X and Y scales may be different sizes (pixels per unit), I had to calculate it independently for X and Y.

Plot plt = new();
plt.AddCirclePlot(0, 0, 5);
TestTools.SaveFig(plt);

image

swharden added 6 commits March 4, 2023 11:49
modify the constructor so it only accepts data (not styling)

styling is modified by assigning to public properties rather than being passed into the constructor

also gave AddCircle() a Color argument
the same plot type can be used for AddEllipse() and AddCircle()
@swharden
Copy link
Member

swharden commented Mar 4, 2023

I'm adding legend support while I'm in here too

Plot plt = new(400, 300);

var c1 = plt.AddCircle(0, 0, 1);
c1.Label = "outlined";
c1.BorderLineWidth = 3;
c1.BorderLineStyle = LineStyle.Solid;
c1.BorderColor = System.Drawing.Color.Blue;

var c2 = plt.AddCircle(1, 1, 1);
c2.Label = "filled";
c2.BorderLineStyle = LineStyle.None;
c2.Color = System.Drawing.Color.Green;

var c3 = plt.AddCircle(2, 2, 1);
c3.Label = "both";
c3.Color = System.Drawing.Color.FromArgb(100, System.Drawing.Color.Green);
c3.BorderColor = System.Drawing.Color.Blue;
c3.BorderLineStyle = LineStyle.Dot;

plt.Legend();

image

@swharden swharden changed the title CirclePlot Ellipse and Circle Plots Mar 4, 2023
@swharden
Copy link
Member

swharden commented Mar 4, 2023

... and while the hood was popped, I made some changes elsewhere in the code base using this pull request. I hope it's not too confusing! 😅

This looks great, and I'm going to merge in a few minutes and hopefully release a new version of ScottPlot at the end of this weekend 🚀

@bukkideme
Copy link
Contributor Author

Awesome! :) I did not hope for such quick release! :) 🚀

@swharden swharden enabled auto-merge March 4, 2023 18:26
@swharden swharden merged commit e3d925a into ScottPlot:main Mar 4, 2023
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.

New Plot Type: Circle

3 participants