Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame^] | 1 | google.load('visualization', '1', {'packages' : ['controls','table','corechart','geochart']}); |
| 2 | |
| 3 | function renderChartJson(jsondata, yField, xField, legend) { |
| 4 | $('#graph').empty(); |
| 5 | $('#chartsModal').modal('show'); |
| 6 | $('.modal-body').scrollTop(0); |
| 7 | |
| 8 | var data = new google.visualization.DataTable(); |
| 9 | data.addColumn("number", "Date"); |
| 10 | data.addColumn("number", "NodeCount"); |
| 11 | |
| 12 | var arr = []; |
| 13 | jsondata.rows.forEach(function(d) { |
| 14 | arr.push([ +d[yField], +d[xField] ]); |
| 15 | }); |
| 16 | |
| 17 | console.log(arr); |
| 18 | |
| 19 | data.addRows(arr); |
| 20 | |
| 21 | var lineChart = new google.visualization.ChartWrapper({ |
| 22 | 'chartType': 'LineChart', |
| 23 | 'containerId': 'graph', |
| 24 | 'options': { |
| 25 | 'width': 520, |
| 26 | 'height': 300, |
| 27 | 'title': 'Network-wide usage', |
| 28 | 'pages': true, |
| 29 | 'numRows': 9 |
| 30 | }, |
| 31 | 'view': {'columns': [0, 1]} |
| 32 | }); |
| 33 | lineChart.setDataTable(data); |
| 34 | lineChart.draw(); |
| 35 | } |
| 36 | |
| 37 | function renderChart(origQuery, yColumn, xColumn) { |
| 38 | $('#graph').empty(); |
| 39 | $('#chartsModal').modal('show'); |
| 40 | $('.modal-body').scrollTop(0) |
| 41 | |
| 42 | var queryString = encodeURIComponent(origQuery); |
| 43 | var serverPart = "http://cloud-scrutiny.appspot.com/command?action=send_query&force=ColumnChart&q="; |
| 44 | var dataSourceUrl = serverPart + queryString; |
| 45 | |
| 46 | //var dataSourceUrl = "http://node36.princeton.vicci.org:8000/analytics/bigquery/?avg=%25cpu&count=%25hostname&format=raw"; |
| 47 | |
| 48 | var query = new google.visualization.Query(dataSourceUrl) |
| 49 | query && query.abort(); |
| 50 | console.log("query.send") |
| 51 | query.send(function(response) {handleResponse_psg(response, yColumn, xColumn);}); |
| 52 | console.log("query.sent") |
| 53 | } |
| 54 | |
| 55 | // NOTE: appended _psg to showLine() and handleResponse() to prevent conflict |
| 56 | // with Sapan's analytics page. |
| 57 | |
| 58 | function showLine_psg(dt) { |
| 59 | console.log("showline") |
| 60 | var lineChart = new google.visualization.ChartWrapper({ |
| 61 | 'chartType': 'LineChart', |
| 62 | 'containerId': 'graph', |
| 63 | 'options': { |
| 64 | 'width': 520, |
| 65 | 'height': 300, |
| 66 | 'title': 'Network-wide usage', |
| 67 | 'pages': true, |
| 68 | 'numRows': 9 |
| 69 | }, |
| 70 | 'view': {'columns': [0, 1]} |
| 71 | }); |
| 72 | lineChart.setDataTable(dt); |
| 73 | lineChart.draw(); |
| 74 | } |
| 75 | |
| 76 | function handleResponse_psg(response, yColumn, xColumn) { |
| 77 | console.log("handleResponse") |
| 78 | |
| 79 | var supportedClasses = { |
| 80 | 'Table':google.visualization.Table, |
| 81 | 'LineChart':google.visualization.LineChart, |
| 82 | 'ScatterChart':google.visualization.ScatterChart, |
| 83 | 'ColumnChart':google.visualization.ColumnChart, |
| 84 | 'GeoChart':google.visualization.GeoChart, |
| 85 | 'PieChart':google.visualization.PieChart, |
| 86 | 'Histogram':google.visualization.Histogram}; |
| 87 | |
| 88 | var proxy = new google.visualization.ChartWrapper({ |
| 89 | 'chartType': 'Table', |
| 90 | 'containerId': 'graph_work', |
| 91 | 'options': { |
| 92 | 'width': 800, |
| 93 | 'height': 300, |
| 94 | pageSize:5, |
| 95 | page:'enable', |
| 96 | 'legend': 'none', |
| 97 | 'title': 'Nodes' |
| 98 | }, |
| 99 | 'view': {'columns': [0,1]} |
| 100 | }); |
| 101 | |
| 102 | google.visualization.events.addListener(proxy, 'ready', function () { |
| 103 | // 0 - time 1 - city 2 - node 3 - site 4 - cpu 5 - bytes |
| 104 | var dt = proxy.getDataTable(); |
| 105 | var groupedData1 = google.visualization.data.group(dt, [yColumn], [{ |
| 106 | column: xColumn, |
| 107 | type: 'number', |
| 108 | label: dt.getColumnLabel(xColumn), |
| 109 | aggregation: google.visualization.data.sum}]); |
| 110 | |
| 111 | showLine_psg(groupedData1); |
| 112 | |
| 113 | console.log(xColumn); |
| 114 | }); |
| 115 | |
| 116 | console.log(response.getReasons()); |
| 117 | console.log(response.getDataTable()); |
| 118 | console.log(response.getDetailedMessage()); |
| 119 | console.log(response.getMessage()); |
| 120 | |
| 121 | proxy.setDataTable(response.getDataTable()); |
| 122 | |
| 123 | proxy.draw(); |
| 124 | } |
| 125 | |
| 126 | $('.nodesLabel, .nodesValue').click(function() { |
| 127 | var jsonData = window.pageAnalyticsData; |
| 128 | renderChart(jsonData.query, 0, 2); |
| 129 | //renderChartJson(jsonData, "MinuteTime", "count_hostname", "Node Count"); |
| 130 | }); |
| 131 | |
| 132 | $('.cpuLabel, .cpuValue').click(function() { |
| 133 | var jsonData = window.pageAnalyticsData; |
| 134 | renderChart(jsonData.query,0, 1); |
| 135 | }); |
| 136 | $('.bandwidthLabel, .bandwidthValue').click(function() { |
| 137 | var jsonData = window.pageBandData; |
| 138 | renderChart(jsonData.query, 0, 1); |
| 139 | }); |