@@ -60,6 +60,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
60
60
show_icons = false ,
61
61
hide_title = false ,
62
62
hide_border = false ,
63
+ card_width,
63
64
hide_rank = false ,
64
65
include_all_commits = false ,
65
66
line_height = 25 ,
@@ -75,6 +76,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
75
76
disable_animations = false ,
76
77
} = options ;
77
78
79
+
78
80
const lheight = parseInt ( line_height , 10 ) ;
79
81
80
82
// returns theme based colors with proper overrides and defaults
@@ -168,26 +170,6 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
168
170
hide_rank ? 0 : 150 ,
169
171
) ;
170
172
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
-
191
173
// the better user's score the the rank will be closer to zero so
192
174
// subtracting 100 to get the progress in 100%
193
175
const progress = 100 - rank . score ;
@@ -203,13 +185,22 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
203
185
return measureText ( custom_title ? custom_title : i18n . t ( "statcard.title" ) ) ;
204
186
} ;
205
187
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
207
194
? clampValue (
208
195
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
+ }
213
204
214
205
const card = new Card ( {
215
206
customTitle : custom_title ,
@@ -232,6 +223,26 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
232
223
233
224
if ( disable_animations ) card . disableAnimations ( ) ;
234
225
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
+
235
246
return card . render ( `
236
247
${ rankCircle }
237
248
0 commit comments