change way that linear scales calculate min and max (#10591)

This commit is contained in:
Jacco van den Berg 2022-08-18 13:33:15 +02:00 committed by GitHub
parent bd29fcbf67
commit c74260b745
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 9 deletions

View 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

View 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);