Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 1 | google.load('visualization', '1', {'packages' : ['controls','table','corechart','geochart']}); |
| 2 | |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 3 | function 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 Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 12 | |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 13 | console.log(dataSourceUrl); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 14 | |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 15 | var query = new google.visualization.Query(dataSourceUrl); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 16 | query && query.abort(); |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 17 | query.send(function(response) {handleResponse_psg(container, response, yColumn, xColumn, aggFunc, options);}); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | // NOTE: appended _psg to showLine() and handleResponse() to prevent conflict |
| 21 | // with Sapan's analytics page. |
| 22 | |
Scott Baker | 7c972e5 | 2014-03-21 16:47:09 -0700 | [diff] [blame] | 23 | function 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 Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 31 | function showLine_psg(container, dt, options) { |
| 32 | console.log("showline_psg"); |
| 33 | |
| 34 | var base_options = { |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 35 | 'width': 520, |
| 36 | 'height': 300, |
Scott Baker | 4cf99b5 | 2014-03-20 15:09:26 -0700 | [diff] [blame] | 37 | 'pages': true, |
| 38 | 'numRows': 9, |
| 39 | 'backgroundColor': 'transparent', |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 40 | 'titleTextStyle': {"color": "black"}, |
Scott Baker | 4cf99b5 | 2014-03-20 15:09:26 -0700 | [diff] [blame] | 41 | 'legend': 'none', |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 42 | '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 Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 55 | }); |
| 56 | lineChart.setDataTable(dt); |
| 57 | lineChart.draw(); |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 58 | |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Scott Baker | 4cf99b5 | 2014-03-20 15:09:26 -0700 | [diff] [blame] | 61 | function fixDate(unixDate) { |
| 62 | return new Date(unixDate*1000); |
| 63 | } |
| 64 | |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 65 | function fixDate2(unixDate) { |
| 66 | return new Date(unixDate); |
| 67 | } |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 68 | |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 69 | function handleResponse_psg(container, response, yColumn, xColumn, aggFunc, options) { |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 70 | 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 Baker | 4cf99b5 | 2014-03-20 15:09:26 -0700 | [diff] [blame] | 85 | pageSize:5, |
| 86 | page:'enable', |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 87 | 'legend': 'none', |
| 88 | 'title': 'Nodes' |
| 89 | }, |
| 90 | 'view': {'columns': [0,1]} |
| 91 | }); |
| 92 | |
| 93 | google.visualization.events.addListener(proxy, 'ready', function () { |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 94 | var dt = proxy.getDataTable(); |
Scott Baker | 4cf99b5 | 2014-03-20 15:09:26 -0700 | [diff] [blame] | 95 | var groupedData1 = google.visualization.data.group(dt, [{ |
| 96 | column: yColumn, |
| 97 | type: 'datetime', |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 98 | modifier: fixDate2, |
Scott Baker | 4cf99b5 | 2014-03-20 15:09:26 -0700 | [diff] [blame] | 99 | }], |
| 100 | [{ |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 101 | column: xColumn, |
| 102 | type: 'number', |
| 103 | label: dt.getColumnLabel(xColumn), |
Scott Baker | 7c972e5 | 2014-03-21 16:47:09 -0700 | [diff] [blame] | 104 | aggregation: aggFunc}]); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 105 | |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 106 | console.log(groupedData1.getColumnRange(0)) |
| 107 | console.log(groupedData1.getColumnRange(1)) |
| 108 | showLine_psg(container, groupedData1, options); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 109 | }); |
| 110 | |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 111 | proxy.setDataTable(response.getDataTable()); |
| 112 | |
| 113 | proxy.draw(); |
| 114 | } |
| 115 | |
| 116 | $('.nodesLabel, .nodesValue').click(function() { |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 117 | renderChart(false,"#chartsModal", "#graph", window.pageAnalyticsUrl, 0, "Number of Nodes", 2, "Node Count", google.visualization.data.sum); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 118 | }); |
| 119 | |
| 120 | $('.cpuLabel, .cpuValue').click(function() { |
| 121 | var jsonData = window.pageAnalyticsData; |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 122 | renderChart(false,"#chartsModal", "#graph", window.pageAnalyticsUrl, 0, "Average CPU", 1, "Average CPU", google.visualization.data.sum); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 123 | }); |
| 124 | $('.bandwidthLabel, .bandwidthValue').click(function() { |
| 125 | var jsonData = window.pageBandData; |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 126 | renderChart(false,"#chartsModal", "#graph", window.pageBandUrl, 0, "Total Bandwidth (Gbps)", 1, "Total Bandwidth", agg_bandwidth); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 127 | }); |