mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
VizTooltip: Allow setting the maxWidth
option (#88652)
This commit is contained in:
parent
f8f44f28d3
commit
3ad03d869d
@ -46,6 +46,7 @@ export const VizTooltipContent = ({
|
|||||||
justify={'space-between'}
|
justify={'space-between'}
|
||||||
isPinned={isPinned}
|
isPinned={isPinned}
|
||||||
lineStyle={lineStyle}
|
lineStyle={lineStyle}
|
||||||
|
showValueScroll={!scrollable}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
{children}
|
{children}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { css, cx } from '@emotion/css';
|
import { css, cx } from '@emotion/css';
|
||||||
import React, { ReactNode, useEffect, useRef, useState } from 'react';
|
import React, { CSSProperties, ReactNode, useEffect, useRef, useState } from 'react';
|
||||||
|
|
||||||
import { GrafanaTheme2 } from '@grafana/data';
|
import { GrafanaTheme2 } from '@grafana/data';
|
||||||
|
|
||||||
@ -16,6 +16,7 @@ interface VizTooltipRowProps extends Omit<VizTooltipItem, 'value'> {
|
|||||||
isActive?: boolean; // for series list
|
isActive?: boolean; // for series list
|
||||||
marginRight?: string;
|
marginRight?: string;
|
||||||
isPinned: boolean;
|
isPinned: boolean;
|
||||||
|
showValueScroll?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum LabelValueTypes {
|
enum LabelValueTypes {
|
||||||
@ -37,11 +38,23 @@ export const VizTooltipRow = ({
|
|||||||
marginRight = '0px',
|
marginRight = '0px',
|
||||||
isPinned,
|
isPinned,
|
||||||
lineStyle,
|
lineStyle,
|
||||||
|
showValueScroll,
|
||||||
}: VizTooltipRowProps) => {
|
}: VizTooltipRowProps) => {
|
||||||
const styles = useStyles2(getStyles, justify, marginRight);
|
const styles = useStyles2(getStyles, justify, marginRight);
|
||||||
|
|
||||||
|
const innerValueScrollStyle: CSSProperties = showValueScroll
|
||||||
|
? {
|
||||||
|
maxHeight: 55,
|
||||||
|
whiteSpace: 'wrap',
|
||||||
|
wordBreak: 'break-word',
|
||||||
|
overflowY: 'scroll',
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
whiteSpace: 'wrap',
|
||||||
|
wordBreak: 'break-word',
|
||||||
|
};
|
||||||
|
|
||||||
const [showLabelTooltip, setShowLabelTooltip] = useState(false);
|
const [showLabelTooltip, setShowLabelTooltip] = useState(false);
|
||||||
const [showValueTooltip, setShowValueTooltip] = useState(false);
|
|
||||||
|
|
||||||
const [copiedText, setCopiedText] = useState<Record<string, string> | null>(null);
|
const [copiedText, setCopiedText] = useState<Record<string, string> | null>(null);
|
||||||
const [showCopySuccess, setShowCopySuccess] = useState(false);
|
const [showCopySuccess, setShowCopySuccess] = useState(false);
|
||||||
@ -106,14 +119,6 @@ export const VizTooltipRow = ({
|
|||||||
|
|
||||||
const onMouseLeaveLabel = () => setShowLabelTooltip(false);
|
const onMouseLeaveLabel = () => setShowLabelTooltip(false);
|
||||||
|
|
||||||
const onMouseEnterValue = (event: React.MouseEvent<HTMLDivElement>) => {
|
|
||||||
if (event.currentTarget.offsetWidth < event.currentTarget.scrollWidth) {
|
|
||||||
setShowValueTooltip(true);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onMouseLeaveValue = () => setShowValueTooltip(false);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.contentWrapper}>
|
<div className={styles.contentWrapper}>
|
||||||
{(color || label) && (
|
{(color || label) && (
|
||||||
@ -160,27 +165,26 @@ export const VizTooltipRow = ({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{!isPinned ? (
|
{!isPinned ? (
|
||||||
<div className={cx(styles.value, isActive)}>{value}</div>
|
<div className={cx(styles.value, isActive)} style={innerValueScrollStyle}>
|
||||||
|
{value}
|
||||||
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<Tooltip content={value ? value.toString() : ''} interactive={false} show={showValueTooltip}>
|
<>
|
||||||
<>
|
{showCopySuccess && copiedText?.value && (
|
||||||
{showCopySuccess && copiedText?.value && (
|
<InlineToast placement="top" referenceElement={valueRef.current}>
|
||||||
<InlineToast placement="top" referenceElement={valueRef.current}>
|
{SUCCESSFULLY_COPIED_TEXT}
|
||||||
{SUCCESSFULLY_COPIED_TEXT}
|
</InlineToast>
|
||||||
</InlineToast>
|
)}
|
||||||
)}
|
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions */}
|
||||||
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions */}
|
<div
|
||||||
<div
|
className={cx(styles.value, isActive, navigator?.clipboard && styles.copy)}
|
||||||
className={cx(styles.value, isActive, navigator?.clipboard && styles.copy)}
|
style={innerValueScrollStyle}
|
||||||
onMouseEnter={onMouseEnterValue}
|
onClick={() => copyToClipboard(value ? value.toString() : '', LabelValueTypes.value)}
|
||||||
onMouseLeave={onMouseLeaveValue}
|
ref={valueRef}
|
||||||
onClick={() => copyToClipboard(value ? value.toString() : '', LabelValueTypes.value)}
|
>
|
||||||
ref={valueRef}
|
{value}
|
||||||
>
|
</div>
|
||||||
{value}
|
</>
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
</Tooltip>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{color && colorPlacement === ColorPlacement.trailing && (
|
{color && colorPlacement === ColorPlacement.trailing && (
|
||||||
@ -199,9 +203,8 @@ export const VizTooltipRow = ({
|
|||||||
const getStyles = (theme: GrafanaTheme2, justify: string, marginRight: string) => ({
|
const getStyles = (theme: GrafanaTheme2, justify: string, marginRight: string) => ({
|
||||||
contentWrapper: css({
|
contentWrapper: css({
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'start',
|
||||||
justifyContent: justify,
|
justifyContent: justify,
|
||||||
flexWrap: 'wrap',
|
|
||||||
marginRight: marginRight,
|
marginRight: marginRight,
|
||||||
}),
|
}),
|
||||||
label: css({
|
label: css({
|
||||||
@ -219,7 +222,6 @@ const getStyles = (theme: GrafanaTheme2, justify: string, marginRight: string) =
|
|||||||
valueWrapper: css({
|
valueWrapper: css({
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
minWidth: 0,
|
|
||||||
}),
|
}),
|
||||||
activeSeries: css({
|
activeSeries: css({
|
||||||
fontWeight: theme.typography.fontWeightBold,
|
fontWeight: theme.typography.fontWeightBold,
|
||||||
|
@ -125,8 +125,6 @@ export const TooltipPlugin2 = ({
|
|||||||
const [{ plot, isHovering, isPinned, contents, style, dismiss }, setState] = useReducer(mergeState, null, initState);
|
const [{ plot, isHovering, isPinned, contents, style, dismiss }, setState] = useReducer(mergeState, null, initState);
|
||||||
|
|
||||||
const sizeRef = useRef<TooltipContainerSize>();
|
const sizeRef = useRef<TooltipContainerSize>();
|
||||||
|
|
||||||
maxWidth = isPinned ? DEFAULT_TOOLTIP_WIDTH : maxWidth ?? DEFAULT_TOOLTIP_WIDTH;
|
|
||||||
const styles = useStyles2(getStyles, maxWidth);
|
const styles = useStyles2(getStyles, maxWidth);
|
||||||
|
|
||||||
const renderRef = useRef(render);
|
const renderRef = useRef(render);
|
||||||
|
@ -66,7 +66,6 @@ export function addTooltipOptions<T extends OptionsWithTooltip>(
|
|||||||
settings: {
|
settings: {
|
||||||
integer: true,
|
integer: true,
|
||||||
},
|
},
|
||||||
showIf: (options: T) => false, // options.tooltip?.mode !== TooltipDisplayMode.None,
|
|
||||||
})
|
})
|
||||||
.addNumberInput({
|
.addNumberInput({
|
||||||
path: 'tooltip.maxHeight',
|
path: 'tooltip.maxHeight',
|
||||||
|
@ -421,7 +421,6 @@ export const plugin = new PanelPlugin<Options, GraphFieldConfig>(HeatmapPanel)
|
|||||||
settings: {
|
settings: {
|
||||||
integer: true,
|
integer: true,
|
||||||
},
|
},
|
||||||
showIf: (options) => false,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.addNumberInput({
|
builder.addNumberInput({
|
||||||
|
Loading…
Reference in New Issue
Block a user