Skip to content

Commit

Permalink
Bubble: Properly parse radius for non-object data (#9764)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Oct 15, 2021
1 parent 0dcf025 commit 81acad9
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 14 deletions.
46 changes: 32 additions & 14 deletions src/controllers/controller.bubble.js
@@ -1,28 +1,46 @@
import DatasetController from '../core/core.datasetController';
import {resolveObjectKey, valueOrDefault} from '../helpers/helpers.core';
import {valueOrDefault} from '../helpers/helpers.core';

export default class BubbleController extends DatasetController {
initialize() {
this.enableOptionSharing = true;
super.initialize();
}

/**
* Parse array of primitive values
* @protected
*/
parsePrimitiveData(meta, data, start, count) {
const parsed = super.parsePrimitiveData(meta, data, start, count);
for (let i = 0; i < parsed.length; i++) {
parsed[i]._custom = this.resolveDataElementOptions(i + start).radius;
}
return parsed;
}

/**
* Parse array of arrays
* @protected
*/
parseArrayData(meta, data, start, count) {
const parsed = super.parseArrayData(meta, data, start, count);
for (let i = 0; i < parsed.length; i++) {
const item = data[start + i];
parsed[i]._custom = valueOrDefault(item[2], this.resolveDataElementOptions(i + start).radius);
}
return parsed;
}

/**
* Parse array of objects
* @protected
*/
parseObjectData(meta, data, start, count) {
const {xScale, yScale} = meta;
const {xAxisKey = 'x', yAxisKey = 'y'} = this._parsing;
const parsed = [];
let i, ilen, item;
for (i = start, ilen = start + count; i < ilen; ++i) {
item = data[i];
parsed.push({
x: xScale.parse(resolveObjectKey(item, xAxisKey), i),
y: yScale.parse(resolveObjectKey(item, yAxisKey), i),
_custom: item && item.r && +item.r
});
const parsed = super.parseObjectData(meta, data, start, count);
for (let i = 0; i < parsed.length; i++) {
const item = data[start + i];
parsed[i]._custom = valueOrDefault(item && item.r && +item.r, this.resolveDataElementOptions(i + start).radius);
}
return parsed;
}
Expand All @@ -31,11 +49,11 @@ export default class BubbleController extends DatasetController {
* @protected
*/
getMaxOverflow() {
const {data, _parsed} = this._cachedMeta;
const data = this._cachedMeta.data;

let max = 0;
for (let i = data.length - 1; i >= 0; --i) {
max = Math.max(max, data[i].size() / 2, _parsed[i]._custom);
max = Math.max(max, data[i].size(this.resolveDataElementOptions(i)) / 2);
}
return max > 0 && max;
}
Expand Down
Binary file modified test/fixtures/controller.bubble/clip.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions test/fixtures/controller.bubble/hover-radius-zero.js
@@ -0,0 +1,48 @@
module.exports = {
config: {
type: 'bubble',
data: {
labels: [2, 2, 2, 2],
datasets: [{
data: [
[1, 1],
[1, 2],
[1, 3, 20],
[1, 4, 20]
]
}, {
data: [1, 2, 3, 4]
}, {
data: [{x: 3, y: 1}, {x: 3, y: 2}, {x: 3, y: 3, r: 15}, {x: 3, y: 4, r: 15}]
}]
},
options: {
events: [],
radius: 10,
hoverRadius: 0,
backgroundColor: 'blue',
hoverBackgroundColor: 'red',
scales: {
x: {display: false, bounds: 'data'},
y: {display: false}
},
layout: {
padding: 24
}
}
},
options: {
canvas: {
height: 256,
width: 256
},
run(chart) {
chart.setActiveElements([
{datasetIndex: 0, index: 1}, {datasetIndex: 0, index: 2},
{datasetIndex: 1, index: 1}, {datasetIndex: 1, index: 2},
{datasetIndex: 2, index: 1}, {datasetIndex: 2, index: 2},
]);
chart.update();
}
}
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/controller.bubble/padding.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/controller.bubble/point-style.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/controller.bubble/radius-data.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/core.scale/border-behind-elements.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 81acad9

Please sign in to comment.