Skip to content

Commit ea2ccfa

Browse files
committed
#416 (New Frontend) Refactor Visualizations to AuthorState Usage
- added merge function to codeExpertise - added filter to be able to search for all children authors in commits to group data by parent
1 parent f42264c commit ea2ccfa

File tree

6 files changed

+42
-16
lines changed

6 files changed

+42
-16
lines changed

binocular-frontend-new/src/plugins/visualizationPlugins/expertise/codeExpertise/src/chart/chart.tsx

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,29 @@ function drawChart(options: {
205205
}
206206
});
207207

208+
// Merge child authors into their parents according to parent-child relation
209+
props.authorList
210+
.filter((a) => a.parent > 0)
211+
.forEach((child) => {
212+
const parent = props.authorList.find((a) => a.id === child.parent);
213+
if (!parent) return;
214+
const childSig = child.user.gitSignature;
215+
const parentSig = parent.user.gitSignature;
216+
const childData = devDataMap[childSig];
217+
if (!childData) return;
218+
if (devDataMap[parentSig]) {
219+
devDataMap[parentSig].commits = [...devDataMap[parentSig].commits, ...childData.commits];
220+
devDataMap[parentSig].additions = (devDataMap[parentSig].additions || 0) + (childData.additions || 0);
221+
devDataMap[parentSig].linesOwned = (devDataMap[parentSig].linesOwned || 0) + (childData.linesOwned || 0);
222+
} else {
223+
devDataMap[parentSig] = { ...childData };
224+
}
225+
delete devDataMap[childSig];
226+
});
227+
228+
// Recalculate maxCommitsPerDev after merging
229+
maxCommitsPerDev = Object.values(devDataMap).reduce((max, dev) => Math.max(max, dev.commits.length), 0);
230+
208231
const newSegments: React.JSX.Element[] = [];
209232
let totalPercent = 0;
210233

