This repository has been archived by the owner on Oct 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mhvVersion1.html
153 lines (133 loc) · 4.52 KB
/
mhvVersion1.html
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<html>
<head>
<script type="text/javascript" src="lib/jquery/jquery-1.5.2.js"></script>
<script type="text/javascript" src="lib/jquery-jtwitter/jquery.jtwitter.js"></script>
<script type="text/javascript" src="../d3/d3.js"></script>
<script type="text/javascript" src="../d3/d3.time.js"></script>
<style type="text/css">
#chart {
width: 640px;
height: 320px;
border: 1px solid lightgray;
font-size: 12px;
}
#chart .bar {
fill: steelblue;
}
#chart .xaxis {
stroke: black;
}
</style>
<script type="text/javascript">
// var createdAtFormat = d3.time.format("%a %b %d %H:%M:%S %Z %Y");
var outputFormat = d3.time.format("%Y %m %d %H:%M:%S");
var newData = new Array();
$(document).ready(function(){
// Get latest 6 tweets by jQueryHowto
$.jTwitter('makehackvoid', 400, function(data){
$('#posts').empty();
$.each(data, function(i, post){
// possible matches (~hh:mm) is the estimated closing time
// note, all time estimates in brackets seem to be rounded to nearest 15 minutes
// The MHV space will remain open for approximately another xxxx hours (~hh:mm)
// The MHV space will remain open for approximately another nn minutes (~18:15)
// The MHV space is now open for approximately xxxx hours (~hh:mm)
// The MHV space is now open for approximately an hour (~hh:mm)
// The MHV space is now closed (was open 4 1/2 hours)
// The MHV space is now closed (was open nnn minutes)
// The MHV space is now closed (was open xxxx hours)
// post.created_at have the format "Fri Aug 12 23:38:49 +0000 2011"
// only look at tweets that say they came from the Space Probe
if (post.source.indexOf("MHV Space Probe") != -1 ) {
// if (post.text.indexOf("is now open") != -1) {
var tweetDate = new Date(post.created_at);
textDate = outputFormat(tweetDate);
$('#posts').append(
'<div class="post">'
+' <div class="date">'
+ tweetDate
+' </div>'
+'<div class="txt">'
+ post.text
+' </div>'
+'</div>'
);
newData.push(tweetDate);
// }
}
});
// alert(newData[0].getMinutes());
drawGraph(newData);
});
});
function drawGraph(data) {
// function to draw the graph
var w = 640,
h = 320;
var x = d3.scale.linear()
// .domain([0, data.length])
.domain([1, 7])
.range([0, w]);
var y = d3.scale.linear()
.domain([0, 24.0])
.rangeRound([h, 0]);
var chart = d3.select("body")
.append("svg:svg")
.attr("class", "chart")
.attr("width", w+30)
.attr("height", h+20)
.append("svg:g")
.attr("transform", "translate(15,15)");
var circle = chart.selectAll("circle")
.data(data);
// I think that "24:00" might be at the bottom of the graph, not the top
// trying to get the circles to have their hour in them so I can see what is going on.
circle.enter().append("svg:circle")
.attr("cy", function(d) { return y((d.getHours() + (d.getMinutes()/60.0))); })
.attr("cx", function(d) { return x(d.getDay()+1); })
.attr("r", 15)
.style("fill", "steelblue");
chart.selectAll("text").
data(data)
.enter().append("svg:text")
.attr("x", function(d) { return x(d.getDay()+1); })
.attr("y", function(d) { return y((d.getHours() + (d.getMinutes()/60.0))); })
.attr("dy", 3)
.attr("text-anchor", "middle")
.text(function(d) { return d.getHours() + ":" + d.getMinutes();})
.attr("style", "font-size: 10; font-family: Helvetica, sans-serif")
.attr("fill", "white");
// getDay() gives day of week from 0 to 6
circle.exit().remove();
chart.selectAll("line")
.data(x.ticks(7))
.enter().append("svg:line")
.attr("x1", x)
.attr("x2", x)
.attr("y1", 0)
.attr("y2", h)
.attr("stroke", "#ccc");
chart.selectAll("text.rule")
.data(['sun','mon','tue','wed','thu','fri','sat'])
.enter().append("svg:text")
.attr("class", "rule")
.attr("x", function(d,i) { return x(i+1); })
.attr("y", 0)
.attr("dy", -3)
.attr("text-anchor", "middle")
.text(String);
chart.append("svg:line")
.attr("x1", 0)
.attr("x2", w)
.attr("y1", h)
.attr("y2", h)
.attr("stroke", "#000");
}
</script>
</head>
<body>
<h1>jQuery Howto's Tweets</h1>
<div id="posts">Getting your tweets...</div>
<div id="junk"> </div>
</body>
</html>