]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
change way that linear scales calculate min and max (#10591)
authorJacco van den Berg <jaccoberg2281@gmail.com>
Thu, 18 Aug 2022 11:33:15 +0000 (13:33 +0200)
committerGitHub <noreply@github.com>
Thu, 18 Aug 2022 11:33:15 +0000 (07:33 -0400)
docs/migration/v4-migration.md
src/scales/scale.linearbase.js

index 8a79afe218f302af46ff065ede1eca9946a30b8e..a7ec15b8394337ba2a78d90627d82f4b40509ac6 100644 (file)
@@ -13,6 +13,7 @@ A number of changes were made to the configuration options passed to the `Chart`
 * The radialLinear grid indexable and scriptable options don't decrease the index of the specified grid line anymore.
 * The `destroy` plugin hook has been removed and replaced with `afterDestroy`.
 * Ticks callback on time scale now receives timestamp instead of a formatted label.
+* Linear scales now add and subtracts `5%` of the max value to the range if the min and max are the same instead of `1`.
 * If the tooltip callback returns `undefined`, then the default callback will be used.
 
 #### Type changes
index 346e0bc0d4abef0569bd50fa23ad7c15d712a7d4..2bcbc44ffe430e2e65d10be919c981955ad1d05d 100644 (file)
@@ -194,15 +194,7 @@ export default class LinearScaleBase extends Scale {
     }
 
     if (min === max) {
-      let offset = 1;
-      if (max >= Number.MAX_SAFE_INTEGER || min <= Number.MIN_SAFE_INTEGER) {
-        // In this case, the magnitude of the number is so large that
-        // max === max + 1 due to how IEEE754 doubles work. We need to increase
-        // the range by a larger number. Let's be safe and make this 5% of the number
-        //
-        // TODO - V4, make this the new default behaviour and eliminate +1 in other cases
-        offset = Math.abs(max * 0.05);
-      }
+      let offset = max === 0 ? 1 : Math.abs(max * 0.05);
 
       setMax(max + offset);