Skip to content

AxisLine: Allow override of automatic label alignment#3640

Merged
swharden merged 4 commits intoScottPlot:mainfrom
MCF:fix-axisline-label-positioning
Apr 11, 2024
Merged

AxisLine: Allow override of automatic label alignment#3640
swharden merged 4 commits intoScottPlot:mainfrom
MCF:fix-axisline-label-positioning

Conversation

@MCF
Copy link
Contributor

@MCF MCF commented Apr 11, 2024

Fixes #3624

New flag on AxisLine objects called UseAutoAlignment. Defaults to true, if set to false the Label.Alignment property not set to the AxisLine default. Gives full control over the label positioning, allowing such things as rotating the label sensibly.

New cookbook recipe is included in the PR. Recipe is shown below along with the resulting plot below that.

myPlot.Add.Signal(Generate.Sin());
myPlot.Add.Signal(Generate.Cos());

var axLine1 = myPlot.Add.VerticalLine(42);
axLine1.Text = "Line 1";
axLine1.Label.Rotation = -90;
axLine1.UseAutoAlignment = false;   // Disable automatic alignment
axLine1.Label.Alignment = Alignment.MiddleRight;

var axLine2 = myPlot.Add.HorizontalLine(0.75);
axLine2.Text = "Line 2";
axLine2.Label.Rotation = 0;
axLine2.UseAutoAlignment = false;   // Disable automatic alignment
axLine2.Label.Alignment = Alignment.MiddleRight;

// extra padding on the bottom and left for the rotated labels
myPlot.Axes.Bottom.MinimumSize = 60;
myPlot.Axes.Left.MinimumSize = 60;

AxisLineLabelPositioning

MCF and others added 4 commits April 10, 2024 17:23
Introduce a flag called UseAutoAlignment which defaults to true.
Setting to false will prevent overriding the Lable.Alignment property
with the default label alignment.
@swharden
Copy link
Member

This looks great @MCF, thanks so much! The cookbook recipe is helpful too.

I extended this PR to add a more shortcut properties to these classes so users don't have to reach into the Label or LineStyle classes for the most typical customizations, which also simplified the cookbook recipes. I also made TextAlignment nullable, so it's used when assigned and the default alignment is used when it's not without requiring a bool flag.

These revisions really improved the cookbook recipes for these plot types. Thanks again! 🚀

@swharden swharden merged commit 695629d into ScottPlot:main Apr 11, 2024
@MCF MCF deleted the fix-axisline-label-positioning branch April 11, 2024 16:28
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.

AxisLine: Text should respect Label alignment

2 participants