]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix backdrop padding (#11577)
authorJacco van den Berg <jaccoberg2281@gmail.com>
Thu, 9 Nov 2023 23:25:36 +0000 (00:25 +0100)
committerGitHub <noreply@github.com>
Thu, 9 Nov 2023 23:25:36 +0000 (00:25 +0100)
* fix for alignment inner

* Add test

* Remove eslint ignores

* remove unecesarry config

* Remove text from test

src/core/core.scale.js
test/fixtures/core.scale/tick-backdrop-alignment-inner.js [new file with mode: 0644]
test/fixtures/core.scale/tick-backdrop-alignment-inner.png [new file with mode: 0644]

index 8b8bf34729253f3f2a39bf61659bef4ca47e1345..3265e103d1a8c4f80c9cbeed780e662f66932018 100644 (file)
@@ -1288,6 +1288,13 @@ export default class Scale extends Element {
         case 'right':
           left -= width;
           break;
+        case 'inner':
+          if (i === ilen - 1) {
+            left -= width;
+          } else if (i > 0) {
+            left -= width / 2;
+          }
+          break;
         default:
           break;
         }
diff --git a/test/fixtures/core.scale/tick-backdrop-alignment-inner.js b/test/fixtures/core.scale/tick-backdrop-alignment-inner.js
new file mode 100644 (file)
index 0000000..f9fbadd
--- /dev/null
@@ -0,0 +1,48 @@
+module.exports = {
+  config: {
+    type: 'line',
+    data: {
+      labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
+      datasets: [
+        {
+          label: '# of Votes',
+          data: [12, 19, 3, 5, 2, 3],
+        },
+        {
+          label: '# of Points',
+          data: [7, 11, 5, 8, 3, 7],
+        }
+      ]
+    },
+    options: {
+      scales: {
+        y: {
+          ticks: {
+            display: false,
+          },
+          grid: {
+            lineWidth: 0
+          }
+        },
+        x: {
+          position: 'top',
+          ticks: {
+            color: 'transparent',
+            backdropColor: 'red',
+            showLabelBackdrop: true,
+            align: 'inner',
+          },
+          grid: {
+            lineWidth: 0
+          }
+        }
+      }
+    }
+  },
+  options: {
+    canvas: {
+      height: 256,
+      width: 512
+    }
+  }
+};
diff --git a/test/fixtures/core.scale/tick-backdrop-alignment-inner.png b/test/fixtures/core.scale/tick-backdrop-alignment-inner.png
new file mode 100644 (file)
index 0000000..2cddb8d
Binary files /dev/null and b/test/fixtures/core.scale/tick-backdrop-alignment-inner.png differ