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) { |
| 34 | console.log("showline_psg"); |
| 35 | |
| 36 | var base_options = { |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 37 | 'width': 520, |
| 38 | 'height': 300, |
Scott Baker | 4cf99b5 | 2014-03-20 15:09:26 -0700 | [diff] [blame] | 39 | 'pages': true, |
| 40 | 'numRows': 9, |
| 41 | 'backgroundColor': 'transparent', |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 42 | 'titleTextStyle': {"color": "black"}, |
Scott Baker | 4cf99b5 | 2014-03-20 15:09:26 -0700 | [diff] [blame] | 43 | 'legend': 'none', |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 44 | 'hAxis': {"baselineColor": "darkBlue", |
| 45 | "textStyle": {"color": "black"}}, |
| 46 | 'vAxis': {"baselineColor": "darkBlue", |
| 47 | "textStyle": {"color": "black"}}, |
| 48 | } |
| 49 | |
| 50 | options = $.extend(true, {}, base_options, options); |
| 51 | |
| 52 | var lineChart = new google.visualization.ChartWrapper({ |
| 53 | 'chartType': 'LineChart', |
| 54 | 'containerId': container.substring(1), |
| 55 | 'view': {'columns': [0, 1]}, |
| 56 | 'options': options |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 57 | }); |
| 58 | lineChart.setDataTable(dt); |
| 59 | lineChart.draw(); |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 60 | |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Scott Baker | 4cf99b5 | 2014-03-20 15:09:26 -0700 | [diff] [blame] | 63 | function fixDate(unixDate) { |
| 64 | return new Date(unixDate*1000); |
| 65 | } |
| 66 | |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 67 | function fixDate2(unixDate) { |
| 68 | return new Date(unixDate); |
| 69 | } |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 70 | |
Scott Baker | 0c4758a | 2014-06-09 16:02:50 -0700 | [diff] [blame^] | 71 | function handleResponse_psg(container, dataSourceUrl, response, yColumn, xColumn, aggFunc, options) { |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 72 | var supportedClasses = { |
| 73 | 'Table':google.visualization.Table, |
| 74 | 'LineChart':google.visualization.LineChart, |
| 75 | 'ScatterChart':google.visualization.ScatterChart, |
| 76 | 'ColumnChart':google.visualization.ColumnChart, |
| 77 | 'GeoChart':google.visualization.GeoChart, |
| 78 | 'PieChart':google.visualization.PieChart, |
| 79 | 'Histogram':google.visualization.Histogram}; |
| 80 | |
Scott Baker | 0c4758a | 2014-06-09 16:02:50 -0700 | [diff] [blame^] | 81 | if (response.isError()) { |
| 82 | #console.log("retry chart"); |
| 83 | setTimeout(function () { startQuery(container, dataSourceUrl, yColumn, xColumn, aggFunc, options) }, 5000); |
| 84 | return |
| 85 | } |
| 86 | |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 87 | var proxy = new google.visualization.ChartWrapper({ |
| 88 | 'chartType': 'Table', |
| 89 | 'containerId': 'graph_work', |
| 90 | 'options': { |
| 91 | 'width': 800, |
| 92 | 'height': 300, |
Scott Baker | 4cf99b5 | 2014-03-20 15:09:26 -0700 | [diff] [blame] | 93 | pageSize:5, |
| 94 | page:'enable', |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 95 | 'legend': 'none', |
| 96 | 'title': 'Nodes' |
| 97 | }, |
| 98 | 'view': {'columns': [0,1]} |
| 99 | }); |
| 100 | |
| 101 | google.visualization.events.addListener(proxy, 'ready', function () { |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 102 | var dt = proxy.getDataTable(); |
Scott Baker | 4cf99b5 | 2014-03-20 15:09:26 -0700 | [diff] [blame] | 103 | var groupedData1 = google.visualization.data.group(dt, [{ |
| 104 | column: yColumn, |
| 105 | type: 'datetime', |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 106 | modifier: fixDate2, |
Scott Baker | 4cf99b5 | 2014-03-20 15:09:26 -0700 | [diff] [blame] | 107 | }], |
| 108 | [{ |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 109 | column: xColumn, |
| 110 | type: 'number', |
| 111 | label: dt.getColumnLabel(xColumn), |
Scott Baker | 7c972e5 | 2014-03-21 16:47:09 -0700 | [diff] [blame] | 112 | aggregation: aggFunc}]); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 113 | |
Scott Baker | 8465c2b | 2014-03-27 09:11:14 -0700 | [diff] [blame] | 114 | console.log(groupedData1.getColumnRange(0)) |
| 115 | console.log(groupedData1.getColumnRange(1)) |
| 116 | showLine_psg(container, groupedData1, options); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 117 | }); |
| 118 | |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 119 | proxy.setDataTable(response.getDataTable()); |
| 120 | |
| 121 | proxy.draw(); |
| 122 | } |
| 123 | |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 124 | |