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 format stats option #2155

Merged
merged 15 commits into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default async (req, res) => {
locale,
disable_animations,
border_radius,
short_values,
number_format,
border_color,
} = req.query;
res.setHeader("Content-Type", "image/svg+xml");
Expand Down Expand Up @@ -85,7 +85,7 @@ export default async (req, res) => {
custom_title,
border_radius,
border_color,
short_values: parseBoolean(short_values),
number_format,
locale: locale ? locale.toLowerCase() : null,
disable_animations: parseBoolean(disable_animations),
}),
Expand Down
47 changes: 33 additions & 14 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,38 @@ Visit <https://indiafightscorona.giveindia.org> and make a small donation to hel

# Features

- [GitHub Stats Card](#github-stats-card)
- [GitHub Extra Pins](#github-extra-pins)
- [Top Languages Card](#top-languages-card)
- [Wakatime Week Stats](#wakatime-week-stats)
- [Themes](#themes)
- [Customization](#customization)
- [Common Options](#common-options)
- [Stats Card Exclusive Options](#stats-card-exclusive-options)
- [Repo Card Exclusive Options](#repo-card-exclusive-options)
- [Language Card Exclusive Options](#language-card-exclusive-options)
- [Wakatime Card Exclusive Option](#wakatime-card-exclusive-options)
- [Deploy Yourself](#deploy-on-your-own-vercel-instance)
- [Keep your fork up to date](#keep-your-fork-up-to-date)
- [Features](#features)
- [GitHub Stats Card](#github-stats-card)
- [Hiding individual stats](#hiding-individual-stats)
- [Adding private contributions count to total commits count](#adding-private-contributions-count-to-total-commits-count)
- [Showing icons](#showing-icons)
- [Themes](#themes)
- [All inbuilt themes](#all-inbuilt-themes)
- [Customization](#customization)
- [Common Options](#common-options)
- [Gradient in bg_color](#gradient-in-bg_color)
- [Stats Card Exclusive Options](#stats-card-exclusive-options)
- [Repo Card Exclusive Options](#repo-card-exclusive-options)
- [Language Card Exclusive Options](#language-card-exclusive-options)
- [Wakatime Card Exclusive Options](#wakatime-card-exclusive-options)
- [GitHub Extra Pins](#github-extra-pins)
- [Usage](#usage)
- [Demo](#demo)
- [Top Languages Card](#top-languages-card)
- [Usage](#usage-1)
- [Exclude individual repositories](#exclude-individual-repositories)
- [Hide individual languages](#hide-individual-languages)
- [Show more languages](#show-more-languages)
- [Compact Language Card Layout](#compact-language-card-layout)
- [Demo](#demo-1)
- [Wakatime Week Stats](#wakatime-week-stats)
- [Demo](#demo-2)
- [All Demos](#all-demos)
- [Quick Tip (Align The Repo Cards)](#quick-tip-align-the-repo-cards)
- [Deploy on your own Vercel instance](#deploy-on-your-own-vercel-instance)
- [Check Out Step By Step Video Tutorial By @codeSTACKr](#check-out-step-by-step-video-tutorial-by-codestackr)
- [Keep your fork up to date](#keep-your-fork-up-to-date)
- [:sparkling_heart: Support the project](#sparkling_heart-support-the-project)

# GitHub Stats Card

Expand Down Expand Up @@ -196,7 +215,7 @@ You can provide multiple comma-separated values in the bg_color option to render
- `custom_title` - Sets a custom title for the card. Default: `<username> Github Stats`.
- `text_bold` - Use bold text _(boolean)_. Default: `true`.
- `disable_animations` - Disables all animations in the card _(boolean)_. Default: `false`.
- `short_values` - Use `k`-suffix to shorten the card values _(boolean)_. Default: `true`.
- `number_format` - Use `k`-suffix to shorten the card values. Either `short` or `long` _(string)_. Default: `short`.

> **Note**
> When hide_rank=`true`, the minimum card width is 270 px + the title length and padding.
Expand Down
8 changes: 4 additions & 4 deletions src/cards/stats-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ const createTextNode = ({
showIcons,
shiftValuePos,
bold,
short_values,
number_format,
}) => {
const kValue = short_values ? kFormatter(value) : value;
const kValue = number_format === "short" ? kFormatter(value) : value;
const staggerDelay = (index + 3) * 150;

const labelOffset = showIcons ? `x="25"` : "";
Expand Down Expand Up @@ -98,7 +98,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
custom_title,
border_radius,
border_color,
short_values = true,
number_format = "short",
locale,
disable_animations = false,
} = options;
Expand Down Expand Up @@ -187,7 +187,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
shiftValuePos:
(!include_all_commits ? 50 : 35) + (isLongLocale ? 50 : 0),
bold: text_bold,
short_values,
number_format,
}),
);

Expand Down
2 changes: 1 addition & 1 deletion src/cards/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type StatCardOptions = CommonOptions & {
line_height: number | string;
custom_title: string;
disable_animations: boolean;
short_values: boolean;
number_format: string;
};

export type RepoCardOptions = CommonOptions & {
Expand Down
2 changes: 1 addition & 1 deletion tests/renderStatsCard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ describe("Test renderStatsCard", () => {

document.body.innerHTML = renderStatsCard(stats);
expect(getByTestId(document.body, "commits").textContent).toBe("2k");
document.body.innerHTML = renderStatsCard(stats, { short_values: false });
document.body.innerHTML = renderStatsCard(stats, { number_format: "long" });
expect(getByTestId(document.body, "commits").textContent).toBe("1999");
});
});