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

[#1899] Add graphic for commit diffstat #2010

Merged
merged 32 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2963a8f
Add diffstat component
nseah21 Jun 23, 2023
cc4c913
Update zoom view to use diffstat graphic
nseah21 Jun 23, 2023
eef1ea0
Modify threshold in c-diffstat
nseah21 Jun 24, 2023
b7d47ea
Rename c-diffstat to c-histogram
nseah21 Jun 25, 2023
168dac9
Add contribution bar for commit diffstat
nseah21 Jun 25, 2023
e78c45e
Add c-stacked-bar-chart component for summary charts
nseah21 Jun 29, 2023
02a87a6
Remove references to old diffstat in zoom view
nseah21 Jun 29, 2023
7783db8
Add support for rendering diffstat
nseah21 Jun 29, 2023
4bcd5a8
Add diffstat component to zoom view
nseah21 Jun 29, 2023
2cc49e7
Use average contribution for diffstat calculations
nseah21 Jun 29, 2023
56ff61e
Add support for toggling diffstat view
nseah21 Jun 29, 2023
afe8c4c
Remove unused components
nseah21 Jun 29, 2023
d0fe7b0
Remove old calculation for average contribution
nseah21 Jun 29, 2023
9e3e48b
Refactor c-stacked-bar-chart component
nseah21 Jul 3, 2023
b53af8b
Use latest stacked bar chart for diffstat
nseah21 Jul 3, 2023
b8d718e
Merge branch 'refactor-diffstat-graphic' into add-diffstat-graphic
nseah21 Jul 3, 2023
8b8a1ff
Add fix for overflowing contribution bars
nseah21 Jul 4, 2023
5168a60
Refactor stacked-bar-chart to use new selectors
nseah21 Jul 10, 2023
9d063b5
Refactor bar generation methods
nseah21 Jul 10, 2023
2f5acbb
Fix broken frontend tests
nseah21 Jul 10, 2023
70a69f4
Add initial tests for stacked-bar-chart component
nseah21 Jul 10, 2023
06d2f55
Revert changes to chartView_mergeCommits.cy.js
nseah21 Jul 11, 2023
8b592e3
Fix bug in bar generation methods
nseah21 Jul 11, 2023
eb9b0d6
Add target attribute for lines changed
nseah21 Jul 11, 2023
2698ade
Add more tests for diffstat component
nseah21 Jul 11, 2023
40962d2
Fix CI issues
nseah21 Jul 11, 2023
e6f2cb8
Fix environmental checks
nseah21 Jul 14, 2023
2860caa
Merge branch 'master' into add-diffstat-graphic
ckcherry23 Jul 15, 2023
59ce334
Fix linting checks
nseah21 Jul 15, 2023
2366ad1
Merge branch 'add-diffstat-graphic' of github.com:nseah21/RepoSense i…
nseah21 Jul 15, 2023
0ae39bd
Remove old implementation for bar generation
nseah21 Jul 15, 2023
70183cf
Add comments for tests in zoomView_diffstat.cy.js
nseah21 Jul 15, 2023
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
23 changes: 23 additions & 0 deletions frontend/src/components/c-stacked-bar-chart.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<template lang="pug">
#summary
.summary-chart__contrib--bar(
vvidday marked this conversation as resolved.
Show resolved Hide resolved
v-for="bar in bars"
v-bind:title="bar.tooltipText",
v-bind:style="{ width: `${bar.width}%`,\
'background-color': bar.color }"
)
</template>

<script lang="ts">
import { PropType, defineComponent } from 'vue';
import { Bar } from '../types/types';

export default defineComponent({
props: {
bars: {
type: Array as PropType<Bar[]>,
required: true,
},
},
});
</script>
43 changes: 33 additions & 10 deletions frontend/src/components/c-summary-charts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -223,22 +223,25 @@
.summary-chart__contrib(
v-for="(widths, fileType) in getFileTypeContributionBars(user.fileTypeContribution)"
)
.summary-chart__contrib--bar(
v-for="width in widths",
v-bind:style="{ width: `${width}%`,\
'background-color': fileTypeColors[fileType] }",
v-bind:title="`${fileType}: ${user.fileTypeContribution[fileType]} lines, \
total: ${user.checkedFileTypeContribution} lines (contribution from ${minDate} to \
${maxDate})`"
c-stacked-bar-chart(
v-bind:bars="widths.map((width) => {\
return {width: width,\
color: fileTypeColors[fileType],\
tooltipText: `${fileType}: ${user.fileTypeContribution[fileType]} lines, \
total: ${user.checkedFileTypeContribution} lines (contribution from ${minDate} to \
${maxDate})`}\
})"
)
template(v-else)
.summary-chart__contrib(
v-bind:title="`Total contribution from ${minDate} to ${maxDate}: \
${user.checkedFileTypeContribution} lines`"
)
.summary-chart__contrib--bar(
v-for="width in getContributionBars(user.checkedFileTypeContribution)",
v-bind:style="{ width: `${width}%` }"
c-stacked-bar-chart(
v-bind:bars="getContributionBars(user.checkedFileTypeContribution)\
.map((width) => {\
return {width: width};\
})"
)
</template>

Expand All @@ -248,6 +251,7 @@

import brokenLinkDisabler from '../mixin/brokenLinkMixin';
import cRamp from './c-ramp.vue';
import cStackedBarChart from './c-stacked-bar-chart.vue';
import { Repo, User } from '../types/types';
import { FilterGroupSelection, FilterTimeFrame, SortGroupSelection } from '../types/summary';
import { StoreState, ZoomInfo } from '../types/vuex.d';
Expand All @@ -257,6 +261,7 @@
name: 'c-summary-charts',
components: {
cRamp,
cStackedBarChart,
},
mixins: [brokenLinkDisabler],
props: {
Expand Down Expand Up @@ -559,6 +564,7 @@
zFileTypeColors: this.fileTypeColors,
zFromRamp: false,
zFilterSearch: filterSearch,
zAvgContributionSize: this.getAvgContributionSize(user.repoId),
};
this.addSelectedTab(user.name, user.repoName, 'zoom', isMerged);
this.$store.commit('updateTabZoomInfo', info);
Expand Down Expand Up @@ -627,7 +633,7 @@
getBaseTarget(target: HTMLElement | null): HTMLElement | null {
if (!target) {
// Should never reach here - function assumes that target is a child of the div with class 'summary-chart__ramp'
console.error('Error: The getBaseTarget function in c-summary-charts.vue has been called on an element that is '

Check warning on line 636 in frontend/src/components/c-summary-charts.vue

View workflow job for this annotation

GitHub Actions / Cypress frontend tests

Unexpected console statement
+ 'not a child of the div with class summary-chart__ramp. This might affect the drag view functionality.');
return null;
}
Expand Down Expand Up @@ -794,6 +800,23 @@
return explanation;
},

getAvgContributionSize(repoId: string): number {
let totalContribution = 0;
let totalCommits = 0;

this.filteredRepos.forEach((repo) => {
repo.forEach((user) => {
if (user.repoId === repoId) {
user.commits?.forEach((commit) => {
totalCommits += 1;
totalContribution += (commit.insertions + commit.deletions);
});
}
});
});

return totalContribution / totalCommits;
},
},
});
</script>
6 changes: 6 additions & 0 deletions frontend/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,9 @@ export interface AuthorshipFile {
segments?: AuthorshipFileSegment[];
wasCodeLoaded: boolean;
}

