Skip to content

Commit 200c71f

Browse files
authored
VizTooltips: Optimize performance (grafana#80102)
1 parent 90fb6a0 commit 200c71f

File tree

13 files changed

+69
-264
lines changed

13 files changed

+69
-264
lines changed

packages/grafana-ui/src/components/VizTooltip/HeaderLabel.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@ import { LabelValue } from './types';
55

66
interface Props {
77
headerLabel: LabelValue;
8+
isPinned: boolean;
89
}
910

10-
export const HeaderLabel = ({ headerLabel }: Props) => {
11+
export const HeaderLabel = ({ headerLabel, isPinned }: Props) => {
1112
const { label, value, color, colorIndicator } = headerLabel;
1213

1314
return (
14-
<VizTooltipRow label={label} value={value} color={color} colorIndicator={colorIndicator} marginRight={'22px'} />
15+
<VizTooltipRow
16+
label={label}
17+
value={value}
18+
color={color}
19+
colorIndicator={colorIndicator}
20+
marginRight={'22px'}
21+
isPinned={isPinned}
22+
/>
1523
);
1624
};

packages/grafana-ui/src/components/VizTooltip/SeriesList.tsx

Lines changed: 0 additions & 43 deletions
This file was deleted.

packages/grafana-ui/src/components/VizTooltip/VizTooltipContent.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import { LabelValue } from './types';
1111
interface Props {
1212
contentLabelValue: LabelValue[];
1313
customContent?: ReactElement[];
14+
isPinned: boolean;
1415
}
1516

16-
export const VizTooltipContent = ({ contentLabelValue, customContent }: Props) => {
17+
export const VizTooltipContent = ({ contentLabelValue, customContent, isPinned }: Props) => {
1718
const styles = useStyles2(getStyles);
1819

1920
return (
@@ -31,6 +32,7 @@ export const VizTooltipContent = ({ contentLabelValue, customContent }: Props) =
3132
colorPlacement={colorPlacement}
3233
isActive={isActive}
3334
justify={'space-between'}
35+
isPinned={isPinned}
3436
/>
3537
);
3638
})}

packages/grafana-ui/src/components/VizTooltip/VizTooltipHeader.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ interface Props {
1313
headerLabel: LabelValue;
1414
keyValuePairs?: LabelValue[];
1515
customValueDisplay?: ReactElement | null;
16+
isPinned: boolean;
1617
}
17-
export const VizTooltipHeader = ({ headerLabel, keyValuePairs, customValueDisplay }: Props) => {
18+
export const VizTooltipHeader = ({ headerLabel, keyValuePairs, customValueDisplay, isPinned }: Props) => {
1819
const styles = useStyles2(getStyles);
1920

2021
return (
2122
<div className={styles.wrapper}>
22-
<HeaderLabel headerLabel={headerLabel} />
23-
{customValueDisplay || <VizTooltipHeaderLabelValue keyValuePairs={keyValuePairs} />}
23+
<HeaderLabel headerLabel={headerLabel} isPinned={isPinned} />
24+
{customValueDisplay || <VizTooltipHeaderLabelValue keyValuePairs={keyValuePairs} isPinned={isPinned} />}
2425
</div>
2526
);
2627
};

packages/grafana-ui/src/components/VizTooltip/VizTooltipHeaderLabelValue.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { LabelValue } from './types';
55

66
interface Props {
77
keyValuePairs?: LabelValue[];
8+
isPinned: boolean;
89
}
910

10-
export const VizTooltipHeaderLabelValue = ({ keyValuePairs }: Props) => (
11+
export const VizTooltipHeaderLabelValue = ({ keyValuePairs, isPinned }: Props) => (
1112
<>
1213
{keyValuePairs?.map((keyValuePair, i) => (
1314
<VizTooltipRow
@@ -17,6 +18,7 @@ export const VizTooltipHeaderLabelValue = ({ keyValuePairs }: Props) => (
1718
color={keyValuePair.color}
1819
colorIndicator={keyValuePair.colorIndicator!}
1920
justify={'space-between'}
21+
isPinned={isPinned}
2022
/>
2123
))}
2224
</>

packages/grafana-ui/src/components/VizTooltip/VizTooltipRow.tsx

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface Props extends LabelValue {
1313
justify?: string;
1414
isActive?: boolean; // for series list
1515
marginRight?: string;
16+
isPinned: boolean;
1617
}
1718

1819
export const VizTooltipRow = ({
@@ -24,6 +25,7 @@ export const VizTooltipRow = ({
2425
justify = 'flex-start',
2526
isActive = false,
2627
marginRight = '0px',
28+
isPinned,
2729
}: Props) => {
2830
const styles = useStyles2(getStyles, justify, marginRight);
2931

@@ -53,27 +55,40 @@ export const VizTooltipRow = ({
5355
{color && colorPlacement === ColorPlacement.first && (
5456
<VizTooltipColorIndicator color={color} colorIndicator={colorIndicator} />
5557
)}
56-
<Tooltip content={label} interactive={false} show={showLabelTooltip}>
57-
<div
58-
className={cx(styles.label, isActive && styles.activeSeries)}
59-
onMouseEnter={onMouseEnterLabel}
60-
onMouseLeave={onMouseLeaveLabel}
61-
>
62-
{label}
63-
</div>
64-
</Tooltip>
58+
{!isPinned ? (
59+
<div className={cx(styles.label, isActive && styles.activeSeries)}>{label}</div>
60+
) : (
61+
<Tooltip content={label} interactive={false} show={showLabelTooltip}>
62+
<div
63+
className={cx(styles.label, isActive && styles.activeSeries)}
64+
onMouseEnter={onMouseEnterLabel}
65+
onMouseLeave={onMouseLeaveLabel}
66+
>
67+
{label}
68+
</div>
69+
</Tooltip>
70+
)}
6571
</div>
6672
)}
6773

6874
<div className={styles.valueWrapper}>
6975
{color && colorPlacement === ColorPlacement.leading && (
7076
<VizTooltipColorIndicator color={color} colorIndicator={colorIndicator} />
7177
)}
72-
<Tooltip content={value ? value.toString() : ''} interactive={false} show={showValueTooltip}>
73-
<div className={cx(styles.value, isActive)} onMouseEnter={onMouseEnterValue} onMouseLeave={onMouseLeaveValue}>
74-
{value}
75-
</div>
76-
</Tooltip>
78+
{!isPinned ? (
79+
<div className={cx(styles.value, isActive)}>{value}</div>
80+
) : (
81+
<Tooltip content={value ? value.toString() : ''} interactive={false} show={showValueTooltip}>
82+
<div
83+
className={cx(styles.value, isActive)}
84+
onMouseEnter={onMouseEnterValue}
85+
onMouseLeave={onMouseLeaveValue}
86+
>
87+
{value}
88+
</div>
89+
</Tooltip>
90+
)}
91+
7792
{color && colorPlacement === ColorPlacement.trailing && (
7893
<>
7994
&nbsp;
@@ -86,24 +101,13 @@ export const VizTooltipRow = ({
86101
};
87102

88103
const getStyles = (theme: GrafanaTheme2, justify: string, marginRight: string) => ({
89-
wrapper: css({
90-
display: 'flex',
91-
flexDirection: 'column',
92-
flex: 1,
93-
gap: 4,
94-
borderTop: `1px solid ${theme.colors.border.medium}`,
95-
padding: theme.spacing(1),
96-
}),
97104
contentWrapper: css({
98105
display: 'flex',
99106
alignItems: 'center',
100107
justifyContent: justify,
101108
flexWrap: 'wrap',
102109
marginRight: marginRight,
103110
}),
104-
customContentPadding: css({
105-
padding: `${theme.spacing(1)} 0`,
106-
}),
107111
label: css({
108112
color: theme.colors.text.secondary,
109113
fontWeight: 400,

public/app/plugins/panel/heatmap/HeatmapHoverView.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,12 @@ const HeatmapHoverCell = ({
382382

383383
return (
384384
<div className={styles.wrapper}>
385-
<VizTooltipHeader headerLabel={getHeaderLabel()} />
386-
<VizTooltipContent contentLabelValue={getContentLabelValue()} customContent={getCustomContent()} />
385+
<VizTooltipHeader headerLabel={getHeaderLabel()} isPinned={isPinned} />
386+
<VizTooltipContent
387+
contentLabelValue={getContentLabelValue()}
388+
customContent={getCustomContent()}
389+
isPinned={isPinned}
390+
/>
387391
{isPinned && <VizTooltipFooter dataLinks={links} canAnnotate={canAnnotate} />}
388392
</div>
389393
);

public/app/plugins/panel/state-timeline/StateTimelineTooltip2.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ export const StateTimelineTooltip2 = ({
180180

181181
return (
182182
<div className={styles.wrapper}>
183-
<VizTooltipHeader headerLabel={getHeaderLabel()} />
184-
<VizTooltipContent contentLabelValue={getContentLabelValue()} />
183+
<VizTooltipHeader headerLabel={getHeaderLabel()} isPinned={isPinned} />
184+
<VizTooltipContent contentLabelValue={getContentLabelValue()} isPinned={isPinned} />
185185
{isPinned && <VizTooltipFooter dataLinks={links} canAnnotate={false} />}
186186
</div>
187187
);

public/app/plugins/panel/status-history/StatusHistoryTooltip2.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ export const StatusHistoryTooltip2 = ({
142142

143143
return (
144144
<div className={styles.wrapper}>
145-
<VizTooltipHeader headerLabel={getHeaderLabel()} />
146-
<VizTooltipContent contentLabelValue={getContentLabelValue()} />
145+
<VizTooltipHeader headerLabel={getHeaderLabel()} isPinned={isPinned} />
146+
<VizTooltipContent contentLabelValue={getContentLabelValue()} isPinned={isPinned} />
147147
{isPinned && <VizTooltipFooter dataLinks={links} canAnnotate={false} />}
148148
</div>
149149
);

public/app/plugins/panel/timeseries/TimeSeriesTooltip.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export const TimeSeriesTooltip = ({
133133

134134
const getHeaderLabel = (): LabelValue => {
135135
return {
136-
label: '',
136+
label: xField.type === FieldType.time ? '' : getFieldDisplayName(xField, seriesFrame, frames),
137137
value: xVal,
138138
};
139139
};
@@ -145,8 +145,8 @@ export const TimeSeriesTooltip = ({
145145
return (
146146
<div>
147147
<div className={styles.wrapper}>
148-
<VizTooltipHeader headerLabel={getHeaderLabel()} />
149-
<VizTooltipContent contentLabelValue={getContentLabelValue()} />
148+
<VizTooltipHeader headerLabel={getHeaderLabel()} isPinned={isPinned} />
149+
<VizTooltipContent contentLabelValue={getContentLabelValue()} isPinned={isPinned} />
150150
{isPinned && <VizTooltipFooter dataLinks={links} canAnnotate={false} />}
151151
</div>
152152
</div>

0 commit comments

Comments
 (0)