Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 1 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ All notable changes to this project will be documented in this file.
- Add properties for `MinimumSegmentLength` to series and annotations (#1853)
- Add fractal examples for PolygonAnnotation and PolylineAnnotations (#1853)
- Add `AxisPreference` to `PlotManipulator`
- Add MinimumMajorIntervalCount and MaximumMajorIntervalCount Axis Properties (#24)
- Add VisualStudioToolsManifest.xml to add components to the Visual Studio Designer toolbox (#1446)

### Changed
Expand Down
83 changes: 83 additions & 0 deletions 83 Source/Examples/ExampleLibrary/Axes/AxisExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,89 @@ public static PlotModel MarginsAndPaddingAsymmetrical()
return plot;
}

[Example("Minimum Major Interval Count")]
public static PlotModel MinimumMajorIntervalCount()
{
var plot = new PlotModel
{
Title = "MinimumMajorIntervalCount = 10",
};

var xaxis = new LinearAxis
{
Position = AxisPosition.Bottom,
MinimumMajorIntervalCount = 10,
};

plot.Axes.Add(xaxis);

var yaxis = new LinearAxis
{
Position = AxisPosition.Left,
MinimumMajorIntervalCount = 10,
};

plot.Axes.Add(yaxis);

return plot;
}

[Example("Maximum Major Interval Count")]
public static PlotModel MaximumMajorIntervalCount()
{
var plot = new PlotModel
{
Title = "MaximumMajorIntervalCount = 5",
};

var xaxis = new LinearAxis
{
Position = AxisPosition.Bottom,
MaximumMajorIntervalCount = 5,
};

plot.Axes.Add(xaxis);

var yaxis = new LinearAxis
{
Position = AxisPosition.Left,
MaximumMajorIntervalCount = 5,
};

plot.Axes.Add(yaxis);

return plot;
}

[Example("Minimum and Maximum Major Interval Count")]
public static PlotModel MinimumAndMaximumMajorIntervalCount()
{
var plot = new PlotModel
{
Title = "MinimumMajorIntervalCount = MaximumMajorIntervalCount = 4",
};

var xaxis = new LinearAxis
{
Position = AxisPosition.Bottom,
MinimumMajorIntervalCount = 4,
MaximumMajorIntervalCount = 4,
};

plot.Axes.Add(xaxis);

var yaxis = new LinearAxis
{
Position = AxisPosition.Left,
MinimumMajorIntervalCount = 4,
MaximumMajorIntervalCount = 4,
};

plot.Axes.Add(yaxis);

return plot;
}

private static CategoryAxis GetLongLabelSeries()
{
var axis = new CategoryAxis() { Position = AxisPosition.Bottom };
Expand Down
37 changes: 28 additions & 9 deletions 37 Source/OxyPlot/Axes/Axis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ protected Axis()
this.MajorStep = double.NaN;
this.MinimumMinorStep = 0;
this.MinimumMajorStep = 0;
this.MinimumMajorIntervalCount = 2;
this.MaximumMajorIntervalCount = double.MaxValue;

this.MinimumPadding = 0.01;
this.MaximumPadding = 0.01;
Expand Down Expand Up @@ -162,6 +164,20 @@ protected Axis()
/// </summary>
public double ActualMajorStep { get; protected set; }

/// <summary>
/// Gets or sets the minimum number of major intervals on the axis.
/// </summary>
/// <remarks>Non-integer values are accepted.</remarks>
public double MinimumMajorIntervalCount { get; set; }

/// <summary>
/// Gets or sets the minimum number of major intervals on the axis.
/// </summary>
/// <remarks>Non-integer values are accepted.
/// The maximum will be bounded acording to the <see cref="IntervalLength" />.
/// The <see cref="MinimumMajorIntervalCount" /> takes precedence over the <see cref="MaximumMajorIntervalCount" /> when determining the major step.</remarks>
public double MaximumMajorIntervalCount { get; set; }

/// <summary>
/// Gets or sets the actual maximum value of the axis.
/// </summary>
Expand Down Expand Up @@ -1376,7 +1392,7 @@ internal virtual void UpdateIntervals(OxyRect plotArea)

this.ActualMajorStep = !double.IsNaN(this.MajorStep)
? this.MajorStep
: this.CalculateActualInterval(length, labelSize);
: this.CalculateActualInterval(length, labelSize, this.MinimumMajorIntervalCount, this.MaximumMajorIntervalCount);

this.ActualMinorStep = !double.IsNaN(this.MinorStep)
? this.MinorStep
Expand Down Expand Up @@ -1804,10 +1820,12 @@ protected void SetTransform(double newScale, double newOffset)
/// </summary>
/// <param name="availableSize">Size of the available area.</param>
/// <param name="maxIntervalSize">Maximum length of the intervals.</param>
/// <param name="minIntervalCount">The minimum number of intervals.</param>
/// <param name="maxIntervalCount">The maximum number of intervals, once the minimum number of intervals is satisfied.</param>
/// <returns>The calculate actual interval.</returns>
protected virtual double CalculateActualInterval(double availableSize, double maxIntervalSize)
protected virtual double CalculateActualInterval(double availableSize, double maxIntervalSize, double minIntervalCount, double maxIntervalCount)
{
return this.CalculateActualInterval(availableSize, maxIntervalSize, this.ActualMaximum - this.ActualMinimum);
return this.CalculateActualInterval(availableSize, maxIntervalSize, this.ActualMaximum - this.ActualMinimum, minIntervalCount, maxIntervalCount);
}

/// <summary>
Expand All @@ -1816,8 +1834,10 @@ protected virtual double CalculateActualInterval(double availableSize, double ma
/// <param name="availableSize">The available size.</param>
/// <param name="maxIntervalSize">The maximum interval size.</param>
/// <param name="range">The range.</param>
/// <param name="minIntervalCount">The minimum number of intervals.</param>
/// <param name="maxIntervalCount">The maximum number of intervals, once the minimum number of intervals is satisfied.</param>
/// <returns>Actual interval to use to determine which values are displayed in the axis.</returns>
protected double CalculateActualInterval(double availableSize, double maxIntervalSize, double range)
protected double CalculateActualInterval(double availableSize, double maxIntervalSize, double range, double minIntervalCount, double maxIntervalCount)
{
if (availableSize <= 0)
{
Expand All @@ -1837,10 +1857,9 @@ protected double CalculateActualInterval(double availableSize, double maxInterva
Func<double, double> exponent = x => Math.Ceiling(Math.Log(x, 10));
Func<double, double> mantissa = x => x / Math.Pow(10, exponent(x) - 1);

// reduce intervals for horizontal axis.
// double maxIntervals = Orientation == AxisOrientation.x ? MaximumAxisIntervalsPer200Pixels * 0.8 : MaximumAxisIntervalsPer200Pixels;
// real maximum interval count
double maxIntervalCount = availableSize / maxIntervalSize;
// bound min/max interval counts
minIntervalCount = Math.Max(minIntervalCount, 0);
maxIntervalCount = Math.Min(maxIntervalCount, availableSize / maxIntervalSize);

range = Math.Abs(range);
double interval = Math.Pow(10, exponent(range));
Expand Down Expand Up @@ -1869,7 +1888,7 @@ protected double CalculateActualInterval(double availableSize, double maxInterva
intervalCandidate = removeNoise(intervalCandidate / 2.0);
}

if (range / intervalCandidate > maxIntervalCount)
if (range / interval >= minIntervalCount && range / intervalCandidate > maxIntervalCount)
{
break;
}
Expand Down
24 changes: 13 additions & 11 deletions 24 Source/OxyPlot/Axes/DateTimeAxis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,8 @@ protected override string FormatValueOverride(double x)
return string.Format(this.ActualCulture, fmt, time);
}

/// <summary>
/// Calculates the actual interval.
/// </summary>
/// <param name="availableSize">Size of the available area.</param>
/// <param name="maxIntervalSize">Maximum length of the intervals.</param>
/// <returns>The calculate actual interval.</returns>
protected override double CalculateActualInterval(double availableSize, double maxIntervalSize)
/// <inheritdoc/>
protected override double CalculateActualInterval(double availableSize, double maxIntervalSize, double minIntervalCount, double maxIntervalCount)
{
const double Year = 365.25;
const double Month = 30.5;
Expand All @@ -341,11 +336,13 @@ protected override double CalculateActualInterval(double availableSize, double m

double interval = goodIntervals[0];

int maxNumberOfIntervals = Math.Max((int)(availableSize / maxIntervalSize), 2);
// bound min/max interval counts
minIntervalCount = Math.Max(minIntervalCount, 0);
maxIntervalCount = Math.Min(maxIntervalCount, Math.Max((int)(availableSize / maxIntervalSize), 2));

while (true)
{
if (range / interval < maxNumberOfIntervals)
if (range / interval < maxIntervalCount)
{
break;
}
Expand All @@ -356,6 +353,11 @@ protected override double CalculateActualInterval(double availableSize, double m
nextInterval = interval * 2;
}

if (range / nextInterval < minIntervalCount)
{
break;
}

interval = nextInterval;
}

Expand Down Expand Up @@ -400,13 +402,13 @@ protected override double CalculateActualInterval(double availableSize, double m
if (this.actualIntervalType == DateTimeIntervalType.Months)
{
double monthsRange = range / 30.5;
interval = this.CalculateActualInterval(availableSize, maxIntervalSize, monthsRange);
interval = this.CalculateActualInterval(availableSize, maxIntervalSize, monthsRange, this.MinimumMajorIntervalCount, this.MaximumMajorIntervalCount);
}

if (this.actualIntervalType == DateTimeIntervalType.Years)
{
double yearsRange = range / 365.25;
interval = this.CalculateActualInterval(availableSize, maxIntervalSize, yearsRange);
interval = this.CalculateActualInterval(availableSize, maxIntervalSize, yearsRange, this.MinimumMajorIntervalCount, this.MaximumMajorIntervalCount);
}

if (this.actualMinorIntervalType == DateTimeIntervalType.Auto)
Expand Down
24 changes: 14 additions & 10 deletions 24 Source/OxyPlot/Axes/TimeSpanAxis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,22 @@ protected override string FormatValueOverride(double x)
return string.Format(this.ActualCulture, fmt, span);
}

/// <summary>
/// Calculates the actual interval.
/// </summary>
/// <param name="availableSize">Size of the available area.</param>
/// <param name="maxIntervalSize">Maximum length of the intervals.</param>
/// <returns>The calculate actual interval.</returns>
protected override double CalculateActualInterval(double availableSize, double maxIntervalSize)
/// <inheritdoc/>
protected override double CalculateActualInterval(double availableSize, double maxIntervalSize, double minIntervalCount, double maxIntervalCount)
{
double range = Math.Abs(this.ClipMinimum - this.ClipMaximum);
double interval = 1;
var goodIntervals = new[] { 1.0, 5, 10, 30, 60, 120, 300, 600, 900, 1200, 1800, 3600 };

int maxNumberOfIntervals = Math.Max((int)(availableSize / maxIntervalSize), 2);
// bound min/max interval counts
minIntervalCount = Math.Max(minIntervalCount, 0);
maxIntervalCount = Math.Min(maxIntervalCount, Math.Max((int)(availableSize / maxIntervalSize), 2));

while (true)
{
if (range / interval < maxNumberOfIntervals)
if (range / interval < maxIntervalCount)
{
return interval;
break;
}

double nextInterval = goodIntervals.FirstOrDefault(i => i > interval);
Expand All @@ -105,8 +102,15 @@ protected override double CalculateActualInterval(double availableSize, double m
nextInterval = interval * 2;
}

if (range / nextInterval < minIntervalCount)
{
break;
}

interval = nextInterval;
}

return interval;
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.