Skip to content

Commit ec5deaf

Browse files
committed
chore(demo): progress chart
1 parent 549fa83 commit ec5deaf

File tree

11 files changed

+937
-125
lines changed

11 files changed

+937
-125
lines changed

package-lock.json

Lines changed: 618 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"@ngtools/webpack": "^1.6.0",
4242
"@types/body-parser": "^1.16.4",
4343
"@types/cors": "^2.8.1",
44+
"@types/d3": "^4.10.1",
4445
"@types/express": "^4.0.36",
4546
"@types/jasmine": "^2.5.53",
4647
"@types/multer": "^1.3.2",
@@ -53,6 +54,7 @@
5354
"core-js": "^2.5.0",
5455
"cors": "^2.8.4",
5556
"css-loader": "^0.28.4",
57+
"d3": "^4.10.2",
5658
"express": "^4.15.4",
5759
"extract-text-webpack-plugin": "^3.0.0",
5860
"file-loader": "^0.11.2",
@@ -79,6 +81,7 @@
7981
"style-loader": "^0.18.2",
8082
"to-string-loader": "^1.1.5",
8183
"ts-node": "^3.3.0",
84+
"tslint": "^5.7.0",
8285
"typescript": "^2.4.2",
8386
"webpack": "^3.5.4",
8487
"webpack-dev-server": "^2.7.1",

src/app.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { FormsModule } from '@angular/forms';
55
import { NgUploaderModule } from './ngx-uploader/module/ngx-uploader.module';
66
import { AppComponent } from './app.component';
77
import { AppHomeComponent } from './components/app-home';
8+
import { AppProgressChartComponent } from './components/app-progress-chart';
89

910
@NgModule({
1011
imports: [
@@ -16,7 +17,7 @@ import { AppHomeComponent } from './components/app-home';
1617
providers: [
1718
{ provide: APP_BASE_HREF, useValue: '/' }
1819
],
19-
declarations: [ AppComponent, AppHomeComponent ],
20+
declarations: [ AppComponent, AppHomeComponent, AppProgressChartComponent ],
2021
bootstrap: [ AppComponent ]
2122
})
2223
export class AppModule {}

src/assets/public/images/document.svg

Lines changed: 23 additions & 0 deletions
Loading

src/components/app-home/app-home.component.html

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
<div class="hero is-fullheight">
2+
<div class="hero-body">
3+
<div class="container">
4+
<div class="columns">
5+
<div class="column is-12">
6+
<div class="browser-window">
7+
<div class="browser-topbar">
8+
<span class="dot red"></span>
9+
<span class="dot yellow"></span>
10+
<span class="dot green"></span>
11+
<span class="browser-title">
12+
http://ngx-uploader.com
13+
</span>
14+
</div>
15+
<div class="browser-container">
16+
<app-progress-chart [percent]="'20'"></app-progress-chart>
17+
</div>
18+
</div>
19+
</div>
20+
</div>
21+
</div>
22+
</div>
23+
</div>
24+
25+
<!-- <div class="hero is-fullheight">
226
<div class="hero-body">
327
<div class="container">
428
<div class="columns">
@@ -38,4 +62,6 @@ <h1>Drag & Drop</h1>
3862
</div>
3963
</div>
4064
</div>
41-
</div>
65+
</div> -->
66+
67+

src/components/app-home/app-home.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class AppHomeComponent {
1818
humanizeBytes: Function;
1919
dragOver: boolean;
2020
options: UploaderOptions;
21+
percent: number;
2122

2223
constructor() {
2324
this.options = { concurrency: 1 };
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="progress-chart">
2+
<img src="images/document.svg">
3+
</div>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { Component, Input, ElementRef, OnChanges, SimpleChanges } from '@angular/core';
2+
import { pie, select, arc, interpolate, easeCubic } from 'd3';
3+
4+
@Component({
5+
selector: 'app-progress-chart',
6+
templateUrl: 'app-progress-chart.component.html'
7+
})
8+
export class AppProgressChartComponent implements OnChanges {
9+
@Input() percent: number;
10+
11+
el: HTMLElement;
12+
ratio: number;
13+
line: any;
14+
chart: any;
15+
16+
constructor(private elementRef: ElementRef) { }
17+
18+
ngOnChanges(changes: SimpleChanges) {
19+
if (!this.el) {
20+
this.el = this.elementRef.nativeElement.querySelector('.progress-chart');
21+
this.render();
22+
}
23+
24+
this.ratio = this.percent / 100;
25+
this.animate();
26+
}
27+
28+
render(): void {
29+
const w = 230;
30+
const h = 230;
31+
32+
const outerRadius = w / 2;
33+
const innerRadius = 105;
34+
35+
const svg = select(this.el)
36+
.append('svg')
37+
.attr('width', w)
38+
.attr('height', h);
39+
40+
const g = svg.append('g')
41+
.attr('transform', `translate(${w / 2}, ${(h / 2)})`);
42+
43+
const a = arc()
44+
.innerRadius(innerRadius)
45+
.outerRadius(outerRadius)
46+
.startAngle(0)
47+
.endAngle(2 * Math.PI);
48+
49+
this.line = arc()
50+
.innerRadius(innerRadius)
51+
.outerRadius(outerRadius)
52+
.startAngle(0);
53+
54+
this.chart = g.append('path')
55+
.datum({ endAngle: 0 })
56+
.attr('d', this.line)
57+
.attr('fill', '#4083FF');
58+
}
59+
60+
arcTween = (transition: any, newAngle: number) => {
61+
transition.attrTween('d', d => {
62+
const ipolate = interpolate(d.endAngle, newAngle);
63+
64+
return (t) => {
65+
d.endAngle = ipolate(t);
66+
return this.line(d);
67+
};
68+
});
69+
}
70+
71+
animate(): void {
72+
this.chart.transition()
73+
.duration(500)
74+
.ease(easeCubic)
75+
.call(this.arcTween, ((2 * Math.PI) * this.ratio))
76+
}
77+
78+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './app-progress-chart.component';

src/ngx-uploader/classes/ngx-uploader.class.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ import { EventEmitter } from '@angular/core';
22
import { Observable } from 'rxjs/Observable';
33
import { Subject } from 'rxjs/Subject';
44
import { Subscription } from 'rxjs/Subscription';
5-
import { Subscriber } from 'rxjs/Subscriber';
6-
import 'rxjs/add/observable/of';
7-
import 'rxjs/add/observable/from';
85
import 'rxjs/add/operator/mergeMap';
9-
import 'rxjs/add/operator/map';
106

117
export interface BlobFile extends Blob {
128
name: string;

0 commit comments

Comments
 (0)