From: Jacco van den Berg Date: Thu, 18 Aug 2022 11:33:15 +0000 (+0200) Subject: change way that linear scales calculate min and max (#10591) X-Git-Tag: v4.0.0~56 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c74260b745761f4cd229101f00542cf7bef81c9a;p=thirdparty%2FChart.js.git change way that linear scales calculate min and max (#10591) --- diff --git a/docs/migration/v4-migration.md b/docs/migration/v4-migration.md index 8a79afe21..a7ec15b83 100644 --- a/docs/migration/v4-migration.md +++ b/docs/migration/v4-migration.md @@ -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 diff --git a/src/scales/scale.linearbase.js b/src/scales/scale.linearbase.js index 346e0bc0d..2bcbc44ff 100644 --- a/src/scales/scale.linearbase.js +++ b/src/scales/scale.linearbase.js @@ -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);