@@ -29,7 +29,6 @@ const MicroServiceTraffic = (props) => {
29
29
}
30
30
31
31
else {
32
-
33
32
for ( let i = communicationsData . length - 1 ; i >= 0 ; i -- ) {
34
33
const element = communicationsData [ i ] ;
35
34
if ( resObj [ element . correlatingid ] ) resObj [ element . correlatingid ] . push ( element . currentmicroservice ) ;
@@ -40,26 +39,30 @@ const MicroServiceTraffic = (props) => {
40
39
41
40
//use object values to destructure locations
42
41
const tracePoints = Object . values ( resObj ) ;
43
- let position = communicationsData [ 0 ] . correlatingid ? 0 : tracePoints . length - 1 ;
44
-
42
+
45
43
// Declare Micro-server-count dictinary to capture the amount of times a particular server is hit
46
44
const microServiceCountdictionary = { } ;
47
45
46
+ //array logging every ping present in communications table ---> flat used to flatten multidimensional array and return 1d array
47
+ const tracePointLog = tracePoints . flat ( Infinity ) ;
48
+
48
49
// iterate over Trace Points
49
- for ( let i = 0 ; i < tracePoints [ position ] . length ; i += 1 ) {
50
+ for ( let i = 0 ; i < tracePointLog . length ; i += 1 ) {
50
51
51
52
// populate Micro-count dictionary
52
- if ( ! microServiceCountdictionary [ tracePoints [ position ] [ i ] ] ) {
53
- microServiceCountdictionary [ tracePoints [ position ] [ i ] ] = 1 ;
53
+ if ( ! microServiceCountdictionary [ tracePointLog [ i ] ] ) {
54
+ microServiceCountdictionary [ tracePointLog [ i ] ] = 1 ;
54
55
} else {
55
- microServiceCountdictionary [ tracePoints [ position ] [ i ] ] += 1
56
+ microServiceCountdictionary [ tracePointLog [ i ] ] += 1
56
57
}
57
58
} ;
58
59
59
60
// capture values of microServiceCountdictionary to use as data to populate chart object
60
61
const serverPingCount = Object . values ( microServiceCountdictionary ) ;
61
62
62
-
63
+ // variable 10 points higher than max number in microservicesDictionary aggregation --> variable allows for top level spacing on bar graph
64
+ const yAxisHeadRoom = ( Math . max ( ...serverPingCount ) + 10 ) ;
65
+
63
66
// Create chart object data to feed into bar component
64
67
const myChart = {
65
68
//spread dictionary keys inorder to properly label chart x axis
@@ -70,9 +73,9 @@ const MicroServiceTraffic = (props) => {
70
73
backgroundColor : 'rgba(241, 207, 70,1)' ,
71
74
borderColor : 'rgba(0,0,0,1)' ,
72
75
borderWidth : 1 ,
73
- data : [ ...serverPingCount , 0 ] // spread ping count array into data array to have chart populate the Y axis
76
+ data : [ ...serverPingCount , 0 , yAxisHeadRoom ] // spread ping count array into data array to have chart populate the Y axis
74
77
}
75
- ]
78
+ ] ,
76
79
}
77
80
78
81
0 commit comments