]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Consider dynamically positioned scales for padding (#8868)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Sat, 10 Apr 2021 12:58:39 +0000 (15:58 +0300)
committerGitHub <noreply@github.com>
Sat, 10 Apr 2021 12:58:39 +0000 (08:58 -0400)
src/core/core.layouts.js
test/fixtures/core.scale/x-axis-position-dynamic-margin.js [new file with mode: 0644]
test/fixtures/core.scale/x-axis-position-dynamic-margin.png [new file with mode: 0644]
test/fixtures/core.scale/x-axis-position-dynamic.png

index 5b8ef42e5d0a219a0b04cf093468473685bd3aca..dfd0dd31b986e59436864998714a72dd469d1a2b 100644 (file)
@@ -93,16 +93,15 @@ function updateDims(chartArea, params, layout) {
   const box = layout.box;
   const maxPadding = chartArea.maxPadding;
 
-  if (isObject(layout.pos)) {
-    // dynamically placed boxes are not considered
-    return {same: false, other: false};
-  }
-  if (layout.size) {
-    // this layout was already counted for, lets first reduce old size
-    chartArea[layout.pos] -= layout.size;
+  // dynamically placed boxes size is not considered
+  if (!isObject(layout.pos)) {
+    if (layout.size) {
+      // this layout was already counted for, lets first reduce old size
+      chartArea[layout.pos] -= layout.size;
+    }
+    layout.size = layout.horizontal ? box.height : box.width;
+    chartArea[layout.pos] += layout.size;
   }
-  layout.size = layout.horizontal ? box.height : box.width;
-  chartArea[layout.pos] += layout.size;
 
   if (box.getPadding) {
     updateMaxPadding(maxPadding, box.getPadding());
diff --git a/test/fixtures/core.scale/x-axis-position-dynamic-margin.js b/test/fixtures/core.scale/x-axis-position-dynamic-margin.js
new file mode 100644 (file)
index 0000000..7e8bf6e
--- /dev/null
@@ -0,0 +1,27 @@
+module.exports = {
+  config: {
+    type: 'line',
+    options: {
+      scales: {
+        x: {
+          labels: ['Left Label', 'Center Label', 'Right Label'],
+          position: {
+            y: 30
+          },
+        },
+        y: {
+          display: false,
+          min: -100,
+          max: 100,
+        }
+      }
+    }
+  },
+  options: {
+    canvas: {
+      height: 256,
+      width: 512
+    },
+    spriteText: true
+  }
+};
diff --git a/test/fixtures/core.scale/x-axis-position-dynamic-margin.png b/test/fixtures/core.scale/x-axis-position-dynamic-margin.png
new file mode 100644 (file)
index 0000000..3dffa31
Binary files /dev/null and b/test/fixtures/core.scale/x-axis-position-dynamic-margin.png differ
index 62fc3ec86e7912fcc44d030cd2485f908cf518ee..bbebdd33b7ef520ae961cedd24bdae6169d539f4 100644 (file)
Binary files a/test/fixtures/core.scale/x-axis-position-dynamic.png and b/test/fixtures/core.scale/x-axis-position-dynamic.png differ