forked from mirrored/github-readme-stats
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
42e90ef886 | ||
|
|
ff2e02ba68 | ||
|
|
c8d5eda27c | ||
|
|
f9427b2a54 |
+1
-1
@@ -171,7 +171,7 @@ dark, radical, merko, gruvbox, tokyonight, onedark, cobalt, synthwave, highcontr
|
|||||||
|
|
||||||
- `hide` - 从卡片中隐藏指定语言 _(Comma seperated values)_
|
- `hide` - 从卡片中隐藏指定语言 _(Comma seperated values)_
|
||||||
- `hide_title` - _(boolean)_
|
- `hide_title` - _(boolean)_
|
||||||
- `layout` - 提供四種佈局 `normal` & `compact` & `donut` & `pie` 间切换
|
- `layout` - 提供五種佈局 `normal` & `compact` & `donut` & `donut-vertical` & `pie` 间切换
|
||||||
- `card_width` - 手动设置卡片的宽度 _(number)_
|
- `card_width` - 手动设置卡片的宽度 _(number)_
|
||||||
|
|
||||||
> :warning: **重要:**
|
> :warning: **重要:**
|
||||||
|
|||||||
+1
-1
@@ -161,7 +161,7 @@ Du kannst mehrere, mit Kommas separierte, Werte in der bg_color Option angeben,
|
|||||||
|
|
||||||
- `hide` - Verbirgt die angegebenen Sprachen von der Karte _(Komma separierte Werte)_
|
- `hide` - Verbirgt die angegebenen Sprachen von der Karte _(Komma separierte Werte)_
|
||||||
- `hide_title` - _(Boolean)_
|
- `hide_title` - _(Boolean)_
|
||||||
- `layout` - Wechseln Sie zwischen den vier verfügbaren Layouts `normal` & `compact` & `donut` & `pie`
|
- `layout` - Wechseln Sie zwischen den fünf verfügbaren Layouts `normal` & `compact` & `donut` & `donut-vertical` & `pie`
|
||||||
- `card_width` - Lege die Breite der Karte manuell fest _(Zahl)_
|
- `card_width` - Lege die Breite der Karte manuell fest _(Zahl)_
|
||||||
|
|
||||||
> :warning: **Wichtig:**
|
> :warning: **Wichtig:**
|
||||||
|
|||||||
+1
-1
@@ -175,7 +175,7 @@ Puedes pasar mútliples valores separados por coma en la opción `bg_color` para
|
|||||||
|
|
||||||
- `hide` - Oculta de la tarjeta los lenguajes especificados _(valores separados por comas)_
|
- `hide` - Oculta de la tarjeta los lenguajes especificados _(valores separados por comas)_
|
||||||
- `hide_title` - _(booleano)_
|
- `hide_title` - _(booleano)_
|
||||||
- `layout` - Cambiar entre los cuatro diseños disponibles `normal` & `compact` & `donut` & `pie`
|
- `layout` - Cambiar entre los cinco diseños disponibles `normal` & `compact` & `donut` & `donut-vertical` & `pie`
|
||||||
- `card_width` - Establece el ancho de la tarjeta manualmente _(número)_
|
- `card_width` - Establece el ancho de la tarjeta manualmente _(número)_
|
||||||
- `langs_count` - Muestra más lenguajes en la tarjeta, entre 1-10, por defecto 5 _(número)_
|
- `langs_count` - Muestra más lenguajes en la tarjeta, entre 1-10, por defecto 5 _(número)_
|
||||||
- `exclude_repo` - Excluye los repositorios especificados _(valores separados por comas)_
|
- `exclude_repo` - Excluye los repositorios especificados _(valores separados por comas)_
|
||||||
|
|||||||
+14
-2
@@ -90,6 +90,18 @@ Pour masquer des statistiques spécifiques, vous pouvez passer un paramètre de
|
|||||||

|

