1+ import { GRAPH_TOOLTIP_MAX_WIDTH_PX } from '@/page-layout/widgets/graph/components/constants/GraphTooltipMaxWidthPx' ;
2+ import { GRAPH_TOOLTIP_MIN_WIDTH_PX } from '@/page-layout/widgets/graph/components/constants/GraphTooltipMinWidthPx' ;
3+ import { GRAPH_TOOLTIP_SCROLL_MAX_HEIGHT_PX } from '@/page-layout/widgets/graph/components/constants/GraphTooltipScrollMaxHeightPx' ;
14import { useTheme } from '@emotion/react' ;
25import styled from '@emotion/styled' ;
36import { t } from '@lingui/core/macro' ;
@@ -12,9 +15,9 @@ const StyledTooltip = styled.div`
1215 display: flex;
1316 flex-direction: column;
1417 gap: 2px;
15- max-width: min(300px , calc(100vw - 40px));
16- min-width: 160px ;
17- pointer-events: none ;
18+ max-width: min(${ GRAPH_TOOLTIP_MAX_WIDTH_PX } px , calc(100vw - 40px));
19+ min-width: ${ GRAPH_TOOLTIP_MIN_WIDTH_PX } px ;
20+ pointer-events: auto ;
1821` ;
1922
2023const StyledTooltipContent = styled . div `
@@ -35,10 +38,12 @@ const StyledTooltipRowContainer = styled.div`
3538 display: flex;
3639 flex-direction: column;
3740 gap: ${ ( { theme } ) => theme . spacing ( 2 ) } ;
41+ max-height: ${ GRAPH_TOOLTIP_SCROLL_MAX_HEIGHT_PX } px;
42+ overflow-y: auto;
3843` ;
3944
40- const StyledDot = styled . div < { $ color : string } > `
41- background: ${ ( { $ color } ) => $ color} ;
45+ const StyledDot = styled . div < { color : string } > `
46+ background: ${ ( { color } ) => color } ;
4247 border-radius: 50%;
4348 height: 6px;
4449 width: 6px;
@@ -48,7 +53,7 @@ const StyledDot = styled.div<{ $color: string }>`
4853const StyledTooltipLink = styled . div `
4954 align-items: center;
5055 color: ${ ( { theme } ) => theme . font . color . light } ;
51- cursor: default ;
56+ cursor: pointer ;
5257 display: flex;
5358 justify-content: space-between;
5459 height: ${ ( { theme } ) => theme . spacing ( 6 ) } ;
@@ -85,32 +90,39 @@ const StyledTooltipRowRightContent = styled.div`
8590 width: 100%;
8691` ;
8792
88- const StyledTooltipLabel = styled . span `
89- color: ${ ( { theme } ) => theme . font . color . tertiary } ;
93+ const StyledTooltipLabel = styled . span < { isHighlighted ?: boolean } > `
94+ color: ${ ( { theme, isHighlighted } ) =>
95+ isHighlighted ? theme . font . color . secondary : theme . font . color . tertiary } ;
9096 flex: 1;
9197 min-width: 0;
9298 overflow: hidden;
9399 text-overflow: ellipsis;
94100 white-space: nowrap;
101+ font-weight: ${ ( { theme, isHighlighted } ) =>
102+ isHighlighted ? theme . font . weight . medium : theme . font . weight . regular } ;
95103` ;
96104
97- const StyledTooltipValue = styled . span `
105+ const StyledTooltipValue = styled . span < { isHighlighted ?: boolean } > `
106+ color: ${ ( { theme, isHighlighted } ) =>
107+ isHighlighted ? theme . font . color . tertiary : theme . font . color . extraLight } ;
98108 flex-shrink: 0;
99- font-weight: ${ ( { theme } ) => theme . font . weight . medium } ;
109+ font-weight: ${ ( { theme, isHighlighted } ) =>
110+ isHighlighted ? theme . font . weight . semiBold : theme . font . weight . medium } ;
100111 white-space: nowrap;
101112` ;
102113
103114const StyledHorizontalSectionPadding = styled . div < {
104- $ addTop ?: boolean ;
105- $ addBottom ?: boolean ;
115+ addTop ?: boolean ;
116+ addBottom ?: boolean ;
106117} > `
107118 padding-inline: ${ ( { theme } ) => theme . spacing ( 1 ) } ;
108- margin-top: ${ ( { $ addTop, theme } ) => ( $ addTop ? theme . spacing ( 1 ) : 0 ) } ;
109- margin-bottom: ${ ( { $ addBottom, theme } ) =>
110- $ addBottom ? theme . spacing ( 1 ) : 0 } ;
119+ margin-top: ${ ( { addTop, theme } ) => ( addTop ? theme . spacing ( 1 ) : 0 ) } ;
120+ margin-bottom: ${ ( { addBottom, theme } ) =>
121+ addBottom ? theme . spacing ( 1 ) : 0 } ;
111122` ;
112123
113124export type GraphWidgetTooltipItem = {
125+ key : string ;
114126 label : string ;
115127 formattedValue : string ;
116128 value : number ;
@@ -119,46 +131,63 @@ export type GraphWidgetTooltipItem = {
119131
120132type GraphWidgetTooltipProps = {
121133 items : GraphWidgetTooltipItem [ ] ;
122- showClickHint ?: boolean ;
123134 indexLabel ?: string ;
135+ highlightedKey ?: string ;
136+ linkTo ?: string ;
124137} ;
125138
126139export const GraphWidgetTooltip = ( {
127140 items,
128- showClickHint = false ,
129141 indexLabel,
142+ highlightedKey,
143+ linkTo,
130144} : GraphWidgetTooltipProps ) => {
131145 const theme = useTheme ( ) ;
132146
133147 const filteredItems = items . filter (
134148 ( item ) => item . value !== 0 && isNonEmptyString ( item . formattedValue ) ,
135149 ) ;
136150
151+ const shouldHighlight = filteredItems . length > 1 ;
152+ const hasLink = isNonEmptyString ( linkTo ) ;
153+
137154 return (
138155 < StyledTooltip >
139- < StyledHorizontalSectionPadding $ addTop $ addBottom= { ! showClickHint } >
156+ < StyledHorizontalSectionPadding addTop addBottom = { ! hasLink } >
140157 < StyledTooltipContent >
141158 { indexLabel && (
142159 < StyledTooltipHeader > { indexLabel } </ StyledTooltipHeader >
143160 ) }
144161 < StyledTooltipRowContainer >
145- { filteredItems . map ( ( item , index ) => (
146- < StyledTooltipRow key = { index } >
147- < StyledDot $color = { item . dotColor } />
148- < StyledTooltipRowRightContent >
149- < StyledTooltipLabel > { item . label } </ StyledTooltipLabel >
150- < StyledTooltipValue > { item . formattedValue } </ StyledTooltipValue >
151- </ StyledTooltipRowRightContent >
152- </ StyledTooltipRow >
153- ) ) }
162+ { filteredItems . map ( ( item ) => {
163+ const isHighlighted =
164+ shouldHighlight && highlightedKey === item . key ;
165+ return (
166+ < StyledTooltipRow key = { item . key } >
167+ < StyledDot color = { item . dotColor } />
168+ < StyledTooltipRowRightContent >
169+ < StyledTooltipLabel isHighlighted = { isHighlighted } >
170+ { item . label }
171+ </ StyledTooltipLabel >
172+ < StyledTooltipValue isHighlighted = { isHighlighted } >
173+ { item . formattedValue }
174+ </ StyledTooltipValue >
175+ </ StyledTooltipRowRightContent >
176+ </ StyledTooltipRow >
177+ ) ;
178+ } ) }
154179 </ StyledTooltipRowContainer >
155180 </ StyledTooltipContent >
156181 </ StyledHorizontalSectionPadding >
157- { showClickHint && (
182+ { hasLink && (
158183 < >
159184 < StyledTooltipSeparator />
160- < StyledHorizontalSectionPadding $addBottom >
161- < StyledTooltipLink >
185+ < StyledHorizontalSectionPadding addBottom >
186+ < StyledTooltipLink
187+ onClick = { ( ) => {
188+ window . location . href = String ( linkTo ) ;
189+ } }
190+ >
162191 < span > { t `Click to see data` } </ span >
163192 < IconArrowUpRight size = { theme . icon . size . sm } />
164193 </ StyledTooltipLink >
0 commit comments