]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Only consider visible vertical boxes in layout (#8483)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Sun, 21 Feb 2021 20:43:31 +0000 (22:43 +0200)
committerGitHub <noreply@github.com>
Sun, 21 Feb 2021 20:43:31 +0000 (15:43 -0500)
src/core/core.layouts.js
test/fixtures/core.layouts/hidden-vertical-boxes.js [new file with mode: 0644]
test/fixtures/core.layouts/hidden-vertical-boxes.png [new file with mode: 0644]
test/fixtures/plugin.legend/title/left-center-center.png
test/fixtures/plugin.legend/title/left-end-end.png
test/fixtures/plugin.legend/title/right-center-center.png
test/fixtures/plugin.legend/title/right-end-end.png
test/fixtures/plugin.legend/title/right-start-start.png

index 30661a17f0da8c4cf2746249bd1587c01ece8323..acb1b4ce2ec37340254f7415273737d93a9effd9 100644 (file)
@@ -343,13 +343,16 @@ export default {
     // |----------------------------------------------------|
     //
 
+    const visibleVerticalBoxCount = verticalBoxes.reduce((total, wrap) =>
+      wrap.box.options && wrap.box.options.display === false ? total : total + 1, 0);
+
     const params = Object.freeze({
       outerWidth: width,
       outerHeight: height,
       padding,
       availableWidth,
       availableHeight,
-      vBoxMaxWidth: availableWidth / 2 / verticalBoxes.length,
+      vBoxMaxWidth: availableWidth / 2 / visibleVerticalBoxCount,
       hBoxMaxHeight: availableHeight / 2
     });
     const chartArea = Object.assign({
diff --git a/test/fixtures/core.layouts/hidden-vertical-boxes.js b/test/fixtures/core.layouts/hidden-vertical-boxes.js
new file mode 100644 (file)
index 0000000..5b55600
--- /dev/null
@@ -0,0 +1,62 @@
+module.exports = {
+  config: {
+    type: 'line',
+    data: {
+      datasets: [
+        {data: [10, 5, 0, 25, 78, -10]}
+      ],
+      labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', '']
+    },
+    options: {
+      plugins: {
+        legend: false
+      },
+      scales: {
+        x: {
+          display: false
+        },
+        y: {
+          type: 'linear',
+          position: 'left',
+          ticks: {
+            callback: function(value) {
+              return value + ' very long unit!';
+            },
+          }
+        },
+        y1: {
+          type: 'linear',
+          position: 'left',
+          display: false
+        },
+        y2: {
+          type: 'linear',
+          position: 'left',
+          display: false
+        },
+        y3: {
+          type: 'linear',
+          position: 'left',
+          display: false
+        },
+        y4: {
+          type: 'linear',
+          position: 'left',
+          display: false
+        },
+        y5: {
+          type: 'linear',
+          position: 'left',
+          display: false
+        }
+      }
+    }
+  },
+  options: {
+    spriteText: true,
+    canvas: {
+      height: 256,
+      width: 256
+    }
+  }
+};
diff --git a/test/fixtures/core.layouts/hidden-vertical-boxes.png b/test/fixtures/core.layouts/hidden-vertical-boxes.png
new file mode 100644 (file)
index 0000000..5746067
Binary files /dev/null and b/test/fixtures/core.layouts/hidden-vertical-boxes.png differ
index cbcdb6593d35b1f36d6e00aa42bb2a960072a24a..7ffd400944999943943f914c134114498ae3109e 100644 (file)
Binary files a/test/fixtures/plugin.legend/title/left-center-center.png and b/test/fixtures/plugin.legend/title/left-center-center.png differ
index 85c33c674ac20545afad44d57fca101e94432fec..a60610ab5009b914322f7745dbb64813861715e3 100644 (file)
Binary files a/test/fixtures/plugin.legend/title/left-end-end.png and b/test/fixtures/plugin.legend/title/left-end-end.png differ
index 794aea86cdfd9941eef8584df3207a1281b00c26..9900784a4b3cfbc976d0f5b5ca5d88a835848378 100644 (file)
Binary files a/test/fixtures/plugin.legend/title/right-center-center.png and b/test/fixtures/plugin.legend/title/right-center-center.png differ
index 97a0c8489c8d70d744b5fe6c0956dfc7e40e3c86..ec2acbf131253de7d8b46207d4d24f7d509239b4 100644 (file)
Binary files a/test/fixtures/plugin.legend/title/right-end-end.png and b/test/fixtures/plugin.legend/title/right-end-end.png differ
index bd49b4b80514b780aaad042ad5133ee2781c5bd2..89c5286ef37f14cc84c17290a57b8777cad5edcb 100644 (file)
Binary files a/test/fixtures/plugin.legend/title/right-start-start.png and b/test/fixtures/plugin.legend/title/right-start-start.png differ