Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: statistics popup and progress bar share same colors #2855

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/Frontend/Components/ProgressBar/ProgressBar.util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import MuiBox from '@mui/material/Box';
import { sum } from 'lodash';

import { Criticality } from '../../../shared/shared-types';
import { criticalityColor, OpossumColors } from '../../shared-styles';
import {
classificationUnknownColor,
criticalityColor,
OpossumColors,
} from '../../shared-styles';
import { navigateToSelectedPathOrOpenUnsavedPopup } from '../../state/actions/popup-actions/popup-actions';
import { useAppDispatch, useAppSelector } from '../../state/hooks';
import {
Expand Down Expand Up @@ -254,7 +258,7 @@ function calculateProgressBarSteps(
);
progressBarSteps.push({
widthInPercent: 100 - totalPercentage,
color: OpossumColors.lightestBlue,
color: classificationUnknownColor,
});

return roundPercentagesToAtLeastOnePercentAndNormalize(progressBarSteps);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
// SPDX-License-Identifier: Apache-2.0
import { Criticality } from '../../../../shared/shared-types';
import { faker } from '../../../../testing/Faker';
import { criticalityColor, OpossumColors } from '../../../shared-styles';
import {
classificationUnknownColor,
criticalityColor,
OpossumColors,
} from '../../../shared-styles';
import {
ClassificationStatistics,
ProgressBarData,
Expand Down Expand Up @@ -98,7 +102,7 @@ describe('ProgressBar helpers', () => {

const background = getClassificationBarBackground(testProgressBarData);

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% )`;
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% )`;
expect(background).toEqual(expectedBackground);
});

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

const background = getClassificationBarBackground(testProgressBarData);

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% )`;
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% )`;
expect(background).toEqual(expectedBackground);
});

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

const background = getClassificationBarBackground(testProgressBarData);

const expectedBackground = `linear-gradient(to right, ${classificationStatisticsEntry.color} 0% 25% , hsl(220, 41%, 92%) 25% 100% )`;
const expectedBackground = `linear-gradient(to right, ${classificationStatisticsEntry.color} 0% 25% , ${classificationUnknownColor} 25% 100% )`;
expect(background).toBe(expectedBackground);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ export const ProjectStatisticsPopup: React.FC = () => {
licenseNamesWithCriticality,
);

const signalCountByClassification = getSignalCountByClassification(
licenseCounts,
licenseNamesWithClassification,
classifications,
);
const [signalCountByClassification, classificationColorMap] =
getSignalCountByClassification(
licenseCounts,
licenseNamesWithClassification,
classifications,
);

const attributionBarChartData =
aggregateAttributionPropertiesFromAttributions(manualAttributions);
Expand Down Expand Up @@ -158,7 +159,10 @@ export const ProjectStatisticsPopup: React.FC = () => {
.signalCountByClassificationPieChart.title
}
</MuiTypography>
<PieChart segments={signalCountByClassification} />
<PieChart
segments={signalCountByClassification}
colorMap={classificationColorMap}
/>
</ChartGridItem>
<ChartGridItem
shouldRender={incompleteAttributionsData.length > 0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
PackageInfo,
} from '../../../shared/shared-types';
import { text } from '../../../shared/text';
import { classificationUnknownColor } from '../../shared-styles';
import {
AttributionCountPerSourcePerLicense,
ChartDataItem,
Expand Down Expand Up @@ -337,11 +338,13 @@ export function getCriticalSignalsCount(
return criticalityData.filter(({ count }) => count > 0);
}

type ColoredChartDataItem = ChartDataItem & { color: string };

export function getSignalCountByClassification(
licenseCounts: LicenseCounts,
licenseNamesWithClassification: LicenseNamesWithClassification,
classifications: ClassificationsConfig,
): Array<ChartDataItem> {
): [Array<ChartDataItem>, { [segmentName: string]: string }] {
const NO_CLASSIFICATION = -1;
const classificationCounts: Record<Classification, number> = {};

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

const pieChartData = Object.keys(classifications)
.map(Number)
.map<ChartDataItem>((classification) => {
.map<ColoredChartDataItem>((classification) => {
const classificationName = classifications[classification].description;
const classificationCount =
classificationCounts[toNumber(classification)] ?? 0;
const color = classifications[classification].color;

return {
name: classificationName,
count: classificationCount,
color,
};
})
.filter(({ count }) => count > 0);

if (classificationCounts[NO_CLASSIFICATION]) {
return pieChartData.concat({
pieChartData.push({
name: text.projectStatisticsPopup.charts
.signalCountByClassificationPieChart.noClassification,
count: classificationCounts[NO_CLASSIFICATION],
color: classificationUnknownColor,
});
}

return pieChartData;
const colorMap = Object.fromEntries(
pieChartData.map((colorChartEntry) => [
colorChartEntry.name,
colorChartEntry.color,
]),
);

return [pieChartData, colorMap];
}

export function getIncompleteAttributionsCount(
Expand Down
2 changes: 2 additions & 0 deletions src/Frontend/shared-styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export const OpossumColors = {
brown: 'hsl(33, 55%, 44%)',
};

export const classificationUnknownColor = OpossumColors.lightOrange;

export const criticalityColor = {
[Criticality.High]: OpossumColors.orange,
[Criticality.Medium]: OpossumColors.mediumOrange,
Expand Down
Loading