getEfficientInterval method
Returns an efficient interval for showing axis titles, or grid lines or ...
If there isn't any provided interval, we use this function to calculate an interval to apply,
using axisViewSize
/ pixelPerInterval
, we calculate the allowedCount lines in the axis,
then using diffInAxis
/ allowedCount, we can find out how much interval we need,
then we round that number by finding nearest number in this pattern:
1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 5000, 10000,...
Implementation
double getEfficientInterval(
double axisViewSize,
double diffInAxis, {
double pixelPerInterval = 40,
}) {
final allowedCount = math.max(axisViewSize ~/ pixelPerInterval, 1);
if (diffInAxis == 0) {
return 1;
}
final accurateInterval =
diffInAxis == 0 ? axisViewSize : diffInAxis / allowedCount;
if (allowedCount <= 2) {
return accurateInterval;
}
return roundInterval(accurateInterval);
}