]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix: Fill vertical lines (#8919)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Sat, 17 Apr 2021 11:31:58 +0000 (14:31 +0300)
committerGitHub <noreply@github.com>
Sat, 17 Apr 2021 11:31:58 +0000 (07:31 -0400)
src/plugins/plugin.filler.js
test/fixtures/plugin.filler/line/vertical.js [new file with mode: 0644]
test/fixtures/plugin.filler/line/vertical.png [new file with mode: 0644]

index 4d36f4bd71b0faa6a3f0d7ac9df582e2b207c670..1bd851da47b11d64d596ec1b4c25b9bcd616fbba 100644 (file)
@@ -496,7 +496,7 @@ function _fill(ctx, cfg) {
 
 function doFill(ctx, cfg) {
   const {line, target, above, below, area, scale} = cfg;
-  const property = line._loop ? 'angle' : 'x';
+  const property = line._loop ? 'angle' : cfg.axis;
 
   ctx.save();
 
@@ -514,14 +514,14 @@ function doFill(ctx, cfg) {
 
 function drawfill(ctx, source, area) {
   const target = getTarget(source);
-  const {line, scale} = source;
+  const {line, scale, axis} = source;
   const lineOpts = line.options;
   const fillOption = lineOpts.fill;
   const color = lineOpts.backgroundColor;
   const {above = color, below = color} = fillOption || {};
   if (target && line.points.length) {
     clipArea(ctx, area);
-    doFill(ctx, {line, target, above, below, area, scale});
+    doFill(ctx, {line, target, above, below, area, scale, axis});
     unclipArea(ctx);
   }
 }
@@ -545,6 +545,7 @@ export default {
           index: i,
           fill: decodeFill(line, i, count),
           chart,
+          axis: meta.controller.options.indexAxis,
           scale: meta.vScale,
           line,
         };
diff --git a/test/fixtures/plugin.filler/line/vertical.js b/test/fixtures/plugin.filler/line/vertical.js
new file mode 100644 (file)
index 0000000..864f8b4
--- /dev/null
@@ -0,0 +1,42 @@
+const data = [
+  {y: 1, x: 12},
+  {y: 3, x: 14},
+  {y: 4, x: 20},
+  {y: 6, x: 13},
+  {y: 9, x: 18},
+];
+
+module.exports = {
+  config: {
+    type: 'line',
+    data: {
+      datasets: [{
+        data: data,
+        borderColor: 'red',
+        fill: false,
+      }, {
+        data: data.map((v) => ({y: v.y, x: 2 * v.x - 1.5 * v.y})),
+        fill: '-1',
+        borderColor: 'blue',
+        backgroundColor: 'rgba(255, 200, 0, 0.5)',
+      }]
+    },
+    options: {
+      indexAxis: 'y',
+      radius: 0,
+      plugins: {
+        legend: false
+      },
+      scales: {
+        x: {
+          display: false,
+          type: 'linear'
+        },
+        y: {
+          display: false,
+          type: 'linear'
+        }
+      }
+    }
+  }
+};
diff --git a/test/fixtures/plugin.filler/line/vertical.png b/test/fixtures/plugin.filler/line/vertical.png
new file mode 100644 (file)
index 0000000..5d0dd3a
Binary files /dev/null and b/test/fixtures/plugin.filler/line/vertical.png differ