Skip to content

Commit 5853263

Browse files
authored
Merge pull request #2855 from opossum-tool/feat/align_statistics_popup_and_progress_bar_colors
feat: statistics popup and progress bar share same colors
2 parents ba9aff3 + 35e7f60 commit 5853263

File tree

5 files changed

+43
-16
lines changed

5 files changed

+43
-16
lines changed

src/Frontend/Components/ProgressBar/ProgressBar.util.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import MuiBox from '@mui/material/Box';
66
import { sum } from 'lodash';
77

88
import { Criticality } from '../../../shared/shared-types';
9-
import { criticalityColor, OpossumColors } from '../../shared-styles';
9+
import {
10+
classificationUnknownColor,
11+
criticalityColor,
12+
OpossumColors,
13+
} from '../../shared-styles';
1014
import { navigateToSelectedPathOrOpenUnsavedPopup } from '../../state/actions/popup-actions/popup-actions';
1115
import { useAppDispatch, useAppSelector } from '../../state/hooks';
1216
import {
@@ -254,7 +258,7 @@ function calculateProgressBarSteps(
254258
);
255259
progressBarSteps.push({
256260
widthInPercent: 100 - totalPercentage,
257-
color: OpossumColors.lightestBlue,
261+
color: classificationUnknownColor,
258262
});
259263

260264
return roundPercentagesToAtLeastOnePercentAndNormalize(progressBarSteps);

src/Frontend/Components/ProgressBar/__tests__/ProgressBar.util.test.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
// SPDX-License-Identifier: Apache-2.0
55
import { Criticality } from '../../../../shared/shared-types';
66
import { faker } from '../../../../testing/Faker';
7-
import { criticalityColor, OpossumColors } from '../../../shared-styles';
7+
import {
8+
classificationUnknownColor,
9+
criticalityColor,
10+
OpossumColors,
11+
} from '../../../shared-styles';
812
import {
913
ClassificationStatistics,
1014
ProgressBarData,
@@ -98,7 +102,7 @@ describe('ProgressBar helpers', () => {
98102

99103
const background = getClassificationBarBackground(testProgressBarData);
100104

101-
const expectedBackground = `linear-gradient(to right, ${classificationStatistics[3].color} 0% 5% , ${classificationStatistics[2].color} 5% 25% , ${classificationStatistics[1].color} 25% 40% , ${classificationStatistics[0].color} 40% 65% , hsl(220, 41%, 92%) 65% 100% )`;
105+
const expectedBackground = `linear-gradient(to right, ${classificationStatistics[3].color} 0% 5% , ${classificationStatistics[2].color} 5% 25% , ${classificationStatistics[1].color} 25% 40% , ${classificationStatistics[0].color} 40% 65% , ${classificationUnknownColor} 65% 100% )`;
102106
expect(background).toEqual(expectedBackground);
103107
});
104108

@@ -125,7 +129,7 @@ describe('ProgressBar helpers', () => {
125129

126130
const background = getClassificationBarBackground(testProgressBarData);
127131

128-
const expectedBackground = `linear-gradient(to right, ${classificationStatistics[11].color} 0% 5% , ${classificationStatistics[2].color} 5% 25% , ${classificationStatistics[1].color} 25% 40% , ${classificationStatistics[0].color} 40% 65% , hsl(220, 41%, 92%) 65% 100% )`;
132+
const expectedBackground = `linear-gradient(to right, ${classificationStatistics[11].color} 0% 5% , ${classificationStatistics[2].color} 5% 25% , ${classificationStatistics[1].color} 25% 40% , ${classificationStatistics[0].color} 40% 65% , ${classificationUnknownColor} 65% 100% )`;
129133
expect(background).toEqual(expectedBackground);
130134
});
131135

@@ -168,7 +172,7 @@ describe('ProgressBar helpers', () => {
168172

169173
const background = getClassificationBarBackground(testProgressBarData);
170174

171-
const expectedBackground = `linear-gradient(to right, ${classificationStatisticsEntry.color} 0% 25% , hsl(220, 41%, 92%) 25% 100% )`;
175+
const expectedBackground = `linear-gradient(to right, ${classificationStatisticsEntry.color} 0% 25% , ${classificationUnknownColor} 25% 100% )`;
172176
expect(background).toBe(expectedBackground);
173177
});
174178
});

