@@ -39,7 +39,7 @@ const HealthContainer: React.FC<HealthContainerProps> = React.memo(props => {
3939 */
4040 const filterSelectedMetricsAndHealthData = ( ) : DataObject => {
4141 // define a filtered health data object for output
42- // define an array of filteredMetricNames
42+ // define an array of filteredMetricNames for later use
4343 const filteredHealthData = { } ;
4444 const filteredMetricNames : string [ ] = [ ] ;
4545 // iterate over the selectedMetrics from QueryContext
@@ -113,6 +113,7 @@ const HealthContainer: React.FC<HealthContainerProps> = React.memo(props => {
113113 const typeGroupedObject = { } ;
114114 // iterate over the services in the healthData object
115115 for ( const serviceName in filteredHealthData ) {
116+ console . log ( 'service name in datatype function: ' , serviceName ) ;
116117 // save the filtered metrics of the current service to a variable
117118 // define the types of each metric in the metrics object as an array
118119 const metrics : object = filteredHealthData [ serviceName ] ;
@@ -122,46 +123,53 @@ const HealthContainer: React.FC<HealthContainerProps> = React.memo(props => {
122123 // iterate over the types array and assign the typeGroupedObject a key of type, with a value of an object
123124 // then assign that newly created object a key of the current service and a value of an object
124125 typesArray . forEach ( ( metricType : string ) => {
125- typeGroupedObject [ metricType ] = { } ;
126+ if ( ! typeGroupedObject [ metricType ] ) {
127+ // if the metric type doesn't exist, initalize it
128+ typeGroupedObject [ metricType ] = { } ;
129+ } // if it does exist alread, add the service name to it
126130 typeGroupedObject [ metricType ] [ serviceName ] = { } ;
127- } )
128- // iterate over the metrics object
131+ } ) ;
132+ // iterate over the metrics object of the current service
129133 for ( const metric in metrics ) {
130134 // define the current metric's type
131135 const metricType : string = defineDataValueType ( metric ) ;
132136 // store the current metric and its value in the typeGrouped object at the appropriate type and serviceName
133137 typeGroupedObject [ metricType ] [ serviceName ] [ metric ] = metrics [ metric ] ;
134138 }
135139 }
136-
140+
137141 return typeGroupedObject ;
138142 } ;
139143
140144 // function to generate charts using the type-sorted data
141145 const generateCharts = sortedData => {
142146 const chartsArray : JSX . Element [ ] = [ ] ;
143147 const keymaker = ( ) => {
144- return Math . floor ( Math . random ( ) * 1000 )
145- }
146- // iterate over the sortedData and create a chart for each data type
148+ return Math . floor ( Math . random ( ) * 1000 ) ;
149+ } ;
150+ // iterate over the sortedData and create a chart for each data type and each service of that data
147151 for ( const dataType in sortedData ) {
148- // pass down the value of the current data type object
149- const chartData = sortedData [ dataType ] ;
150- console . log ( 'dataType: ' , dataType , 'chartData: ' , chartData ) ;
151- chartsArray . push (
152- < HealthChart
153- key = { 'H' + keymaker ( ) }
154- dataType = { dataType }
155- chartData = { sortedData [ dataType ] }
156- categoryName = { `${ category } ` }
157- sizing = { props . sizing }
158- colourGenerator = { props . colourGenerator }
159- />
160- ) ;
152+ const serviceObjects = sortedData [ dataType ] ;
153+ for ( const serviceName in serviceObjects ) {
154+ // pass down the value of the current data type object
155+ const chartData = serviceObjects [ serviceName ] ;
156+ console . log ( 'dataType: ' , dataType , 'chartData: ' , chartData ) ;
157+ chartsArray . push (
158+ < HealthChart
159+ key = { 'H' + keymaker ( ) }
160+ dataType = { dataType }
161+ serviceName = { serviceName }
162+ chartData = { sortedData [ dataType ] }
163+ categoryName = { `${ category } ` }
164+ sizing = { props . sizing }
165+ colourGenerator = { props . colourGenerator }
166+ />
167+ ) ;
168+ }
161169 }
162170 setHealthChartsArr ( chartsArray ) ;
163171 } ;
164-
172+
165173 useEffect ( ( ) => {
166174 // returns an object containing only the healthData for the current category and the metrics the User selected
167175 const filteredHealthData = filterSelectedMetricsAndHealthData ( ) ;
0 commit comments