From c7609ce1f6315e58467b43eb9deb15839d14683c Mon Sep 17 00:00:00 2001 From: Ritik Raj <84488726+ritik48@users.noreply.github.com> Date: Fri, 24 Nov 2023 00:43:48 +0530 Subject: [PATCH] feat: show wakatime stats in percentage (resolves #3016) (#3326) * added option to display wakatime in percentage * updated exclusive options in wakatime * added percent sign * Update readme.md Co-authored-by: Rick Staa * made the required changes * Update wakatime-card.js * Update wakatime-card.js --------- Co-authored-by: Rick Staa Co-authored-by: Alexandr --- api/wakatime.js | 2 ++ readme.md | 1 + src/cards/types.d.ts | 1 + src/cards/wakatime-card.js | 6 +++++- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/api/wakatime.js b/api/wakatime.js index d00e773f7be52..de263e0644c43 100644 --- a/api/wakatime.js +++ b/api/wakatime.js @@ -30,6 +30,7 @@ export default async (req, res) => { api_domain, border_radius, border_color, + display_format, disable_animations, } = req.query; @@ -84,6 +85,7 @@ export default async (req, res) => { locale: locale ? locale.toLowerCase() : null, layout, langs_count, + display_format, disable_animations: parseBoolean(disable_animations), }), ); diff --git a/readme.md b/readme.md index bec204dc15fed..06bbdfc39616c 100644 --- a/readme.md +++ b/readme.md @@ -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`. *** diff --git a/src/cards/types.d.ts b/src/cards/types.d.ts index a1230231246ee..a51fd2d71f90b 100644 --- a/src/cards/types.d.ts +++ b/src/cards/types.d.ts @@ -54,6 +54,7 @@ type WakaTimeOptions = CommonOptions & { custom_title: string; layout: "compact" | "normal"; langs_count: number; + display_format: "time" | "percent"; disable_animations: boolean; }; diff --git a/src/cards/wakatime-card.js b/src/cards/wakatime-card.js index 22b93aa521ae6..2d451ef072356 100644 --- a/src/cards/wakatime-card.js +++ b/src/cards/wakatime-card.js @@ -218,6 +218,7 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => { langs_count = languages.length, border_radius, border_color, + display_format = "time", disable_animations, } = options; @@ -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