@@ -29,7 +29,6 @@ const MicroServiceTraffic = (props) => {
2929 }
3030
3131 else {
32-
3332 for ( let i = communicationsData . length - 1 ; i >= 0 ; i -- ) {
3433 const element = communicationsData [ i ] ;
3534 if ( resObj [ element . correlatingid ] ) resObj [ element . correlatingid ] . push ( element . currentmicroservice ) ;
@@ -40,26 +39,30 @@ const MicroServiceTraffic = (props) => {
4039
4140 //use object values to destructure locations
4241 const tracePoints = Object . values ( resObj ) ;
43- let position = communicationsData [ 0 ] . correlatingid ? 0 : tracePoints . length - 1 ;
44-
42+
4543 // Declare Micro-server-count dictinary to capture the amount of times a particular server is hit
4644 const microServiceCountdictionary = { } ;
4745
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+
4849 // 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 ) {
5051
5152 // 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 ;
5455 } else {
55- microServiceCountdictionary [ tracePoints [ position ] [ i ] ] += 1
56+ microServiceCountdictionary [ tracePointLog [ i ] ] += 1
5657 }
5758 } ;
5859
5960 // capture values of microServiceCountdictionary to use as data to populate chart object
6061 const serverPingCount = Object . values ( microServiceCountdictionary ) ;
6162
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+
6366 // Create chart object data to feed into bar component
6467 const myChart = {
6568 //spread dictionary keys inorder to properly label chart x axis
@@ -70,9 +73,9 @@ const MicroServiceTraffic = (props) => {
7073 backgroundColor : 'rgba(241, 207, 70,1)' ,
7174 borderColor : 'rgba(0,0,0,1)' ,
7275 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
7477 }
75- ]
78+ ] ,
7679 }
7780
7881
0 commit comments