Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bubble: Properly parse radius for non-object data #9764

Merged
merged 1 commit into from Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.