Skip to content

Commit a5acc5e

Browse files
committed
feat: Add support for configurable language ordering in Wakatime cards (horizontal/vertical)
1 parent 0087bfd commit a5acc5e

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

api/wakatime.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export default async (req, res) => {
3333
border_color,
3434
display_format,
3535
disable_animations,
36+
ordering,
3637
} = req.query;
3738

3839
res.setHeader("Content-Type", "image/svg+xml");
@@ -105,6 +106,7 @@ export default async (req, res) => {
105106
langs_count,
106107
display_format,
107108
disable_animations: parseBoolean(disable_animations),
109+
ordering,
108110
}),
109111
);
110112
} catch (err) {
@@ -124,4 +126,4 @@ export default async (req, res) => {
124126
}),
125127
);
126128
}
127-
};
129+
};

readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ You can customize the appearance and behavior of the WakaTime stats card using t
639639
| `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 | `wakatime.com` |
640640
| `display_format` | Sets the WakaTime stats display format. Choose `time` to display time-based stats or `percent` to show percentages. | enum | `time` |
641641
| `disable_animations` | Disables all animations in the card. | boolean | `false` |
642+
| `ordering` | Only effective when `layout=compact`. Sets the ordering algorithm for the languages in a two-column layout. `horizontal` alternates items left and right (zig-zag pattern), while `vertical` fills the left column first, then the right column. | enum | `horizontal` |
642643

643644
### Demo
644645

@@ -896,4 +897,4 @@ Thanks! :heart:
896897

897898
Contributions are welcome! <3
898899

899-
Made with :heart: and JavaScript.
900+
Made with :heart: and JavaScript.

src/cards/wakatime.js

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,28 +85,40 @@ const createCompactLangNode = ({ lang, x, y, display_format }) => {
8585
* @param {number} args.y The y position of the language node.
8686
* @param {"time" | "percent"} args.display_format The display format of the language node.
8787
* @param {number} args.lineHeight The line height for spacing.
88+
* @param {"horizontal" | "vertical"} args.ordering The ordering of the languages.
8889
* @returns {string[]} The language text node items.
8990
*/
90-
const createLanguageTextNode = ({ langs, y, display_format, lineHeight = 25 }) => {
91-
const halfLength = Math.ceil(langs.length / 2);
92-
93-
return langs.map((lang, index) => {
94-
if (index < halfLength) {
91+
const createLanguageTextNode = ({ langs = [], y, display_format, lineHeight = 25, ordering = "horizontal" }) => {
92+
if (ordering === "horizontal") {
93+
return langs.map((lang, index) => {
94+
const row = Math.floor(index / 2);
95+
const col = index % 2;
9596
return createCompactLangNode({
9697
lang,
97-
x: 25,
98-
y: lineHeight * index + y,
98+
x: col === 0 ? 25 : 230,
99+
y: y + lineHeight * row,
99100
display_format,
100101
});
101-
} else {
102+
});
103+
}
104+
105+
else if (ordering === "vertical") {
106+
const halfLength = Math.ceil(langs.length / 2);
107+
108+
return langs.map((lang, index) => {
109+
const inLeft = index < halfLength;
110+
const col = inLeft ? 0 : 1;
111+
const row = inLeft ? index : index - halfLength;
102112
return createCompactLangNode({
103113
lang,
104-
x: 230,
105-
y: lineHeight * (index - halfLength) + y,
114+
x: col === 0 ? 25 : 230,
115+
y: y + lineHeight * row,
106116
display_format,
107117
});
108-
}
109-
});
118+
});
119+
}
120+
121+
return [];
110122
};
111123

112124
/**
@@ -243,6 +255,7 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
243255
border_color,
244256
display_format = "time",
245257
disable_animations,
258+
ordering = "horizontal",
246259
} = options;
247260

248261
const shouldHideLangs = Array.isArray(hide) && hide.length > 0;
@@ -338,6 +351,7 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
338351
langs: filteredLanguages,
339352
display_format,
340353
lineHeight: lheight,
354+
ordering,
341355
}).join("")
342356
: noCodingActivityNode({
343357
// @ts-ignore

0 commit comments

Comments
 (0)