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 | 0c4758a | 2014-06-09 16:02:50 -0700 | [diff] [blame] | 13 | startQuery(container, dataSourceUrl, yColumn, xColumn, aggFunc, options) |
| 14 | } |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 15 | |
Scott Baker | 0c4758a | 2014-06-09 16:02:50 -0700 | [diff] [blame] | 16 | function startQuery(container, dataSourceUrl, yColumn, xColumn, aggFunc, options) { |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 17 | var query = new google.visualization.Query(dataSourceUrl); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 18 | query && query.abort(); |
Scott Baker | 0c4758a | 2014-06-09 16:02:50 -0700 | [diff] [blame] | 19 | query.send(function(response) {handleResponse_psg(container, dataSourceUrl, response, yColumn, xColumn, aggFunc, options);}); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | // NOTE: appended _psg to showLine() and handleResponse() to prevent conflict |
| 23 | // with Sapan's analytics page. |
| 24 | |
Scott Baker | 7c972e5 | 2014-03-21 16:47:09 -0700 | [diff] [blame] | 25 | function agg_bandwidth(arr) { |
| 26 | var ret = 0; |
| 27 | for (var i = 0; i < arr.length; i++) { |
| 28 | ret+=arr[i]*8.0/1024.0/1024.0/1024.0; |
| 29 | } |
| 30 | return ret; |
| 31 | } |
| 32 | |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 33 | function showLine_psg(container, dt, options) { |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 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 | 0c4758a | 2014-06-09 16:02:50 -0700 | [diff] [blame] | 69 | function handleResponse_psg(container, dataSourceUrl, 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 | |
Scott Baker | 0c4758a | 2014-06-09 16:02:50 -0700 | [diff] [blame] | 79 | if (response.isError()) { |
Scott Baker | 6c0e784 | 2014-06-10 19:51:07 -0700 | [diff] [blame] | 80 | //console.log("retry chart"); |
Scott Baker | 0c4758a | 2014-06-09 16:02:50 -0700 | [diff] [blame] | 81 | setTimeout(function () { startQuery(container, dataSourceUrl, yColumn, xColumn, aggFunc, options) }, 5000); |
| 82 | return |
| 83 | } |
| 84 | |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 85 | var proxy = new google.visualization.ChartWrapper({ |
| 86 | 'chartType': 'Table', |
| 87 | 'containerId': 'graph_work', |
| 88 | 'options': { |
| 89 | 'width': 800, |
| 90 | 'height': 300, |
Scott Baker | 4cf99b5 | 2014-03-20 15:09:26 -0700 | [diff] [blame] | 91 | pageSize:5, |
| 92 | page:'enable', |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 93 | 'legend': 'none', |
| 94 | 'title': 'Nodes' |
| 95 | }, |
| 96 | 'view': {'columns': [0,1]} |
| 97 | }); |
| 98 | |
| 99 | google.visualization.events.addListener(proxy, 'ready', function () { |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 100 | var dt = proxy.getDataTable(); |
Scott Baker | 4cf99b5 | 2014-03-20 15:09:26 -0700 | [diff] [blame] | 101 | var groupedData1 = google.visualization.data.group(dt, [{ |
| 102 | column: yColumn, |
| 103 | type: 'datetime', |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 104 | modifier: fixDate2, |
Scott Baker | 4cf99b5 | 2014-03-20 15:09:26 -0700 | [diff] [blame] | 105 | }], |
| 106 | [{ |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 107 | column: xColumn, |
| 108 | type: 'number', |
| 109 | label: dt.getColumnLabel(xColumn), |
Scott Baker | 7c972e5 | 2014-03-21 16:47:09 -0700 | [diff] [blame] | 110 | aggregation: aggFunc}]); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 111 | |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 112 | showLine_psg(container, groupedData1, options); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 113 | }); |
| 114 | |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 115 | proxy.setDataTable(response.getDataTable()); |
| 116 | |
| 117 | proxy.draw(); |
| 118 | } |
| 119 | |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 120 | |