]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Address bar chart performance regression (#7234)
authorBen McCann <322311+benmccann@users.noreply.github.com>
Mon, 30 Mar 2020 21:31:54 +0000 (14:31 -0700)
committerGitHub <noreply@github.com>
Mon, 30 Mar 2020 21:31:54 +0000 (17:31 -0400)
src/controllers/controller.bar.js

index eea8cd97c15426792a3161c806067f84fffdf2de..fa0806ed01e1b4538448842cf3196f45ecd5df3a 100644 (file)
@@ -66,14 +66,10 @@ function computeMinSampleSize(scale, pixels) {
 function computeFitCategoryTraits(index, ruler, options) {
        const thickness = options.barThickness;
        const count = ruler.stackCount;
-       const curr = ruler.pixels[index];
-       const min = isNullOrUndef(thickness)
-               ? computeMinSampleSize(ruler.scale, ruler.pixels)
-               : -1;
        let size, ratio;
 
        if (isNullOrUndef(thickness)) {
-               size = min * options.categoryPercentage;
+               size = ruler.min * options.categoryPercentage;
                ratio = options.barPercentage;
        } else {
                // When bar thickness is enforced, category and bar percentages are ignored.
@@ -86,7 +82,7 @@ function computeFitCategoryTraits(index, ruler, options) {
        return {
                chunk: size / count,
                ratio,
-               start: curr - (size / 2)
+               start: ruler.pixels[index] - (size / 2)
        };
 }
 
@@ -385,7 +381,14 @@ export default class BarController extends DatasetController {
                        pixels.push(iScale.getPixelForValue(me.getParsed(i)[iScale.axis]));
                }
 
+               // Note: a potential optimization would be to skip computing this
+               // only if the barThickness option is defined
+               // Since a scriptable option may return null or undefined that
+               // means the option would have to be of type number
+               const min = computeMinSampleSize(iScale, pixels);
+
                return {
+                       min,
                        pixels,
                        start: iScale._startPixel,
                        end: iScale._endPixel,