1
1
import { makeStyles } from '@material-ui/core/styles' ;
2
2
import React , { useContext } from 'react' ;
3
- import { CommsContext } from '../context/CommsContext' ;
4
3
import Graph from 'react-graph-vis' ;
4
+ import { CommsContext } from '../context/CommsContext' ;
5
5
6
6
const RouteChart = React . memo ( ( ) => {
7
7
const communicationsData = useContext ( CommsContext ) . commsData ;
@@ -26,10 +26,10 @@ const RouteChart = React.memo(() => {
26
26
resObj [ element . correlatingid ] . push ( {
27
27
microservice : element . microservice ,
28
28
time : element . time ,
29
- request : element . request , //here
29
+ request : element . request , // here
30
30
} ) ;
31
31
}
32
- //? What does this else block do?
32
+ // ? What does this else block do?
33
33
} else {
34
34
for ( let i = communicationsData . length - 1 ; i >= 0 ; i -- ) {
35
35
const element = communicationsData [ i ] ;
@@ -49,7 +49,6 @@ const RouteChart = React.memo(() => {
49
49
}
50
50
}
51
51
52
-
53
52
// Filter the array so that only subarrays w/ len > 1 are kept.
54
53
// (len == 1 means there's only one point in the route. There's no meaningful data to be gained from those.)
55
54
const tracePoints = Object . values ( resObj ) . filter ( subArray => subArray . length > 1 ) ;
@@ -72,26 +71,26 @@ const RouteChart = React.memo(() => {
72
71
// ======Graphs logic =======//
73
72
const nodeListObj = { } ;
74
73
const edgeListObj = { } ;
75
- for ( let route of tracePoints ) {
74
+ for ( const route of tracePoints ) {
76
75
for ( let i = 0 ; i < route . length ; i += 1 ) {
77
76
// check if node exists if not then add node
78
- let id = route [ i ] . microservice ;
77
+ const id = route [ i ] . microservice ;
79
78
if ( nodeListObj [ id ] === undefined ) {
80
- nodeListObj [ id ] = {
81
- id : id ,
82
- label : id
83
- }
79
+ nodeListObj [ id ] = {
80
+ id,
81
+ label : id ,
82
+ } ;
84
83
}
85
84
// add edge from node to node (repeat til end)
86
85
if ( i !== 0 ) {
87
- let from = route [ i - 1 ] . microservice ;
88
- let to = id ;
89
- let request = route [ i - 1 ] . request ; //here
90
- let edgeStr = JSON . stringify ( { from, to, request } )
86
+ const from = route [ i - 1 ] . microservice ;
87
+ const to = id ;
88
+ const { request } = route [ i - 1 ] ; // here
89
+ const edgeStr = JSON . stringify ( { from, to, request } ) ;
91
90
let duration = new Date ( route [ i ] . time ) - new Date ( route [ i - 1 ] . time ) ;
92
91
// only want one edge per route with the average duration
93
92
if ( edgeListObj [ edgeStr ] ) {
94
- //? wrong math
93
+ // ? wrong math
95
94
duration = ( duration + edgeListObj [ edgeStr ] ) / 2 ;
96
95
}
97
96
edgeListObj [ edgeStr ] = duration ;
@@ -102,10 +101,12 @@ const RouteChart = React.memo(() => {
102
101
// turn objects into valid arrays to input into graph
103
102
const nodeList = Object . values ( nodeListObj ) ;
104
103
const edgeList = [ ] ;
105
- for ( let [ edgeStr , duration ] of Object . entries ( edgeListObj ) ) {
104
+ for ( const [ edgeStr , duration ] of Object . entries ( edgeListObj ) ) {
106
105
const edge = JSON . parse ( edgeStr ) ;
107
- console . log ( edge . request )
108
- edge . label = edge . request ? `${ edge . request } - ${ ( duration * 10 ) . toFixed ( 0 ) } ms` : `${ ( duration * 10 ) . toFixed ( 0 ) } ms`
106
+ // console.log(edge.request)
107
+ edge . label = edge . request
108
+ ? `${ edge . request } - ${ ( duration * 10 ) . toFixed ( 0 ) } ms`
109
+ : `${ ( duration * 10 ) . toFixed ( 0 ) } ms` ;
109
110
edgeList . push ( edge ) ;
110
111
}
111
112
@@ -120,12 +121,12 @@ const RouteChart = React.memo(() => {
120
121
hierarchical : false ,
121
122
} ,
122
123
edges : {
123
- color : " #444d56" ,
124
+ color : ' #444d56' ,
124
125
physics : true ,
125
126
smooth : {
126
- type : " curvedCCW" ,
127
- forceDirection : " none" ,
128
- roundness : 0.3
127
+ type : ' curvedCCW' ,
128
+ forceDirection : ' none' ,
129
+ roundness : 0.3 ,
129
130
} ,
130
131
font : {
131
132
color : '#444d56' ,
@@ -141,27 +142,38 @@ const RouteChart = React.memo(() => {
141
142
} ,
142
143
highlight : {
143
144
background : '#fc4039' ,
144
- }
145
+ } ,
145
146
} ,
146
147
shape : 'circle' ,
147
148
font : {
148
149
color : '#ffffff' ,
149
150
size : 10 ,
150
- face : 'roboto'
151
+ face : 'roboto' ,
151
152
} ,
152
- }
153
- }
153
+ } ,
154
+ } ;
154
155
155
156
const events = {
156
- select : function ( event ) {
157
- let { nodes, edges } = event ;
157
+ select ( event ) {
158
+ const { nodes, edges } = event ;
158
159
} ,
159
160
} ;
160
161
161
162
return (
162
- < div className = 'traceContainer' >
163
- < span id = 'tracesTitle' > Route Traces</ span >
164
- < Graph className = { classes . paper } graph = { graph } options = { options } events = { events } style = { { fontFamily : 'Roboto' , boxShadow : '3px 3px 6px 1px rgb(175, 175, 175)' , backgroundColor : 'white' , borderRadius : '3px' } } />
163
+ < div className = "traceContainer" >
164
+ < span id = "tracesTitle" > Route Traces</ span >
165
+ < Graph
166
+ className = { classes . paper }
167
+ graph = { graph }
168
+ options = { options }
169
+ events = { events }
170
+ style = { {
171
+ fontFamily : 'Roboto' ,
172
+ boxShadow : '3px 3px 6px 1px rgb(175, 175, 175)' ,
173
+ backgroundColor : 'white' ,
174
+ borderRadius : '3px' ,
175
+ } }
176
+ />
165
177
</ div >
166
178
) ;
167
179
} ) ;
0 commit comments