-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMMM-RescueTime.js
95 lines (90 loc) · 2.36 KB
/
MMM-RescueTime.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
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
/* global Module, window, Log */
Module.register("MMM-RescueTime", {
defaults: {
interval: 60,
pointBackgroundColor: "#fff",
borderColor: "rgba(255,255,255,0.5)",
backgroundColor: "rgba(255,255,255,0.2)",
angleLinesColor: "rgba(255,255,255,0.2)",
gridLinesColor: "rgba(255,255,255,0.2)",
},
// Override socket notification handler.
socketNotificationReceived: function(notification, payload) {
if (notification === "TODAY") {
Log.info("Got rescuetime today data: " + this.name);
this.today = payload;
this.initialLoaded = true;
this.updateDom(3000);
}
},
start: function() {
var self = this;
self.today = {
labels: [],
dataSet: [],
};
self.initialLoaded = false;
self.sendSocketNotification("CONFIG", self.config);
Log.info("Starting module: " + self.name);
var seconds = self.config.interval * 1000;
Log.info("RescueTime fetches every " + seconds + "seconds");
window.setInterval(function() {
self.sendSocketNotification("GET_TODAY");
}, seconds);
},
getScripts: function() {
return [this.file("node_modules/chart.js/dist/Chart.bundle.min.js")];
},
getDom: function() {
let labels = this.today.labels;
let dataSet = this.today.dataSet;
let wrapper = document.createElement("div");
let info = document.createElement("h1");
info.style.fontSize = ".8em";
info.style.fontWeight = "lighter";
if(!this.initialLoaded) {
info.innerHTML = "Loading...";
wrapper.appendChild(info);
return wrapper;
}
if(this.initialLoaded && (labels.length === 0 || dataSet.length === 0)) {
info.innerHTML = "No data available yet";
wrapper.appendChild(info);
return wrapper;
}
let ctx = document.createElement("canvas");
wrapper.appendChild(ctx);
let data = {
labels: labels,
datasets: [
{
pointBackgroundColor: this.config.pointBackgroundColor,
borderColor: this.config.borderColor,
backgroundColor: this.config.backgroundColor,
data: dataSet,
},
],
};
new Chart(ctx, {
type: "radar",
data: data,
options: {
legend: {
display: false,
},
scale: {
angleLines: {color: this.config.angleLinesColor},
gridLines: {color: this.config.gridLinesColor},
ticks: {
backdropColor: "black",
fontSize: 15,
backdropPaddingX: 5,
backdropPaddingY: 5,
fontColor: "#fff",
},
},
},
});
return wrapper;
},
});