]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Don't measure undefined or null strings. 2234/head
authorEvert Timberg <evert.timberg+github@gmail.com>
Sun, 10 Apr 2016 14:10:31 +0000 (10:10 -0400)
committerEvert Timberg <evert.timberg+github@gmail.com>
Sun, 10 Apr 2016 14:10:31 +0000 (10:10 -0400)
src/core/core.helpers.js

index 763e88932ad9c9b6f85341ebb1b1d8a090bacf3e..8eec93b243a9755d9d138801c326abb1ca4dad7f 100644 (file)
@@ -830,13 +830,18 @@ module.exports = function(Chart) {
                ctx.font = font;
                var longest = 0;
                helpers.each(arrayOfStrings, function(string) {
-                       var textWidth = cache.data[string];
-                       if (!textWidth) {
-                               textWidth = cache.data[string] = ctx.measureText(string).width;
-                               cache.garbageCollect.push(string);
+                       // Undefined strings should not be measured
+                       if (string !== undefined && string !== null) {
+                               var textWidth = cache.data[string];
+                               if (!textWidth) {
+                                       textWidth = cache.data[string] = ctx.measureText(string).width;
+                                       cache.garbageCollect.push(string);
+                               }
+
+                               if (textWidth > longest) {
+                                       longest = textWidth;
+                               }
                        }
-                       if (textWidth > longest)
-                               longest = textWidth;
                });
 
                var gcLen = cache.garbageCollect.length / 2;