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

Conversation

nseah21
Copy link
Contributor

@nseah21 nseah21 commented Jun 24, 2023

Fixes #1899

Add graphic for commit diffstat

A diffstat graphic is useful in providing a visual representation
of the changes within and between commits. 

Let's add a diffstat graphic emulating the diffstat used by cgit, 
to help users have a high-level overview of the impact of a
commit. 

Other information

NA

@damithc
Copy link
Collaborator

damithc commented Jun 25, 2023

@nseah21 Thanks for taking this up. I personally prefer the other alternative (i.e., similar to the contribution bar), which is more consistent with RepoSense. Plus RepoSense is supposed to complement what GitHub does, rather than duplicate it.
We can show the bar as a separate line, similar to how we do in the chart view.

@ckcherry23
Copy link
Member

Hi @nseah21, your code changes look great for a first attempt at creating the GitHub style diffstat!
However, since we prefer the contribution bar (cgit) style, let us start with that as our first/default.

The reason we prefer the cgit style is that we can reuse the same code we have for the contribution bars below each ramp chart for creating the diffstat as well.

.summary-chart__contribution
template(v-if="filterBreakdown")
.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})`"
)
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}%` }"
)

While you can copy over the same code for the diffstat, I would suggest that we move out this contribution bars code outside of c-summary-charts.vue into a separate file called c-stacked-bar-chart.vue and generalize it to be used by both the contribution bars and the diffstat. @vvidday can give his thoughts as well.

We can discuss whether we want a toggle mode for the 2 styles in a separate PR, where we can make use of the current set of changes.

Feel free to reach out to us if you have any questions with the c-stacked-bar-chart.vue implementation and we will be glad to help!

