]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix toggling showLine option on scatter controller (#11334)
authorstockiNail <stocki.nail@gmail.com>
Thu, 8 Jun 2023 12:53:50 +0000 (14:53 +0200)
committerGitHub <noreply@github.com>
Thu, 8 Jun 2023 12:53:50 +0000 (08:53 -0400)
src/controllers/controller.scatter.js
test/fixtures/controller.scatter/showLine/changed.js [new file with mode: 0644]
test/fixtures/controller.scatter/showLine/changed.png [new file with mode: 0644]

index aae36ed6068fbdd6cba8e35e3d90e955bd32b360..15445ea8ae3c72e126f1c7fe53f43f1f9cd08eed 100644 (file)
@@ -70,6 +70,10 @@ export default class ScatterController extends DatasetController {
 
     if (this.options.showLine) {
 
+      // https://github.com/chartjs/Chart.js/issues/11333
+      if (!this.datasetElementType) {
+        this.addElements();
+      }
       const {dataset: line, _dataset} = meta;
 
       // Update Line
@@ -84,6 +88,10 @@ export default class ScatterController extends DatasetController {
         animated: !animationsDisabled,
         options
       }, mode);
+    } else if (this.datasetElementType) {
+      // https://github.com/chartjs/Chart.js/issues/11333
+      delete meta.dataset;
+      this.datasetElementType = false;
     }
 
     // Update Points
diff --git a/test/fixtures/controller.scatter/showLine/changed.js b/test/fixtures/controller.scatter/showLine/changed.js
new file mode 100644 (file)
index 0000000..ac85be4
--- /dev/null
@@ -0,0 +1,34 @@
+module.exports = {
+  description: 'showLine option should draw a line if true',
+  config: {
+    type: 'scatter',
+    data: {
+      datasets: [{
+        data: [{x: 10, y: 15}, {x: 15, y: 10}],
+        pointRadius: 10,
+        backgroundColor: 'red',
+        label: 'dataset1'
+      }],
+    },
+    options: {
+      scales: {
+        x: {
+          display: false
+        },
+        y: {
+          display: false
+        }
+      }
+    }
+  },
+  options: {
+    canvas: {
+      width: 256,
+      height: 256
+    },
+    run(chart) {
+      chart.options.showLine = true;
+      chart.update();
+    }
+  }
+};
diff --git a/test/fixtures/controller.scatter/showLine/changed.png b/test/fixtures/controller.scatter/showLine/changed.png
new file mode 100644 (file)
index 0000000..9e5eae7
Binary files /dev/null and b/test/fixtures/controller.scatter/showLine/changed.png differ