blob: fb33022857b02f85092522a1fee3f1e489e26258 [file] [log] [blame]
Scott Baker771819b2014-03-19 22:10:17 -07001google.load('visualization', '1', {'packages' : ['controls','table','corechart','geochart']});
2
Scott Baker8465c2b2014-03-27 09:11:14 -07003function renderChart(newStyle, dialog, container, dataSourceUrl, yColumn, xColumn, aggFunc, options) {
4 if ( newStyle ) {
5 $(dialog).dialog("open");
6 }
7 else {
8 $(container).empty();
9 $(dialog).modal('show');
10 $('.modal-body').scrollTop(0);
11 }
Scott Baker771819b2014-03-19 22:10:17 -070012
Scott Baker8465c2b2014-03-27 09:11:14 -070013 console.log(dataSourceUrl);
Scott Baker771819b2014-03-19 22:10:17 -070014
Scott Baker8465c2b2014-03-27 09:11:14 -070015 var query = new google.visualization.Query(dataSourceUrl);
Scott Baker771819b2014-03-19 22:10:17 -070016 query && query.abort();
Scott Baker8465c2b2014-03-27 09:11:14 -070017 query.send(function(response) {handleResponse_psg(container, response, yColumn, xColumn, aggFunc, options);});
Scott Baker771819b2014-03-19 22:10:17 -070018}
19
20// NOTE: appended _psg to showLine() and handleResponse() to prevent conflict
21// with Sapan's analytics page.
22
Scott Baker7c972e52014-03-21 16:47:09 -070023function agg_bandwidth(arr) {
24 var ret = 0;
25 for (var i = 0; i < arr.length; i++) {
26 ret+=arr[i]*8.0/1024.0/1024.0/1024.0;
27 }
28 return ret;
29}
30
Scott Baker8465c2b2014-03-27 09:11:14 -070031function showLine_psg(container, dt, options) {
32 console.log("showline_psg");
33
34 var base_options = {
Scott Baker771819b2014-03-19 22:10:17 -070035 'width': 520,
36 'height': 300,
Scott Baker4cf99b52014-03-20 15:09:26 -070037 'pages': true,
38 'numRows': 9,
39 'backgroundColor': 'transparent',
Scott Baker8465c2b2014-03-27 09:11:14 -070040 'titleTextStyle': {"color": "black"},
Scott Baker4cf99b52014-03-20 15:09:26 -070041 'legend': 'none',
Scott Baker8465c2b2014-03-27 09:11:14 -070042 'hAxis': {"baselineColor": "darkBlue",
43 "textStyle": {"color": "black"}},
44 'vAxis': {"baselineColor": "darkBlue",
45 "textStyle": {"color": "black"}},
46 }
47
48 options = $.extend(true, {}, base_options, options);
49
50 var lineChart = new google.visualization.ChartWrapper({
51 'chartType': 'LineChart',
52 'containerId': container.substring(1),
53 'view': {'columns': [0, 1]},
54 'options': options
Scott Baker771819b2014-03-19 22:10:17 -070055 });
56 lineChart.setDataTable(dt);
57 lineChart.draw();
Scott Baker8465c2b2014-03-27 09:11:14 -070058
Scott Baker771819b2014-03-19 22:10:17 -070059}
60
Scott Baker4cf99b52014-03-20 15:09:26 -070061function fixDate(unixDate) {
62 return new Date(unixDate*1000);
63}
64
Scott Baker8465c2b2014-03-27 09:11:14 -070065function fixDate2(unixDate) {
66 return new Date(unixDate);
67}
Scott Baker771819b2014-03-19 22:10:17 -070068
Scott Baker8465c2b2014-03-27 09:11:14 -070069function handleResponse_psg(container, response, yColumn, xColumn, aggFunc, options) {
Scott Baker771819b2014-03-19 22:10:17 -070070 var supportedClasses = {
71 'Table':google.visualization.Table,
72 'LineChart':google.visualization.LineChart,
73 'ScatterChart':google.visualization.ScatterChart,
74 'ColumnChart':google.visualization.ColumnChart,
75 'GeoChart':google.visualization.GeoChart,
76 'PieChart':google.visualization.PieChart,
77 'Histogram':google.visualization.Histogram};
78
79 var proxy = new google.visualization.ChartWrapper({
80 'chartType': 'Table',
81 'containerId': 'graph_work',
82 'options': {
83 'width': 800,
84 'height': 300,
Scott Baker4cf99b52014-03-20 15:09:26 -070085 pageSize:5,
86 page:'enable',
Scott Baker771819b2014-03-19 22:10:17 -070087 'legend': 'none',
88 'title': 'Nodes'
89 },
90 'view': {'columns': [0,1]}
91 });
92
93 google.visualization.events.addListener(proxy, 'ready', function () {
Scott Baker771819b2014-03-19 22:10:17 -070094 var dt = proxy.getDataTable();
Scott Baker4cf99b52014-03-20 15:09:26 -070095 var groupedData1 = google.visualization.data.group(dt, [{
96 column: yColumn,
97 type: 'datetime',
Scott Baker8465c2b2014-03-27 09:11:14 -070098 modifier: fixDate2,
Scott Baker4cf99b52014-03-20 15:09:26 -070099 }],
100 [{
Scott Baker771819b2014-03-19 22:10:17 -0700101 column: xColumn,
102 type: 'number',
103 label: dt.getColumnLabel(xColumn),
Scott Baker7c972e52014-03-21 16:47:09 -0700104 aggregation: aggFunc}]);
Scott Baker771819b2014-03-19 22:10:17 -0700105
Scott Baker8465c2b2014-03-27 09:11:14 -0700106 console.log(groupedData1.getColumnRange(0))
107 console.log(groupedData1.getColumnRange(1))
108 showLine_psg(container, groupedData1, options);
Scott Baker771819b2014-03-19 22:10:17 -0700109 });
110
Scott Baker771819b2014-03-19 22:10:17 -0700111 proxy.setDataTable(response.getDataTable());
112
113 proxy.draw();
114}
115
116$('.nodesLabel, .nodesValue').click(function() {
Scott Baker8465c2b2014-03-27 09:11:14 -0700117 renderChart(false,"#chartsModal", "#graph", window.pageAnalyticsUrl, 0, "Number of Nodes", 2, "Node Count", google.visualization.data.sum);
Scott Baker771819b2014-03-19 22:10:17 -0700118});
119
120$('.cpuLabel, .cpuValue').click(function() {
121 var jsonData = window.pageAnalyticsData;
Scott Baker8465c2b2014-03-27 09:11:14 -0700122 renderChart(false,"#chartsModal", "#graph", window.pageAnalyticsUrl, 0, "Average CPU", 1, "Average CPU", google.visualization.data.sum);
Scott Baker771819b2014-03-19 22:10:17 -0700123});
124$('.bandwidthLabel, .bandwidthValue').click(function() {
125 var jsonData = window.pageBandData;
Scott Baker8465c2b2014-03-27 09:11:14 -0700126 renderChart(false,"#chartsModal", "#graph", window.pageBandUrl, 0, "Total Bandwidth (Gbps)", 1, "Total Bandwidth", agg_bandwidth);
Scott Baker771819b2014-03-19 22:10:17 -0700127});