mirror of
https://github.com/anuraghazra/github-readme-stats.git
synced 2024-11-27 05:30:32 +08:00
Add format stats option (#2155)
* feat: added `format_stats` option (#2128) * refactor: change `format_stats` to `short_values` (#2128) * test: create shorten values test (#2128) * Update readme.md Co-authored-by: Rick Staa <rick.staa@outlook.com> * refactor: rename ``short_values`` to ``number_format`` * Update readme.md Co-authored-by: Rick Staa <rick.staa@outlook.com> * Update src/cards/stats-card.js Co-authored-by: Rick Staa <rick.staa@outlook.com> * refactor: format codebase --------- Co-authored-by: Rick Staa <rick.staa@outlook.com>
This commit is contained in:
parent
b928f51442
commit
d8244a7fe5
@ -35,6 +35,7 @@ export default async (req, res) => {
|
|||||||
locale,
|
locale,
|
||||||
disable_animations,
|
disable_animations,
|
||||||
border_radius,
|
border_radius,
|
||||||
|
number_format,
|
||||||
border_color,
|
border_color,
|
||||||
} = req.query;
|
} = req.query;
|
||||||
res.setHeader("Content-Type", "image/svg+xml");
|
res.setHeader("Content-Type", "image/svg+xml");
|
||||||
@ -88,6 +89,7 @@ export default async (req, res) => {
|
|||||||
custom_title,
|
custom_title,
|
||||||
border_radius,
|
border_radius,
|
||||||
border_color,
|
border_color,
|
||||||
|
number_format,
|
||||||
locale: locale ? locale.toLowerCase() : null,
|
locale: locale ? locale.toLowerCase() : null,
|
||||||
disable_animations: parseBoolean(disable_animations),
|
disable_animations: parseBoolean(disable_animations),
|
||||||
}),
|
}),
|
||||||
|
@ -289,6 +289,7 @@ You can provide multiple comma-separated values in the bg_color option to render
|
|||||||
- `text_bold` - Use bold text _(boolean)_. Default: `true`.
|
- `text_bold` - Use bold text _(boolean)_. Default: `true`.
|
||||||
- `disable_animations` - Disables all animations in the card _(boolean)_. Default: `false`.
|
- `disable_animations` - Disables all animations in the card _(boolean)_. Default: `false`.
|
||||||
- `ring_color` - Color of the rank circle _(hex color)_. Defaults to the theme ring color if it exists and otherwise the title color.
|
- `ring_color` - Color of the rank circle _(hex color)_. Defaults to the theme ring color if it exists and otherwise the title color.
|
||||||
|
- `number_format` - Switch between two available formats for displaying the card values `short` (i.e. `6.6k`) and `long` (i.e. `6626`). Default: `short`.
|
||||||
|
|
||||||
> **Note**
|
> **Note**
|
||||||
> When hide_rank=`true`, the minimum card width is 270 px + the title length and padding.
|
> When hide_rank=`true`, the minimum card width is 270 px + the title length and padding.
|
||||||
|
@ -39,8 +39,10 @@ const createTextNode = ({
|
|||||||
showIcons,
|
showIcons,
|
||||||
shiftValuePos,
|
shiftValuePos,
|
||||||
bold,
|
bold,
|
||||||
|
number_format,
|
||||||
}) => {
|
}) => {
|
||||||
const kValue = kFormatter(value);
|
const kValue =
|
||||||
|
number_format.toLowerCase() === "long" ? value : kFormatter(value);
|
||||||
const staggerDelay = (index + 3) * 150;
|
const staggerDelay = (index + 3) * 150;
|
||||||
|
|
||||||
const labelOffset = showIcons ? `x="25"` : "";
|
const labelOffset = showIcons ? `x="25"` : "";
|
||||||
@ -103,6 +105,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
|
|||||||
custom_title,
|
custom_title,
|
||||||
border_radius,
|
border_radius,
|
||||||
border_color,
|
border_color,
|
||||||
|
number_format = "short",
|
||||||
locale,
|
locale,
|
||||||
disable_animations = false,
|
disable_animations = false,
|
||||||
} = options;
|
} = options;
|
||||||
@ -192,6 +195,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
|
|||||||
showIcons: show_icons,
|
showIcons: show_icons,
|
||||||
shiftValuePos: 79.01 + (isLongLocale ? 50 : 0),
|
shiftValuePos: 79.01 + (isLongLocale ? 50 : 0),
|
||||||
bold: text_bold,
|
bold: text_bold,
|
||||||
|
number_format,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
1
src/cards/types.d.ts
vendored
1
src/cards/types.d.ts
vendored
@ -22,6 +22,7 @@ export type StatCardOptions = CommonOptions & {
|
|||||||
line_height: number | string;
|
line_height: number | string;
|
||||||
custom_title: string;
|
custom_title: string;
|
||||||
disable_animations: boolean;
|
disable_animations: boolean;
|
||||||
|
number_format: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type RepoCardOptions = CommonOptions & {
|
export type RepoCardOptions = CommonOptions & {
|
||||||
|
@ -357,4 +357,13 @@ describe("Test renderStatsCard", () => {
|
|||||||
document.body.innerHTML = renderStatsCard(stats, {});
|
document.body.innerHTML = renderStatsCard(stats, {});
|
||||||
expect(document.querySelector("rect")).toHaveAttribute("rx", "4.5");
|
expect(document.querySelector("rect")).toHaveAttribute("rx", "4.5");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should shorten values", () => {
|
||||||
|
stats["totalCommits"] = 1999;
|
||||||
|
|
||||||
|
document.body.innerHTML = renderStatsCard(stats);
|
||||||
|
expect(getByTestId(document.body, "commits").textContent).toBe("2k");
|
||||||
|
document.body.innerHTML = renderStatsCard(stats, { number_format: "long" });
|
||||||
|
expect(getByTestId(document.body, "commits").textContent).toBe("1999");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user