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