* Account for floating point error in niceNum helper
* Better solution
* @return {number}
*/
export function niceNum(range) {
+ const roundedRange = Math.round(range);
+ range = almostEquals(range, roundedRange, range / 1000) ? roundedRange : range;
const niceRange = Math.pow(10, Math.floor(log10(range)));
const fraction = range / niceRange;
const niceFraction = fraction <= 1 ? 1 : fraction <= 2 ? 2 : fraction <= 5 ? 5 : 10;
// Case 1: If min, max and stepSize are set and they make an evenly spaced scale use it.
// spacing = step;
// numSpaces = (max - min) / spacing;
- numSpaces = Math.min((max - min) / spacing, maxTicks);
+ // Note that we round here to handle the case where almostWhole translated an FP error
+ numSpaces = Math.round(Math.min((max - min) / spacing, maxTicks));
spacing = (max - min) / numSpaces;
niceMin = min;
niceMax = max;
--- /dev/null
+module.exports = {
+ description: 'https://github.com/chartjs/Chart.js/issues/9334',
+ config: {
+ type: 'line',
+ options: {
+ scales: {
+ y: {
+ display: false,
+ },
+ x: {
+ type: 'linear',
+ min: 7.2,
+ max: 21.6,
+ ticks: {
+ stepSize: 1.8
+ }
+ },
+ }
+ }
+ },
+ options: {
+ spriteText: true
+ }
+};