blob: d8690ed89cba8d062dc2d865ecd202e4ae535a71 [file] [log] [blame]
Scott Baker771819b2014-03-19 22:10:17 -07001google.load('visualization', '1', {'packages' : ['controls','table','corechart','geochart']});
2
Scott Baker8465c2b2014-03-27 09:11:14 -07003function 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 Baker771819b2014-03-19 22:10:17 -070012
Scott Baker0c4758a2014-06-09 16:02:50 -070013 startQuery(container, dataSourceUrl, yColumn, xColumn, aggFunc, options)
14}
Scott Baker771819b2014-03-19 22:10:17 -070015
Scott Baker0c4758a2014-06-09 16:02:50 -070016function startQuery(container, dataSourceUrl, yColumn, xColumn, aggFunc, options) {
Scott Baker8465c2b2014-03-27 09:11:14 -070017 var query = new google.visualization.Query(dataSourceUrl);
Scott Baker771819b2014-03-19 22:10:17 -070018 query && query.abort();
Scott Baker0c4758a2014-06-09 16:02:50 -070019 query.send(function(response) {handleResponse_psg(container, dataSourceUrl, response, yColumn, xColumn, aggFunc, options);});
Scott Baker771819b2014-03-19 22:10:17 -070020}
21
22// NOTE: appended _psg to showLine() and handleResponse() to prevent conflict
23// with Sapan's analytics page.
24
Scott Baker7c972e52014-03-21 16:47:09 -070025function 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 Baker8465c2b2014-03-27 09:11:14 -070033function showLine_psg(container, dt, options) {
Scott Baker8465c2b2014-03-27 09:11:14 -070034 var base_options = {
Scott Baker771819b2014-03-19 22:10:17 -070035 'width': 520,
36 'height': 300,
Scott Baker4cf99b52014-03-20 15:09:26 -070037 'pages': true,
38 'numRows': 9,
39 'backgroundColor': 'transparent',
Scott Baker8465c2b2014-03-27 09:11:14 -070040 'titleTextStyle': {"color": "black"},
Scott Baker4cf99b52014-03-20 15:09:26 -070041 'legend': 'none',
Scott Baker8465c2b2014-03-27 09:11:14 -070042 '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 Baker771819b2014-03-19 22:10:17 -070055 });
56 lineChart.setDataTable(dt);
57 lineChart.draw();
Scott Baker8465c2b2014-03-27 09:11:14 -070058
Scott Baker771819b2014-03-19 22:10:17 -070059}
60
Scott Baker4cf99b52014-03-20 15:09:26 -070061function fixDate(unixDate) {
62 return new Date(unixDate*1000);
63}
64
Scott Baker8465c2b2014-03-27 09:11:14 -070065function fixDate2(unixDate) {
66 return new Date(unixDate);
67}
Scott Baker771819b2014-03-19 22:10:17 -070068
Scott Baker0c4758a2014-06-09 16:02:50 -070069function handleResponse_psg(container, dataSourceUrl, response, yColumn, xColumn, aggFunc, options) {
Scott Baker771819b2014-03-19 22:10:17 -070070 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 Baker0c4758a2014-06-09 16:02:50 -070079 if (response.isError()) {
Scott Baker6c0e7842014-06-10 19:51:07 -070080 //console.log("retry chart");
Scott Baker0c4758a2014-06-09 16:02:50 -070081 setTimeout(function () { startQuery(container, dataSourceUrl, yColumn, xColumn, aggFunc, options) }, 5000);
82 return
83 }
84
Scott Baker771819b2014-03-19 22:10:17 -070085 var proxy = new google.visualization.ChartWrapper({
86 'chartType': 'Table',
87 'containerId': 'graph_work',
88 'options': {
89 'width': 800,
90 'height': 300,
Scott Baker4cf99b52014-03-20 15:09:26 -070091 pageSize:5,
92 page:'enable',
Scott Baker771819b2014-03-19 22:10:17 -070093 'legend': 'none',
94 'title': 'Nodes'
95 },
96 'view': {'columns': [0,1]}
97 });
98
99 google.visualization.events.addListener(proxy, 'ready', function () {
Scott Baker771819b2014-03-19 22:10:17 -0700100 var dt = proxy.getDataTable();
Scott Baker4cf99b52014-03-20 15:09:26 -0700101 var groupedData1 = google.visualization.data.group(dt, [{
102 column: yColumn,
103 type: 'datetime',
Scott Baker8465c2b2014-03-27 09:11:14 -0700104 modifier: fixDate2,
Scott Baker4cf99b52014-03-20 15:09:26 -0700105 }],
106 [{
Scott Baker771819b2014-03-19 22:10:17 -0700107 column: xColumn,
108 type: 'number',
109 label: dt.getColumnLabel(xColumn),
Scott Baker7c972e52014-03-21 16:47:09 -0700110 aggregation: aggFunc}]);
Scott Baker771819b2014-03-19 22:10:17 -0700111
Scott Baker8465c2b2014-03-27 09:11:14 -0700112 showLine_psg(container, groupedData1, options);
Scott Baker771819b2014-03-19 22:10:17 -0700113 });
114
Scott Baker771819b2014-03-19 22:10:17 -0700115 proxy.setDataTable(response.getDataTable());
116
117 proxy.draw();
118}
119
Scott Baker771819b2014-03-19 22:10:17 -0700120