RealtimeTraffic.js
2.63 KB
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
import React from 'react';
import {
Progress,
} from 'reactstrap';
import Rickshaw from 'rickshaw';
class RealtimeTraffic extends React.Component {
state = { graph: null }
constructor(prop) {
super(prop);
this.onResizeRickshaw = this.onResizeRickshaw.bind(this);
}
componentDidMount() {
this.initChart();
window.addEventListener('resize', this.onResizeRickshaw);
}
componentWillUnmount() {
window.removeEventListener('resize', this.onResizeRickshaw);
}
onResizeRickshaw() {
this.graph.configure({ height: 130 });
this.graph.render();
}
initChart() {
const seriesData = [[], []];
const random = new Rickshaw.Fixtures.RandomData(30);
for (let i = 0; i < 30; i += 1) {
random.addData(seriesData);
}
this.graph = new Rickshaw.Graph({
element: this.rickshawChart,
height: 130,
realtime: true,
series: [
{
color: '#343434', // 'gray-dark'
data: seriesData[0],
name: 'Uploads',
}, {
color: '#666', // gray,
data: seriesData[1],
name: 'Downloads',
},
],
});
const hoverDetail = new Rickshaw.Graph.HoverDetail({
graph: this.graph,
xFormatter: x => new Date(x * 1000).toString(),
});
hoverDetail.show();
setInterval(() => {
random.removeData(seriesData);
random.addData(seriesData);
this.graph.update();
}, 1000);
this.graph.render();
}
render() {
return (
<div>
<h4 className="mb-lg">Recent <span className="fw-semi-bold">Update</span></h4>
<h6>Node.js <span className="fw-semi-bold">4.0.1 distribution</span></h6>
<Progress className="bg-gray-lighter progress-xs" color="danger" value="77" />
<p className="mt-sm mb fs-mini ">
<small><span className="circle bg-warning text-gray-dark"><i
className="glyphicon glyphicon-chevron-up"
/></span></small>
<strong className="px-1">17% higher</strong>
than last month
</p>
<p className="fs-sm text-gray-lighter mb-0">Remaining hours</p>
<button className="btn btn-xs btn-gray pull-right ml-xs">
<i className="fa fa-compress" /> track
</button>
<button className="btn btn-xs btn-gray pull-right">
<i className="fa fa-pause" /> pause
</button>
<p className="value4">2h 56m</p>
<br />
<div
ref={(r) => {
this.rickshawChart = r;
}} className="text-gray-dark chart-overflow-bottom" style={{ height: '130px' }}
/>
</div>
);
}
}
export default RealtimeTraffic;