Skip to content

Commit f9c0e0b

Browse files
committed
Change default stats card width with hide rank
1 parent 97690e1 commit f9c0e0b

File tree

2 files changed

+38
-25
lines changed

2 files changed

+38
-25
lines changed

Diff for: api/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = async (req, res) => {
1717
hide,
1818
hide_title,
1919
hide_border,
20+
card_width,
2021
hide_rank,
2122
show_icons,
2223
count_private,
@@ -67,6 +68,7 @@ module.exports = async (req, res) => {
6768
show_icons: parseBoolean(show_icons),
6869
hide_title: parseBoolean(hide_title),
6970
hide_border: parseBoolean(hide_border),
71+
card_width: parseInt(card_width, 10),
7072
hide_rank: parseBoolean(hide_rank),
7173
include_all_commits: parseBoolean(include_all_commits),
7274
line_height,

Diff for: src/cards/stats-card.js

+36-25
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
6060
show_icons = false,
6161
hide_title = false,
6262
hide_border = false,
63+
card_width,
6364
hide_rank = false,
6465
include_all_commits = false,
6566
line_height = 25,
@@ -75,6 +76,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
7576
disable_animations = false,
7677
} = options;
7778

79+
7880
const lheight = parseInt(line_height, 10);
7981

8082
// returns theme based colors with proper overrides and defaults
@@ -168,26 +170,6 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
168170
hide_rank ? 0 : 150,
169171
);
170172

171-
// Conditionally rendered elements
172-
const rankCircle = hide_rank
173-
? ""
174-
: `<g data-testid="rank-circle"
175-
transform="translate(400, ${height / 2 - 50})">
176-
<circle class="rank-circle-rim" cx="-10" cy="8" r="40" />
177-
<circle class="rank-circle" cx="-10" cy="8" r="40" />
178-
<g class="rank-text">
179-
<text
180-
x="${rank.level.length === 1 ? "-4" : "0"}"
181-
y="0"
182-
alignment-baseline="central"
183-
dominant-baseline="central"
184-
text-anchor="middle"
185-
>
186-
${rank.level}
187-
</text>
188-
</g>
189-
</g>`;
190-
191173
// the better user's score the the rank will be closer to zero so
192174
// subtracting 100 to get the progress in 100%
193175
const progress = 100 - rank.score;
@@ -203,13 +185,22 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
203185
return measureText(custom_title ? custom_title : i18n.t("statcard.title"));
204186
};
205187

206-
const width = hide_rank
188+
/*
189+
When hide_rank=true, minimum card width is max of 270 and length of title + paddings.
190+
When hide_rank=false, minimum card_width is 340.
191+
Numbers are picked by looking at existing dimensions on production.
192+
*/
193+
const minCardWidth = hide_rank
207194
? clampValue(
208195
50 /* padding */ + calculateTextWidth() * 2,
209-
270 /* min */,
210-
Infinity,
211-
)
212-
: 495;
196+
270,
197+
Infinity)
198+
: 340
199+
const defaultCardWidth = hide_rank ? 270 : 495
200+
let width = isNaN(card_width) ? defaultCardWidth : card_width
201+
if (width < minCardWidth) {
202+
width = minCardWidth
203+
}
213204

214205
const card = new Card({
215206
customTitle: custom_title,
@@ -232,6 +223,26 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
232223

233224
if (disable_animations) card.disableAnimations();
234225

226+
// Conditionally rendered elements
227+
const rankCircle = hide_rank
228+
? ""
229+
: `<g data-testid="rank-circle"
230+
transform="translate(${width - 50}, ${height / 2 - 50})">
231+
<circle class="rank-circle-rim" cx="-10" cy="8" r="40" />
232+
<circle class="rank-circle" cx="-10" cy="8" r="40" />
233+
<g class="rank-text">
234+
<text
235+
x="${rank.level.length === 1 ? "-4" : "0"}"
236+
y="0"
237+
alignment-baseline="central"
238+
dominant-baseline="central"
239+
text-anchor="middle"
240+
>
241+
${rank.level}
242+
</text>
243+
</g>
244+
</g>`;
245+
235246
return card.render(`
236247
${rankCircle}
237248

0 commit comments

Comments
 (0)