Skip to content
This repository was archived by the owner on Feb 19, 2022. It is now read-only.

prevent error in bubble plots with single z value #539

Merged
merged 1 commit into from
Nov 15, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/components/victory-scatter/helper-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,18 @@ export default {

getBubbleSize(datum, props) {
const { data, z, maxBubbleSize, minBubbleSize } = props;
const zData = data.map((point) => point[z]);
const zMin = Math.min(...zData);
const zMax = Math.max(...zData);
const getMaxRadius = () => {
const minPadding = Math.min(...values(Helpers.getPadding(props)));
return Math.max(minPadding, 5); // eslint-disable-line no-magic-numbers
};
const zData = data.map((point) => point[z]);
const zMin = Math.min(...zData);
const zMax = Math.max(...zData);
const maxRadius = maxBubbleSize || getMaxRadius();
const minRadius = minBubbleSize || maxRadius * 0.1; // eslint-disable-line no-magic-numbers
if (zMax === zMin) {
return Math.max(minRadius, 1);
}
const maxArea = Math.PI * Math.pow(maxRadius, 2);
const minArea = Math.PI * Math.pow(minRadius, 2);
const pointArea = ((datum[z] - zMin) / (zMax - zMin)) * maxArea;
Expand Down