-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEtaSource.js
67 lines (52 loc) · 1.48 KB
/
EtaSource.js
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
import moment from 'moment';
import { massAveEta } from './mbta';
import CanvasSource from './CanvasSource';
export default class EtaSource extends CanvasSource {
timeString(date) {
const seconds = moment(date).diff(moment(), 'seconds');
if (seconds <= 0) {
return 'Arriving';
} else if (seconds < 60) {
return seconds + ' s';
}
return Math.floor(seconds / 60) + ' min';
}
etaText(predictions) {
if (predictions && predictions.length) {
let text = '';
for (var i = 0; i < 2 && i < predictions.length; i++) {
if (text.length) text += ', ';
text += this.timeString(predictions[i]);
}
return text;
}
// If there are no predictions show nothing
return '';
}
lineOne() {
return 'Oak Grove';
}
lineTwo() {
return this.etaText(massAveEta.oakGrove);
}
lineThree() {
return 'Forest Hills';
}
lineFour() {
return this.etaText(massAveEta.forestHills);
}
render() {
this.context.fillStyle = '#fc8b00';
this.context.textAlign = 'left';
this.context.fillText(this.lineOne(), 0, 12);
this.context.fillStyle = '#00B157';
this.context.textAlign = 'right';
this.context.fillText(this.lineTwo(), 64, 20);
this.context.fillStyle = '#fc8b00';
this.context.textAlign = 'left';
this.context.fillText(this.lineThree(), 0, 28);
this.context.fillStyle = '#00B157';
this.context.textAlign = 'right';
this.context.fillText(this.lineFour(), 64, 36);
}
}