-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlotAxisLimitRule.cs
More file actions
51 lines (43 loc) · 1.57 KB
/
PlotAxisLimitRule.cs
File metadata and controls
51 lines (43 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Linq;
using ScottPlot;
namespace QuickLook.Plugin.WavLabelViewer;
public class PlotAxisLimitRule(AxisLimits limits, IAxis axis) : IAxisRule
{
public AxisLimits Limits { get; set; } = limits;
public IAxis Axis { get; set; } = axis;
public void Apply(RenderPack rp, bool beforeLayout)
{
if (rp.Plot.Axes.GetAxes().Any(ax => ax == this.Axis))
{
if (this.Axis is IXAxis xAxis)
{
double xSpan = Math.Min(xAxis.Range.Span, this.Limits.HorizontalSpan);
if (xAxis.Range.Max > this.Limits.Right)
{
xAxis.Range.Max = this.Limits.Right;
xAxis.Range.Min = this.Limits.Right - xSpan;
}
if (xAxis.Range.Min < this.Limits.Left)
{
xAxis.Range.Min = this.Limits.Left;
xAxis.Range.Max = this.Limits.Left + xSpan;
}
}
else if (this.Axis is IYAxis yAxis)
{
double ySpan = Math.Min(yAxis.Range.Span, this.Limits.VerticalSpan);
if (yAxis.Range.Max > this.Limits.Top)
{
yAxis.Range.Max = this.Limits.Top;
yAxis.Range.Min = this.Limits.Top - ySpan;
}
if (yAxis.Range.Min < this.Limits.Bottom)
{
yAxis.Range.Min = this.Limits.Bottom;
yAxis.Range.Max = this.Limits.Bottom + ySpan;
}
}
}
}
}