@@ -31,6 +31,22 @@ const TickContainer = styled.div`
3131 justify-content: center;
3232` ;
3333
34+ // Stacks a multi-line tick label (e.g. time + date on a midnight crossover)
35+ // tightly. The reduced line-height keeps the two lines visually grouped; each
36+ // line stays its own ConstrainedText so it truncates independently.
37+ const MultilineTickContainer = styled . div `
38+ width: 100%;
39+ display: flex;
40+ flex-direction: column;
41+ align-items: center;
42+ & span {
43+ line-height: 1.1;
44+ }
45+ ` ;
46+
47+ // Extra height granted per wrapped line so a second line is not clipped.
48+ const TICK_LINE_HEIGHT = 12 ;
49+
3450interface ChartLoadingOrErrorProps {
3551 height : number ;
3652}
@@ -158,42 +174,57 @@ export const CustomTick = ({
158174 1000
159175 : 0 ;
160176
177+ const tooltipStyle = {
178+ backgroundColor : theme . backgroundLevel1 ,
179+ padding : spacing . r10 ,
180+ borderRadius : spacing . r8 ,
181+ border : `1px solid ${ theme . border } ` ,
182+ position : 'absolute' as const ,
183+ } ;
184+
185+ const labelLine = ( content : React . ReactNode , key ?: React . Key ) => (
186+ < ConstrainedText
187+ key = { key }
188+ color = "textSecondary"
189+ text = { < Text variant = "Smaller" > { content } </ Text > }
190+ centered
191+ tooltipStyle = { tooltipStyle }
192+ />
193+ ) ;
194+
195+ // A category label may carry a second line (e.g. a date on a midnight
196+ // crossover) separated by "\n"; those lines are stacked tightly.
197+ const lines = type . type === 'time' ? [ ] : String ( payload . value ) . split ( '\n' ) ;
198+ const isMultiline = lines . length > 1 ;
199+
200+ const content =
201+ type . type === 'time' ? (
202+ labelLine (
203+ < FormattedDateTime
204+ format = { formatXAxisDate ( duration ) }
205+ value = { new Date ( payload . value ) }
206+ /> ,
207+ )
208+ ) : isMultiline ? (
209+ < MultilineTickContainer >
210+ { lines . map ( ( line , index ) => labelLine ( line , index ) ) }
211+ </ MultilineTickContainer >
212+ ) : (
213+ labelLine ( String ( payload . value ) )
214+ ) ;
215+
161216 return (
162217 < foreignObject
163218 x = { centerX }
164219 y = { numY - 10 }
165220 width = { tickWidth }
166- height = { 30 }
221+ height = { 30 + ( isMultiline ? ( lines . length - 1 ) * TICK_LINE_HEIGHT : 0 ) }
167222 style = { {
168223 overflow : 'visible' ,
169224 pointerEvents : 'none' ,
170225 } }
171226 >
172- < TickContainer >
173- < ConstrainedText
174- color = "textSecondary"
175- text = {
176- < Text variant = "Smaller" >
177- { type . type === 'time' ? (
178- < FormattedDateTime
179- format = { formatXAxisDate ( duration ) }
180- value = { new Date ( payload . value ) }
181- />
182- ) : (
183- String ( payload . value )
184- ) }
185- </ Text >
186- }
187- centered
188- tooltipStyle = { {
189- backgroundColor : theme . backgroundLevel1 ,
190- padding : spacing . r10 ,
191- borderRadius : spacing . r8 ,
192- border : `1px solid ${ theme . border } ` ,
193- position : 'absolute' ,
194- } }
195- />
196- </ TickContainer >
227+ < TickContainer > { content } </ TickContainer >
197228 </ foreignObject >
198229 ) ;
199230} ;
0 commit comments