export interface Bar {
width: number;
color?: string;
tooltipText?: string;
}
1 change: 1 addition & 0 deletions frontend/src/types/vuex.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface ZoomInfo {
zTimeFrame: string;
zUntil: string;
zUser?: User;
zAvgContributionSize?: number;
}

interface SummaryDates {
Expand Down
84 changes: 80 additions & 4 deletions frontend/src/views/c-zoom.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
.toolbar--multiline(v-if="filteredUser.commits.length && totalCommitMessageBodyCount")
a(
v-if="expandedCommitMessagesCount < totalCommitMessageBodyCount",
v-on:click="toggleAllCommitMessagesBody(true)"
) show all commit messages
v-on:click="toggleAllCommitMessagesBody(true); toggleDiffstatView(true);"
) show all commit details
a(
v-if="expandedCommitMessagesCount > 0",
v-on:click="toggleAllCommitMessagesBody(false)"
) hide all commit messages
v-on:click="toggleAllCommitMessagesBody(false); toggleDiffstatView(false);"
) hide all commit details
vvidday marked this conversation as resolved.
Show resolved Hide resolved
.panel-heading
.group-name
span(
Expand Down Expand Up @@ -132,6 +132,16 @@
.body(v-if="slice.messageBody !== ''", v-show="slice.isOpen")
pre {{ slice.messageBody }}
.dashed-border
template(
v-if="showDiffstat"
v-for="(widths, color) in getContributionBars(slice)"
)
c-stacked-bar-chart(
v-bind:bars="widths.map((width) => {\
return {width: width,\
color: color}\
})"
)
vvidday marked this conversation as resolved.
Show resolved Hide resolved
</template>

<script lang="ts">
Expand All @@ -140,6 +150,7 @@ import { mapState } from 'vuex';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import brokenLinkDisabler from '../mixin/brokenLinkMixin';
import cRamp from '../components/c-ramp.vue';
import cStackedBarChart from '../components/c-stacked-bar-chart.vue';
import User from '../utils/user';
import {
Commit,
Expand All @@ -153,6 +164,7 @@ import { StoreState } from '../types/vuex.d';
function zoomInitialState() {
return {
showAllCommitMessageBody: true,
showDiffstat: true,
commitsSortType: CommitsSortType.Time,
toReverseSortedCommits: true,
isCommitsFinalized: false,
Expand All @@ -166,6 +178,7 @@ export default defineComponent({
components: {
FontAwesomeIcon,
cRamp,
cStackedBarChart,
},
mixins: [brokenLinkDisabler],
data() {
Expand Down Expand Up @@ -300,6 +313,65 @@ export default defineComponent({
this.selectedFileTypes = this.fileTypes.slice();
},

getContributionBars(slice: CommitResult): { [key: string]: number[] } {
let currentBarWidth = 0;
const fullBarWidth = 100;

let avgContributionSize = this.info.zAvgContributionSize;
if (avgContributionSize === undefined || avgContributionSize > 1000) {
avgContributionSize = 1000;
}

const contributionPerFullBar = avgContributionSize;

const diffstatMappings: { [key: string]: number } = { limegreen: slice.insertions, red: slice.deletions };
const allContributionBars: { [key: string]: number[] } = {};

if (contributionPerFullBar === 0) {
return allContributionBars;
}

Object.keys(diffstatMappings)
.forEach((color) => {
const contribution = diffstatMappings[color];
let barWidth = (contribution / contributionPerFullBar) * fullBarWidth;
const contributionBars = [];

// if contribution bar for file type is able to fit on the current line
if (currentBarWidth + barWidth < fullBarWidth) {
contributionBars.push(barWidth);
currentBarWidth += barWidth;
} else {
// take up all the space left on the current line
contributionBars.push(fullBarWidth - currentBarWidth);
barWidth -= fullBarWidth - currentBarWidth;
// additional bar width will start on a new line
const numOfFullBars = Math.floor(barWidth / fullBarWidth);
for (let i = 0; i < numOfFullBars; i += 1) {
contributionBars.push(fullBarWidth);
}
const remainingBarWidth = barWidth % fullBarWidth;
if (remainingBarWidth > 0) {
contributionBars.push(remainingBarWidth);
}
currentBarWidth = remainingBarWidth;
}

allContributionBars[color] = contributionBars;
});

// Pad with transparent bars to prevent overflowing bars
// from sticking to message title of subsequent commits
const transparentBars = [];
transparentBars.push(100 - currentBarWidth);
for (let i = 0; i < 3; i += 1) {
transparentBars.push(100);
}
allContributionBars.transparent = transparentBars;

return allContributionBars;
},

getSliceLink(slice: CommitResult): string | undefined {
if (this.info.zIsMerged) {
return window.getCommitLink(slice.repoId, slice.hash);
Expand Down Expand Up @@ -393,6 +465,10 @@ export default defineComponent({
});
},

toggleDiffstatView(isVisible: boolean) {
this.showDiffstat = isVisible;
},

removeZoomHashes() {
window.removeHash('zA');
window.removeHash('zR');
Expand Down
Loading