-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
175 lines (144 loc) · 4.19 KB
/
index.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Nest Thermostat history</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../../excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="javascript/jquery.js"></script>
<script language="javascript" type="text/javascript" src="javascript/jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="javascript/jquery.flot.time.js"></script>
<script language="javascript" type="text/javascript" src="javascript/jquery.flot.selection.js"></script>
<script type="text/javascript">
$.getJSON("json.php", function(data){
// create empty arrays for different data color sets
var data1 = [];
var data2 = [];
var data3 = [];
var data4 = [];
// start counting
var j = 0;
// loop through JSON array, push results to empty array
$.each(data, function (timestamp, input) {
var newval = [timestamp, input['value']];
if (input['color'] == "red") {
data1[j] = newval;
} else if (input['color'] == "green") {
data2[j] = newval;
} else if (input['color'] == "blue") {
data3[j] = newval;
} else {
data4[j] = newval;
}
j++;
});
$(function() {
// helper for returning the weekends in a period
function weekendAreas(axes) {
var markings = [],
d = new Date(axes.xaxis.min);
// go to the first Saturday
d.setUTCDate(d.getUTCDate() - ((d.getUTCDay() + 1) % 7))
d.setUTCSeconds(0);
d.setUTCMinutes(0);
d.setUTCHours(0);
var i = d.getTime();
// when we don't set yaxis, the rectangle automatically
// extends to infinity upwards and downwards
do {
markings.push({ xaxis: { from: i, to: i + 2 * 24 * 60 * 60 * 1000 } });
i += 7 * 24 * 60 * 60 * 1000;
} while (i < axes.xaxis.max);
return markings;
}
var options = {
series: {
bars: {
show: true,
barWidth: 300000,
align: "center",
fill: true,
lineWidth: 0,
fillColor: { colors: [{ opacity: 1.0 }, { opacity: 0.7}] }
},
shadowSize: 0
},
xaxis: {
mode: "time",
tickLength: 5
},
yaxis: {
min: 14
},
selection: {
mode: "x"
},
grid: {
markings: weekendAreas
},
colors: ["#CB4B4B", "#4DA74D", "#AFD8F8", "#EDC240"]
};
var plot = $.plot("#placeholder", [{ data: data1 }, { data: data2 }, { data: data3 }, { data: data4 }], options);
var overview = $.plot("#overview", [{ data: data1 }, { data: data2 }, { data: data3 }, { data: data4 }], {
series: {
lines: {
show: true,
lineWidth: 1,
fill: true,
fillColor: { colors: [ { opacity: 0.8 }, { opacity: 0.1 } ] }
},
shadowSize: 0
},
xaxis: {
ticks: [],
mode: "time"
},
yaxis: {
ticks: [],
min: 10,
autoscaleMargin: 0.4
},
selection: {
mode: "x"
},
colors: ["#CB4B4B", "#4DA74D", "#AFD8F8", "#EDC240"]
});
// now connect the two
$("#placeholder").bind("plotselected", function (event, ranges) {
// do the zooming
$.each(plot.getXAxes(), function(_, axis) {
var opts = axis.options;
opts.min = ranges.xaxis.from;
opts.max = ranges.xaxis.to;
});
plot.setupGrid();
plot.draw();
plot.clearSelection();
// don't fire event on the overview to prevent eternal loop
overview.setSelection(ranges, true);
});
$("#overview").bind("plotselected", function (event, ranges) {
plot.setSelection(ranges);
});
});
});
</script>
</head>
<body>
<div id="header">
<h2>Nest thermostat temperature history</h2>
</div>
<div id="content">
<div class="demo-container">
<div id="placeholder" class="demo-placeholder"></div>
</div>
<div class="demo-container" style="height:150px;">
<div id="overview" class="demo-placeholder"></div>
</div>
<p>This plot shows the nest thermostat temperature history.</p>
</div>
<div id="footer">
Copyright © 2014 Piethein Strengholt
</div>
</body>
</html>