1- import { useState , useMemo , useEffect , useRef , useCallback } from 'react' ;
1+ import { useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
22
33import {
44 Chart ,
88 ChartLabel ,
99 ChartLegend ,
1010 ChartThemeColor ,
11- ChartTooltip ,
1211 ChartVoronoiContainer ,
1312} from '@patternfly/react-charts/victory' ;
1413import {
@@ -25,16 +24,53 @@ import {
2524 t_global_color_status_warning_default ,
2625} from '@patternfly/react-tokens' ;
2726import { useDispatch , useSelector } from 'react-redux' ;
27+ import { VictoryPortal } from 'victory' ;
2828import { setAlertsAreLoading , setChooseIncident } from '../../../actions/observe' ;
2929import { MonitoringState } from '../../../reducers/observe' ;
30+ import '../incidents-styles.css' ;
3031import { Incident } from '../model' ;
3132import {
3233 createIncidentsChartBars ,
3334 formatDate ,
3435 generateDateArray ,
3536 updateBrowserUrl ,
3637} from '../utils' ;
37- import { VictoryPortal } from 'victory' ;
38+
39+ const TOOLTIP_MAX_HEIGHT = 300 ;
40+ const TOOLTIP_MAX_WIDTH = 500 ;
41+
42+ const IncidentsTooltip = ( {
43+ x,
44+ y,
45+ x0,
46+ height,
47+ text,
48+ } : {
49+ x ?: number ;
50+ y ?: number ;
51+ x0 ?: number ;
52+ height ?: number ;
53+ text ?: string | Array < string > ;
54+ } ) => {
55+ const posx = x - ( x - x0 ) / 2 - TOOLTIP_MAX_WIDTH / 2 ;
56+ const posy = y - Math . min ( height || 0 , TOOLTIP_MAX_HEIGHT ) / 2 - 20 ;
57+ const textArray : Array < string > = Array . isArray ( text ) ? text : [ text ] ;
58+
59+ return (
60+ < VictoryPortal >
61+ < foreignObject height = { TOOLTIP_MAX_HEIGHT } width = { TOOLTIP_MAX_WIDTH } x = { posx } y = { posy } >
62+ < div className = "incidents__tooltip-wrap" >
63+ < div className = "incidents__tooltip" >
64+ { textArray . map ( ( text , index ) => (
65+ < p key = { index } > { text } </ p >
66+ ) ) }
67+ </ div >
68+ < div className = "incidents__tooltip-arrow" />
69+ </ div >
70+ </ foreignObject >
71+ </ VictoryPortal >
72+ ) ;
73+ } ;
3874
3975const IncidentsChart = ( {
4076 incidentsData,
@@ -132,17 +168,7 @@ const IncidentsChart = ({
132168 < Chart
133169 containerComponent = {
134170 < ChartVoronoiContainer
135- labelComponent = {
136- < VictoryPortal >
137- < ChartTooltip
138- activateData = { false }
139- orientation = "top"
140- dx = { ( { x, x0 } : any ) => - ( x - x0 ) / 2 }
141- dy = { - 5 } // Position tooltip so pointer appears above bar
142- labelComponent = { < ChartLabel /> }
143- />
144- </ VictoryPortal >
145- }
171+ labelComponent = { < IncidentsTooltip /> }
146172 voronoiPadding = { 0 }
147173 labels = { ( { datum } ) => {
148174 if ( datum . nodata ) {
0 commit comments