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

add github like contribution graph css and ceil for 1,2 report count #453

Merged

Conversation

kelvin2go
Copy link
Contributor

#413

  • math.ceil for 1,2
  • add github contribution graph like css

screen-capture (1)

@kelvin2go
Copy link
Contributor Author

kelvin2go commented Oct 7, 2021

adaptive max contribution
max(10, max(user_contribution)) 作為 contribution graph 的 max scale

for this, should it changes max scale to 10 ?

https://github.com/cofacts/rumors-site/pull/453/files#diff-b170cff4fb01eac4d00fe240d828301e6e8900a7ae3443ad833eeff2a6d64d8fR13

and for test part should i update the story snapshot after implement?

@MrOrz any suggestion :)

@nonumpa nonumpa requested a review from MrOrz October 9, 2021 02:03
@MrOrz
Copy link
Member

MrOrz commented Oct 10, 2021

Sorry for the late reply, and thanks for taking this issue!

  • Current coloring of attribution is fixed at 5 contributions per level (SCALING_FACTOR). Therefore, daily contribution must exceed 23 (23 / SCALING_FACTOR = 4.6 ~= 5) to be painted to deepest color.
  • The adaptive max contribution proposal wants that max scale to adapt to each user. For example, if the max contribution count of the user is 16 for the past 365 days, we should color the contribution count 1 ~ 4 with light color, 5 ~ 8 with deeper color, 9 ~ 12 with 2nd deeper color, and 13 ~ 16 with deepest color.
  • However, if the max contribution count of the user for the past 365 days is lower than 10, it would be a bit unfair for other contributors if we also paint those contribution as deepest color. Therefore, in the proposal we added a max-contribution lower-bound: if the max contribution count of the user for the past 365 days is lower than 10, we will use 10 when calculating the color scale.

If we put it in code,

  • MAX_SCALE remains 4, as available colorCofactsN still ranges from colorCofacts0 to colorCofacts4.
  • SCALING_FACTOR (number of contributions needed to go to the deeper color) should no longer be a constant across different users. If max contribution in data is below 10, the scaling factor is 10/MAX_SCALE = 2.5; otherwise, it is max contribution / MAX_SCALE.
  • The logic of scaleColor is Math.max(Math.min(Math.ceil(count / varingScalingFactor), MAX_SCALE), 0). The inner-most Math.ceil is identical to your current PR 👍

And yes, the storyshot should be updated and attached to the PR, so that we can know there are DOM changes in the PR 👀

@MrOrz MrOrz linked an issue Oct 10, 2021 that may be closed by this pull request
@kelvin2go
Copy link
Contributor Author

kelvin2go commented Oct 15, 2021

@MrOrz I updated varingScalingFactor and the snapshot. Can you check it ? but snapshot test seem fail on other component.

        modified:   components/AppLayout/AppHeader.js
        modified:   components/AppLayout/AppSidebar.js
        modified:   components/AppLayout/__snapshots__/UpgradeDialog.stories.storyshot
        modified:   components/ArticleCategories/CategoryOption.js
        modified:   components/ArticleReplyFeedbackControl/__snapshots__/ArticleReplyFeedbackControl.stories.storyshot
        modified:   components/Infos/__snapshots__/Infos.stories.storyshot
        modified:   components/ListPageControls/__snapshots__/BaseSortInput.stories.storyshot
        modified:   components/ListPageControls/__snapshots__/BaseTimeRange.stories.storyshot
        modified:   components/ListPageControls/__snapshots__/Filters.stories.storyshot
        modified:   components/ListPageControls/__snapshots__/LoadMore.stories.storyshot
        modified:   components/ProfilePage/UserPageHeader.js
        modified:   components/ReportPage/__snapshots__/ActionButton.stories.storyshot
        modified:   components/__snapshots__/Hyperlinks.stories.storyshot
        modified:   components/__snapshots__/TrendPlot.stories.storyshot
        modified:   components/__snapshots__/icons.stories.storyshot

@nonumpa
Copy link
Member

nonumpa commented Oct 16, 2021

@kelvin2go It seems that your local material-ui version is different from this project.

You can try the command writing in README.md :

# install the same npm package as this project
npm install

