@@ -336,7 +336,7 @@ const OTHER_NAME = 'other';
336
336
const OTHER_COLOR = '#444444';
337
337
const bgcolor = '#ffffff';
338
338
const fgcolor = '#00000f';
339
- const createPieLanguage = (svg, userInfo, x, y, width, height) => {
339
+ const createPieLanguage = (svg, userInfo, x, y, width, height, isAnimate ) => {
340
340
if (userInfo.totalContributions === 0) {
341
341
return;
342
342
}
@@ -352,6 +352,11 @@ const createPieLanguage = (svg, userInfo, x, y, width, height) => {
352
352
contributions: otherContributions,
353
353
});
354
354
}
355
+ const animeSteps = 5;
356
+ const animateOpacity = (num) => Array(languages.length + animeSteps)
357
+ .fill('')
358
+ .map((d, i) => (i < num ? 0 : Math.min((i - num) / animeSteps, 1)))
359
+ .join(';');
355
360
const radius = height / 2;
356
361
const margin = radius / 10;
357
362
const row = 8;
@@ -367,7 +372,7 @@ const createPieLanguage = (svg, userInfo, x, y, width, height) => {
367
372
.append('g')
368
373
.attr('transform', `translate(${radius * 2.1}, ${0})`);
369
374
// markers for label
370
- groupLabel
375
+ const markers = groupLabel
371
376
.selectAll(null)
372
377
.data(pieData)
373
378
.enter()
@@ -379,8 +384,16 @@ const createPieLanguage = (svg, userInfo, x, y, width, height) => {
379
384
.attr('fill', (d) => d.data.color)
380
385
.attr('stroke', bgcolor)
381
386
.attr('stroke-width', '1px');
387
+ if (isAnimate) {
388
+ markers
389
+ .append('animate')
390
+ .attr('attributeName', 'fill-opacity')
391
+ .attr('values', (d, i) => animateOpacity(i))
392
+ .attr('dur', '3s')
393
+ .attr('repeatCount', '1');
394
+ }
382
395
// labels
383
- groupLabel
396
+ const labels = groupLabel
384
397
.selectAll(null)
385
398
.data(pieData)
386
399
.enter()
@@ -391,12 +404,20 @@ const createPieLanguage = (svg, userInfo, x, y, width, height) => {
391
404
.attr('y', (d) => (d.index + offset) * (height / row))
392
405
.attr('fill', fgcolor)
393
406
.attr('font-size', `${fontSize}px`);
407
+ if (isAnimate) {
408
+ labels
409
+ .append('animate')
410
+ .attr('attributeName', 'fill-opacity')
411
+ .attr('values', (d, i) => animateOpacity(i))
412
+ .attr('dur', '3s')
413
+ .attr('repeatCount', '1');
414
+ }
394
415
const arc = d3
395
416
.arc()
396
417
.outerRadius(radius - margin)
397
418
.innerRadius(radius / 2);
398
419
// pie chart
399
- group
420
+ const paths = group
400
421
.append('g')
401
422
.attr('transform', `translate(${radius}, ${radius})`)
402
423
.selectAll(null)
@@ -406,9 +427,18 @@ const createPieLanguage = (svg, userInfo, x, y, width, height) => {
406
427
.attr('d', arc)
407
428
.style('fill', (d) => d.data.color)
408
429
.attr('stroke', bgcolor)
409
- .attr('stroke-width', '2px')
430
+ .attr('stroke-width', '2px');
431
+ paths
410
432
.append('title')
411
433
.text((d) => `${d.data.language} ${d.data.contributions}`);
434
+ if (isAnimate) {
435
+ paths
436
+ .append('animate')
437
+ .attr('attributeName', 'fill-opacity')
438
+ .attr('values', (d, i) => animateOpacity(i))
439
+ .attr('dur', '3s')
440
+ .attr('repeatCount', '1');
441
+ }
412
442
};
413
443
exports.createPieLanguage = createPieLanguage;
414
444
//# sourceMappingURL=create-pie-language.js.map
@@ -605,7 +635,7 @@ const createSvg = (userInfo, seasonMode, isAnimate) => {
605
635
// pie chart
606
636
const pieHeight = 200 * 1.3;
607
637
const pieWidth = pieHeight * 2;
608
- pie.createPieLanguage(svg, userInfo, 40, height - pieHeight - 70, pieWidth, pieHeight);
638
+ pie.createPieLanguage(svg, userInfo, 40, height - pieHeight - 70, pieWidth, pieHeight, isAnimate );
609
639
const group = svg.append('g');
610
640
const positionXContrib = (width * 3) / 10;
611
641
const positionYContrib = height - 20;
0 commit comments