-
Notifications
You must be signed in to change notification settings - Fork 1
/
players-detail-leveling.ts
149 lines (124 loc) · 3.85 KB
/
players-detail-leveling.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import { Component, Input, ViewContainerRef } from '@angular/core'
import { Colors } from '../../components.common/colors'
const experience :any[] = require('./players-detail-leveling.json');
@Component({
selector: 'players-detail-leveling',
template: require('./players-detail-leveling.html'),
styles: [require('./players-detail-leveling.styl')]
})
export class PlayersDetailLeveling {
private _exp :number;
@Input() set exp (val :number) {
this._exp = val;
this.init();
};
get exp () { return this._exp; }
private _level :number;
@Input() set level (val :number) {
this._level = val;
this.init();
};
get level () { return this._level; }
private initer :any;
private _init () {
if (this.level >= 100) {
this.data = null;
return;
}
this.setData();
}
private init () {
clearTimeout(this.initer);
this.initer = setTimeout(this._init.bind(this), 10);
}
constructor (private view :ViewContainerRef) { }
private type = 'bar';
private experience = experience;
private options = {
maintainAspectRatio: false,
responsive: true,
responsiveAnimationDuration: 150,
scales: {
xAxes: [{
stacked: true,
gridLines: {
display: false,
zeroLineWidth: 0
},
ticks: {
fontColor: Colors['gray-4'].color
}
}],
yAxes: [{
gridLines: {
display: false
},
ticks: {
display: false
}
}]
},
legend: {
display: false
},
onClick: this.toggleMode.bind(this)
};
private data :any;
private fullMode :boolean = false;
private setData() {
let start = 0;
let data = experience;
let width = this.view.element.nativeElement.offsetWidth;
if (!this.fullMode) {
start = this.level - 2;
if (start < 0) {
start = 0;
}
let right = width < 400 ? 10 : 20;
data = data.slice(start, this.level + right);
}
let pos = this.level - start;
let exp = this.exp;
let playerPos = [];
playerPos[pos] = exp;
let nearest = data.slice().map(limit => exp > limit ? limit : exp);
let labelLimit = width < 400 ? 50 : width < 600 ? 25 : 10;
let labels = this.fullMode ?
data.map((val, i) => {
let label = start + i + 1;
return (label === 1 || !(label % labelLimit)) ? label : ' ';
}) :
data.map((val, i) => start + i + 1);
this.data = {
datasets: [
{
data: playerPos,
label: 'Player level',
borderColor: Colors['transparent'],
borderWidth: 3,
backgroundColor: Colors['sun-flower'].color
},
{
data: nearest,
label: 'Player level',
borderColor: Colors['transparent'],
borderWidth: 3,
backgroundColor: Colors['sun-flower'].soft
},
{
data: data,
label: 'Exp',
borderColor: Colors['turquoise'].color,
borderWidth: 1,
backgroundColor: Colors['turquoise'].backgroundColor,
}
],
labels: labels
};
}
private toggleMode() {
this.fullMode = !this.fullMode;
this.setData();
}
}
export default PlayersDetailLeveling