Skip to content

Commit f6c6d38

Browse files
committed
Added threshold rounding function to address issue #589. Added example
for issue 589. Updated changelog and contributors. Cleaned up example for issue #42.
1 parent cadccc0 commit f6c6d38

4 files changed

Lines changed: 57 additions & 30 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ All notable changes to this project will be documented in this file.
169169
- LineSeries with smoothing raises exception (#72)
170170
- Exception when legend is outside and plot area is small (#880)
171171
- Axis alignment with MinimumRange (#794)
172+
- Fixed strange number formatting when using LogarithmicAxis with very large or very small Series (#589)
172173

173174
## [2014.1.546] - 2014-10-22
174175
### Added

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Oystein Bjorke <oystein.bjorke@gmail.com>
7676
Patrice Marin <patrice.marin@thomsonreuters.com>
7777
Philippe AURIOU <p.auriou@live.fr>
7878
Piotr Warzocha <pw@piootr.pl>
79+
Rik Borger <isolocis@gmail.com>
7980
ryang <decatf@gmail.com>
8081
Senen Fernandez <senenf@gmail.com>
8182
Shun-ichi Goto <shunichi.goto@gmail.com>

Source/Examples/ExampleLibrary/Issues/Issues.cs

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,38 +1157,27 @@ public static PlotModel NormalHeatMap()
11571157
return model;
11581158
}
11591159

1160+
/// <summary>
1161+
/// Contains example code for https://github.com/oxyplot/oxyplot/issues/42
1162+
/// </summary>
1163+
/// <returns>The plot model.</returns>
11601164
[Example("#42: ContourSeries not working for not square data array")]
1161-
public static PlotModel IssueDescription()
1165+
public static PlotModel IndexOutOfRangeContour()
11621166
{
1163-
int n = 100;
1164-
double x0 = -3.1;
1165-
double x1 = 3.1;
1166-
double y0 = -3;
1167-
double y1 = 3;
1168-
Func<double, double, double> peaks = (x, y) => 3 * (1 - x) * (1 - x) * Math.Exp(-(x * x) - (y + 1) * (y + 1)) - 10 * (x / 5 - x * x * x - y * y * y * y * y) * Math.Exp(-x * x - y * y) - 1.0 / 3 * Math.Exp(-(x + 1) * (x + 1) - y * y);
1169-
// see https://github.com/oxyplot/oxyplot/issues/511
1170-
var xvalues = ArrayBuilder.CreateVector(x0, x1, n * 10);
1171-
var yvalues = ArrayBuilder.CreateVector(y0, y1, n);
1172-
var peaksData = ArrayBuilder.Evaluate(peaks, xvalues, yvalues);
1173-
var model = new PlotModel { Title = "Peaks" };
1174-
model.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = OxyPalettes.Jet(500), HighColor = OxyColors.Gray, LowColor = OxyColors.Black });
1167+
var model = new PlotModel { Title = "Issue #42" };
1168+
model.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = OxyPalettes.Jet(5) });
11751169

1176-
var hms = new HeatMapSeries { X0 = x0, X1 = x1, Y0 = y0, Y1 = y1, Data = peaksData };
1177-
model.Series.Add(hms);
1178-
//if (includeContours)
1170+
var x = ArrayBuilder.CreateVector(0, 1, 20);
1171+
var y = ArrayBuilder.CreateVector(-1, 1, 2);
1172+
var data = ArrayBuilder.Evaluate((a, b) => a * b, x, y);
1173+
1174+
var contour = new ContourSeries
11791175
{
1180-
var cs = new ContourSeries
1181-
{
1182-
Color = OxyColors.Black,
1183-
FontSize = 0,
1184-
ContourLevelStep = 1,
1185-
LabelBackground = OxyColors.Undefined,
1186-
ColumnCoordinates = yvalues,
1187-
RowCoordinates = xvalues,
1188-
Data = peaksData
1189-
};
1190-
model.Series.Add(cs);
1191-
}
1176+
ColumnCoordinates = y,
1177+
RowCoordinates = x,
1178+
Data = data
1179+
};
1180+
model.Series.Add(contour);
11921181

11931182
return model;
11941183
}
@@ -1631,6 +1620,37 @@ public static PlotModel MinimumRangeAbsoluteMinimumTest()
16311620
return model;
16321621
}
16331622

1623+
/// Creates a demo PlotModel with the data from the issue.
1624+
/// </summary>
1625+
/// <returns>The created PlotModel</returns>
1626+
[Example("#589: LogarithmicAxis glitches with multiple series containing small data")]
1627+
public static PlotModel LogaritmicAxesSuperExponentialFormatTest()
1628+
{
1629+
var model = new PlotModel();
1630+
model.Axes.Add(new LogarithmicAxis
1631+
{
1632+
UseSuperExponentialFormat = true,
1633+
Position = AxisPosition.Bottom,
1634+
MajorGridlineStyle = LineStyle.Dot,
1635+
PowerPadding = true
1636+
});
1637+
1638+
model.Axes.Add(new LogarithmicAxis
1639+
{
1640+
UseSuperExponentialFormat = true,
1641+
Position = AxisPosition.Left,
1642+
MajorGridlineStyle = LineStyle.Dot,
1643+
PowerPadding = true
1644+
});
1645+
1646+
var series1 = new LineSeries();
1647+
series1.Points.Add(new DataPoint(1e5, 1e-14));
1648+
series1.Points.Add(new DataPoint(4e7, 1e-12));
1649+
model.Series.Add(series1);
1650+
1651+
return model;
1652+
}
1653+
16341654
/* NEW ISSUE TEMPLATE
16351655
[Example("#123: Issue Description")]
16361656
public static PlotModel IssueDescription()

Source/OxyPlot/Axes/Axis.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@ public abstract class Axis : PlotElement
2222
/// <summary>
2323
/// Exponent function.
2424
/// </summary>
25-
protected static readonly Func<double, double> Exponent = x => Math.Floor(Math.Log(Math.Abs(x), 10));
25+
protected static readonly Func<double, double> Exponent = x => Math.Floor(ThresholdRound(Math.Log(Math.Abs(x), 10)));
2626

2727
/// <summary>
2828
/// Mantissa function.
2929
/// </summary>
30-
protected static readonly Func<double, double> Mantissa = x => x / Math.Pow(10, Exponent(x));
30+
protected static readonly Func<double, double> Mantissa = x => ThresholdRound(x / Math.Pow(10, Exponent(x)));
31+
32+
/// <summary>
33+
/// Rounds a value if the difference between the rounded value and the original value is less than 1e-6.
34+
/// </summary>
35+
protected static readonly Func<double, double> ThresholdRound = x => Math.Abs(Math.Round(x) - x) < 1e-6 ? Math.Round(x) : x;
3136

3237
/// <summary>
3338
/// The offset.

0 commit comments

Comments
 (0)