Skip to content

Commit

Permalink
Merge pull request ScottPlot#1736 from ScottPlot/1732-resetlayout
Browse files Browse the repository at this point in the history
Axis: ResetLayout()
  • Loading branch information
swharden authored Mar 19, 2022
2 parents 3581f8c + 0bfe83c commit bbae257
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/ScottPlot4/ScottPlot.Tests/Colormap/ColormapTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ namespace ScottPlotTests.ColormapTests
{
class ColormapTests
{
[Test]
public void Test_Colormap_LayoutCanBeReset()
{
var plt = new ScottPlot.Plot(400, 300);
plt.Style(figureBackground: System.Drawing.ColorTranslator.FromHtml("#dadada"));
var bmpOriginal = new MeanPixel(plt.GetBitmap());

var cb = plt.AddColorbar();
var bmpWithColorbar = new MeanPixel(plt.GetBitmap());

plt.Remove(cb);
plt.YAxis2.ResetLayout();
var bmpWithColorbarRemoved = new MeanPixel(plt.GetBitmap());

Assert.AreNotEqual(bmpOriginal, bmpWithColorbar);
Assert.AreEqual(bmpOriginal, bmpWithColorbarRemoved);
}

[Test]
public void Test_Colormap_MultipleRequests()
{
Expand Down
9 changes: 9 additions & 0 deletions src/ScottPlot4/ScottPlot/Plot/Plot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,15 @@ public void Style(
plottable.SetStyle(tick, axisLabel);
}

/// <summary>
/// Reset axis padding to the default values for all axes
/// </summary>
public void ResetLayout()
{
foreach (var axis in settings.Axes)
axis.ResetLayout();
}

#endregion

#region renderable customization
Expand Down
17 changes: 14 additions & 3 deletions src/ScottPlot4/ScottPlot/Renderable/Axis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ public Edge Edge
return (AxisLabel, AxisTicks, AxisLine);
}

/// <summary>
/// Reset axis padding to the default values
/// </summary>
public void ResetLayout()
{
PixelSizeMinimum = 5;
PixelSizeMaximum = float.PositiveInfinity;
PixelSizePadding = 3;
}

/// <summary>
/// Define the minimum and maximum limits for the pixel size of this axis
/// </summary>
Expand All @@ -95,9 +105,10 @@ public void SetSizeLimit(float? min = null, float? max = null, float? pad = null
private float PixelSize; // how large this axis is
private float PixelOffset; // distance from the data area
private bool Collapsed = false; // true if axes are hidden
private float PixelSizeMinimum = 5;
private float PixelSizeMaximum = float.PositiveInfinity;
private float PixelSizePadding = 3;

private float PixelSizeMinimum = 5; // also defined in ResetLayout()
private float PixelSizeMaximum = float.PositiveInfinity; // also defined in ResetLayout()
private float PixelSizePadding = 3; // also defined in ResetLayout()

/// <summary>
/// Define how many pixels away from the data area this axis will be.
Expand Down
1 change: 1 addition & 0 deletions src/ScottPlot4/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
_In development / not yet on NuGet ..._
* Eto.Forms: Improved handling of events (#1719, #1718) _Thanks @rafntor and @VPKSoft_
* Axis: Allow grid line and tick mark pixel snapping to be disabled (#1721, #1722) _Thanks @Xerxes004_
* Axis: `ResetLayout()` sets padding to original values to reverse changes made by adding colorbars (#1732, #1736) _Thanks @ccopsey_

## ScottPlot 4.1.34
_Published on [NuGet](https://www.nuget.org/packages?q=scottplot) on 2022-03-03_
Expand Down

0 comments on commit bbae257

Please sign in to comment.