-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathd3.html
More file actions
89 lines (68 loc) · 2.07 KB
/
d3.html
File metadata and controls
89 lines (68 loc) · 2.07 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Emerging tech</title>
<style type="text/css">
body{font-family: sans-serif;} label{display:block;}
path {
stroke: #08f;
fill: none;
stroke-width: 2;
}
</style>
</head>
<body>
<script src="bower_components/pubnub/web/pubnub.min.js"></script>
<script src="bower_components/d3/d3.min.js"></script>
<script type="text/javascript">
var byId = document.getElementById.bind(document);
var pubnub = PUBNUB.init({
subscribe_key: 'sub-c-9c92c072-698f-11e4-97dd-02ee2ddab7fe',
publish_key: 'pub-c-10a63f9f-359c-472b-a6ba-d55766a60e69'
});
var width = 300,
height = 200;
var x = d3.time.scale()
.range([0, width]);
var y = d3.scale.linear()
.range([height, 0]);
var line = d3.svg.line()
.x(function(d) { return x(d.time); })
.y(function(d) { return y(d.value); });
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
var path = svg.append("path");
var data = {}
// write the messages into the pre divs
pubnub.subscribe({
channel: 'outbound,network_def',
backfill: true,
callback: function(message, _stuff, channel){
if(channel == 'outbound'){
if(message.node && message.payload && message.node == 'e884'){
var value = parseInt(message.payload.substr(0,4),16),
points = (data[message.node] = data[message.node] || []);
console.log(value)
points.push({
time: + new Date,
value: value
})
while(points.length > 50){
points.shift()
}
x.domain(d3.extent(points, function(d) { return d.time; }));
y.domain(d3.extent(points, function(d) { return d.value; }));
path.attr("d", line(points));
}
// data.message[mess]
}
// var element = byId(channel);
// if(element)
// element.innerText = JSON.stringify(message, null, 2);
}
});
</script>
</body>
</html>