@@ -296,17 +296,80 @@ export class MaturityDashboardComponent implements OnInit, AfterViewInit, OnDest
296296 }
297297
298298 loadExamples ( ) : void {
299- const exampleFiles = [
300- 'assets/maturity/dashboard-examples/maturity-assessment-results (9).json' ,
301- 'assets/maturity/dashboard-examples/maturity-assessment-results (10).json' ,
302- 'assets/maturity/dashboard-examples/maturity-assessment-results (11).json'
303- ] ;
299+ // Load index file that lists all available JSON files
300+ const indexUrl = 'assets/maturity/dashboard-examples/index.json' ;
301+
304302 this . uploadedData = [ ] ;
305303 this . kpasNames = { } ;
306- this . totalFilesCount = exampleFiles . length ;
307- this . filesReadCount = 0 ;
308- for ( const file of exampleFiles ) {
309- this . readJSONFileFromUrl ( file ) ;
304+
305+ fetch ( indexUrl )
306+ . then ( response => {
307+ if ( ! response . ok ) {
308+ throw new Error ( `Error fetching index file: ${ response . statusText } ` ) ;
309+ }
310+ return response . json ( ) ;
311+ } )
312+ . then ( indexData => {
313+ // Get the list of files from the index
314+ const exampleFiles = indexData . files . map ( ( filename : string ) =>
315+ `assets/maturity/dashboard-examples/${ filename } `
316+ ) ;
317+
318+ this . totalFilesCount = exampleFiles . length ;
319+ this . filesReadCount = 0 ;
320+
321+ // Load each file listed in the index
322+ for ( const file of exampleFiles ) {
323+ this . readJSONFileFromUrl ( file ) ;
324+ }
325+ } )
326+ . catch ( error => {
327+ console . error ( 'Error loading example files index:' , error ) ;
328+ this . _snackBar . openFromComponent ( SnackAlertComponent , {
329+ duration : 5 * 1000 ,
330+ data : `Error loading example files: ${ error instanceof Error ? error . message : 'Unknown error' } ` ,
331+ panelClass : [ 'red-snackbar' ]
332+ } ) ;
333+ } ) ;
334+ }
335+
336+ /**
337+ * Convert 0-100 scale to 0-5 scale for display (same as maturity-results component)
338+ */
339+ private convertToFiveScale ( value : number ) : number {
340+ return Math . round ( ( value / 100 ) * 5 * 100 ) / 100 ; // Round to 2 decimal places
341+ }
342+
343+ /**
344+ * Normalize scores in the data entry: use normalized scores if available, otherwise convert from 0-100 to 0-5
345+ */
346+ private normalizeScores ( entry : any ) : void {
347+ // If normalized scores exist, use them directly
348+ if ( entry . overallScoreNormalized !== undefined ) {
349+ entry . overallScore = entry . overallScoreNormalized ;
350+ } else if ( entry . overallScore !== undefined && entry . overallScore > 5 ) {
351+ // If overallScore is > 5, it's likely in 0-100 scale, convert it
352+ entry . overallScore = this . convertToFiveScale ( entry . overallScore ) ;
353+ }
354+
355+ // Normalize KPA scores
356+ if ( entry . kpasScoresNormalized !== undefined ) {
357+ entry . kpasScores = entry . kpasScoresNormalized ;
358+ } else if ( entry . kpasScores ) {
359+ // Check if any KPA score is > 5, indicating 0-100 scale
360+ const hasLargeScores = Object . values ( entry . kpasScores ) . some (
361+ ( score : any ) => typeof score === 'number' && score > 5
362+ ) ;
363+
364+ if ( hasLargeScores ) {
365+ // Convert all KPA scores from 0-100 to 0-5
366+ entry . kpasScores = Object . fromEntries (
367+ Object . entries ( entry . kpasScores ) . map ( ( [ key , value ] ) => [
368+ key ,
369+ typeof value === 'number' ? this . convertToFiveScale ( value ) : value
370+ ] )
371+ ) ;
372+ }
310373 }
311374 }
312375
@@ -319,6 +382,8 @@ export class MaturityDashboardComponent implements OnInit, AfterViewInit, OnDest
319382 return response . json ( ) ;
320383 } )
321384 . then ( jsonContent => {
385+ // Normalize scores before adding to uploadedData
386+ this . normalizeScores ( jsonContent ) ;
322387 this . uploadedData . push ( jsonContent ) ;
323388 this . filesReadCount ++ ;
324389 if ( this . filesReadCount === this . totalFilesCount ) {
@@ -1494,7 +1559,13 @@ export class MaturityDashboardComponent implements OnInit, AfterViewInit, OnDest
14941559 }
14951560
14961561 getScoreColor ( score : number ) : string {
1497- const clamped = Math . max ( 1 , Math . min ( 5 , score ) ) ;
1562+ // Clamp score to valid range (0-5), allowing 0 for "None"
1563+ const clamped = Math . max ( 0 , Math . min ( 5 , score ) ) ;
1564+
1565+ // Handle score of 0 (None) - return gray
1566+ if ( clamped === 0 ) {
1567+ return '#808080' ; // Gray for None
1568+ }
14981569
14991570 // Factor for darkening each color channel.
15001571 const darkenFactor = 0.7 ; // Adjust as desired (0.7, 0.9, etc.)
@@ -1551,6 +1622,8 @@ export class MaturityDashboardComponent implements OnInit, AfterViewInit, OnDest
15511622 try {
15521623 // Convert the file content from text to JSON
15531624 const jsonContent = JSON . parse ( reader . result as string ) ;
1625+ // Normalize scores before adding to uploadedData
1626+ this . normalizeScores ( jsonContent ) ;
15541627 // You can store it for later use (for example, building charts or metrics)
15551628 this . uploadedData . push ( jsonContent ) ;
15561629 } catch ( error ) {
0 commit comments