Compare commits

...
Author SHA1 Message Date
rickstaa 3afe547077 feat: add 'progress' rank icon
This commit gives users the ability to show the `progress` compared to
the highest possible rank in the stats card.
2023-06-22 10:45:25 +02:00
4 changed files with 19 additions and 3 deletions
+1 -1
View File
@@ -304,7 +304,7 @@ You can provide multiple comma-separated values in the bg\_color option to rende
* `hide_title` - *(boolean)*. Default: `false`.
* `card_width` - Set the card's width manually *(number)*. Default: `500px (approx.)`.
* `hide_rank` - *(boolean)* hides the rank and automatically resizes the card width. Default: `false`.
* `rank_icon` - Shows alternative rank icon (i.e. `github`, `percentile` or `default`). Default: `default`.
* `rank_icon` - Shows alternative rank icon (i.e. `github`, `percentile`, `progress` or `default`). Default: `default`.
* `show_icons` - *(boolean)*. Default: `false`.
* `include_all_commits` - Count total commits instead of just the current year commits *(boolean)*. Default: `false`.
* `line_height` - Sets the line height between text *(number)*. Default: `25`.
+1 -1
View File
@@ -1,5 +1,5 @@
type ThemeNames = keyof typeof import("../../themes/index.js");
type RankIcon = "default" | "github" | "percentile";
type RankIcon = "default" | "github" | "percentile" | "progress";
export type CommonOptions = {
title_color: string;
+7 -1
View File
@@ -36,13 +36,19 @@ const rankIcon = (rankIcon, rankLevel, percentile) => {
${percentile.toFixed(1)}%
</text>
`;
case "progress":
return `
<text x="-5" y="3" alignment-baseline="central" dominant-baseline="central" text-anchor="middle" data-testid="progress-rank-icon" class="rank-percentile-text">
${(100.0 - percentile).toFixed(1)}%
</text>
`;
case "default":
default:
return `
<text x="-5" y="3" alignment-baseline="central" dominant-baseline="central" text-anchor="middle" data-testid="level-rank-icon">
${rankLevel}
</text>
`;
`;
}
};
+10
View File
@@ -431,4 +431,14 @@ describe("Test renderStatsCard", () => {
queryByTestId(document.body, "percentile-rank-value").textContent.trim(),
).toBe(stats.rank.percentile.toFixed(1) + "%");
});
it("should show the progress", () => {
document.body.innerHTML = renderStatsCard(stats, {
rank_icon: "progress",
});
expect(queryByTestId(document.body, "rank-progress-text")).toBeDefined();
expect(
queryByTestId(document.body, "progress-rank-icon").textContent.trim(),
).toBe((100 - stats.rank.percentile).toFixed(1) + "%");
});
});