Skip to content

Commit

Permalink
feat: show wakatime stats in percentage (resolves anuraghazra#3016) (a…
Browse files Browse the repository at this point in the history
…nuraghazra#3326)

* added option to display wakatime in percentage

* updated exclusive options in wakatime

* added percent sign

* Update readme.md

Co-authored-by: Rick Staa <rick.staa@outlook.com>

* made the required changes

* Update wakatime-card.js

* Update wakatime-card.js

---------

Co-authored-by: Rick Staa <rick.staa@outlook.com>
Co-authored-by: Alexandr <qwerty541zxc@gmail.com>
  • Loading branch information
3 people authored Nov 23, 2023
1 parent a8663a8 commit b8983dd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions api/wakatime.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default async (req, res) => {
api_domain,
border_radius,
border_color,
display_format,
disable_animations,
} = req.query;

Expand Down Expand Up @@ -84,6 +85,7 @@ export default async (req, res) => {
locale: locale ? locale.toLowerCase() : null,
layout,
langs_count,
display_format,
disable_animations: parseBoolean(disable_animations),
}),
);
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ If we don't support your language, please consider contributing! You can find mo
* `layout` - Switches between two available layouts `default` & `compact`. Default `default`.
* `langs_count` - Limits the number of languages on the card, defaults to all reported languages *(number)*.
* `api_domain` - Sets a custom API domain for the card, e.g. to use services like [Hakatime](https://github.com/mujx/hakatime) or [Wakapi](https://github.com/muety/wakapi) *(string)*. Default `Waka API`.
* `display_format` - Sets the WakaTime stats display format. Choose `time` to display time-based stats or `percent` to show percentages. Default: `time`.
* `disable_animations` - Disables all animations in the card *(boolean)*. Default: `false`.

***
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 @@ -54,6 +54,7 @@ type WakaTimeOptions = CommonOptions & {
custom_title: string;
layout: "compact" | "normal";
langs_count: number;
display_format: "time" | "percent";
disable_animations: boolean;
};

Expand Down
6 changes: 5 additions & 1 deletion src/cards/wakatime-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
langs_count = languages.length,
border_radius,
border_color,
display_format = "time",
disable_animations,
} = options;

Expand Down Expand Up @@ -331,7 +332,10 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
return createTextNode({
id: language.name,
label: language.name,
value: language.text,
value:
display_format === "percent"
? `${language.percent.toFixed(2).toString()} %`
: language.text,
index,
percent: language.percent,
// @ts-ignore
Expand Down

0 comments on commit b8983dd

Please sign in to comment.