]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix layout bug when there are no visible boxes (#8507)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Wed, 24 Feb 2021 21:27:11 +0000 (23:27 +0200)
committerGitHub <noreply@github.com>
Wed, 24 Feb 2021 21:27:11 +0000 (16:27 -0500)
src/core/core.layouts.js
test/fixtures/core.layouts/no-boxes-all-padding.js [new file with mode: 0644]
test/fixtures/core.layouts/no-boxes-all-padding.png [new file with mode: 0644]

index acb1b4ce2ec37340254f7415273737d93a9effd9..7868eb676216ecdf1f95722049ad8826841dc701 100644 (file)
@@ -344,7 +344,7 @@ export default {
     //
 
     const visibleVerticalBoxCount = verticalBoxes.reduce((total, wrap) =>
-      wrap.box.options && wrap.box.options.display === false ? total : total + 1, 0);
+      wrap.box.options && wrap.box.options.display === false ? total : total + 1, 0) || 1;
 
     const params = Object.freeze({
       outerWidth: width,
diff --git a/test/fixtures/core.layouts/no-boxes-all-padding.js b/test/fixtures/core.layouts/no-boxes-all-padding.js
new file mode 100644 (file)
index 0000000..ae85008
--- /dev/null
@@ -0,0 +1,39 @@
+module.exports = {
+  config: {
+    type: 'line',
+    data: {
+      labels: [0],
+      datasets: [{
+        data: [0],
+        radius: 16,
+        backgroundColor: 'red'
+      }],
+    },
+    options: {
+      plugins: {
+        legend: false,
+        tooltip: false,
+        title: false,
+        filler: false
+      },
+      scales: {
+        x: {
+          display: false,
+          offset: true
+        },
+        y: {
+          display: false
+        }
+      },
+      layout: {
+        padding: 16
+      }
+    }
+  },
+  options: {
+    canvas: {
+      height: 32,
+      width: 32
+    }
+  }
+};
diff --git a/test/fixtures/core.layouts/no-boxes-all-padding.png b/test/fixtures/core.layouts/no-boxes-all-padding.png
new file mode 100644 (file)
index 0000000..6bade81
Binary files /dev/null and b/test/fixtures/core.layouts/no-boxes-all-padding.png differ