Log scale jumps due to slightly out-of-range data points
Hi! I noticed an issue with charts using a log scale.
https://jsfiddle.net/8zvexnwd/2/
In the example above, both axes use distr: 3 and auto: true.
The list of data points includes values just slightly above 100k and 1M, which causes the scale to jump to 1M and 10M, making the chart hard to read:
const data = [
[1704326400, 1704412800, 1704499200],
[1000001, 1000000, 990000],
[99000, 100000, 100000.001]
];
what behavior do you expect?
Ideally, the range boundaries would adapt - for example, with a 10% gap above the maximum and below the minimum values. Is it possible to achieve this in auto mode, or should I define a custom range with explicit min and max values instead?
imo, it is really important to have a tick/reference above the highest data value, especially in Log scales, otherwise it is way too easy to misinterpret the magnitude of unbounded whitespace.
the built-in log ranging util uPlot.rangeLog(dataMin, dataMax, logBase, fullMags) includes the last option to snap to partial magnitudes, you should be able to pretty easily improve the above scenario by having the top go to 2M and 200k, without writing fully manual scale.range functions.
https://github.com/leeoniya/uPlot/blob/1c147324e32c0a6db65b069062632bbd330c0799/dist/uPlot.d.ts#L141-L142
this should work, but appears to be broken right now:
{
range: (u, dataMin, dataMax) => uPlot.rangeLog(dataMin, dataMax, 10, false),
}
i'll try to get it fixed this week.
just to be clear, even when fixed, it won't really address "Log scale jumps due to slightly out-of-range data points". it will still jump, just less.
if you want to eliminate any kind of jumping, you'll have to do your own scale.range logic that either allows the plotted data to be clipped by the plot limits, or pre-configure the scale min/max that accommodates values that may go slightly above or below the outermost ticks.
fixed the partial magnitudes issue. added your example to bottom here:
https://leeoniya.github.io/uPlot/demos/log-scales2.html
thanks!
Thank you! :)