1- import React , { useContext , useEffect } from 'react' ;
1+ import {
2+ IconButton ,
3+ Modal ,
4+ Card ,
5+ CardHeader ,
6+ CardContent ,
7+ Button ,
8+ Typography
9+ } from '@material-ui/core' ;
10+ import { Theme , makeStyles } from '@material-ui/core/styles' ;
11+ import { BaseCSSProperties } from '@material-ui/core/styles/withStyles' ;
12+ import React , { useContext } from 'react' ;
213// import OverviewContext from '../context/OverviewContext';
314import { CommsContext } from '../context/CommsContext' ;
415// import { log } from 'console';
516import Graph from 'react-graph-vis' ;
617
718const RouteLocations = props => {
819 const communicationsData = useContext ( CommsContext ) . commsData ;
9-
10- useEffect ( ( ) => {
11- const parentNode = document . querySelector ( 'div.chart' ) ;
12- const childNode = document . querySelectorAll ( 'canvas' ) [ 0 ] ;
13- if ( parentNode && childNode ) {
14- parentNode . append ( childNode ) ;
15- childNode . id = `canvasGraph`
16- }
17- return childNode ;
18- } )
19-
2020 console . log ( 'commdata=======>' , communicationsData ) ;
2121 console . log ( 'try again' ) ;
2222
@@ -88,19 +88,63 @@ const RouteLocations = props => {
8888 const tracePoints = Object . values ( resObj ) . filter ( subArray => subArray . length > 1 ) ;
8989 console . log ( 'tracepoints =======>' , tracePoints ) ;
9090
91+ const useStyles = makeStyles ( theme => ( {
92+ paper : {
93+ height : 280 ,
94+ width : 280 ,
95+ textAlign : 'center' ,
96+ color : '#888888' ,
97+ whiteSpace : 'nowrap' ,
98+ backgroundColor : '#ffffff' ,
99+ borderRadius : 8 ,
100+ border : '0' ,
101+ boxShadow : '0 6px 6px 0 rgba(153, 153, 153, 0.14), 0 6px 6px -2px rgba(153, 153, 153, 0.2), 0 6px 8px 0 rgba(153, 153, 153, 0.12)' ,
102+ '&:hover, &.Mui-focusVisible' : {
103+ backgroundColor : `#ccd8e1` ,
104+ color : '#ffffff' ,
105+ } ,
106+ } ,
107+ hover : {
108+ boxShadow : 'none' ,
109+ color : 'transparent'
110+ } ,
111+ btnStyle : {
112+ position : 'absolute' ,
113+ top : - 10 ,
114+ left : - 10 ,
115+ margin : '0' ,
116+ color : '#eeeeee' ,
117+ borderRadius : '0' ,
118+ backgroundColor : 'transparent' ,
119+ '&:hover' : {
120+ backgroundColor : 'none'
121+ }
122+ } ,
123+ icon : {
124+ width : '75px' ,
125+ height : '75px' ,
126+ boxShadow : 'none' ,
127+ } ,
128+ } ) ) ;
129+ const classes = useStyles ( { } ) ;
130+
131+
132+
133+ // ======Graphs logic =======//
91134 const nodeListObj = { } ;
92135 const edgeList = [ ] ;
93136 for ( let route of tracePoints ) {
94137 for ( let i = 0 ; i < route . length ; i += 1 ) {
138+ const colors = [ '#75b6d7' , '#cc000' , '#fce356' , '#888888' , '#ccd8e1' ]
95139 // check if node exists if not then add node
96140 let id = route [ i ] . microservice
97141 if ( nodeListObj [ id ] === undefined ) {
98- nodeListObj [ id ] = { id : id , label : id , color : '#e04141 ' }
142+ nodeListObj [ id ] = { id : id , label : id , color : { background : '#24d2f1' , border : 'white' , hover : { background : '#4d55ec' , border : 'white' } } , shape : 'circle ' }
99143 }
100144 // add edge from node 1 to node 2 (repeat til end)
101145 if ( i !== 0 ) {
102- let duration = new Date ( route [ i ] . time ) - new Date ( route [ i - 1 ] . time ) ;
103- let edge = { from : route [ i - 1 ] . microservice , to : id , label : `${ duration } ms` }
146+ let duration = new Date ( route [ i ] . time ) - new Date ( route [ i - 1 ] . time ) ;
147+ let edge = { from : route [ i - 1 ] . microservice , to : id , label : `${ duration * 100 } ms` }
104148 edgeList . push ( edge )
105149 }
106150 }
@@ -124,15 +168,20 @@ const RouteLocations = props => {
124168 // edges: [{ from: 4, to: 2, label: 'hello' }, { from: 'one', to: 3 }, { from: 2, to: 4 }, { from: 2, to: 5 }]
125169 // };
126170 const options = {
171+
172+ height : '400px' ,
173+ width : '400px' ,
174+ style : 'surface' ,
127175 layout : {
128176 hierarchical : false
129177 } ,
130178 edges : {
131179 color : "#000000" ,
132- physics : false ,
180+ physics : true ,
133181 smooth : {
134182 type : "curvedCCW" ,
135- forceDirection : "none"
183+ forceDirection : "none" ,
184+ roundness : 0.3
136185 }
137186 } ,
138187 } ;
@@ -147,10 +196,11 @@ const RouteLocations = props => {
147196 }
148197 } ;
149198
150-
199+
151200 return (
152- < div className = "chart" >
153- < Graph id = "visGraph" graph = { graph } options = { options } events = { events } style = { { height : "640px" } } />
201+ < div className = 'traceContainer' >
202+ < span id = 'trace' > Traces</ span >
203+ < Graph className = { classes . paper } graph = { graph } options = { options } events = { events } style = { { fontSize : '8px' , color : '#555555' , fontFamily : 'Open Sans' , boxShadow : '0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)' , backgroundColor : 'white' } } />
154204 </ div >
155205 ) ;
156206} ;
0 commit comments