From: Jukka Kurkela Date: Fri, 26 Mar 2021 22:20:05 +0000 (+0200) Subject: Bubble: Fix maxOverflow before elements update (#8736) X-Git-Tag: v3.0.0-rc.6~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=396cbcb979bc775e561fcc7049c78c1e24d92611;p=thirdparty%2FChart.js.git Bubble: Fix maxOverflow before elements update (#8736) --- diff --git a/src/controllers/controller.bubble.js b/src/controllers/controller.bubble.js index 08632e72b..8cad718b9 100644 --- a/src/controllers/controller.bubble.js +++ b/src/controllers/controller.bubble.js @@ -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 index 000000000..0fd616c45 --- /dev/null +++ b/test/fixtures/controller.bubble/padding-update.js @@ -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 index 000000000..72a0d6b9c 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 index 000000000..4acb79201 --- /dev/null +++ b/test/fixtures/controller.bubble/padding.js @@ -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 index 000000000..6a03d5c08 Binary files /dev/null and b/test/fixtures/controller.bubble/padding.png differ diff --git a/test/specs/controller.bubble.tests.js b/test/specs/controller.bubble.tests.js index 57a124841..50589aa4c 100644 --- a/test/specs/controller.bubble.tests.js +++ b/test/specs/controller.bubble.tests.js @@ -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);