-
Notifications
You must be signed in to change notification settings - Fork 0
/
starsValoration.ts
45 lines (43 loc) · 1.33 KB
/
starsValoration.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Component, Input } from "@angular/core";
@Component({
selector: "stars-valoration",
templateUrl : "starsValoration.html",
})
export class StarsValorationComponent {
@Input() valoration: number = Math.floor(Math.random() * 100);
@Input() starsNumber: number = 5;
@Input() starSize: number = 20;
@Input() color: string = "#ffaf1d";
@Input() fontSize: string = "25px";
stars: Array<string> = [];
constructor() {
}
ngOnInit() {
this.printStars(this.starsNumber, this.starSize);
}
printStars(starsNumber, starSize) {
let start = 1;
let end = starSize;
let valoration = this.valoration + 1;
if (starSize <= 1) {
valoration = this.valoration;
}
let initStar = 0;
for (let idx = 1; idx <= starsNumber ; idx++) {
let finishStar = idx * end;
if (starSize <= 1) {
initStar = finishStar - (starSize - 0.001);
} else {
initStar = finishStar - (starSize - 1);
}
let middleStar = finishStar - (starSize / 2);
if (valoration >= finishStar) {
this.stars.push("md-star");
} else if ((valoration >= initStar && valoration < middleStar) || (valoration < initStar)) {
this.stars.push("md-star-outline");
} else if (valoration >= middleStar && valoration < finishStar) {
this.stars.push("md-star-half");
}
}
}
}