src/Frontend/Components/ProjectStatisticsPopup/ProjectStatisticsPopup.tsx

+10-6
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ export const ProjectStatisticsPopup: React.FC = () => {
7171
licenseNamesWithCriticality,
7272
);
7373

74-
const signalCountByClassification = getSignalCountByClassification(
75-
licenseCounts,
76-
licenseNamesWithClassification,
77-
classifications,
78-
);
74+
const [signalCountByClassification, classificationColorMap] =
75+
getSignalCountByClassification(
76+
licenseCounts,
77+
licenseNamesWithClassification,
78+
classifications,
79+
);
7980

8081
const attributionBarChartData =
8182
aggregateAttributionPropertiesFromAttributions(manualAttributions);
@@ -158,7 +159,10 @@ export const ProjectStatisticsPopup: React.FC = () => {
158159
.signalCountByClassificationPieChart.title
159160
}
160161
</MuiTypography>
161-
<PieChart segments={signalCountByClassification} />
162+
<PieChart
163+
segments={signalCountByClassification}
164+
colorMap={classificationColorMap}
165+
/>
162166
</ChartGridItem>
163167
<ChartGridItem
164168
shouldRender={incompleteAttributionsData.length > 0}

src/Frontend/Components/ProjectStatisticsPopup/ProjectStatisticsPopup.util.ts

+17-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
PackageInfo,
1414
} from '../../../shared/shared-types';
1515
import { text } from '../../../shared/text';
16+
import { classificationUnknownColor } from '../../shared-styles';
1617
import {
1718
AttributionCountPerSourcePerLicense,
1819
ChartDataItem,
@@ -337,11 +338,13 @@ export function getCriticalSignalsCount(
337338
return criticalityData.filter(({ count }) => count > 0);
338339
}
339340

341+
type ColoredChartDataItem = ChartDataItem & { color: string };
342+
340343
export function getSignalCountByClassification(
341344
licenseCounts: LicenseCounts,
342345
licenseNamesWithClassification: LicenseNamesWithClassification,
343346
classifications: ClassificationsConfig,
344-
): Array<ChartDataItem> {
347+
): [Array<ChartDataItem>, { [segmentName: string]: string }] {
345348
const NO_CLASSIFICATION = -1;
346349
const classificationCounts: Record<Classification, number> = {};
347350

@@ -356,27 +359,37 @@ export function getSignalCountByClassification(
356359

357360
const pieChartData = Object.keys(classifications)
358361
.map(Number)
359-
.map<ChartDataItem>((classification) => {
362+
.map<ColoredChartDataItem>((classification) => {
360363
const classificationName = classifications[classification].description;
361364
const classificationCount =
362365
classificationCounts[toNumber(classification)] ?? 0;
366+
const color = classifications[classification].color;
363367

364368
return {
365369
name: classificationName,
366370
count: classificationCount,
371+
color,
367372
};
368373
})
369374
.filter(({ count }) => count > 0);
370375

371376
if (classificationCounts[NO_CLASSIFICATION]) {
372-
return pieChartData.concat({
377+
pieChartData.push({
373378
name: text.projectStatisticsPopup.charts
374379
.signalCountByClassificationPieChart.noClassification,
375380
count: classificationCounts[NO_CLASSIFICATION],
381+
color: classificationUnknownColor,
376382
});
377383
}
378384

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];
380393
}
381394

382395
export function getIncompleteAttributionsCount(

src/Frontend/shared-styles.ts

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export const OpossumColors = {
4040
brown: 'hsl(33, 55%, 44%)',
4141
};
4242

43+
export const classificationUnknownColor = OpossumColors.lightOrange;
44+
4345
export const criticalityColor = {
4446
[Criticality.High]: OpossumColors.orange,
4547
[Criticality.Medium]: OpossumColors.mediumOrange,

0 commit comments

Comments
 (0)