# run test and update snapshot
npm test -- -u

@kelvin2go
Copy link
Contributor Author

@kelvin2go It seems that your local material-ui version is different from this project.

You can try the command writing in README.md :

# install the same npm package as this project
npm install

# run test and update snapshot
npm test -- -u

hi @nonumpa,
i only changed components/ContributionChart.js
so i update only
components/snapshots/ContributionChart.stories.storyshot
or when i run test -- -u it changed other files as below. shoud i updated it to branch as well?

    modified:   components/AppLayout/__snapshots__/UpgradeDialog.stories.storyshot
        modified:   components/ArticleReplyFeedbackControl/__snapshots__/ArticleReplyFeedbackControl.stories.storyshot
        modified:   components/Infos/__snapshots__/Infos.stories.storyshot
        modified:   components/ListPageControls/__snapshots__/BaseSortInput.stories.storyshot
        modified:   components/ListPageControls/__snapshots__/BaseTimeRange.stories.storyshot
        modified:   components/ListPageControls/__snapshots__/Filters.stories.storyshot
        modified:   components/ListPageControls/__snapshots__/LoadMore.stories.storyshot
        modified:   components/ReportPage/__snapshots__/ActionButton.stories.storyshot
        modified:   components/__snapshots__/Hyperlinks.stories.storyshot
        modified:   components/__snapshots__/TrendPlot.stories.storyshot
        modified:   components/__snapshots__/icons.stories.storyshot

@nonumpa
Copy link
Member

nonumpa commented Oct 16, 2021

It's abnormal, and I guess other .storyshot files also change className="makeStyles-tooltipText-311" to className="makeStyles-tooltipText-74".

Maybe you can google the keyword "npm local vs global package" to solve this problem.


Explanation of why I guess your local material-ui version is different from this project and why it should not have className="makeStyles-tooltipText-*" change :

First, we take a look at the .storyshot change
snapshot

And then look what CI test result says

line 35 and 36 means
It should be aria-hidden="true" not aria-hidden={true}

line 48 and 49 means
It should be className="makeStyles-tooltipText-311" not className="makeStyles-tooltipText-74"

That means only className="makeStyles-colorCofacts*" is the right change.
This makes sense because you only change the function scaleColor which only affects colorCofacts*.

@MrOrz
Copy link
Member

MrOrz commented Oct 16, 2021

No worries, I think I can make a commit that tries to fix CI 💪

@kelvin2go
Copy link
Contributor Author

hi @MrOrz ,
after test with @nonumpa
look like "@material-ui/core": "^4.9.7",

4.9.9 can pass the test.

not sure, which version is CI using @@'

@coveralls
Copy link

coveralls commented Oct 16, 2021

Coverage Status

Coverage increased (+0.03%) to 75.294% when pulling 157a563 on kelvin2go:feature/413-contribution-graph-enhancements into 8c26bbb on cofacts:master.

Copy link
Member

@MrOrz MrOrz 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 trying to fix this issue! An implementation detail of color scale is attached below.

components/ContributionChart.js Outdated Show resolved Hide resolved
Copy link
Contributor

@johnson-liang johnson-liang left a comment

Choose a reason for hiding this comment

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

I will make a commit that fix the bug below

return Math.max(Math.min(Math.round(count / SCALING_FACTOR), MAX_SCALE), 0);
function scaleColor(count, maxContribution) {
const varingScalingFactor =
count < 10 ? 10 / MAX_SCALE : maxContribution.count / MAX_SCALE;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be

Suggested change
count < 10 ? 10 / MAX_SCALE : maxContribution.count / MAX_SCALE;
maxContribution.count < 10 ? 10 / MAX_SCALE : maxContribution.count / MAX_SCALE;

Current logic will cause count < 10 to have deeper color than count > 10.
8-10

Copy link
Member

@MrOrz MrOrz left a comment

Choose a reason for hiding this comment

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

Now the new color system and mobile style is working as expected. Thank you for the fix!

@MrOrz MrOrz merged commit 3b5ad97 into cofacts:master Oct 20, 2021
@kelvin2go kelvin2go deleted the feature/413-contribution-graph-enhancements branch October 21, 2021 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Contribution graph enhancements
5 participants