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

fix(wakatime card): add percent display format for compact layout (resolves #3503) #3504

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
15 changes: 12 additions & 3 deletions src/cards/wakatime-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,21 @@ const noCodingActivityNode = ({ color, text }) => {
* @param {WakaTimeLang} args.lang The languages array.
* @param {number} args.x The x position of the language node.
* @param {number} args.y The y position of the language node.
* @param {"time" | "percent"} args.display_format The display format of the language node.
* @returns {string} The compact layout language SVG node.
*/
const createCompactLangNode = ({ lang, x, y }) => {
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;

return `
<g transform="translate(${x}, ${y})">
<circle cx="5" cy="6" r="5" fill="${color}" />
<text data-testid="lang-name" x="15" y="10" class='lang-name'>
${lang.name} - ${lang.text}
${lang.name} - ${value}
</text>
</g>
`;
Expand All @@ -67,21 +72,24 @@ const createCompactLangNode = ({ lang, x, y }) => {
* @param {Object} args The function arguments.
* @param {WakaTimeLang[]} args.langs The language objects.
* @param {number} args.y The y position of the language node.
* @param {"time" | "percent"} args.display_format The display format of the language node.
* @returns {string[]} The language text node items.
*/
const createLanguageTextNode = ({ langs, y }) => {
const createLanguageTextNode = ({ langs, y, display_format }) => {
return langs.map((lang, index) => {
if (index % 2 === 0) {
return createCompactLangNode({
lang,
x: 25,
y: 12.5 * index + y,
display_format,
});
}
return createCompactLangNode({
lang,
x: 230,
y: 12.5 + 12.5 * index,
display_format,
});
});
};
Expand Down Expand Up @@ -313,6 +321,7 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
? createLanguageTextNode({
y: 25,
langs: filteredLanguages,
display_format,
}).join("")
: noCodingActivityNode({
// @ts-ignore
Expand Down