@@ -35,10 +35,10 @@ const createTextNode = ({
35
35
<g class="stagger" style="animation-delay: ${ staggerDelay } ms" transform="translate(25, 0)">
36
36
${ iconSvg }
37
37
<text class="stat bold" ${ labelOffset } y="12.5">${ label } :</text>
38
- <text
39
- class="stat"
40
- x="${ ( showIcons ? 140 : 120 ) + shiftValuePos } "
41
- y="12.5"
38
+ <text
39
+ class="stat"
40
+ x="${ ( showIcons ? 140 : 120 ) + shiftValuePos } "
41
+ y="12.5"
42
42
data-testid="${ id } "
43
43
>${ kValue } </text>
44
44
</g>
@@ -76,7 +76,6 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
76
76
disable_animations = false ,
77
77
} = options ;
78
78
79
-
80
79
const lheight = parseInt ( line_height , 10 ) ;
81
80
82
81
// returns theme based colors with proper overrides and defaults
@@ -186,20 +185,18 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
186
185
} ;
187
186
188
187
/*
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.
188
+ When hide_rank=true, the minimum card width is 270 px + the title length and padding .
189
+ When hide_rank=false, the minimum card_width is 340 px + the icon width (if show_icons=true) .
191
190
Numbers are picked by looking at existing dimensions on production.
192
191
*/
192
+ const iconWidth = show_icons ? 16 : 0 ;
193
193
const minCardWidth = hide_rank
194
- ? clampValue (
195
- 50 /* padding */ + calculateTextWidth ( ) * 2 ,
196
- 270 ,
197
- Infinity )
198
- : 340
199
- const defaultCardWidth = hide_rank ? 270 : 495
200
- let width = isNaN ( card_width ) ? defaultCardWidth : card_width
194
+ ? clampValue ( 50 /* padding */ + calculateTextWidth ( ) * 2 , 270 , Infinity )
195
+ : 340 + iconWidth ;
196
+ const defaultCardWidth = hide_rank ? 270 : 495 ;
197
+ let width = isNaN ( card_width ) ? defaultCardWidth : card_width ;
201
198
if ( width < minCardWidth ) {
202
- width = minCardWidth
199
+ width = minCardWidth ;
203
200
}
204
201
205
202
const card = new Card ( {
@@ -223,11 +220,30 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
223
220
224
221
if ( disable_animations ) card . disableAnimations ( ) ;
225
222
223
+ /**
224
+ * Calculates the right rank circle translation values such that the rank circle
225
+ * keeps respecting the padding.
226
+ *
227
+ * width > 450: The default left padding of 50 px will be used.
228
+ * width < 450: The left and right padding will shrink equally.
229
+ *
230
+ * @returns {number } - Rank circle translation value.
231
+ */
232
+ const calculateRankXTranslation = ( ) => {
233
+ if ( width < 450 ) {
234
+ return width - 95 + ( 45 * ( 450 - 340 ) ) / 110 ;
235
+ } else {
236
+ return width - 95 ;
237
+ }
238
+ } ;
239
+
226
240
// Conditionally rendered elements
227
241
const rankCircle = hide_rank
228
242
? ""
229
- : `<g data-testid="rank-circle"
230
- transform="translate(${ width - 50 } , ${ height / 2 - 50 } )">
243
+ : `<g data-testid="rank-circle"
244
+ transform="translate(${ calculateRankXTranslation ( ) } , ${
245
+ height / 2 - 50
246
+ } )">
231
247
<circle class="rank-circle-rim" cx="-10" cy="8" r="40" />
232
248
<circle class="rank-circle" cx="-10" cy="8" r="40" />
233
249
<g class="rank-text">
@@ -252,7 +268,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
252
268
gap : lheight ,
253
269
direction : "column" ,
254
270
} ) . join ( "" ) }
255
- </svg>
271
+ </svg>
256
272
` ) ;
257
273
} ;
258
274
0 commit comments