Skip to content

Commit

Permalink
Handle AxisTicks.SnapPx appropriately ScottPlot#1721
Browse files Browse the repository at this point in the history
  • Loading branch information
Xerxes004 committed Mar 10, 2022
1 parent cd733f7 commit c8c7a3d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/ScottPlot4/ScottPlot/Renderable/Axis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void Render(PlotDimensions dims, Bitmap bmp, bool lowQuality = false)
{
AxisTicks.Render(dims, bmp, lowQuality);
AxisLabel.Render(dims, bmp, lowQuality);
AxisLine.Render(dims, bmp, lowQuality);
AxisLine.Render(dims, bmp, AxisTicks.SnapPx || lowQuality);
}
}

Expand Down
14 changes: 9 additions & 5 deletions src/ScottPlot4/ScottPlot/Renderable/AxisTicks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ public void Render(PlotDimensions dims, Bitmap bmp, bool lowQuality = false)
if (!IsVisible)
return;

using Graphics gfx = GDI.Graphics(bmp, dims, lowQuality, false);
using Graphics gfxLow = GDI.Graphics(bmp, dims, true, false);
using Graphics gfxHigh = GDI.Graphics(bmp, dims, false, false);

var gfx = lowQuality ? gfxLow : gfxHigh;
var gfxSnap = SnapPx ? gfxLow : gfxHigh;

double[] visibleMajorTicks = TickCollection.GetVisibleMajorTicks(dims)
.Select(t => t.Position)
Expand All @@ -71,15 +75,15 @@ public void Render(PlotDimensions dims, Bitmap bmp, bool lowQuality = false)
.ToArray();

if (MajorGridVisible)
AxisTicksRender.RenderGridLines(dims, gfx, visibleMajorTicks, MajorGridStyle, MajorGridColor, MajorGridWidth, Edge);
AxisTicksRender.RenderGridLines(dims, gfxSnap, visibleMajorTicks, MajorGridStyle, MajorGridColor, MajorGridWidth, Edge);

if (MinorGridVisible)
AxisTicksRender.RenderGridLines(dims, gfx, visibleMinorTicks, MinorGridStyle, MinorGridColor, MinorGridWidth, Edge);
AxisTicksRender.RenderGridLines(dims, gfxSnap, visibleMinorTicks, MinorGridStyle, MinorGridColor, MinorGridWidth, Edge);

if (MinorTickVisible)
{
float tickLength = TicksExtendOutward ? MinorTickLength : -MinorTickLength;
AxisTicksRender.RenderTickMarks(dims, gfx, visibleMinorTicks, tickLength, MinorTickColor, Edge, PixelOffset);
AxisTicksRender.RenderTickMarks(dims, gfxSnap, visibleMinorTicks, tickLength, MinorTickColor, Edge, PixelOffset);
}

if (MajorTickVisible)
Expand All @@ -91,7 +95,7 @@ public void Render(PlotDimensions dims, Bitmap bmp, bool lowQuality = false)

tickLength = TicksExtendOutward ? tickLength : -tickLength;

AxisTicksRender.RenderTickMarks(dims, gfx, visibleMajorTicks, tickLength, MajorTickColor, Edge, PixelOffset);
AxisTicksRender.RenderTickMarks(dims, gfxSnap, visibleMajorTicks, tickLength, MajorTickColor, Edge, PixelOffset);
}

if (TickLabelVisible)
Expand Down

0 comments on commit c8c7a3d

Please sign in to comment.