-
Notifications
You must be signed in to change notification settings - Fork 981
Description
Question:
I am having an issue with the LogMinorTickGenerator function and I'm not sure whether it's a bug or if I'm not using it correctly. In my application, I have multiple charts that utilize the logarithmic scale, but for some reason the program completely crashes when it tries to resize the chart, which can happen if the user resizes the entire application window, or only the section in which the chart is plotted.
After some inspection, I noticed that in the LogMinorTickGenerator class, there's a function GetMinorTicks which is always triggered whenever the chart is resized. This function receives a list of doubles named majorPositions, and there's a for loop iterator that increments by a deltaMajor which is calculated by the difference between the first and second values of majorPositions.
Problem is, sometimes the majorPositions list comes with two identical values, and the deltaMajor value will be 0, resulting in an infinite loop and a crash.
I couldn't figure out where this majorPositions come from, and I don't kow if I have any way of defending it against sending identical values.
The code below shows the way I'm building the plot with the logarithmic scale.
Am I doing something wrong, or is this a bug that's beyond my control?
Thank you for your time
ScottPlot Version:
5.0.40
Code Sample:
ScottPlot.TickGenerators.LogMinorTickGenerator minorTickGen = new();
ScottPlot.TickGenerators.EvenlySpacedMinorTickGenerator bottomGen = new(5);
ScottPlot.TickGenerators.NumericAutomatic tickGen = new();
ScottPlot.TickGenerators.NumericAutomatic bottomTicks = new();
//minorTickGen.Divisions = 5;
tickGen.MinorTickGenerator = minorTickGen;
bottomTicks.MinorTickGenerator = bottomGen;
bottomTicks.IntegerTicksOnly = true;
//bottomTicks.TargetTickCount = Convert.ToInt32(logXs[^1]);
static string LogTickLabelFormatter(double y) => $"x10^{y:F1}";
//bottomTicks.IntegerTicksOnly = true;
tickGen.IntegerTicksOnly = true;
tickGen.LabelFormatter = LogTickLabelFormatter;
//bottomTicks.LabelFormatter = LogTickLabelFormatter;
WpfPlotDmgTime.Plot.Axes.Left.TickGenerator = tickGen;
//WpfPlotDmgTime.Plot.Axes.Bottom.TickGenerator = bottomTicks;
WpfPlotDmgTime.Plot.Grid.MajorLineWidth = 1;
WpfPlotDmgTime.Plot.Grid.MinorLineWidth = 1;
WpfPlotDmgTime.Plot.Grid.MinorLineColor = ThemeType == ThemeType.SoftDark ? ScottPlot.Color.FromHex("#0e3d54").WithOpacity(0.4) : ScottPlot.Color.FromHex("#565656").WithOpacity(0.4);
WpfPlotDmgTime.Plot.Legend.Alignment = Alignment.UpperRight;
WpfPlotDmgTime.Plot.Axes.AutoScale();
WpfPlotDmgTime.Refresh();

