-
Notifications
You must be signed in to change notification settings - Fork 15
/
aggregatedMiners.js
81 lines (70 loc) · 2.28 KB
/
aggregatedMiners.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
'use strict';
var Rickshaw = require('rickshaw'),
_ = require('lodash'),
timeHelper = require('../handlebars/helpers/time'),
hashrateHelper = require('../handlebars/helpers/hashrate'),
View = require('../View');
module.exports = View.extend({
template: 'aggregatedMiners',
graph: null,
getChartData: function () {
return this.module.get('historicalData').map(function (measurement) {
return {
x: (measurement.timestamp / 1000),
y: measurement.currentHashrate
};
});
},
initializeGraph: function () {
this.graph = new Rickshaw.Graph({
element: this.$('.graph')[0],
height: 120,
renderer: 'area',
interpolation: 'linear',
stroke: true,
series: [
{
color: '#cae2f7',
name: 'Total Hashrate',
data: this.getChartData()
}
]
});
this.detail = new Rickshaw.Graph.HoverDetail({
graph: this.graph,
yFormatter: function (value) {
return hashrateHelper(value);
},
xFormatter: function (value) {
return timeHelper(value * 1000);
}
});
this.xAxis = new Rickshaw.Graph.Axis.Time({
graph: this.graph
});
this.yAxis = new Rickshaw.Graph.Axis.Y({
graph: this.graph
});
},
updateGraph: function () {
var chartData = this.getChartData();
this.graph.min = _(chartData).pluck('y').min().value() * 0.99;
this.graph.max = _(chartData).pluck('y').max().value() * 1.01;
this.graph.series[0].data = this.getChartData();
this.xAxis.render();
this.yAxis.render();
this.graph.update();
},
postRender: function () {
var graphElement = this.$('.graph'),
graphShouldBeRendered = graphElement.length > 0 && this.module.get('historicalData');
if (graphShouldBeRendered) {
if (this.graph) {
graphElement.replaceWith(this.graph.element);
} else {
this.initializeGraph();
}
this.updateGraph();
}
}
});