@nseah21 nseah21 changed the title Add graphic for commit diffstat [#1899] Add graphic for commit diffstat Jun 25, 2023
@nseah21
Copy link
Contributor Author

nseah21 commented Jun 25, 2023

@damithc @ckcherry23 Thank you for your comments. I have pushed some changes based on the initial feedback.

I will look into using the code in c-summary-charts.vue for this feature.

@damithc
Copy link
Collaborator

damithc commented Jun 25, 2023

@nseah21 Good progress. A few comments:

  1. The bar should be below the tags, not between title and tags.
  2. The same scale should be used for all commits in a report (not just one author) so that a visual comparison is possible. A 100 line commit of person A should be the same length as that of person B.
  3. For consistency (similar to ramp charts view), the bar should overflow to the next line if too long to show in one line. That way, very big commits will stand out by appearing as multiple lines.

@vvidday
Copy link
Contributor

vvidday commented Jun 25, 2023

Great job so far and thanks for taking up this issue! Definitely agree with @ckcherry23 on re-using some of the code for the contribution bar - I believe it also has some logic that will help with what Prof mentioned above (overflow & scale).

Also, as we are trying to unify the frontend to use TypeScript (#1936), it would be great if all new features/files could also be started in TypeScript. This can be done by adding lang="ts" inside the opening <script> tag, and wrapping the export in defineComponent.

Copy link
Contributor

@vvidday vvidday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @nseah21 with the progress! This wasn't an easy issue to take up and your progress on this has been impressive. The functionality works well, I left some comments w.r.t implementation details.

Regarding your questions, I think (1) can go either way - I don't think we necessarily need to follow the average across report like in summary, since that view contains charts across the whole report but the zoom view is restricted to a repo. Not too sure about (2), the non-linear scaling might be a bit misleading visually? Would love to get more opinions on these 2 questions!

frontend/src/components/c-stacked-bar-chart.vue Outdated Show resolved Hide resolved
frontend/src/views/c-zoom.vue Show resolved Hide resolved
frontend/src/views/c-zoom.vue Outdated Show resolved Hide resolved
@damithc
Copy link
Collaborator

damithc commented Jul 6, 2023

@nseah21 remember to let reviewers know when the PR is ready for the next round of reviews.

@nseah21
Copy link
Contributor Author

nseah21 commented Jul 6, 2023

@vvidday I have attempted some changes for this feature based on the feedback. The PR is ready for the next round of reviews.

@ckcherry23 ckcherry23 requested a review from a team July 6, 2023 17:33
Copy link
Contributor

@vvidday vvidday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes @nseah21 and apologies again for the late reply.

Will reply regarding the CSS overflow issue in the old thread above.

Also, before this pr is merged, it will be good to add cypress test cases for the new feature.

frontend/src/components/c-stacked-bar-chart.vue Outdated Show resolved Hide resolved
frontend/src/views/c-zoom.vue Outdated Show resolved Hide resolved
Copy link
Member

@ckcherry23 ckcherry23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new changes look great @nseah21! I agree with David's comments and have a few more to add.

Regarding your questions,
For (1), according to prof's earlier comments, I think we should consider the average contribution size across the entire report.

  1. The same scale should be used for all commits in a report (not just one author) so that a visual comparison is possible. A 100 line commit of person A should be the same length as that of person B.

For (2), I also think the length of the diffstat should scale linearly as it's easier to comprehend for users.


Also, I think we should avoid the use of default red-colored bars on the summary chart contribution bars so that they are not confused with the deletions bar in the commit diffstat. I'd suggest using a shade of blue as the default for contribution bars.

Screenshot 2023-07-08 at 3 56 32 PM

@nseah21
Copy link
Contributor Author

nseah21 commented Jul 10, 2023

I have just pushed the latest changes for the feature.

Here is a summary of what has been changed:

  1. The selectors and bar generation methods for c-stacked-bar-chart.vue have been updated
  2. The default color for the contribution bar is now blue to avoid confusion with the deletion bars in the diffstat
  3. The average contribution size is taken over the whole report instead of within each repository
  4. Broken tests have been updated, including some errors in chartView_mergeCommits.cy.js which did not arise from changing the selectors
  5. Initial tests for the stacked-bar-chart component have been added

May I have some guidance on what other tests should be added for the stacked-bar-chart component?

Copy link
Member

@ckcherry23 ckcherry23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick iteration! I've left a few comments to address

@@ -1,7 +1,7 @@
describe('include merge commits in chart view', () => {
it('show merge commits in summary chart', () => {
// ramp chart should have merge commit slices
cy.get('[title="[2023-03-03] Merge branch \'new-branch\' into cypress: +0 -0 lines "]')
cy.get('[title="[2023-03-04] Merge branch \'new-branch\' into cypress: +0 -0 lines "]')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look into this @nseah21. The date 2023-03-03 may not pass Cypress tests in your local machine but is the date that is required for the CI frontend tests to pass. The discrepancy is probably due to a time zone issue as the commit was made close to midnight. Perhaps we can create a new issue to investigate why the date varies on different machines.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for starting with the Cypress tests for this feature @nseah21. I think this file can be renamed to something like zoomView_diffstat.cy.js.

Apart from checking if the diffstat has rendered, we can also check:

  1. if both green and red bars are rendered for a general commit with > 0 insertions and deletions.
  2. if the contribution bar is not visible for empty commits with 0 insertions/deletions.
  3. if the size of the green/red bars is proportional to the insertion/deletion size. I think a naïve way to do this is to check whether the green bar length is greater or less than the red bar length depending on the contribution size.

@vvidday

const contributionLimit = (this.avgContributionSize * 2);
if (contributionLimit === 0) {
return res;
}
const cnt = Math.floor(totalContribution / contributionLimit);
for (let cntId = 0; cntId < cnt; cntId += 1) {
res.push(100);
res.push({ color: 'red', width: 100 });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may have to remove the color attribute here to ensure all the contribution bar rows are rendered blue by default.

Screenshot 2023-07-10 at 8 50 28 PM

Copy link
Contributor

@vvidday vvidday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nseah21, overall LGTM, just some minor things to tie up

frontend/src/views/c-zoom.vue Outdated Show resolved Hide resolved
Copy link
Contributor

@vvidday vvidday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Member

@ckcherry23 ckcherry23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, LGTM! Just remember to update your commit message with the latest changes and follow the guidelines.

@nseah21
Copy link
Contributor Author

nseah21 commented Jul 23, 2023

I have updated the commit message accordingly.

@ckcherry23

@chan-j-d chan-j-d merged commit a9f102d into reposense:master Jul 28, 2023
10 checks passed
@github-actions
Copy link
Contributor

The following links are for previewing this pull request:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add graphic for commit diffstat in Commits Panel
5 participants