|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Ajouter le compte des contributions privées au compte des commits totaux
|
||||||
|
|
||||||
|
Vous pouvez ajouter le compte de toutes vos contributions privées au compte total des engagements en utilisant le paramètre de requête `?count_private=true`.
|
||||||
|
|
||||||
|
_Note: Si vous déployez vous-même ce projet, les contributions privées seront comptées par défaut ; sinon, vous devez choisir de partager les comptes de vos contributions privées._
|
||||||
|
|
||||||
|
> Options: `&count_private=true`
|
||||||
|
|
||||||
|
```md
|
||||||
|

|
||||||
|
```
|
||||||
|
|
||||||
### Afficher les icônes
|
### Afficher les icônes
|
||||||
|
|
||||||
Pour activer les icônes, vous pouvez passer `show_icons=true` dans le paramètre de requête, comme ceci :
|
Pour activer les icônes, vous pouvez passer `show_icons=true` dans le paramètre de requête, comme ceci :
|
||||||
@@ -148,7 +160,7 @@ Vous pouvez fournir plusieurs valeurs (suivie d'une virgule) dans l'option bg_co
|
|||||||
- `hide_rank` - Masquer le rang _(boolean)_
|
- `hide_rank` - Masquer le rang _(boolean)_
|
||||||
- `show_icons` - Afficher les icônes _(boolean)_
|
- `show_icons` - Afficher les icônes _(boolean)_
|
||||||
- `include_all_commits` - Compter le total de commits au lieu de ne compter que les commits de l'année en cours _(boolean)_
|
- `include_all_commits` - Compter le total de commits au lieu de ne compter que les commits de l'année en cours _(boolean)_
|
||||||
- `count_private` - Compter les contributions privées _(boolean)_
|
- `count_private` - Compter les commits privés _(boolean)_
|
||||||
- `line_height` - Fixer la hauteur de la ligne entre les textes _(number)_
|
- `line_height` - Fixer la hauteur de la ligne entre les textes _(number)_
|
||||||
|
|
||||||
#### Repo Card Exclusive Options:
|
#### Repo Card Exclusive Options:
|
||||||
@@ -159,7 +171,7 @@ Vous pouvez fournir plusieurs valeurs (suivie d'une virgule) dans l'option bg_co
|
|||||||
|
|
||||||
- `hide` - Masquer les langages spécifiés sur la carte _(Comma seperated values)_
|
- `hide` - Masquer les langages spécifiés sur la carte _(Comma seperated values)_
|
||||||
- `hide_title` - Masquer le titre _(boolean)_
|
- `hide_title` - Masquer le titre _(boolean)_
|
||||||
- `layout` - Alterner entre 4 mise en page `normal` & `compact` & `donut` & `pie`
|
- `layout` - Alterner entre 5 mise en page `normal` & `compact` & `donut` & `donut-vertical` & `pie`
|
||||||
- `card_width` - Fixer la largeur de la carte manuellement _(number)_
|
- `card_width` - Fixer la largeur de la carte manuellement _(number)_
|
||||||
|
|
||||||
> :warning: **Important:**
|
> :warning: **Important:**
|
||||||
|
|||||||
+1
-1
@@ -171,7 +171,7 @@ Puoi fornire valori separati da virgola nel parametro bg_color per creare un gra
|
|||||||
|
|
||||||
- `hide` - Nasconde un linguaggio specifico _(valori separati da virgola)_
|
- `hide` - Nasconde un linguaggio specifico _(valori separati da virgola)_
|
||||||
- `hide_title` - Nasconde il titolo _(booleano)_
|
- `hide_title` - Nasconde il titolo _(booleano)_
|
||||||
- `layout` - Specificare il tipo di layout, `normal` (esteso), `compact` (compatto), `donut` (ciambella) e `pie` (torta)
|
- `layout` - Specificare il tipo di layout, `normal` (esteso), `compact` (compatto), `donut` (ciambella), `donut-vertical` (ciambella verticale) e `pie` (torta)
|
||||||
- `card_width` - Specifica il valore della larghezza _(numero)_
|
- `card_width` - Specifica il valore della larghezza _(numero)_
|
||||||
|
|
||||||
> :warning: **Importante:**
|
> :warning: **Importante:**
|
||||||
|
|||||||
+1
-1
@@ -174,7 +174,7 @@ bg_color オプションで複数のカンマ区切りの値を指定してグ
|
|||||||
|
|
||||||
- `hide` - 特定の言語を隠す _(カンマ区切りで指定)_
|
- `hide` - 特定の言語を隠す _(カンマ区切りで指定)_
|
||||||
- `hide_title` - _(boolean)_
|
- `hide_title` - _(boolean)_
|
||||||
- `layout` - `normal` & `compact` & `donut` & `pie` のいずれかのレイアウトに切り替える
|
- `layout` - `normal` & `compact` & `donut` & `donut-vertical` & `pie` のいずれかのレイアウトに切り替える
|
||||||
- `card_width` - カードの横幅 _(number)_
|
- `card_width` - カードの横幅 _(number)_
|
||||||
- `langs_count` - 表示される言語の数 _(1 ~ 10, 初期値 5)_
|
- `langs_count` - 表示される言語の数 _(1 ~ 10, 初期値 5)_
|
||||||
- `exclude_repo` - 指定されたリポジトリを除外する _(カンマ区切りで指定)_
|
- `exclude_repo` - 指定されたリポジトリを除外する _(カンマ区切りで指定)_
|
||||||
|
|||||||
+1
-1
@@ -189,7 +189,7 @@ dark, radical, merko, gruvbox, tokyonight, onedark, cobalt, synthwave, highcontr
|
|||||||
|
|
||||||
- `hide` - 카드에서 특정 언어 제외 _(Comma-separated values)_
|
- `hide` - 카드에서 특정 언어 제외 _(Comma-separated values)_
|
||||||
- `hide_title` - 타이틀 제외 _(boolean)_
|
- `hide_title` - 타이틀 제외 _(boolean)_
|
||||||
- `layout` - 4가지 값 사용 가능, `normal` & `compact` & `donut` & `pie` 중 표시 형태 선택
|
- `layout` - 5가지 값 사용 가능, `normal` & `compact` & `donut` & `donut-vertical` & `pie` 중 표시 형태 선택
|
||||||
- `card_width` - 카드 너비 직접 설정 _(number)_
|
- `card_width` - 카드 너비 직접 설정 _(number)_
|
||||||
- `langs_count` - 카드에 표시할 언어의 수 (1-10 사이, 기본 값 : 5) _(number)_
|
- `langs_count` - 카드에 표시할 언어의 수 (1-10 사이, 기본 값 : 5) _(number)_
|
||||||
- `exclude_repo` - 통계에 제외할 저장소 지정 _(Comma-separated values)_
|
- `exclude_repo` - 통계에 제외할 저장소 지정 _(Comma-separated values)_
|
||||||
|
|||||||
+1
-1
@@ -176,7 +176,7 @@ Je kan meerdere komma verdeelde waarden in de bg_color optie geven om een kleure
|
|||||||
|
|
||||||
- `hide` - Verbergt specifieke talen van de kaart _(komma gescheiden waardes)_
|
- `hide` - Verbergt specifieke talen van de kaart _(komma gescheiden waardes)_
|
||||||
- `hide_title` - _(boolean)_
|
- `hide_title` - _(boolean)_
|
||||||
- `layout` - Keuze uit de vier beschikbare indelingen `normal` & `compact` & `donut` & `pie`
|
- `layout` - Kies uit de vijf beschikbare lay-outs `normal` & `compact` & `donut` & `donut-vertical` & `pie`
|
||||||
- `card_width` - Stelt de breedte van de kaart handmatig in. _(nummer)_
|
- `card_width` - Stelt de breedte van de kaart handmatig in. _(nummer)_
|
||||||
- `langs_count` - Laat meer talen op de kaart zien, waarde tussen 1-10, staat standaard op to 5 _(nummer)_
|
- `langs_count` - Laat meer talen op de kaart zien, waarde tussen 1-10, staat standaard op to 5 _(nummer)_
|
||||||
- `exclude_repo` - Verbergt specifieke repositories _(komma gescheiden waardes)_
|
- `exclude_repo` - Verbergt specifieke repositories _(komma gescheiden waardes)_
|
||||||
|
|||||||
+1
-1
@@ -174,7 +174,7 @@ You can provide multiple comma-separated values in bg_color option to render a g
|
|||||||
|
|
||||||
- `hide` - Hide the languages specified from the card _(Comma-separated values)_
|
- `hide` - Hide the languages specified from the card _(Comma-separated values)_
|
||||||
- `hide_title` - _(boolean)_
|
- `hide_title` - _(boolean)_
|
||||||
- `layout` - Switch between four available layouts `normal` & `compact` & `donut` & `pie`. Default: `normal`.
|
- `layout` - Switch between five available layouts `normal` & `compact` & `donut` & `donut-vertical` & `pie`. Default: `normal`.
|
||||||
- `card_width` - Set the card's width manually _(number)_
|
- `card_width` - Set the card's width manually _(number)_
|
||||||
- `langs_count` - Show more languages on the card, between 1-10, defaults to 5 _(number)_
|
- `langs_count` - Show more languages on the card, between 1-10, defaults to 5 _(number)_
|
||||||
- `exclude_repo` - Exclude specified repositories _(Comma-separated values)_
|
- `exclude_repo` - Exclude specified repositories _(Comma-separated values)_
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ Personalize a aparência do seu `Stats Card` ou `Repo Card` da maneira que desej
|
|||||||
|
|
||||||
- `hide` - Oculta linguagens específicas _(Valores separados por vírgulas)_
|
- `hide` - Oculta linguagens específicas _(Valores separados por vírgulas)_
|
||||||
- `hide_title` - Oculta o título _(boolean)_
|
- `hide_title` - Oculta o título _(boolean)_
|
||||||
- `layout` - Alterna entre os quatro layouts disponíveis `normal` & `compact` & `donut` & `pie`
|
- `layout` - Alternar entre os cinco layouts disponíveis `normal` & `compact` & `donut` & `donut-vertical` & `pie`
|
||||||
- `card_width` - Define a largura do cartão manualmente _(number)_
|
- `card_width` - Define a largura do cartão manualmente _(number)_
|
||||||
|
|
||||||
> :warning: **Importante:**
|
> :warning: **Importante:**
|
||||||
|
|||||||
+1
-1
@@ -176,7 +176,7 @@ bg_color içerisinde birden fazla rengi gradient olarak göstermek için virgül
|
|||||||
|
|
||||||
- `hide` - Belirli bir dili listede gizler _(Virgül ile ayırılmış değerlerle)_
|
- `hide` - Belirli bir dili listede gizler _(Virgül ile ayırılmış değerlerle)_
|
||||||
- `hide_title` - _(boolean)_
|
- `hide_title` - _(boolean)_
|
||||||
- `layout` - Dört uygun tasarım / düzen arasında geçiş `normal` & `compact` & `donut` & `pie`
|
- `layout` - Beş uygun tasarım / düzen arasında geçiş yapın `normal` & `compact` & `donut` & `donut-vertical` & `pie`
|
||||||
- `card_width` - Kartın genişliğini manuel olarak belirler _(number)_
|
- `card_width` - Kartın genişliğini manuel olarak belirler _(number)_
|
||||||
- `langs_count` - 1-10 arasında istediğiniz kadar dil gösterebilirsiniz. Varsayılan: 5 _(number)_
|
- `langs_count` - 1-10 arasında istediğiniz kadar dil gösterebilirsiniz. Varsayılan: 5 _(number)_
|
||||||
- `exclude_repo` - Belirli repoları listeden çıkartır _(Virgül ile ayırılmış değerlerle)_
|
- `exclude_repo` - Belirli repoları listeden çıkartır _(Virgül ile ayırılmış değerlerle)_
|
||||||
|
|||||||
@@ -120,6 +120,19 @@ You can pass a query parameter `&hide=` to hide any specific stats with comma-se
|
|||||||

|

|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Adding private contributions count to total commits count
|
||||||
|
|
||||||
|
You can add the count of all your private contributions to the total commits count by using the query parameter `&count_private=true`.
|
||||||
|
|
||||||
|
> **Note**
|
||||||
|
> If you are deploying this project yourself, the private contributions will be counted by default. If you are using the public Vercel instance, you need to choose to [share your private contributions](https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-github-profile/managing-contribution-settings-on-your-profile/showing-your-private-contributions-and-achievements-on-your-profile).
|
||||||
|
|
||||||
|
> Options: `&count_private=true`
|
||||||
|
|
||||||
|
```md
|
||||||
|

|
||||||
|
```
|
||||||
|
|
||||||
### Showing icons
|
### Showing icons
|
||||||
|
|
||||||
To enable icons, you can pass `&show_icons=true` in the query param, like so:
|
To enable icons, you can pass `&show_icons=true` in the query param, like so:
|
||||||
@@ -270,7 +283,7 @@ You can provide multiple comma-separated values in the bg_color option to render
|
|||||||
- `rank_icon` - Shows alternative rank icon (i.e. `github` or `default`). Default: `default`.
|
- `rank_icon` - Shows alternative rank icon (i.e. `github` or `default`). Default: `default`.
|
||||||
- `show_icons` - _(boolean)_. Default: `false`.
|
- `show_icons` - _(boolean)_. Default: `false`.
|
||||||
- `include_all_commits` - Count total commits instead of just the current year commits _(boolean)_. Default: `false`.
|
- `include_all_commits` - Count total commits instead of just the current year commits _(boolean)_. Default: `false`.
|
||||||
- `count_private` - Count private contributions _(boolean)_. Default: `false`.
|
- `count_private` - Count private commits _(boolean)_. Default: `false`.
|
||||||
- `line_height` - Sets the line height between text _(number)_. Default: `25`.
|
- `line_height` - Sets the line height between text _(number)_. Default: `25`.
|
||||||
- `exclude_repo` - Exclude stars from specified repositories _(Comma-separated values)_. Default: `[] (blank array)`.
|
- `exclude_repo` - Exclude stars from specified repositories _(Comma-separated values)_. Default: `[] (blank array)`.
|
||||||
- `custom_title` - Sets a custom title for the card. Default: `<username> GitHub Stats`.
|
- `custom_title` - Sets a custom title for the card. Default: `<username> GitHub Stats`.
|
||||||
@@ -290,7 +303,7 @@ You can provide multiple comma-separated values in the bg_color option to render
|
|||||||
|
|
||||||
- `hide` - Hide the languages specified from the card _(Comma-separated values)_. Default: `[] (blank array)`.
|
- `hide` - Hide the languages specified from the card _(Comma-separated values)_. Default: `[] (blank array)`.
|
||||||
- `hide_title` - _(boolean)_. Default: `false`.
|
- `hide_title` - _(boolean)_. Default: `false`.
|
||||||
- `layout` - Switch between four available layouts `normal` & `compact` & `donut` & `pie`. Default: `normal`.
|
- `layout` - Switch between five available layouts `normal` & `compact` & `donut` & `donut-vertical` & `pie`. Default: `normal`.
|
||||||
- `card_width` - Set the card's width manually _(number)_. Default `300`.
|
- `card_width` - Set the card's width manually _(number)_. Default `300`.
|
||||||
- `langs_count` - Show more languages on the card, between 1-10 _(number)_. Default `5`.
|
- `langs_count` - Show more languages on the card, between 1-10 _(number)_. Default `5`.
|
||||||
- `exclude_repo` - Exclude specified repositories _(Comma-separated values)_. Default: `[] (blank array)`.
|
- `exclude_repo` - Exclude specified repositories _(Comma-separated values)_. Default: `[] (blank array)`.
|
||||||
@@ -418,6 +431,14 @@ You can use the `&layout=donut` option to change the card design.
|
|||||||
[](https://github.com/anuraghazra/github-readme-stats)
|
[](https://github.com/anuraghazra/github-readme-stats)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Donut Vertical Chart Language Card Layout
|
||||||
|
|
||||||
|
You can use the `&layout=donut-vertical` option to change the card design.
|
||||||
|
|
||||||
|
```md
|
||||||
|
[](https://github.com/anuraghazra/github-readme-stats)
|
||||||
|
```
|
||||||
|
|
||||||
### Pie Chart Language Card Layout
|
### Pie Chart Language Card Layout
|
||||||
|
|
||||||
You can use the `&layout=pie` option to change the card design.
|
You can use the `&layout=pie` option to change the card design.
|
||||||
@@ -446,6 +467,10 @@ You can use the `&hide_progress=true` option to hide the percentages and the pro
|
|||||||
|
|
||||||
[](https://github.com/anuraghazra/github-readme-stats)
|
[](https://github.com/anuraghazra/github-readme-stats)
|
||||||
|
|
||||||
|
- Donut Vertical Chart layout
|
||||||
|
|
||||||
|
[](https://github.com/anuraghazra/github-readme-stats)
|
||||||
|
|
||||||
- Pie Chart layout
|
- Pie Chart layout
|
||||||
|
|
||||||
[](https://github.com/anuraghazra/github-readme-stats)
|
[](https://github.com/anuraghazra/github-readme-stats)
|
||||||
|
|||||||
+84
-51
@@ -1,72 +1,105 @@
|
|||||||
function expsf(x, lambda = 1) {
|
/**
|
||||||
return 2 ** (-lambda * x);
|
* Calculates the probability of x taking on x or a value less than x in a normal distribution
|
||||||
}
|
* with mean and standard deviation.
|
||||||
|
*
|
||||||
|
* @see https://stackoverflow.com/a/5263759/10629172
|
||||||
|
*
|
||||||
|
* @param {string} mean The mean of the normal distribution.
|
||||||
|
* @param {number} sigma The standard deviation of the normal distribution.
|
||||||
|
* @param {number} to The value to calculate the probability for.
|
||||||
|
* @returns {number} Probability.
|
||||||
|
*/
|
||||||
|
const normalcdf = (mean, sigma, to) => {
|
||||||
|
var z = (to - mean) / Math.sqrt(2 * sigma * sigma);
|
||||||
|
var t = 1 / (1 + 0.3275911 * Math.abs(z));
|
||||||
|
var a1 = 0.254829592;
|
||||||
|
var a2 = -0.284496736;
|
||||||
|
var a3 = 1.421413741;
|
||||||
|
var a4 = -1.453152027;
|
||||||
|
var a5 = 1.061405429;
|
||||||
|
var erf =
|
||||||
|
1 - ((((a5 * t + a4) * t + a3) * t + a2) * t + a1) * t * Math.exp(-z * z);
|
||||||
|
var sign = 1;
|
||||||
|
if (z < 0) {
|
||||||
|
sign = -1;
|
||||||
|
}
|
||||||
|
return (1 / 2) * (1 + sign * erf);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the users rank.
|
* Calculates the users rank.
|
||||||
*
|
*
|
||||||
* @param {object} params Parameters on which the user's rank depends.
|
* @param {object} params Parameters on which the user's rank depends.
|
||||||
* @param {boolean} params.all_commits Whether `include_all_commits` was used.
|
* @param {number} params.totalRepos Total number of repos.
|
||||||
* @param {number} params.commits Number of commits.
|
* @param {number} params.totalCommits Total number of commits.
|
||||||
|
* @param {number} params.contributions The number of contributions.
|
||||||
|
* @param {number} params.followers The number of followers.
|
||||||
* @param {number} params.prs The number of pull requests.
|
* @param {number} params.prs The number of pull requests.
|
||||||
* @param {number} params.issues The number of issues.
|
* @param {number} params.issues The number of issues.
|
||||||
* @param {number} params.repos Total number of repos.
|
* @param {number} params.stargazers The number of stars.
|
||||||
* @param {number} params.stars The number of stars.
|
|
||||||
* @param {number} params.followers The number of followers.
|
|
||||||
* @returns {{level: string, score: number}}} The users rank.
|
* @returns {{level: string, score: number}}} The users rank.
|
||||||
*/
|
*/
|
||||||
function calculateRank({
|
const calculateRank = ({
|
||||||
all_commits,
|
totalRepos,
|
||||||
commits,
|
totalCommits,
|
||||||
|
contributions,
|
||||||
|
followers,
|
||||||
prs,
|
prs,
|
||||||
issues,
|
issues,
|
||||||
repos, // unused
|
stargazers,
|
||||||
stars,
|
}) => {
|
||||||
followers,
|
const COMMITS_OFFSET = 1.65;
|
||||||
}) {
|
const CONTRIBS_OFFSET = 1.65;
|
||||||
const COMMITS_MEAN = all_commits ? 1000 : 250,
|
const ISSUES_OFFSET = 1;
|
||||||
COMMITS_WEIGHT = 2;
|
const STARS_OFFSET = 0.75;
|
||||||
const PRS_MEAN = 50,
|
const PRS_OFFSET = 0.5;
|
||||||
PRS_WEIGHT = 3;
|
const FOLLOWERS_OFFSET = 0.45;
|
||||||
const ISSUES_MEAN = 25,
|
const REPO_OFFSET = 1;
|
||||||
ISSUES_WEIGHT = 1;
|
|
||||||
const STARS_MEAN = 250,
|
|
||||||
STARS_WEIGHT = 4;
|
|
||||||
const FOLLOWERS_MEAN = 25,
|
|
||||||
FOLLOWERS_WEIGHT = 1;
|
|
||||||
|
|
||||||
const TOTAL_WEIGHT =
|
const ALL_OFFSETS =
|
||||||
COMMITS_WEIGHT +
|
CONTRIBS_OFFSET +
|
||||||
PRS_WEIGHT +
|
ISSUES_OFFSET +
|
||||||
ISSUES_WEIGHT +
|
STARS_OFFSET +
|
||||||
STARS_WEIGHT +
|
PRS_OFFSET +
|
||||||
FOLLOWERS_WEIGHT;
|
FOLLOWERS_OFFSET +
|
||||||
|
REPO_OFFSET;
|
||||||
|
|
||||||
const rank =
|
const RANK_S_VALUE = 1;
|
||||||
(COMMITS_WEIGHT * expsf(commits, 1 / COMMITS_MEAN) +
|
const RANK_DOUBLE_A_VALUE = 25;
|
||||||
PRS_WEIGHT * expsf(prs, 1 / PRS_MEAN) +
|
const RANK_A2_VALUE = 45;
|
||||||
ISSUES_WEIGHT * expsf(issues, 1 / ISSUES_MEAN) +
|
const RANK_A3_VALUE = 60;
|
||||||
STARS_WEIGHT * expsf(stars, 1 / STARS_MEAN) +
|
const RANK_B_VALUE = 100;
|
||||||
FOLLOWERS_WEIGHT * expsf(followers, 1 / FOLLOWERS_MEAN)) /
|
|
||||||
TOTAL_WEIGHT;
|
|
||||||
|
|
||||||
const RANK_S_PLUS = 0.025;
|
const TOTAL_VALUES =
|
||||||
const RANK_S = 0.1;
|
RANK_S_VALUE +
|
||||||
const RANK_A_PLUS = 0.25;
|
RANK_DOUBLE_A_VALUE +
|
||||||
const RANK_A = 0.5;
|
RANK_A2_VALUE +
|
||||||
const RANK_B_PLUS = 0.75;
|
RANK_A3_VALUE +
|
||||||
|
RANK_B_VALUE;
|
||||||
|
|
||||||
|
// prettier-ignore
|
||||||
|
const score = (
|
||||||
|
totalCommits * COMMITS_OFFSET +
|
||||||
|
contributions * CONTRIBS_OFFSET +
|
||||||
|
issues * ISSUES_OFFSET +
|
||||||
|
stargazers * STARS_OFFSET +
|
||||||
|
prs * PRS_OFFSET +
|
||||||
|
followers * FOLLOWERS_OFFSET +
|
||||||
|
totalRepos * REPO_OFFSET
|
||||||
|
) / 100;
|
||||||
|
|
||||||
|
const normalizedScore = normalcdf(score, TOTAL_VALUES, ALL_OFFSETS) * 100;
|
||||||
|
|
||||||
const level = (() => {
|
const level = (() => {
|
||||||
if (rank <= RANK_S_PLUS) return "S+";
|
if (normalizedScore < RANK_S_VALUE) return "S+";
|
||||||
if (rank <= RANK_S) return "S";
|
if (normalizedScore < RANK_DOUBLE_A_VALUE) return "S";
|
||||||
if (rank <= RANK_A_PLUS) return "A+";
|
if (normalizedScore < RANK_A2_VALUE) return "A++";
|
||||||
if (rank <= RANK_A) return "A";
|
if (normalizedScore < RANK_A3_VALUE) return "A+";
|
||||||
if (rank <= RANK_B_PLUS) return "B+";
|
return "B+";
|
||||||
return "B";
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
return { level, score: rank * 100 };
|
return { level, score: normalizedScore };
|
||||||
}
|
};
|
||||||
|
|
||||||
export { calculateRank };
|
export { calculateRank };
|
||||||
export default calculateRank;
|
export default calculateRank;
|
||||||
|
|||||||
@@ -84,6 +84,16 @@ const cartesianToPolar = (centerX, centerY, x, y) => {
|
|||||||
return { radius, angleInDegrees };
|
return { radius, angleInDegrees };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates length of circle.
|
||||||
|
*
|
||||||
|
* @param {number} radius Radius of the circle.
|
||||||
|
* @returns {number} The length of the circle.
|
||||||
|
*/
|
||||||
|
const getCircleLength = (radius) => {
|
||||||
|
return 2 * Math.PI * radius;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates height for the compact layout.
|
* Calculates height for the compact layout.
|
||||||
*
|
*
|
||||||
@@ -114,6 +124,16 @@ const calculateDonutLayoutHeight = (totalLangs) => {
|
|||||||
return 215 + Math.max(totalLangs - 5, 0) * 32;
|
return 215 + Math.max(totalLangs - 5, 0) * 32;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates height for the donut vertical layout.
|
||||||
|
*
|
||||||
|
* @param {number} totalLangs Total number of languages.
|
||||||
|
* @returns {number} Card height.
|
||||||
|
*/
|
||||||
|
const calculateDonutVerticalLayoutHeight = (totalLangs) => {
|
||||||
|
return 300 + Math.round(totalLangs / 2) * 25;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates height for the pie layout.
|
* Calculates height for the pie layout.
|
||||||
*
|
*
|
||||||
@@ -371,6 +391,76 @@ const renderCompactLayout = (langs, width, totalLanguageSize, hideProgress) => {
|
|||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders donut vertical layout to display user's most frequently used programming languages.
|
||||||
|
*
|
||||||
|
* @param {Lang[]} langs Array of programming languages.
|
||||||
|
* @param {number} totalLanguageSize Total size of all languages.
|
||||||
|
* @returns {string} Compact layout card SVG object.
|
||||||
|
*/
|
||||||
|
const renderDonutVerticalLayout = (langs, totalLanguageSize) => {
|
||||||
|
// Donut vertical chart radius and total length
|
||||||
|
const radius = 80;
|
||||||
|
const totalCircleLength = getCircleLength(radius);
|
||||||
|
|
||||||
|
// SVG circles
|
||||||
|
let circles = [];
|
||||||
|
|
||||||
|
// Start indent for donut vertical chart parts
|
||||||
|
let indent = 0;
|
||||||
|
|
||||||
|
// Start delay coefficient for donut vertical chart parts
|
||||||
|
let startDelayCoefficient = 1;
|
||||||
|
|
||||||
|
// Generate each donut vertical chart part
|
||||||
|
for (const lang of langs) {
|
||||||
|
const percentage = (lang.size / totalLanguageSize) * 100;
|
||||||
|
const circleLength = totalCircleLength * (percentage / 100);
|
||||||
|
const delay = startDelayCoefficient * 100;
|
||||||
|
|
||||||
|
circles.push(`
|
||||||
|
<g class="stagger" style="animation-delay: ${delay}ms">
|
||||||
|
<circle
|
||||||
|
cx="150"
|
||||||
|
cy="100"
|
||||||
|
r="${radius}"
|
||||||
|
fill="transparent"
|
||||||
|
stroke="${lang.color}"
|
||||||
|
stroke-width="25"
|
||||||
|
stroke-dasharray="${totalCircleLength}"
|
||||||
|
stroke-dashoffset="${indent}"
|
||||||
|
size="${percentage}"
|
||||||
|
data-testid="lang-donut"
|
||||||
|
/>
|
||||||
|
</g>
|
||||||
|
`);
|
||||||
|
|
||||||
|
// Update the indent for the next part
|
||||||
|
indent += circleLength;
|
||||||
|
// Update the start delay coefficient for the next part
|
||||||
|
startDelayCoefficient += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `
|
||||||
|
<svg data-testid="lang-items">
|
||||||
|
<g transform="translate(0, 0)">
|
||||||
|
<svg data-testid="donut">
|
||||||
|
${circles.join("")}
|
||||||
|
</svg>
|
||||||
|
</g>
|
||||||
|
<g transform="translate(0, 220)">
|
||||||
|
<svg data-testid="lang-names" x="${CARD_PADDING}">
|
||||||
|
${createLanguageTextNode({
|
||||||
|
langs,
|
||||||
|
totalSize: totalLanguageSize,
|
||||||
|
hideProgress: false,
|
||||||
|
})}
|
||||||
|
</svg>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
`;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders pie layout to display user's most frequently used programming languages.
|
* Renders pie layout to display user's most frequently used programming languages.
|
||||||
*
|
*
|
||||||
@@ -610,10 +700,16 @@ const renderTopLanguages = (topLangs, options = {}) => {
|
|||||||
let height = calculateNormalLayoutHeight(langs.length);
|
let height = calculateNormalLayoutHeight(langs.length);
|
||||||
|
|
||||||
let finalLayout = "";
|
let finalLayout = "";
|
||||||
if (layout === "pie") {
|
const layoutParsed = Array.isArray(layout)
|
||||||
|
? layout[0]?.toLocaleLowerCase()
|
||||||
|
: layout?.toLocaleLowerCase();
|
||||||
|
if (layoutParsed === "pie") {
|
||||||
height = calculatePieLayoutHeight(langs.length);
|
height = calculatePieLayoutHeight(langs.length);
|
||||||
finalLayout = renderPieLayout(langs, totalLanguageSize);
|
finalLayout = renderPieLayout(langs, totalLanguageSize);
|
||||||
} else if (layout === "compact" || hide_progress == true) {
|
} else if (layoutParsed === "donut-vertical") {
|
||||||
|
height = calculateDonutVerticalLayoutHeight(langs.length);
|
||||||
|
finalLayout = renderDonutVerticalLayout(langs, totalLanguageSize);
|
||||||
|
} else if (layoutParsed === "compact" || hide_progress == true) {
|
||||||
height =
|
height =
|
||||||
calculateCompactLayoutHeight(langs.length) + (hide_progress ? -25 : 0);
|
calculateCompactLayoutHeight(langs.length) + (hide_progress ? -25 : 0);
|
||||||
|
|
||||||
@@ -623,7 +719,7 @@ const renderTopLanguages = (topLangs, options = {}) => {
|
|||||||
totalLanguageSize,
|
totalLanguageSize,
|
||||||
hide_progress,
|
hide_progress,
|
||||||
);
|
);
|
||||||
} else if (layout?.toLowerCase() === "donut") {
|
} else if (layoutParsed === "donut") {
|
||||||
height = calculateDonutLayoutHeight(langs.length);
|
height = calculateDonutLayoutHeight(langs.length);
|
||||||
width = width + 50; // padding
|
width = width + 50; // padding
|
||||||
finalLayout = renderDonutLayout(langs, width, totalLanguageSize);
|
finalLayout = renderDonutLayout(langs, width, totalLanguageSize);
|
||||||
@@ -688,7 +784,7 @@ const renderTopLanguages = (topLangs, options = {}) => {
|
|||||||
`,
|
`,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (layout === "pie") {
|
if (layoutParsed === "pie" || layoutParsed === "donut-vertical") {
|
||||||
return card.render(finalLayout);
|
return card.render(finalLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -705,9 +801,11 @@ export {
|
|||||||
radiansToDegrees,
|
radiansToDegrees,
|
||||||
polarToCartesian,
|
polarToCartesian,
|
||||||
cartesianToPolar,
|
cartesianToPolar,
|
||||||
|
getCircleLength,
|
||||||
calculateCompactLayoutHeight,
|
calculateCompactLayoutHeight,
|
||||||
calculateNormalLayoutHeight,
|
calculateNormalLayoutHeight,
|
||||||
calculateDonutLayoutHeight,
|
calculateDonutLayoutHeight,
|
||||||
|
calculateDonutVerticalLayoutHeight,
|
||||||
calculatePieLayoutHeight,
|
calculatePieLayoutHeight,
|
||||||
donutCenterTranslation,
|
donutCenterTranslation,
|
||||||
trimTopLanguages,
|
trimTopLanguages,
|
||||||
|
|||||||
Vendored
+1
-1
@@ -39,7 +39,7 @@ export type TopLangOptions = CommonOptions & {
|
|||||||
hide_border: boolean;
|
hide_border: boolean;
|
||||||
card_width: number;
|
card_width: number;
|
||||||
hide: string[];
|
hide: string[];
|
||||||
layout: "compact" | "normal" | "donut" | "pie";
|
layout: "compact" | "normal" | "donut" | "donut-vertical" | "pie";
|
||||||
custom_title: string;
|
custom_title: string;
|
||||||
langs_count: number;
|
langs_count: number;
|
||||||
disable_animations: boolean;
|
disable_animations: boolean;
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ const fetchStats = async (
|
|||||||
totalIssues: 0,
|
totalIssues: 0,
|
||||||
totalStars: 0,
|
totalStars: 0,
|
||||||
contributedTo: 0,
|
contributedTo: 0,
|
||||||
rank: { level: "B", score: 0 },
|
rank: { level: "C", score: 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
let res = await statsFetcher(username);
|
let res = await statsFetcher(username);
|
||||||
@@ -220,44 +220,53 @@ const fetchStats = async (
|
|||||||
|
|
||||||
const user = res.data.data.user;
|
const user = res.data.data.user;
|
||||||
|
|
||||||
stats.name = user.name || user.login;
|
// populate repoToHide map for quick lookup
|
||||||
|
// while filtering out
|
||||||
// if include_all_commits, fetch all commits using the REST API.
|
let repoToHide = {};
|
||||||
if (include_all_commits) {
|
if (exclude_repo) {
|
||||||
stats.totalCommits = await totalCommitsFetcher(username);
|
exclude_repo.forEach((repoName) => {
|
||||||
} else {
|
repoToHide[repoName] = true;
|
||||||
stats.totalCommits = user.contributionsCollection.totalCommitContributions;
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// if count_private, add private contributions to totalCommits.
|
stats.name = user.name || user.login;
|
||||||
|
stats.totalIssues = user.openIssues.totalCount + user.closedIssues.totalCount;
|
||||||
|
|
||||||
|
// normal commits
|
||||||
|
stats.totalCommits = user.contributionsCollection.totalCommitContributions;
|
||||||
|
|
||||||
|
// if include_all_commits then just get that,
|
||||||
|
// since totalCommitsFetcher already sends totalCommits no need to +=
|
||||||
|
if (include_all_commits) {
|
||||||
|
stats.totalCommits = await totalCommitsFetcher(username);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if count_private then add private commits to totalCommits so far.
|
||||||
if (count_private) {
|
if (count_private) {
|
||||||
stats.totalCommits +=
|
stats.totalCommits +=
|
||||||
user.contributionsCollection.restrictedContributionsCount;
|
user.contributionsCollection.restrictedContributionsCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
stats.totalPRs = user.pullRequests.totalCount;
|
stats.totalPRs = user.pullRequests.totalCount;
|
||||||
stats.totalIssues = user.openIssues.totalCount + user.closedIssues.totalCount;
|
|
||||||
stats.contributedTo = user.repositoriesContributedTo.totalCount;
|
stats.contributedTo = user.repositoriesContributedTo.totalCount;
|
||||||
|
|
||||||
// Retrieve stars while filtering out repositories to be hidden.
|
// Retrieve stars while filtering out repositories to be hidden
|
||||||
let repoToHide = new Set(exclude_repo);
|
|
||||||
|
|
||||||
stats.totalStars = user.repositories.nodes
|
stats.totalStars = user.repositories.nodes
|
||||||
.filter((data) => {
|
.filter((data) => {
|
||||||
return !repoToHide.has(data.name);
|
return !repoToHide[data.name];
|
||||||
})
|
})
|
||||||
.reduce((prev, curr) => {
|
.reduce((prev, curr) => {
|
||||||
return prev + curr.stargazers.totalCount;
|
return prev + curr.stargazers.totalCount;
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
stats.rank = calculateRank({
|
stats.rank = calculateRank({
|
||||||
all_commits: include_all_commits,
|
totalCommits: stats.totalCommits,
|
||||||
commits: stats.totalCommits,
|
totalRepos: user.repositories.totalCount,
|
||||||
|
followers: user.followers.totalCount,
|
||||||
|
contributions: stats.contributedTo,
|
||||||
|
stargazers: stats.totalStars,
|
||||||
prs: stats.totalPRs,
|
prs: stats.totalPRs,
|
||||||
issues: stats.totalIssues,
|
issues: stats.totalIssues,
|
||||||
repos: user.repositories.totalCount,
|
|
||||||
stars: stats.totalStars,
|
|
||||||
followers: user.followers.totalCount,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return stats;
|
return stats;
|
||||||
|
|||||||
+38
-7
@@ -12,18 +12,17 @@ const stats = {
|
|||||||
totalCommits: 200,
|
totalCommits: 200,
|
||||||
totalIssues: 300,
|
totalIssues: 300,
|
||||||
totalPRs: 400,
|
totalPRs: 400,
|
||||||
contributedTo: 50,
|
contributedTo: 500,
|
||||||
rank: null,
|
rank: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
stats.rank = calculateRank({
|
stats.rank = calculateRank({
|
||||||
all_commits: false,
|
totalCommits: stats.totalCommits,
|
||||||
commits: stats.totalCommits,
|
totalRepos: 1,
|
||||||
|
followers: 0,
|
||||||
|
contributions: stats.contributedTo,
|
||||||
|
stargazers: stats.totalStars,
|
||||||
prs: stats.totalPRs,
|
prs: stats.totalPRs,
|
||||||
issues: stats.totalIssues,
|
issues: stats.totalIssues,
|
||||||
repos: 1,
|
|
||||||
stars: stats.totalStars,
|
|
||||||
followers: 0,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const data_stats = {
|
const data_stats = {
|
||||||
@@ -230,6 +229,38 @@ describe("Test /api/", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should add private contributions", async () => {
|
||||||
|
const { req, res } = faker(
|
||||||
|
{
|
||||||
|
username: "anuraghazra",
|
||||||
|
count_private: true,
|
||||||
|
},
|
||||||
|
data_stats,
|
||||||
|
);
|
||||||
|
|
||||||
|
await api(req, res);
|
||||||
|
|
||||||
|
expect(res.setHeader).toBeCalledWith("Content-Type", "image/svg+xml");
|
||||||
|
expect(res.send).toBeCalledWith(
|
||||||
|
renderStatsCard(
|
||||||
|
{
|
||||||
|
...stats,
|
||||||
|
totalCommits: stats.totalCommits + 100,
|
||||||
|
rank: calculateRank({
|
||||||
|
totalCommits: stats.totalCommits + 100,
|
||||||
|
totalRepos: 1,
|
||||||
|
followers: 0,
|
||||||
|
contributions: stats.contributedTo,
|
||||||
|
stargazers: stats.totalStars,
|
||||||
|
prs: stats.totalPRs,
|
||||||
|
issues: stats.totalIssues,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
{},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("should allow changing ring_color", async () => {
|
it("should allow changing ring_color", async () => {
|
||||||
const { req, res } = faker(
|
const { req, res } = faker(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,87 +2,17 @@ import "@testing-library/jest-dom";
|
|||||||
import { calculateRank } from "../src/calculateRank.js";
|
import { calculateRank } from "../src/calculateRank.js";
|
||||||
|
|
||||||
describe("Test calculateRank", () => {
|
describe("Test calculateRank", () => {
|
||||||
it("new user gets B rank", () => {
|
it("should calculate rank correctly", () => {
|
||||||
expect(
|
expect(
|
||||||
calculateRank({
|
calculateRank({
|
||||||
all_commits: false,
|
totalCommits: 100,
|
||||||
commits: 0,
|
totalRepos: 5,
|
||||||
prs: 0,
|
|
||||||
issues: 0,
|
|
||||||
repos: 0,
|
|
||||||
stars: 0,
|
|
||||||
followers: 0,
|
|
||||||
}),
|
|
||||||
).toStrictEqual({ level: "B", score: 100 });
|
|
||||||
});
|
|
||||||
|
|
||||||
it("average user gets A rank", () => {
|
|
||||||
expect(
|
|
||||||
calculateRank({
|
|
||||||
all_commits: false,
|
|
||||||
commits: 250,
|
|
||||||
prs: 50,
|
|
||||||
issues: 25,
|
|
||||||
repos: 0,
|
|
||||||
stars: 250,
|
|
||||||
followers: 25,
|
|
||||||
}),
|
|
||||||
).toStrictEqual({ level: "A", score: 50 });
|
|
||||||
});
|
|
||||||
|
|
||||||
it("average user gets A rank (include_all_commits)", () => {
|
|
||||||
expect(
|
|
||||||
calculateRank({
|
|
||||||
all_commits: true,
|
|
||||||
commits: 1000,
|
|
||||||
prs: 50,
|
|
||||||
issues: 25,
|
|
||||||
repos: 0,
|
|
||||||
stars: 250,
|
|
||||||
followers: 25,
|
|
||||||
}),
|
|
||||||
).toStrictEqual({ level: "A", score: 50 });
|
|
||||||
});
|
|
||||||
|
|
||||||
it("more than average user gets A+ rank", () => {
|
|
||||||
expect(
|
|
||||||
calculateRank({
|
|
||||||
all_commits: false,
|
|
||||||
commits: 500,
|
|
||||||
prs: 100,
|
|
||||||
issues: 50,
|
|
||||||
repos: 0,
|
|
||||||
stars: 500,
|
|
||||||
followers: 50,
|
|
||||||
}),
|
|
||||||
).toStrictEqual({ level: "A+", score: 25 });
|
|
||||||
});
|
|
||||||
|
|
||||||
it("expert user gets S rank", () => {
|
|
||||||
expect(
|
|
||||||
calculateRank({
|
|
||||||
all_commits: false,
|
|
||||||
commits: 1000,
|
|
||||||
prs: 200,
|
|
||||||
issues: 100,
|
|
||||||
repos: 0,
|
|
||||||
stars: 1000,
|
|
||||||
followers: 100,
|
followers: 100,
|
||||||
|
contributions: 61,
|
||||||
|
stargazers: 400,
|
||||||
|
prs: 300,
|
||||||
|
issues: 200,
|
||||||
}),
|
}),
|
||||||
).toStrictEqual({ level: "S", score: 6.25 });
|
).toStrictEqual({ level: "A+", score: 49.25629684876535 });
|
||||||
});
|
|
||||||
|
|
||||||
it("ezyang gets S+ rank", () => {
|
|
||||||
expect(
|
|
||||||
calculateRank({
|
|
||||||
all_commits: false,
|
|
||||||
commits: 1000,
|
|
||||||
prs: 4000,
|
|
||||||
issues: 2000,
|
|
||||||
repos: 0,
|
|
||||||
stars: 5000,
|
|
||||||
followers: 2000,
|
|
||||||
}),
|
|
||||||
).toStrictEqual({ level: "S+", score: 1.1363983154296875 });
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+67
-44
@@ -102,13 +102,13 @@ describe("Test fetchStats", () => {
|
|||||||
it("should fetch correct stats", async () => {
|
it("should fetch correct stats", async () => {
|
||||||
let stats = await fetchStats("anuraghazra");
|
let stats = await fetchStats("anuraghazra");
|
||||||
const rank = calculateRank({
|
const rank = calculateRank({
|
||||||
all_commits: false,
|
totalCommits: 100,
|
||||||
commits: 100,
|
totalRepos: 5,
|
||||||
|
followers: 100,
|
||||||
|
contributions: 61,
|
||||||
|
stargazers: 300,
|
||||||
prs: 300,
|
prs: 300,
|
||||||
issues: 200,
|
issues: 200,
|
||||||
repos: 5,
|
|
||||||
stars: 300,
|
|
||||||
followers: 100,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(stats).toStrictEqual({
|
expect(stats).toStrictEqual({
|
||||||
@@ -132,13 +132,13 @@ describe("Test fetchStats", () => {
|
|||||||
|
|
||||||
let stats = await fetchStats("anuraghazra");
|
let stats = await fetchStats("anuraghazra");
|
||||||
const rank = calculateRank({
|
const rank = calculateRank({
|
||||||
all_commits: false,
|
totalCommits: 100,
|
||||||
commits: 100,
|
totalRepos: 5,
|
||||||
|
followers: 100,
|
||||||
|
contributions: 61,
|
||||||
|
stargazers: 300,
|
||||||
prs: 300,
|
prs: 300,
|
||||||
issues: 200,
|
issues: 200,
|
||||||
repos: 5,
|
|
||||||
stars: 300,
|
|
||||||
followers: 100,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(stats).toStrictEqual({
|
expect(stats).toStrictEqual({
|
||||||
@@ -161,26 +161,49 @@ describe("Test fetchStats", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should fetch total commits", async () => {
|
it("should fetch and add private contributions", async () => {
|
||||||
mock
|
let stats = await fetchStats("anuraghazra", true);
|
||||||
.onGet("https://api.github.com/search/commits?q=author:anuraghazra")
|
|
||||||
.reply(200, { total_count: 1000 });
|
|
||||||
|
|
||||||
let stats = await fetchStats("anuraghazra", false, true);
|
|
||||||
const rank = calculateRank({
|
const rank = calculateRank({
|
||||||
all_commits: true,
|
totalCommits: 150,
|
||||||
commits: 1000,
|
totalRepos: 5,
|
||||||
|
followers: 100,
|
||||||
|
contributions: 61,
|
||||||
|
stargazers: 300,
|
||||||
prs: 300,
|
prs: 300,
|
||||||
issues: 200,
|
issues: 200,
|
||||||
repos: 5,
|
|
||||||
stars: 300,
|
|
||||||
followers: 100,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(stats).toStrictEqual({
|
expect(stats).toStrictEqual({
|
||||||
contributedTo: 61,
|
contributedTo: 61,
|
||||||
name: "Anurag Hazra",
|
name: "Anurag Hazra",
|
||||||
totalCommits: 1000,
|
totalCommits: 150,
|
||||||
|
totalIssues: 200,
|
||||||
|
totalPRs: 300,
|
||||||
|
totalStars: 300,
|
||||||
|
rank,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should fetch total commits", async () => {
|
||||||
|
mock
|
||||||
|
.onGet("https://api.github.com/search/commits?q=author:anuraghazra")
|
||||||
|
.reply(200, { total_count: 1000 });
|
||||||
|
|
||||||
|
let stats = await fetchStats("anuraghazra", true, true);
|
||||||
|
const rank = calculateRank({
|
||||||
|
totalCommits: 1050,
|
||||||
|
totalRepos: 5,
|
||||||
|
followers: 100,
|
||||||
|
contributions: 61,
|
||||||
|
stargazers: 300,
|
||||||
|
prs: 300,
|
||||||
|
issues: 200,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(stats).toStrictEqual({
|
||||||
|
contributedTo: 61,
|
||||||
|
name: "Anurag Hazra",
|
||||||
|
totalCommits: 1050,
|
||||||
totalIssues: 200,
|
totalIssues: 200,
|
||||||
totalPRs: 300,
|
totalPRs: 300,
|
||||||
totalStars: 300,
|
totalStars: 300,
|
||||||
@@ -193,21 +216,21 @@ describe("Test fetchStats", () => {
|
|||||||
.onGet("https://api.github.com/search/commits?q=author:anuraghazra")
|
.onGet("https://api.github.com/search/commits?q=author:anuraghazra")
|
||||||
.reply(200, { total_count: 1000 });
|
.reply(200, { total_count: 1000 });
|
||||||
|
|
||||||
let stats = await fetchStats("anuraghazra", false, true, ["test-repo-1"]);
|
let stats = await fetchStats("anuraghazra", true, true, ["test-repo-1"]);
|
||||||
const rank = calculateRank({
|
const rank = calculateRank({
|
||||||
all_commits: true,
|
totalCommits: 1050,
|
||||||
commits: 1000,
|
totalRepos: 5,
|
||||||
|
followers: 100,
|
||||||
|
contributions: 61,
|
||||||
|
stargazers: 200,
|
||||||
prs: 300,
|
prs: 300,
|
||||||
issues: 200,
|
issues: 200,
|
||||||
repos: 5,
|
|
||||||
stars: 200,
|
|
||||||
followers: 100,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(stats).toStrictEqual({
|
expect(stats).toStrictEqual({
|
||||||
contributedTo: 61,
|
contributedTo: 61,
|
||||||
name: "Anurag Hazra",
|
name: "Anurag Hazra",
|
||||||
totalCommits: 1000,
|
totalCommits: 1050,
|
||||||
totalIssues: 200,
|
totalIssues: 200,
|
||||||
totalPRs: 300,
|
totalPRs: 300,
|
||||||
totalStars: 200,
|
totalStars: 200,
|
||||||
@@ -220,13 +243,13 @@ describe("Test fetchStats", () => {
|
|||||||
|
|
||||||
let stats = await fetchStats("anuraghazra");
|
let stats = await fetchStats("anuraghazra");
|
||||||
const rank = calculateRank({
|
const rank = calculateRank({
|
||||||
all_commits: false,
|
totalCommits: 100,
|
||||||
commits: 100,
|
totalRepos: 5,
|
||||||
|
followers: 100,
|
||||||
|
contributions: 61,
|
||||||
|
stargazers: 400,
|
||||||
prs: 300,
|
prs: 300,
|
||||||
issues: 200,
|
issues: 200,
|
||||||
repos: 5,
|
|
||||||
stars: 400,
|
|
||||||
followers: 100,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(stats).toStrictEqual({
|
expect(stats).toStrictEqual({
|
||||||
@@ -245,13 +268,13 @@ describe("Test fetchStats", () => {
|
|||||||
|
|
||||||
let stats = await fetchStats("anuraghazra");
|
let stats = await fetchStats("anuraghazra");
|
||||||
const rank = calculateRank({
|
const rank = calculateRank({
|
||||||
all_commits: false,
|
totalCommits: 100,
|
||||||
commits: 100,
|
totalRepos: 5,
|
||||||
|
followers: 100,
|
||||||
|
contributions: 61,
|
||||||
|
stargazers: 300,
|
||||||
prs: 300,
|
prs: 300,
|
||||||
issues: 200,
|
issues: 200,
|
||||||
repos: 5,
|
|
||||||
stars: 300,
|
|
||||||
followers: 100,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(stats).toStrictEqual({
|
expect(stats).toStrictEqual({
|
||||||
@@ -270,13 +293,13 @@ describe("Test fetchStats", () => {
|
|||||||
|
|
||||||
let stats = await fetchStats("anuraghazra");
|
let stats = await fetchStats("anuraghazra");
|
||||||
const rank = calculateRank({
|
const rank = calculateRank({
|
||||||
all_commits: false,
|
totalCommits: 100,
|
||||||
commits: 100,
|
totalRepos: 5,
|
||||||
|
followers: 100,
|
||||||
|
contributions: 61,
|
||||||
|
stargazers: 300,
|
||||||
prs: 300,
|
prs: 300,
|
||||||
issues: 200,
|
issues: 200,
|
||||||
repos: 5,
|
|
||||||
stars: 300,
|
|
||||||
followers: 100,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(stats).toStrictEqual({
|
expect(stats).toStrictEqual({
|
||||||
|
|||||||
@@ -6,9 +6,11 @@ import {
|
|||||||
radiansToDegrees,
|
radiansToDegrees,
|
||||||
polarToCartesian,
|
polarToCartesian,
|
||||||
cartesianToPolar,
|
cartesianToPolar,
|
||||||
|
getCircleLength,
|
||||||
calculateCompactLayoutHeight,
|
calculateCompactLayoutHeight,
|
||||||
calculateNormalLayoutHeight,
|
calculateNormalLayoutHeight,
|
||||||
calculateDonutLayoutHeight,
|
calculateDonutLayoutHeight,
|
||||||
|
calculateDonutVerticalLayoutHeight,
|
||||||
calculatePieLayoutHeight,
|
calculatePieLayoutHeight,
|
||||||
donutCenterTranslation,
|
donutCenterTranslation,
|
||||||
trimTopLanguages,
|
trimTopLanguages,
|
||||||
@@ -70,6 +72,20 @@ const langPercentFromDonutLayoutSvg = (d, centerX, centerY) => {
|
|||||||
return (endAngle - startAngle) / 3.6;
|
return (endAngle - startAngle) / 3.6;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate language percentage for donut vertical chart SVG.
|
||||||
|
*
|
||||||
|
* @param {number} partLength Length of current chart part..
|
||||||
|
* @param {number} totalCircleLength Total length of circle.
|
||||||
|
* @return {number} Chart part percentage.
|
||||||
|
*/
|
||||||
|
const langPercentFromDonutVerticalLayoutSvg = (
|
||||||
|
partLength,
|
||||||
|
totalCircleLength,
|
||||||
|
) => {
|
||||||
|
return (partLength / totalCircleLength) * 100;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the language percentage from the pie chart SVG.
|
* Retrieve the language percentage from the pie chart SVG.
|
||||||
*
|
*
|
||||||
@@ -230,6 +246,20 @@ describe("Test renderTopLanguages helper functions", () => {
|
|||||||
expect(calculateDonutLayoutHeight(10)).toBe(375);
|
expect(calculateDonutLayoutHeight(10)).toBe(375);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("calculateDonutVerticalLayoutHeight", () => {
|
||||||
|
expect(calculateDonutVerticalLayoutHeight(0)).toBe(300);
|
||||||
|
expect(calculateDonutVerticalLayoutHeight(1)).toBe(325);
|
||||||
|
expect(calculateDonutVerticalLayoutHeight(2)).toBe(325);
|
||||||
|
expect(calculateDonutVerticalLayoutHeight(3)).toBe(350);
|
||||||
|
expect(calculateDonutVerticalLayoutHeight(4)).toBe(350);
|
||||||
|
expect(calculateDonutVerticalLayoutHeight(5)).toBe(375);
|
||||||
|
expect(calculateDonutVerticalLayoutHeight(6)).toBe(375);
|
||||||
|
expect(calculateDonutVerticalLayoutHeight(7)).toBe(400);
|
||||||
|
expect(calculateDonutVerticalLayoutHeight(8)).toBe(400);
|
||||||
|
expect(calculateDonutVerticalLayoutHeight(9)).toBe(425);
|
||||||
|
expect(calculateDonutVerticalLayoutHeight(10)).toBe(425);
|
||||||
|
});
|
||||||
|
|
||||||
it("calculatePieLayoutHeight", () => {
|
it("calculatePieLayoutHeight", () => {
|
||||||
expect(calculatePieLayoutHeight(0)).toBe(300);
|
expect(calculatePieLayoutHeight(0)).toBe(300);
|
||||||
expect(calculatePieLayoutHeight(1)).toBe(325);
|
expect(calculatePieLayoutHeight(1)).toBe(325);
|
||||||
@@ -258,6 +288,18 @@ describe("Test renderTopLanguages helper functions", () => {
|
|||||||
expect(donutCenterTranslation(10)).toBe(35);
|
expect(donutCenterTranslation(10)).toBe(35);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("getCircleLength", () => {
|
||||||
|
expect(getCircleLength(20)).toBeCloseTo(125.663);
|
||||||
|
expect(getCircleLength(30)).toBeCloseTo(188.495);
|
||||||
|
expect(getCircleLength(40)).toBeCloseTo(251.327);
|
||||||
|
expect(getCircleLength(50)).toBeCloseTo(314.159);
|
||||||
|
expect(getCircleLength(60)).toBeCloseTo(376.991);
|
||||||
|
expect(getCircleLength(70)).toBeCloseTo(439.822);
|
||||||
|
expect(getCircleLength(80)).toBeCloseTo(502.654);
|
||||||
|
expect(getCircleLength(90)).toBeCloseTo(565.486);
|
||||||
|
expect(getCircleLength(100)).toBeCloseTo(628.318);
|
||||||
|
});
|
||||||
|
|
||||||
it("trimTopLanguages", () => {
|
it("trimTopLanguages", () => {
|
||||||
expect(trimTopLanguages([])).toStrictEqual({
|
expect(trimTopLanguages([])).toStrictEqual({
|
||||||
langs: [],
|
langs: [],
|
||||||
@@ -569,6 +611,104 @@ describe("Test renderTopLanguages", () => {
|
|||||||
"circle",
|
"circle",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should render with layout donut vertical", () => {
|
||||||
|
document.body.innerHTML = renderTopLanguages(langs, {
|
||||||
|
layout: "donut-vertical",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(queryByTestId(document.body, "header")).toHaveTextContent(
|
||||||
|
"Most Used Languages",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(queryAllByTestId(document.body, "lang-name")[0]).toHaveTextContent(
|
||||||
|
"HTML 40.00%",
|
||||||
|
);
|
||||||
|
expect(queryAllByTestId(document.body, "lang-donut")[0]).toHaveAttribute(
|
||||||
|
"size",
|
||||||
|
"40",
|
||||||
|
);
|
||||||
|
|
||||||
|
const totalCircleLength = queryAllByTestId(
|
||||||
|
document.body,
|
||||||
|
"lang-donut",
|
||||||
|
)[0].getAttribute("stroke-dasharray");
|
||||||
|
|
||||||
|
const HTMLLangPercent = langPercentFromDonutVerticalLayoutSvg(
|
||||||
|
queryAllByTestId(document.body, "lang-donut")[1].getAttribute(
|
||||||
|
"stroke-dashoffset",
|
||||||
|
) -
|
||||||
|
queryAllByTestId(document.body, "lang-donut")[0].getAttribute(
|
||||||
|
"stroke-dashoffset",
|
||||||
|
),
|
||||||
|
totalCircleLength,
|
||||||
|
);
|
||||||
|
expect(HTMLLangPercent).toBeCloseTo(40);
|
||||||
|
|
||||||
|
expect(queryAllByTestId(document.body, "lang-name")[1]).toHaveTextContent(
|
||||||
|
"javascript 40.00%",
|
||||||
|
);
|
||||||
|
expect(queryAllByTestId(document.body, "lang-donut")[1]).toHaveAttribute(
|
||||||
|
"size",
|
||||||
|
"40",
|
||||||
|
);
|
||||||
|
const javascriptLangPercent = langPercentFromDonutVerticalLayoutSvg(
|
||||||
|
queryAllByTestId(document.body, "lang-donut")[2].getAttribute(
|
||||||
|
"stroke-dashoffset",
|
||||||
|
) -
|
||||||
|
queryAllByTestId(document.body, "lang-donut")[1].getAttribute(
|
||||||
|
"stroke-dashoffset",
|
||||||
|
),
|
||||||
|
totalCircleLength,
|
||||||
|
);
|
||||||
|
expect(javascriptLangPercent).toBeCloseTo(40);
|
||||||
|
|
||||||
|
expect(queryAllByTestId(document.body, "lang-name")[2]).toHaveTextContent(
|
||||||
|
"css 20.00%",
|
||||||
|
);
|
||||||
|
expect(queryAllByTestId(document.body, "lang-donut")[2]).toHaveAttribute(
|
||||||
|
"size",
|
||||||
|
"20",
|
||||||
|
);
|
||||||
|
const cssLangPercent = langPercentFromDonutVerticalLayoutSvg(
|
||||||
|
totalCircleLength -
|
||||||
|
queryAllByTestId(document.body, "lang-donut")[2].getAttribute(
|
||||||
|
"stroke-dashoffset",
|
||||||
|
),
|
||||||
|
totalCircleLength,
|
||||||
|
);
|
||||||
|
expect(cssLangPercent).toBeCloseTo(20);
|
||||||
|
|
||||||
|
expect(HTMLLangPercent + javascriptLangPercent + cssLangPercent).toBe(100);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should render with layout donut vertical full donut circle of one language is 100%", () => {
|
||||||
|
document.body.innerHTML = renderTopLanguages(
|
||||||
|
{ HTML: langs.HTML },
|
||||||
|
{ layout: "donut-vertical" },
|
||||||
|
);
|
||||||
|
expect(queryAllByTestId(document.body, "lang-name")[0]).toHaveTextContent(
|
||||||
|
"HTML 100.00%",
|
||||||
|
);
|
||||||
|
expect(queryAllByTestId(document.body, "lang-donut")[0]).toHaveAttribute(
|
||||||
|
"size",
|
||||||
|
"100",
|
||||||
|
);
|
||||||
|
const totalCircleLength = queryAllByTestId(
|
||||||
|
document.body,
|
||||||
|
"lang-donut",
|
||||||
|
)[0].getAttribute("stroke-dasharray");
|
||||||
|
|
||||||
|
const HTMLLangPercent = langPercentFromDonutVerticalLayoutSvg(
|
||||||
|
totalCircleLength -
|
||||||
|
queryAllByTestId(document.body, "lang-donut")[0].getAttribute(
|
||||||
|
"stroke-dashoffset",
|
||||||
|
),
|
||||||
|
totalCircleLength,
|
||||||
|
);
|
||||||
|
expect(HTMLLangPercent).toBeCloseTo(100);
|
||||||
|
});
|
||||||
|
|
||||||
it("should render with layout pie", () => {
|
it("should render with layout pie", () => {
|
||||||
document.body.innerHTML = renderTopLanguages(langs, { layout: "pie" });
|
document.body.innerHTML = renderTopLanguages(langs, { layout: "pie" });
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user