VizTooltip: Wrap labels to new lines when > ~50% screen width (#90798)

This commit is contained in:
Leon Sorokin
2024-07-22 15:52:36 -05:00
committed by GitHub
parent 45f298120e
commit 06a5c970c4
@@ -27,6 +27,7 @@ enum LabelValueTypes {
const SUCCESSFULLY_COPIED_TEXT = 'Copied to clipboard';
const SHOW_SUCCESS_DURATION = 2 * 1000;
const HORIZONTAL_PX_PER_CHAR = 7;
export const VizTooltipRow = ({
label,
@@ -120,6 +121,11 @@ export const VizTooltipRow = ({
const onMouseLeaveLabel = () => setShowLabelTooltip(false);
// if label is > 50% window width, try to put label/value pairs on new lines
if (label.length * HORIZONTAL_PX_PER_CHAR > window.innerWidth / 2) {
label = label.replaceAll('{', '{\n ').replaceAll('}', '\n}').replaceAll(', ', ',\n ');
}
return (
<div className={styles.contentWrapper}>
{(color || label) && (