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

[pull] master from anuraghazra:master #19

Merged
merged 1 commit into from
Dec 26, 2023
Merged
Changes from all commits
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
24 changes: 16 additions & 8 deletions src/cards/wakatime-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ const noCodingActivityNode = ({ color, text }) => {
* @typedef {import('../fetchers/types').WakaTimeLang} WakaTimeLang
*/

/**
* Format language value.
*
* @param {Object} args The function arguments.
* @param {WakaTimeLang} args.lang The language object.
* @param {"time" | "percent"} args.display_format The display format of the language node.
* @returns {string} The formatted language value.
*/
const formatLanguageValue = ({ display_format, lang }) => {
return display_format === "percent"
? `${lang.percent.toFixed(2).toString()} %`
: lang.text;
};

/**
* Create compact WakaTime layout.
*
Expand All @@ -51,10 +65,7 @@ const noCodingActivityNode = ({ color, text }) => {
*/
const createCompactLangNode = ({ lang, x, y, display_format }) => {
const color = languageColors[lang.name] || "#858585";
const value =
display_format === "percent"
? `${lang.percent.toFixed(2).toString()} %`
: lang.text;
const value = formatLanguageValue({ display_format, lang });

return `
<g transform="translate(${x}, ${y})">
Expand Down Expand Up @@ -341,10 +352,7 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
return createTextNode({
id: language.name,
label: language.name,
value:
display_format === "percent"
? `${language.percent.toFixed(2).toString()} %`
: language.text,
value: formatLanguageValue({ display_format, lang: language }),
index,
percent: language.percent,
// @ts-ignore
Expand Down