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

feature(top langs card): add ability to change progress bar background color in normal layout (resolves #3307) #3312

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/top-langs.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export default async (req, res) => {
border_color,
disable_animations,
hide_progress,
prog_bg_color,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's rename it to progress_bar_bg_color or prog_bar_bg_color everywhere for consistency.

} = req.query;
res.setHeader("Content-Type", "image/svg+xml");

if (blacklist.includes(username)) {
return res.send(renderError("Something went wrong"));
}
Expand Down Expand Up @@ -96,6 +96,7 @@ export default async (req, res) => {
locale: locale ? locale.toLowerCase() : null,
disable_animations: parseBoolean(disable_animations),
hide_progress: parseBoolean(hide_progress),
prog_bg_color,
}),
);
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Change the `?username=` value to your GitHub username.
> By default, the stats card only shows statistics like stars, commits and pull requests from public repositories. To show private statistics on the stats card, you should [deploy your own instance](#deploy-on-your-own) using your own GitHub API token.

> [!NOTE]\
> Available ranks are S (top 1%), A+ (12.5%), A (25%), A- (37.5%), B+ (50%), B (62.5%), B- (75%), C+ (87.5%) and C (everyone). This ranking scheme is based on the [Japanese academic grading](https://wikipedia.org/wiki/Academic_grading_in_Japan) system. The global percentile is calculated as a weighted sum of percentiles for each statistic (number of commits, pull requests, reviews, issues, stars and followers), based on the cumulative distribution function of the [exponential](https://wikipedia.org/wiki/exponential_distribution) and the [log-normal](https://wikipedia.org/wiki/Log-normal_distribution) distributions. The implementation can be investigated at [src/calculateRank.js](./src/calculateRank.js). The circle around the rank shows 100 minus the global percentile.
> Available ranks are S (top 1%), A+ (12.5%), A (25%), A- (37.5%), B+ (50%), B (62.5%), B- (75%), C+ (87.5%) and C (everyone). This ranking scheme is based on the [Japanese academic grading](https://wikipedia.org/wiki/Academic_grading_in_Japan) system. The global percentile is calculated as a weighted sum of percentiles for each statistic (number of commits, pull requests, reviews, issues, stars and followers), based on the cumulative distribution function of the [exponential](https://wikipedia.org/wiki/exponential_distribution) and the [log-normal](https://wikipedia.org/wiki/Log-normal_distribution) distributions. The implementation can be investigated at [src/calculateRank.js](https://github.com/anuraghazra/github-readme-stats/blob/master/src/calculateRank.js). The circle around the rank shows 100 minus the global percentile.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Your pull request should contain changes only related to linked issue, you should remove this. Instead of this you should add information about new query parameter into language card options section https://github.com/anuraghazra/github-readme-stats#language-card-exclusive-options.


### Hiding individual stats

Expand Down
28 changes: 23 additions & 5 deletions src/cards/top-languages-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,19 @@ const trimTopLanguages = (topLangs, langs_count, hide) => {
* @param {number} props.width The card width
* @param {string} props.color Color of the programming language.
* @param {string} props.name Name of the programming language.
* @param {string} props.prog_bg_color Color of the background of progress bar
Copy link
Collaborator

Choose a reason for hiding this comment

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

Type of this argument does not indicate that it can be undefined.

* @param {number} props.progress Usage of the programming language in percentage.
* @param {number} props.index Index of the programming language.
* @returns {string} Programming language SVG node.
*/
const createProgressTextNode = ({ width, color, name, progress, index }) => {
const createProgressTextNode = ({
width,
color,
name,
progress,
index,
prog_bg_color,
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's better to use camel case for this function argument.

}) => {
const staggerDelay = (index + 3) * 150;
const paddingRight = 95;
const progressTextX = width - paddingRight + 10;
Expand All @@ -223,7 +231,9 @@ const createProgressTextNode = ({ width, color, name, progress, index }) => {
color,
width: progressWidth,
progress,
progressBarBackgroundColor: "#ddd",
progressBarBackgroundColor: prog_bg_color
? `#${prog_bg_color}`
: "#ddd",
delay: staggerDelay + 300,
})}
</g>
Expand Down Expand Up @@ -322,9 +332,10 @@ const createDonutLanguagesNode = ({ langs, totalSize }) => {
* @param {Lang[]} langs Array of programming languages.
* @param {number} width Card width.
* @param {number} totalLanguageSize Total size of all languages.
* @param {string} prog_bg_color Total size of all languages.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Description of this function argument was copy-pasted from previous. You should write correct description. Also type of argument does not indicate that it can be undefined.

* @returns {string} Normal layout card SVG object.
*/
const renderNormalLayout = (langs, width, totalLanguageSize) => {
const renderNormalLayout = (langs, width, totalLanguageSize, prog_bg_color) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's better to use camel case for this function argument.

return flexLayout({
items: langs.map((lang, index) => {
return createProgressTextNode({
Expand All @@ -335,6 +346,7 @@ const renderNormalLayout = (langs, width, totalLanguageSize) => {
((lang.size / totalLanguageSize) * 100).toFixed(2),
),
index,
prog_bg_color,
});
}),
gap: 40,
Expand Down Expand Up @@ -738,8 +750,9 @@ const renderTopLanguages = (topLangs, options = {}) => {
border_radius,
border_color,
disable_animations,
prog_bg_color,
} = options;

console.log(prog_bg_color);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This console log should be removed

const i18n = new I18n({
locale,
translations: langCardLocales,
Expand Down Expand Up @@ -798,7 +811,12 @@ const renderTopLanguages = (topLangs, options = {}) => {
width = width + 50; // padding
finalLayout = renderDonutLayout(langs, width, totalLanguageSize);
} else {
finalLayout = renderNormalLayout(langs, width, totalLanguageSize);
finalLayout = renderNormalLayout(
langs,
width,
totalLanguageSize,
prog_bg_color,
);
}

const card = new Card({
Expand Down
1 change: 1 addition & 0 deletions src/cards/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type CommonOptions = {
icon_color: string;
text_color: string;
bg_color: string;
prog_bg_color: string;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is wrong place for adding this parameter since it is exclusive for top languages card. It should be moved to TopLangOptions. Most likely that it is the reason why you did not get type error missing undefined variant in previous comments.

theme: ThemeNames;
border_radius: number;
border_color: string;
Expand Down