]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Bubble: Fix maxOverflow before elements update (#8736)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Fri, 26 Mar 2021 22:20:05 +0000 (00:20 +0200)
committerGitHub <noreply@github.com>
Fri, 26 Mar 2021 22:20:05 +0000 (18:20 -0400)
src/controllers/controller.bubble.js
test/fixtures/controller.bubble/padding-update.js [new file with mode: 0644]
test/fixtures/controller.bubble/padding-update.png [new file with mode: 0644]
test/fixtures/controller.bubble/padding.js [new file with mode: 0644]
test/fixtures/controller.bubble/padding.png [new file with mode: 0644]
test/specs/controller.bubble.tests.js

index 08632e72bb17b2b196be7dd7b3c55097aeb72930..8cad718b93a356e81ed49e7a8aa13ce8234e5fdc 100644 (file)
@@ -31,12 +31,11 @@ export default class BubbleController extends DatasetController {
         * @protected
         */
   getMaxOverflow() {
-    const me = this;
-    const meta = me._cachedMeta;
-    const data = meta.data;
+    const {data, _parsed} = this._cachedMeta;
+
     let max = 0;
     for (let i = data.length - 1; i >= 0; --i) {
-      max = Math.max(max, data[i].size());
+      max = Math.max(max, data[i].size() / 2, _parsed[i]._custom);
     }
     return max > 0 && max;
   }
diff --git a/test/fixtures/controller.bubble/padding-update.js b/test/fixtures/controller.bubble/padding-update.js
new file mode 100644 (file)
index 0000000..0fd616c
--- /dev/null
@@ -0,0 +1,24 @@
+module.exports = {
+  config: {
+    type: 'bubble',
+    data: {
+      datasets: [{
+        backgroundColor: 'red',
+        data: [{x: 12, y: 54, r: 22.4}]
+      }, {
+        backgroundColor: 'blue',
+        data: [{x: 18, y: 38, r: 25}]
+      }]
+    }
+  },
+  options: {
+    spriteText: true,
+    canvas: {
+      width: 256,
+      height: 256
+    },
+    run(chart) {
+      chart.update();
+    }
+  }
+};
diff --git a/test/fixtures/controller.bubble/padding-update.png b/test/fixtures/controller.bubble/padding-update.png
new file mode 100644 (file)
index 0000000..72a0d6b
Binary files /dev/null and b/test/fixtures/controller.bubble/padding-update.png differ
diff --git a/test/fixtures/controller.bubble/padding.js b/test/fixtures/controller.bubble/padding.js
new file mode 100644 (file)
index 0000000..4acb792
--- /dev/null
@@ -0,0 +1,21 @@
+module.exports = {
+  config: {
+    type: 'bubble',
+    data: {
+      datasets: [{
+        backgroundColor: 'red',
+        data: [{x: 12, y: 54, r: 22.4}]
+      }, {
+        backgroundColor: 'blue',
+        data: [{x: 18, y: 38, r: 25}]
+      }]
+    }
+  },
+  options: {
+    spriteText: true,
+    canvas: {
+      width: 256,
+      height: 256
+    }
+  }
+};
diff --git a/test/fixtures/controller.bubble/padding.png b/test/fixtures/controller.bubble/padding.png
new file mode 100644 (file)
index 0000000..6a03d5c
Binary files /dev/null and b/test/fixtures/controller.bubble/padding.png differ
index 57a1248417cdbb34ccaee86ef8b0dacffd2aa179..50589aa4c7d5bdb0ad5feeb330db0a2d115bc800 100644 (file)
@@ -135,10 +135,10 @@ describe('Chart.controllers.bubble', function() {
     var meta = chart.getDatasetMeta(0);
 
     [
-      {r: 5, x: 0, y: 0},
-      {r: 1, x: 171, y: 512},
-      {r: 2, x: 341, y: 486},
-      {r: 1, x: 512, y: 0}
+      {r: 5, x: 5, y: 5},
+      {r: 1, x: 171, y: 507},
+      {r: 2, x: 341, y: 482},
+      {r: 1, x: 507, y: 5}
     ].forEach(function(expected, i) {
       expect(meta.data[i].x).toBeCloseToPixel(expected.x);
       expect(meta.data[i].y).toBeCloseToPixel(expected.y);