]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Respect `fill: false` with custom draw times (#10414)
authorJacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com>
Wed, 22 Jun 2022 11:41:18 +0000 (13:41 +0200)
committerGitHub <noreply@github.com>
Wed, 22 Jun 2022 11:41:18 +0000 (07:41 -0400)
* Resolve canvasgradient is not defined in node
* Remove trailing white space
* export isPaternOrGradient helper with typings
* fix lint failure, single qoute
* Respect `fill: false` with custom draw times
* correctly listen to fill property
* remove console log and lint errors
* implement feedback, still update control points

src/plugins/plugin.filler/filler.helper.js
src/plugins/plugin.filler/index.js
test/fixtures/plugin.filler/line/drawTimeFillFalse/beforeDatasetDraw.js [new file with mode: 0644]
test/fixtures/plugin.filler/line/drawTimeFillFalse/beforeDatasetDraw.png [new file with mode: 0644]
test/fixtures/plugin.filler/line/drawTimeFillFalse/beforeDatasetsDraw.js [new file with mode: 0644]
test/fixtures/plugin.filler/line/drawTimeFillFalse/beforeDatasetsDraw.png [new file with mode: 0644]
test/fixtures/plugin.filler/line/drawTimeFillFalse/beforeDraw.js [new file with mode: 0644]
test/fixtures/plugin.filler/line/drawTimeFillFalse/beforeDraw.png [new file with mode: 0644]

index ec9fcdbd704b8baa765b34b2d270d38e5a9ade4a..c3ede0bc9d632c1de502c0d1d086a48c32c056f5 100644 (file)
@@ -32,3 +32,7 @@ export function _createBoundaryLine(boundary, line) {
     _fullLoop: _loop
   }) : null;
 }
+
+export function _shouldApplyFill(source) {
+  return source && source.fill !== false;
+}
index 7cbf5935df728b513b23ca07eaafb23fd6bc4765..12bacb0805ec9ed1ac08ca94352c3355fd75cad0 100644 (file)
@@ -6,6 +6,7 @@
 
 import LineElement from '../../elements/element.line';
 import {_drawfill} from './filler.drawing';
+import {_shouldApplyFill} from './filler.helper';
 import {_decodeFill, _resolveTarget} from './filler.options';
 
 export default {
@@ -58,7 +59,7 @@ export default {
       }
 
       source.line.updateControlPoints(area, source.axis);
-      if (draw) {
+      if (draw && source.fill) {
         _drawfill(chart.ctx, source, area);
       }
     }
@@ -68,10 +69,12 @@ export default {
     if (options.drawTime !== 'beforeDatasetsDraw') {
       return;
     }
+
     const metasets = chart.getSortedVisibleDatasetMetas();
     for (let i = metasets.length - 1; i >= 0; --i) {
       const source = metasets[i].$filler;
-      if (source) {
+
+      if (_shouldApplyFill(source)) {
         _drawfill(chart.ctx, source, chart.chartArea);
       }
     }
@@ -80,7 +83,7 @@ export default {
   beforeDatasetDraw(chart, args, options) {
     const source = args.meta.$filler;
 
-    if (!source || source.fill === false || options.drawTime !== 'beforeDatasetDraw') {
+    if (!_shouldApplyFill(source) || options.drawTime !== 'beforeDatasetDraw') {
       return;
     }
 
diff --git a/test/fixtures/plugin.filler/line/drawTimeFillFalse/beforeDatasetDraw.js b/test/fixtures/plugin.filler/line/drawTimeFillFalse/beforeDatasetDraw.js
new file mode 100644 (file)
index 0000000..a07432a
--- /dev/null
@@ -0,0 +1,22 @@
+module.exports = {
+  config: {
+    type: 'line',
+    data: {
+      labels: ['0', '1', '2', '3', '4', '5'],
+      datasets: [{
+        backgroundColor: 'red',
+        data: [3, -3, 0, 5, -5, 0],
+        fill: false
+      }]
+    },
+    options: {
+      plugins: {
+        legend: false,
+        title: false,
+        filler: {
+          drawTime: 'beforeDatasetDraw'
+        }
+      },
+    }
+  },
+};
diff --git a/test/fixtures/plugin.filler/line/drawTimeFillFalse/beforeDatasetDraw.png b/test/fixtures/plugin.filler/line/drawTimeFillFalse/beforeDatasetDraw.png
new file mode 100644 (file)
index 0000000..c45eb28
Binary files /dev/null and b/test/fixtures/plugin.filler/line/drawTimeFillFalse/beforeDatasetDraw.png differ
diff --git a/test/fixtures/plugin.filler/line/drawTimeFillFalse/beforeDatasetsDraw.js b/test/fixtures/plugin.filler/line/drawTimeFillFalse/beforeDatasetsDraw.js
new file mode 100644 (file)
index 0000000..6401ab7
--- /dev/null
@@ -0,0 +1,22 @@
+module.exports = {
+  config: {
+    type: 'line',
+    data: {
+      labels: ['0', '1', '2', '3', '4', '5'],
+      datasets: [{
+        backgroundColor: 'red',
+        data: [3, -3, 0, 5, -5, 0],
+        fill: false
+      }]
+    },
+    options: {
+      plugins: {
+        legend: false,
+        title: false,
+        filler: {
+          drawTime: 'beforeDatasetsDraw'
+        }
+      },
+    }
+  },
+};
diff --git a/test/fixtures/plugin.filler/line/drawTimeFillFalse/beforeDatasetsDraw.png b/test/fixtures/plugin.filler/line/drawTimeFillFalse/beforeDatasetsDraw.png
new file mode 100644 (file)
index 0000000..c45eb28
Binary files /dev/null and b/test/fixtures/plugin.filler/line/drawTimeFillFalse/beforeDatasetsDraw.png differ
diff --git a/test/fixtures/plugin.filler/line/drawTimeFillFalse/beforeDraw.js b/test/fixtures/plugin.filler/line/drawTimeFillFalse/beforeDraw.js
new file mode 100644 (file)
index 0000000..5b0c1b1
--- /dev/null
@@ -0,0 +1,22 @@
+module.exports = {
+  config: {
+    type: 'line',
+    data: {
+      labels: ['0', '1', '2', '3', '4', '5'],
+      datasets: [{
+        backgroundColor: 'red',
+        data: [3, -3, 0, 5, -5, 0],
+        fill: false
+      }]
+    },
+    options: {
+      plugins: {
+        legend: false,
+        title: false,
+        filler: {
+          drawTime: 'beforeDraw'
+        }
+      },
+    }
+  },
+};
diff --git a/test/fixtures/plugin.filler/line/drawTimeFillFalse/beforeDraw.png b/test/fixtures/plugin.filler/line/drawTimeFillFalse/beforeDraw.png
new file mode 100644 (file)
index 0000000..c45eb28
Binary files /dev/null and b/test/fixtures/plugin.filler/line/drawTimeFillFalse/beforeDraw.png differ