From: Jacco van den Berg Date: Thu, 9 Nov 2023 23:25:36 +0000 (+0100) Subject: Fix backdrop padding (#11577) X-Git-Tag: v4.4.1~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a03e138e903bdc4686acabd65eeabef61efedd0;p=thirdparty%2FChart.js.git Fix backdrop padding (#11577) * fix for alignment inner * Add test * Remove eslint ignores * remove unecesarry config * Remove text from test --- diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 8b8bf3472..3265e103d 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -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 index 000000000..f9fbaddc1 --- /dev/null +++ b/test/fixtures/core.scale/tick-backdrop-alignment-inner.js @@ -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 index 000000000..2cddb8dfd Binary files /dev/null and b/test/fixtures/core.scale/tick-backdrop-alignment-inner.png differ