@@ -220,13 +243,15 @@ function drawChart(options: {
220243
totalPercent = endPercent;
221244
const palette = generatePalette(props.authorList);
222245
const devColor = palette[devName]?.main || '#cccccc';
246+
const author = props.authorList.find((a) => a.user.gitSignature === devName);
247+
const devLabel = author?.displayName || devName;
223248
newSegments.push(
224249
<Segment
225250
key={devName}
226251
rad={radius}
227252
startPercent={startPercent}
228253
endPercent={endPercent}
229-
devName={devName}
254+
devName={devLabel}
230255
devData={devData}
231256
devColor={devColor}
232257
maxCommitsPerDev={maxCommitsPerDev}
@@ -327,10 +352,7 @@ function generatePalette(authors: AuthorType[]): Palette {
327352
authors.forEach((author) => {
328353
if (!author.selected) return;
329354

330-
const displayName = author.displayName || author.user.gitSignature;
331-
332-
// Create palette entries for each metric
333-
palette[`${displayName}`] = {
355+
palette[author.user.gitSignature] = {
334356
main: chroma(author.color.main).hex(),
335357
secondary: chroma(author.color.secondary).hex(),
336358
};

binocular-frontend-new/src/plugins/visualizationPlugins/expertise/codeExpertise/src/utilities/dbUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// So it is not enough that `allCommits` contains all commits with date <= the date of the commit in question.
1010
// To be safe, `allCommits` should really contain all commits of the project.
1111
// Otherwise, this function may return wrong results (if there are commits in the history that have a `date` > the `commit` date).
12-
import type { DataPluginCommit, DataPluginOwnership } from '../../../../interfaces/dataPluginInterfaces/dataPluginCommits.ts';
12+
import type { DataPluginCommit, DataPluginOwnership } from '../../../../../interfaces/dataPluginInterfaces/dataPluginCommits';
1313

1414
export const getHistoryForCommit = (commit: DataPluginCommit, allCommits: DataPluginOwnership[]) => {
1515
// each commit only has the hash of the parent. Build a map, so we can get the actual commit for a given sha.

binocular-frontend-new/src/plugins/visualizationPlugins/expertise/knowledgeRadar/src/chart/authorSelection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const AuthorSelection: React.FC<AuthorSelectionProps> = ({ authorList, selectedA
2020
const inputRef = useRef<HTMLInputElement>(null);
2121
const containerRef = useRef<HTMLDivElement>(null);
2222

23-
const availableAuthors = authorList.filter((author) => author.selected);
23+
const availableAuthors = authorList.filter((author) => author.selected && author.parent === -1);
2424

2525
// Initialize temp selections when dropdown opens
2626
useEffect(() => {

binocular-frontend-new/src/plugins/visualizationPlugins/expertise/knowledgeRadar/src/chart/chart.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,16 @@ function RadarChart(properties: VisualizationPluginProperties<SettingsType, Data
8989

9090
if (selectedDevelopers.length > 0 && data != undefined && data.length > 0) {
9191
selectedDevelopers.forEach((developer) => {
92-
const devData = calculateExpertiseBrowserScores(data, developer.user.gitSignature);
92+
const childSignatures = authorList.filter((a) => a.parent === developer.id).map((a) => a.user.gitSignature);
93+
const allSignatures = [developer.user.gitSignature, ...childSignatures];
94+
const devData = calculateExpertiseBrowserScores(data, allSignatures);
9395
newIndividualData.set(developer.user.gitSignature, devData);
9496
});
9597
}
9698

9799
setIndividualDeveloperData(newIndividualData);
98100
resetNavigation();
99-
}, [data, properties, selectedDevelopers]);
101+
}, [data, properties, selectedDevelopers, authorList]);
100102

101103
/**
102104
* Updates author list and selected developers when author list changes.
@@ -105,6 +107,7 @@ function RadarChart(properties: VisualizationPluginProperties<SettingsType, Data
105107
setAuthorList(properties.authorList);
106108
updateSelectedDevelopers(properties.authorList);
107109
}, [properties.authorList]);
110+
108111
/**
109112
* Sets up resize observer for responsive chart sizing.
110113
*/
@@ -213,8 +216,9 @@ function RadarChart(properties: VisualizationPluginProperties<SettingsType, Data
213216
* @param authorList - Current list of available authors
214217
*/
215218
function updateSelectedDevelopers(authorList: AuthorType[]) {
219+
const available = authorList.filter((a) => a.selected && a.parent === -1);
216220
setSelectedDevelopers((prev) =>
217-
prev.filter((developer) => authorList.some((author) => author.user.gitSignature === developer.user.gitSignature)),
221+
prev.filter((developer) => available.some((author) => author.user.gitSignature === developer.user.gitSignature)),
218222
);
219223
}
220224

binocular-frontend-new/src/plugins/visualizationPlugins/expertise/knowledgeRadar/src/chart/drawRadarChart.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function setTooltipContent(
7272
.style('font-size', '10px')
7373
.style('color', chroma(developer.color.main).darken(1).hex())
7474
.style('font-weight', 'bold')
75-
.text(developer.user.gitSignature);
75+
.text(developer.displayName || developer.user.gitSignature);
7676

7777
devDiv
7878
.append('span')

binocular-frontend-new/src/plugins/visualizationPlugins/expertise/knowledgeRadar/src/utilities/dataConverter.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import type { DataPluginCommit } from '../../../../../interfaces/dataPluginInter
44
/**
55
* Extracts file paths touched by a specific developer
66
*/
7-
export function extractTouchedFiles(commits: DataPluginCommit[], developer: string): Set<string> {
8-
const developerCommits = commits.filter((commit) => commit.user?.gitSignature === developer);
7+
export function extractTouchedFiles(commits: DataPluginCommit[], developers: string[]): Set<string> {
8+
const developerCommits = commits.filter((commit) => developers.includes(commit.user?.gitSignature));
99

1010
const touchedFiles = new Set<string>();
1111

@@ -107,12 +107,12 @@ function calculateOwnershipScores(
107107
/**
108108
* Calculates Expertise Browser scores based on academic literature
109109
*/
110-
export function calculateExpertiseBrowserScores(commits: DataPluginCommit[], targetDeveloper: string): Package[] {
110+
export function calculateExpertiseBrowserScores(commits: DataPluginCommit[], targetDevelopers: string[]): Package[] {
111111
const nonMergeCommits = filterNonMergeCommits(commits);
112112

113-
const developerTouchedFiles = extractTouchedFiles(nonMergeCommits, targetDeveloper);
113+
const developerTouchedFiles = extractTouchedFiles(nonMergeCommits, targetDevelopers);
114114

115-
const developerCommits = nonMergeCommits.filter((commit) => commit.user.gitSignature === targetDeveloper);
115+
const developerCommits = nonMergeCommits.filter((commit) => targetDevelopers.includes(commit.user.gitSignature));
116116

117117
const packageCommits = processCommitFiles(developerCommits, developerTouchedFiles);
118118

0 commit comments

Comments
 (0)