-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphit.html
216 lines (210 loc) · 5.64 KB
/
graphit.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<html>
<head>
<title> graph it</title>
<script src="RGraph/libraries/RGraph.common.js" ></script>
<script src="RGraph/libraries/RGraph.hbar.js" ></script>
<script src="RGraph/libraries/RGraph.line.js" ></script>
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/db.js"></script>
<script type="text/javascript" src="js/lib.js"></script>
<script src="js/graphit.js"></script>
<style type="text/css">
body {
position:absolute;
top:0px;
left:0px;
width:100%;
height:100%;
margin:0px;
}
#hourScroll {
background-color:#CCC;
margin-right:100px;
margin-left:200px;
}
#hourScrollWrapper {
border:1px;
border-color:#000;
}
#maindiv {
text-align:center;
}
</style>
</head>
<body>
<div id="maindiv" style="display:none;">
<h3>Detailed view</h3>
<p>not yet implemented. This is going to have multiple graphs with different views in the future</p>
<a href="javascript:setGraphRange('today');">today</a>|
<a href="javascript:setGraphRange('past7days');">past 7 days</a>|
<a href="javascript:setGraphRange('overall');">overall</a>
<div id="error" class="error"></div>
<canvas id="usage" width="800" height="450"></canvas>
<br>
<button onclick="chrome.tabs.create ({'url':'option.html'});">Options</button>
<!--awesome scroll bar
<div id="hourScrollWrapper">
<canvas id="hourScroll" width="500px" height="15px" ></canvas>
-->
</div>
<div id="disabled">
AnalyseMe has been disabled...
<br>
Turn AnalyseMe on at the <button onclick="chrome.tabs.create ({'url':'option.html'});">Options</button> page.
</div>
<script>
var setGraphRange = function(rangeType) {
localStorage['graphtype'] = rangeType;
graphit();
}
/*
* n - past n days
* title - title of the graph
*/
function graphPastNDays(n, title) {
var errdiv = $('#error');
DB.fetchPastNDays(n,10,
function (dbdata) { //succeed
var graphdata = Lib.makeGraphable(dbdata);
var param = {"title":title, "names":graphdata['host'], "values":graphdata['count']};
errdiv.html("");
Graphit.bargraph(param, 'usage',
function(message) { //error graphing
console.log(message);
errdiv.html(message);
});
},
function (err_message) { //error
$('error').html(err_message);
console.error(err_message);
}
);
}
var graphit = function () {
if (localStorage['enable'] == 1) {
$("#maindiv").slideDown();
$("#disabled").slideUp(0);
var errdiv = $('#error');
if(localStorage['graphtype'] == 'past7days') {
graphPastNDays(7, "Top 10 in last 7 days (in minutes)");
} else if(localStorage['graphtype'] == 'today') {
graphPastNDays(1, "Top 10 today (in minutes)");
} else {
DB.fetchBest(10,
function(data) {//succeed
if(data['hosts'].length == 0) {
errdiv.html("no data for this yet");
}
var param = {"title":"Top 10 ovarall (in minutes)", "names":data['hosts'], "values":data['counts']};
Graphit.bargraph(param, 'usage',
function(message) {
console.log(message);
errdiv.html(message);
});
},
function (err_message) { //error
$('error').html(err_message);
console.error(err_message);
}
);
}
} else {
$("#maindiv").slideUp();
$("#disabled").slideDown();
}
}
window.onload = graphit;
window.setInterval("graphit()", 10000);
//var bar = {};
//var line = {};
/*
//awesome scroll bar
var hourData;
var animateScrollBar = null;
window.onload = function () {
DB.fetchBest(10, function (data) {
graphit (data.hosts,[data.counts]);
});
DB.fetchPerHour(null, function(data) {
hourData = data;
var canvas = $('#hourScroll')[0];
var ctx = canvas.getContext("2d");
var drag = false;
var clearFillStyle = '#ccc';
//x,y,width,height
var scrollBar = {};
scrollBar.rect = [0,0,40,15];
scrollBar.fillStyle = '#aaa';
scrollBar.velocity = 1;
scrollBar.target = [0,0,40,15];
scrollBar.lineWidth = 1;
var moveInterval = null
function renderScrollBar() {
//bar background
ctx.lineWidth = scrollBar.lineWidth;
ctx.fillStyle = clearFillStyle;
ctx.fillRect(0, 0, canvas.width, canvas.height);
//day dividers
ctx.fillStyle = '#000';
ctx.beginPath();
for (var i = 1; i < 7; i++) {
ctx.moveTo(i*canvas.width/7, 0);
ctx.lineTo(i*canvas.width/7, canvas.height);
}
ctx.stroke();
ctx.closePath();
ctx.fillStyle = scrollBar.fillStyle;
ctx.fillRect(scrollBar.rect[0], scrollBar.rect[1], scrollBar.rect[2], scrollBar.rect[3]);
}
function setTarget(pos) {
scrollBar.target[0] = pos - scrollBar.target[2]/2;
if(scrollBar.target[0] < 0) {
scrollBar.target[0] = 0;
}
if(scrollBar.target[0] + scrollBar.target[2] > canvas.width) {
scrollBar.target[0] = canvas.width - scrollBar.target[2];
}
}
animateScrollBar = function() {
var diff = scrollBar.target[0] - scrollBar.rect[0];
if (diff != 0) {
var step = diff/3;
scrollBar.rect[0] += step;
if(scrollBar.rect[0] < 0) {
scrollBar.rect[0] = 0;
}
if(scrollBar.rect[0] + scrollBar.rect[2] > canvas.width) {
scrollBar.rect[0] = canvas.width - scrollBar.rect[2];
}
renderScrollBar();
} else {
if(moveInterval) {
clearInterval(moveInterval);
}
}
}
$('#hourScroll').mousemove(function(e) {
//e.pageY, e.clientY
if(drag) {
//TODO check if it's within the rec region
setTarget(e.offsetX);
}
});
$('#hourScroll').mousedown(function(e) {
setTarget(e.offsetX);
moveInterval = setInterval('animateScrollBar()', 50);
drag = true;
});
$('body').mouseup(function(e) {
if(moveInterval) {
clearInterval(moveInterval);
}
drag = false;
});
});
window.setInterval ('DB.fetchBest(10, function (data) {graphit (data.hosts,[data.counts]);});',10000);
}
*/
</script>
</body>
</html>