@@ -39,46 +39,53 @@ const getLongestLang = (arr) =>
39
39
* Creates a node to display usage of a programming language in percentage
40
40
* using text and a horizontal progress bar.
41
41
*
42
- * @param {object[] } props Function properties.
42
+ * @param {object } props Function properties.
43
43
* @param {number } props.width The card width
44
44
* @param {string } props.name Name of the programming language.
45
45
* @param {string } props.color Color of the programming language.
46
46
* @param {string } props.progress Usage of the programming language in percentage.
47
+ * @param {number } props.index Index of the programming language.
47
48
* @returns {string } Programming language SVG node.
48
49
*/
49
- const createProgressTextNode = ( { width, color, name, progress } ) => {
50
+ const createProgressTextNode = ( { width, color, name, progress, index } ) => {
51
+ const staggerDelay = ( index + 3 ) * 150 ;
50
52
const paddingRight = 95 ;
51
53
const progressTextX = width - paddingRight + 10 ;
52
54
const progressWidth = width - paddingRight ;
53
55
54
56
return `
55
- <text data-testid="lang-name" x="2" y="15" class="lang-name">${ name } </text>
56
- <text x="${ progressTextX } " y="34" class="lang-name">${ progress } %</text>
57
- ${ createProgressNode ( {
58
- x : 0 ,
59
- y : 25 ,
60
- color,
61
- width : progressWidth ,
62
- progress,
63
- progressBarBackgroundColor : "#ddd" ,
64
- } ) }
57
+ <g class="stagger" style="animation-delay: ${ staggerDelay } ms">
58
+ <text data-testid="lang-name" x="2" y="15" class="lang-name">${ name } </text>
59
+ <text x="${ progressTextX } " y="34" class="lang-name">${ progress } %</text>
60
+ ${ createProgressNode ( {
61
+ x : 0 ,
62
+ y : 25 ,
63
+ color,
64
+ width : progressWidth ,
65
+ progress,
66
+ progressBarBackgroundColor : "#ddd" ,
67
+ delay : staggerDelay + 300 ,
68
+ } ) }
69
+ </g>
65
70
` ;
66
71
} ;
67
72
68
73
/**
69
74
* Creates a text only node to display usage of a programming language in percentage.
70
75
*
71
- * @param {object[] } props Function properties.
76
+ * @param {object } props Function properties.
72
77
* @param {Lang } props.lang Programming language object.
73
78
* @param {number } props.totalSize Total size of all languages.
79
+ * @param {number } props.index Index of the programming language.
74
80
* @returns {string } Compact layout programming language SVG node.
75
81
*/
76
- const createCompactLangNode = ( { lang, totalSize } ) => {
82
+ const createCompactLangNode = ( { lang, totalSize, index } ) => {
77
83
const percentage = ( ( lang . size / totalSize ) * 100 ) . toFixed ( 2 ) ;
84
+ const staggerDelay = ( index + 3 ) * 150 ;
78
85
const color = lang . color || "#858585" ;
79
86
80
87
return `
81
- <g>
88
+ <g class="stagger" style="animation-delay: ${ staggerDelay } ms" >
82
89
<circle cx="5" cy="6" r="5" fill="${ color } " />
83
90
<text data-testid="lang-name" x="15" y="10" class='lang-name'>
84
91
${ lang . name } ${ percentage } %
@@ -104,7 +111,6 @@ const createLanguageTextNode = ({ langs, totalSize }) => {
104
111
createCompactLangNode ( {
105
112
lang,
106
113
totalSize,
107
- // @ts -ignore
108
114
index,
109
115
} ) ,
110
116
) ;
@@ -134,12 +140,13 @@ const createLanguageTextNode = ({ langs, totalSize }) => {
134
140
*/
135
141
const renderNormalLayout = ( langs , width , totalLanguageSize ) => {
136
142
return flexLayout ( {
137
- items : langs . map ( ( lang ) => {
143
+ items : langs . map ( ( lang , index ) => {
138
144
return createProgressTextNode ( {
139
- width : width ,
145
+ width,
140
146
name : lang . name ,
141
147
color : lang . color || DEFAULT_LANG_COLOR ,
142
148
progress : ( ( lang . size / totalLanguageSize ) * 100 ) . toFixed ( 2 ) ,
149
+ index,
143
150
} ) ;
144
151
} ) ,
145
152
gap : 40 ,
@@ -187,7 +194,7 @@ const renderCompactLayout = (langs, width, totalLanguageSize) => {
187
194
188
195
return `
189
196
<mask id="rect-mask">
190
- <rect x="0" y="0" width="${ offsetWidth } " height="8" fill="white" rx="5" />
197
+ <rect x="0" y="0" width="${ offsetWidth } " height="8" fill="white" rx="5"/>
191
198
</mask>
192
199
${ compactProgressBar }
193
200
@@ -276,6 +283,7 @@ const renderTopLanguages = (topLangs, options = {}) => {
276
283
langs_count = DEFAULT_LANGS_COUNT ,
277
284
border_radius,
278
285
border_color,
286
+ disable_animations,
279
287
} = options ;
280
288
281
289
const i18n = new I18n ( {
@@ -324,11 +332,43 @@ const renderTopLanguages = (topLangs, options = {}) => {
324
332
colors,
325
333
} ) ;
326
334
327
- card . disableAnimations ( ) ;
335
+ if ( disable_animations ) card . disableAnimations ( ) ;
336
+
328
337
card . setHideBorder ( hide_border ) ;
329
338
card . setHideTitle ( hide_title ) ;
330
339
card . setCSS (
331
- `.lang-name { font: 400 11px 'Segoe UI', Ubuntu, Sans-Serif; fill: ${ colors . textColor } }` ,
340
+ `
341
+ @keyframes slideInAnimation {
342
+ from {
343
+ width: 0;
344
+ }
345
+ to {
346
+ width: calc(100%-100px);
347
+ }
348
+ }
349
+ @keyframes growWidthAnimation {
350
+ from {
351
+ width: 0;
352
+ }
353
+ to {
354
+ width: 100%;
355
+ }
356
+ }
357
+ .lang-name {
358
+ font: 400 11px "Segoe UI", Ubuntu, Sans-Serif;
359
+ fill: ${ colors . textColor } ;
360
+ }
361
+ .stagger {
362
+ opacity: 0;
363
+ animation: fadeInAnimation 0.3s ease-in-out forwards;
364
+ }
365
+ #rect-mask rect{
366
+ animation: slideInAnimation 1s ease-in-out forwards;
367
+ }
368
+ .lang-progress{
369
+ animation: growWidthAnimation 0.6s ease-in-out forwards;
370
+ }
371
+ ` ,
332
372
) ;
333
373
334
374
return card . render ( `
0 commit comments