1
1
import moment from 'moment' ;
2
- import React , { useContext , useState , useEffect } from 'react' ;
2
+ import React , { useEffect , useState } from 'react' ;
3
+
4
+ import { useParams } from 'react-router-dom' ;
5
+
3
6
import Plot from 'react-plotly.js' ;
4
7
import { all , solo as soloStyle } from './sizeSwitch' ;
5
8
6
9
interface HealthChartProps {
7
10
key : string ;
8
- service : string ;
11
+ renderService : string ;
9
12
metric : string ;
10
13
timeList : any ;
11
14
valueList : any ;
@@ -19,11 +22,12 @@ interface SoloStyles {
19
22
}
20
23
21
24
const HealthChart : React . FC < HealthChartProps > = React . memo ( props => {
22
- const { service, metric, timeList, valueList, sizing, colourGenerator } = props ;
25
+ const { service } = useParams < any > ( ) ;
26
+ const { renderService, metric, timeList, valueList, sizing, colourGenerator } = props ;
23
27
const [ solo , setSolo ] = useState < SoloStyles | null > ( null ) ;
24
- console . log ( " in the HealthChart" ) ;
25
- console . log ( " healthchart valuelist:" , JSON . stringify ( valueList ) ) ;
26
- console . log ( " healthchart timelist:" , JSON . stringify ( timeList ) ) ;
28
+ console . log ( ' in the HealthChart' ) ;
29
+ console . log ( ' healthchart valuelist:' , JSON . stringify ( valueList ) ) ;
30
+ console . log ( ' healthchart timelist:' , JSON . stringify ( timeList ) ) ;
27
31
28
32
setInterval ( ( ) => {
29
33
if ( solo !== soloStyle ) {
@@ -32,69 +36,82 @@ const HealthChart: React.FC<HealthChartProps> = React.memo(props => {
32
36
} , 20 ) ;
33
37
34
38
const createChart = ( ) => {
35
- const timeArr = timeList . map ( ( el : any ) => moment ( el ) . format ( 'kk:mm:ss' ) ) ;
36
- const hashedColour = colourGenerator ( service ) ;
37
- let plotlyData : {
38
- name : any ;
39
- x : any ;
40
- y : any ;
41
- type : any ;
42
- mode : any ;
43
- marker : { color : string } ;
44
- } ;
45
- plotlyData = {
46
- name : metric ,
47
- x : timeArr ,
48
- y : valueList ,
49
- type : 'scattergl' ,
50
- mode : 'lines' ,
51
- marker : { color : hashedColour } ,
52
- } ;
53
- const sizeSwitch = sizing === 'all' ? all : solo ;
39
+
40
+ // if (service && renderService && service !== renderService ) {
41
+ // console.log("current service is:", service, "render service is:", renderService);
42
+ // return (<div><p>Loading...</p></div>)
43
+
44
+ // }
45
+ // else{
46
+
47
+ const timeArr = timeList . map ( ( el : any ) => moment ( el ) . format ( 'kk:mm:ss' ) ) ;
48
+ const hashedColour = colourGenerator ( renderService ) ;
49
+ let plotlyData : {
50
+ name : any ;
51
+ x : any ;
52
+ y : any ;
53
+ type : any ;
54
+ mode : any ;
55
+ marker : { color : string } ;
56
+ } ;
57
+ plotlyData = {
58
+ name : metric ,
59
+ x : timeArr ,
60
+ y : valueList ,
61
+ type : 'scattergl' ,
62
+ mode : 'lines' ,
63
+ marker : { color : hashedColour } ,
64
+ } ;
65
+ const sizeSwitch = sizing === 'all' ? all : solo ;
66
+
67
+ return (
68
+ < Plot
69
+ data = { [ plotlyData ] }
70
+ config = { { displayModeBar : false } }
71
+ layout = { {
72
+ title : `${ renderService } | ${ metric } ` ,
73
+ ...sizeSwitch ,
74
+ font : {
75
+ color : '#444d56' ,
76
+ size : 11.5 ,
77
+ family : 'Roboto' ,
78
+ } ,
79
+ paper_bgcolor : 'white' ,
80
+ plot_bgcolor : 'white' ,
81
+ showlegend : true ,
82
+ legend : {
83
+ orientation : 'h' ,
84
+ xanchor : 'center' ,
85
+ x : 0.5 ,
86
+ y : 5 ,
87
+ } ,
88
+ xaxis : {
89
+ title : 'Time' ,
90
+ tickmode : 'auto' ,
91
+ tick0 : 0 ,
92
+ dtick : 10 ,
93
+ rangemode : 'nonnegative' ,
94
+ mirror : false ,
95
+ ticks : 'outside' ,
96
+ showline : true ,
97
+ } ,
98
+ yaxis : {
99
+ rangemode : 'nonnegative' ,
100
+ title : metric ,
101
+ } ,
102
+ } }
103
+ />
104
+ ) ;
54
105
55
- return (
56
- < Plot
57
- data = { [ plotlyData ] }
58
- config = { { displayModeBar : false } }
59
- layout = { {
60
- title : `${ service } | ${ metric } ` ,
61
- ...sizeSwitch ,
62
- font : {
63
- color : '#444d56' ,
64
- size : 11.5 ,
65
- family : 'Roboto' ,
66
- } ,
67
- paper_bgcolor : 'white' ,
68
- plot_bgcolor : 'white' ,
69
- showlegend : true ,
70
- legend : {
71
- orientation : 'h' ,
72
- xanchor : 'center' ,
73
- x : 0.5 ,
74
- y : 5 ,
75
- } ,
76
- xaxis : {
77
- title : 'Time' ,
78
- tickmode : 'auto' ,
79
- tick0 : 0 ,
80
- dtick : 10 ,
81
- rangemode : 'nonnegative' ,
82
- mirror : false ,
83
- ticks : 'outside' ,
84
- showline : true ,
85
- } ,
86
- yaxis : {
87
- rangemode : 'nonnegative' ,
88
- title : metric ,
89
- } ,
90
- } }
91
- />
92
- ) ;
106
+ // }
107
+
93
108
} ;
94
109
95
110
return (
96
111
< div className = "chart" data-testid = "Health Chart" >
97
- { createChart ( ) }
112
+ {
113
+ createChart ( )
114
+ }
98
115
</ div >
99
116
) ;
100
117
} ) ;
0 commit comments