@@ -13,6 +13,7 @@ import {
13
13
PackageInfo ,
14
14
} from '../../../shared/shared-types' ;
15
15
import { text } from '../../../shared/text' ;
16
+ import { classificationUnknownColor } from '../../shared-styles' ;
16
17
import {
17
18
AttributionCountPerSourcePerLicense ,
18
19
ChartDataItem ,
@@ -337,11 +338,13 @@ export function getCriticalSignalsCount(
337
338
return criticalityData . filter ( ( { count } ) => count > 0 ) ;
338
339
}
339
340
341
+ type ColoredChartDataItem = ChartDataItem & { color : string } ;
342
+
340
343
export function getSignalCountByClassification (
341
344
licenseCounts : LicenseCounts ,
342
345
licenseNamesWithClassification : LicenseNamesWithClassification ,
343
346
classifications : ClassificationsConfig ,
344
- ) : Array < ChartDataItem > {
347
+ ) : [ Array < ChartDataItem > , { [ segmentName : string ] : string } ] {
345
348
const NO_CLASSIFICATION = - 1 ;
346
349
const classificationCounts : Record < Classification , number > = { } ;
347
350
@@ -356,27 +359,37 @@ export function getSignalCountByClassification(
356
359
357
360
const pieChartData = Object . keys ( classifications )
358
361
. map ( Number )
359
- . map < ChartDataItem > ( ( classification ) => {
362
+ . map < ColoredChartDataItem > ( ( classification ) => {
360
363
const classificationName = classifications [ classification ] . description ;
361
364
const classificationCount =
362
365
classificationCounts [ toNumber ( classification ) ] ?? 0 ;
366
+ const color = classifications [ classification ] . color ;
363
367
364
368
return {
365
369
name : classificationName ,
366
370
count : classificationCount ,
371
+ color,
367
372
} ;
368
373
} )
369
374
. filter ( ( { count } ) => count > 0 ) ;
370
375
371
376
if ( classificationCounts [ NO_CLASSIFICATION ] ) {
372
- return pieChartData . concat ( {
377
+ pieChartData . push ( {
373
378
name : text . projectStatisticsPopup . charts
374
379
. signalCountByClassificationPieChart . noClassification ,
375
380
count : classificationCounts [ NO_CLASSIFICATION ] ,
381
+ color : classificationUnknownColor ,
376
382
} ) ;
377
383
}
378
384
379
- return pieChartData ;
385
+ const colorMap = Object . fromEntries (
386
+ pieChartData . map ( ( colorChartEntry ) => [
387
+ colorChartEntry . name ,
388
+ colorChartEntry . color ,
389
+ ] ) ,
390
+ ) ;
391
+
392
+ return [ pieChartData , colorMap ] ;
380
393
}
381
394
382
395
export function getIncompleteAttributionsCount (
0 commit comments