@cryptotaxi247 / netdata-1 / commits / 690e1f6ac

made it refresh by itself with limited charts refreshing every time

box@home root committed Jun 19, 2013 at 02:01 UTC 690e1f6ac0f365f2bf39dd08ede8a2561ba63e07
1 file changed +49 -8
netdata.js
+49 -8
@@ -4,9 +4,11 @@
4 // Load the Visualization API and the piechart package.
5 google.load('visualization', '1', {'packages':['corechart']});
6
7 - function refreshChart(index, div, width, height, jsonurl, title) {
7 + function refreshChart(index) {
8 + if(index >= charts.length) return;
9 +
10 var jsonData = $.ajax({
9 - url: jsonurl,
11 + url: charts_urls[index],
12 dataType:"json",
13 async: false,
14 cache: false
@@ -17,16 +19,26 @@
19
20 // Instantiate and draw our chart, passing in some options.
21 if(!charts[index]) {
20 - console.log('Creating new chart for ' + jsonurl);
21 - charts[index] = new google.visualization.AreaChart(document.getElementById(div));
22 + console.log('Creating new chart for ' + charts_urls[index]);
23 + charts[index] = new google.visualization.AreaChart(document.getElementById(charts_divs[index]));
24 }
23 - if(charts[index]) charts[index].draw(charts_data[index], {width: width, height: height, title: title, hAxis: {title: "Time of Day"}, vAxis: {title: "Bandwidth in kbps", minValue: 200}});
24 - else console.log('Cannot create chart for ' + jsonurl);
25 +
26 + var width = charts_widths[index];
27 + if(width == 0) width = (window.innerWidth - 50) / 2;
28 + if(width < 10) width = (window.innerWidth - 50) / width;
29 +
30 + if(charts[index]) charts[index].draw(charts_data[index], {width: width, height: charts_heights[index], title: charts_titles[index], hAxis: {title: "Time of Day"}, vAxis: {title: "Bandwidth in kbps", minValue: 200}});
31 + else console.log('Cannot create chart for ' + charts_urls[index]);
32 }
33
34 var charts = new Array();
35 var charts_data = new Array();
36 var charts_names = new Array();
37 + var charts_divs = new Array();
38 + var charts_widths = new Array();
39 + var charts_heights = new Array();
40 + var charts_urls = new Array();
41 + var charts_titles = new Array();
42
43 function drawChart(name, div, width, height, jsonurl, title) {
44 var i;
@@ -39,13 +51,42 @@
51 charts[i] = null;
52 charts_data[i] = null;
53 charts_names[i] = name;
54 + charts_divs[i] = div;
55 + charts_widths[i] = width;
56 + charts_heights[i] = height;
57 + charts_urls[i] = jsonurl;
58 + charts_titles[i] = title;
59 }
60
61 try {
45 - refreshChart(i, div, width, height, jsonurl, title);
62 + refreshChart(i);
63 }
64 catch(err) {
65 console.log('Cannot create chart for ' + jsonurl);
66 }
67 }
51 -
68 +
69 + var charts_last_drawn = 99;
70 + function refreshCharts(howmany) {
71 +
72 + if(charts.length == 0) return;
73 +
74 + var h = howmany;
75 + if(h == 0) h = 1;
76 + if(h > charts.length) h = charts.length;
77 + console.log('Will run for ' + h + ' charts');
78 +
79 + var i;
80 + for(i = 0; i < h; i++) {
81 + charts_last_drawn++;
82 + if(charts_last_drawn >= charts.length) charts_last_drawn = 0;
83 +
84 + try {
85 + refreshChart(charts_last_drawn);
86 + }
87 + catch(err) {
88 + console.log('Cannot refresh chart for ' + jsonurl);
89 + }
90 + }
91 + return 0;
92 + }