Skip to content

Commit 0b9cd37

Browse files
committed
feat: add animations
1 parent c83633e commit 0b9cd37

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<div class="d3-chart-wrapper">
1+
<div class="d3-chart-wrapper" [@fadeInGrow]="chartState">
22
<svg #svgchart class="d3-chart"></svg>
33
</div>

projects/ngx-simple-charts/donut/src/lib/sc-donut-chart/sc-donut-chart.component.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,23 @@ import {
1818
Input,
1919
OnChanges,
2020
OnDestroy,
21-
OnInit,
2221
SimpleChanges,
2322
ViewChild,
2423
} from '@angular/core';
25-
import { BaseType, ContainerElement, select, Selection } from 'd3-selection';
24+
import {
25+
trigger,
26+
style,
27+
animate,
28+
transition,
29+
group,
30+
} from '@angular/animations';
31+
import { ContainerElement, select, Selection } from 'd3-selection';
2632
import { Subject, Subscription } from 'rxjs';
2733
import { ChartSlice, ChartSlices } from './model/chart-slices';
2834
import { debounceTime } from 'rxjs/operators';
2935
import 'd3-transition';
3036
import { scaleOrdinal } from 'd3-scale';
31-
import { interpolateSpectral, schemeSpectral } from 'd3-scale-chromatic';
37+
import { interpolateSpectral } from 'd3-scale-chromatic';
3238
import { arc, pie } from 'd3-shape';
3339
import { range } from 'd3-array';
3440

@@ -40,6 +46,17 @@ interface ResizeEvent {
4046
selector: 'sc-donut-chart',
4147
templateUrl: './sc-donut-chart.component.html',
4248
styleUrls: ['./sc-donut-chart.component.scss'],
49+
animations: [
50+
trigger('fadeInGrow', [
51+
transition('* => ready', [
52+
style({ opacity: 0, transform: 'scale(0.1)' }),
53+
group([
54+
animate('300ms linear', style({ opacity: 1 })),
55+
animate('1000ms linear', style({ transform: 'scale(1)' })),
56+
]),
57+
]),
58+
]),
59+
],
4360
})
4461
export class ScDonutChartComponent
4562
implements OnChanges, OnDestroy, AfterViewInit
@@ -51,6 +68,8 @@ export class ScDonutChartComponent
5168
private chartUpdateSubscription!: Subscription;
5269
@Input()
5370
chartSlices!: ChartSlices;
71+
@Input()
72+
chartState: 'ready' | 'not-ready' = 'not-ready';
5473

5574
constructor() {}
5675

0 commit comments

Comments
 (0)