@actinc/dls
Version:
Design Language System (DLS) for ACT & Encoura front-end projects.
33 lines • 1.94 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
/**
* Copyright (c) ACT, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { Tooltip } from '@mui/material';
import { StyledLabel } from './styles';
export function calculateLabelWidth(label) {
return Math.min(Math.max(label.length * 9, 10), 100);
}
export var Y_LABEL_MARGIN = 30;
export var MIN_LABEL_WIDTH = 40;
export var CustomizedLabel = function (_a) {
var _b;
var fill = _a.fill, isBlockingOnHovers = _a.isBlockingOnHovers, selectedPoint = _a.selectedPoint, _c = _a.shouldHideLabel, shouldHideLabel = _c === void 0 ? {} : _c, value = _a.value, x = _a.x, y = _a.y;
var opacity = 1;
var isThisSelectedPoint = String(value) === (selectedPoint === null || selectedPoint === void 0 ? void 0 : selectedPoint.label) ||
String(value)
.split(', ')
.find(function (el) { return el === (selectedPoint === null || selectedPoint === void 0 ? void 0 : selectedPoint.label); });
if (selectedPoint && !isThisSelectedPoint) {
opacity = 0.2;
}
var charAmount = ((_b = String(value)) === null || _b === void 0 ? void 0 : _b.length) || 0;
if (shouldHideLabel[value] && !isThisSelectedPoint) {
return null;
}
return (_jsx("foreignObject", { height: 30, requiredFeatures: "http://www.w3.org/TR/SVG11/feature#Extensibility", textAnchor: "middle", width: calculateLabelWidth(String(value)), x: x - Math.min((charAmount / 2) * 4, MIN_LABEL_WIDTH), y: y - Y_LABEL_MARGIN, children: isBlockingOnHovers ? (_jsx(StyledLabel, { fill: fill, opacity: opacity, children: value })) : (_jsx(Tooltip, { sx: { userSelect: 'none' }, title: value || '', children: _jsx(StyledLabel, { fill: fill, opacity: opacity, children: value }) })) }));
};
export default CustomizedLabel;
//# sourceMappingURL=index.js.map