-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_renderer.js
80 lines (61 loc) · 2.48 KB
/
example_renderer.js
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
// jQuery, Underscore and strftime are already included and available
// Sequentially load the needed scripts
/*_KIWI.loadScript('/renderer/punchcard/raphael-min.js', function(){
console.log('loadScript() raphael loaded');
});
// CSS for tooltips
_KIWI.loadStylesheet('example_renderer.css', function(){
console.log('loadStylesheet() delorean CSS loaded');
});
// INPUT:
// kiwiData = {
// rows : [ { id:'timestamp', type: 'unix_utc_timestamp' }, { id: 'kiwis', type: 'number' }, { id: 'apples', type: 'number' }, ... ]
// cols : [ [123324324, 4, 54, ... ], [123324325, 10, 43, ...] ]
// kiwi_options : { title: 'Shiny little chart' }
// }
// OUTPUT is the same as INPUT for punchcard:
*/
// called with JSONP when kiwiData returns from _KIWI.getData()
rendererParseData = function(kiwiData) { console.log('punchcard_renderer.js:parseData(kiwiData)')
var names=[],
data=[],
ordered_data=[];
_.each(kiwiData.cols,function(num){ names.push(num.id); });
_.each(kiwiData.rows,function(num){ data.push(num); });
for(var i=0 ; i<names.length ; i++){
ordered_data.push(new Array());
_.each(data,function(num){ ordered_data[i].push(num[i]); });
}
for(var i=1 ; i<names.length ; i++){
document.write(names[i] + ":");
document.write(" Max: " + _.max(ordered_data[i]));
document.write(" Min: " + _.min(ordered_data[i]));
var trend = 0;
trend = (ordered_data[i][ordered_data[i].length-1]-ordered_data[i][0])/(ordered_data[i].length-1-0);
trend = Math.atan(trend)/1.570796;
document.write(" Trend: " + Math.round(trend*Math.pow(10,3))/Math.pow(10,3));
ordered_data[i] = _.sortBy(ordered_data[i],function(num){return num});
var listlength = ordered_data[i].length;
var median = 0;
if (listlength % 2){
var odd = (listlength / 2 - 0.5);
median = ordered_data[i][odd];
}else{
var even = (ordered_data[i][listlength / 2]);
even += (ordered_data[i][listlength / 2 + 1]);
even = (even / 2);
median = even;
}
document.write(" Median: " + median);
var avg=0;
_.each(ordered_data[i],function(num){ avg += num; })
avg = avg / ordered_data[i].length;
document.write(" Avg: " + Math.round(avg*Math.pow(10,3))/Math.pow(10,3) + "<br />");
}
}
/*
renderChart = function(punchcardData) { console.log('punchcard_renderer.js:renderChart()')
// console.log(deloreanData)
// console.log(deloreanOptions)
punchCard(punchcardData, 1, 'chart_div');
}*/