@awsui/components-react
Version:
AWS UI is a collection of [React](https://reactjs.org/) components that help create intuitive, responsive, and accessible user experiences for web applications. It is developed by Amazon Web Services (AWS). This work is available under the terms of the [A
75 lines (74 loc) • 2.28 kB
JavaScript
import styles from './styles.css.js';
export var dimensionsBySize = {
small: {
innerRadius: 33,
outerRadius: 50,
innerLabelPadding: 8,
padding: 8,
paddingLabels: 44
},
medium: {
innerRadius: 66,
outerRadius: 100,
innerLabelPadding: 12,
padding: 12,
paddingLabels: 44
},
large: {
innerRadius: 93,
outerRadius: 140,
innerLabelPadding: 12,
padding: 12,
paddingLabels: 44
}
};
export var defaultDetails = function (i18nStrings) { return function (datum, dataSum) { return [
{ key: i18nStrings.detailsValue || '', value: datum.value },
{
key: i18nStrings.detailsPercentage || '',
value: ((datum.value * 100) / dataSum).toFixed(0) + "%"
}
]; }; };
export var balanceLabelNodes = function (nodes, markers, leftSide) {
var _a;
var MARGIN = 10;
var previousBBox = null;
var i = leftSide ? nodes.length - 1 : 0;
while ((leftSide && i >= 0) || (!leftSide && i < nodes.length)) {
var node = nodes[i];
var x = parseFloat(node.getAttribute('data-x') || '0');
var y = parseFloat(node.getAttribute('data-y') || '0');
var box = {
x: x,
y: y,
height: node.getBoundingClientRect().height
};
var marker = markers[i];
if (leftSide) {
i--;
}
else {
i++;
}
if (!previousBBox) {
previousBBox = box;
node.setAttribute('transform', '');
continue;
}
if ((!leftSide && box.x < 0) || (leftSide && box.x >= 0)) {
break;
}
node.setAttribute('transform', '');
var offset = previousBBox.y + previousBBox.height + MARGIN - box.y;
if (offset > 0) {
node.setAttribute('transform', "translate(0 " + offset + ")");
var lineNode = (_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.querySelector("." + styles['label-line']);
if (lineNode) {
var endY = marker.endY;
lineNode.setAttribute('y2', '' + (endY + offset));
}
box.y += offset;
}
previousBBox = box;
}
};