Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!-- | 1 <!-- |
| 2 # Copyright 2016 The LUCI Authors. All rights reserved. | 2 Copyright 2016 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed by the Apache v2.0 license that can be | 3 Use of this source code is governed under the Apache License, Version 2.0 |
| 4 # found in the LICENSE file. | 4 that can be found in the LICENSE file. |
| 5 | |
| 6 For more on Google Charts and the data format, see https://developers.google.c om/chart/interactive/docs/datatables_dataviews | |
| 5 --> | 7 --> |
| 6 | 8 |
| 7 <link rel="import" href="/imp/bower_components/polymer/polymer.html"> | 9 <link rel="import" href="/res/imp/bower_components/polymer/polymer.html"> |
| 8 <link rel="import" href="/imp/bower_components/iron-ajax/iron-ajax.html"> | 10 <link rel="import" href="/res/imp/bower_components/iron-ajax/iron-ajax.html"> |
| 9 <link rel="import" href="/imp/bower_components/iron-flex-layout/iron-flex-layout -classes.html"> | 11 <link rel="import" href="/res/imp/bower_components/iron-flex-layout/iron-flex-la yout-classes.html"> |
| 10 | 12 |
| 11 <link rel="import" href="load-charts-api.html"> | 13 <link rel="import" href="load-charts-api.html"> |
| 12 <link rel="import" href="partial-line-chart.html"> | 14 <link rel="import" href="partial-line-chart.html"> |
| 13 | 15 |
| 14 <dom-module id="stats-overview"> | 16 <dom-module id="stats-overview"> |
| 15 <style include="iron-flex iron-flex-alignment iron-positioning"> | 17 <style include="iron-flex iron-flex-alignment iron-positioning"> |
| 16 | 18 |
| 17 </style> | 19 </style> |
| 18 | 20 |
| 19 <template> | 21 <template> |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 title="Requests"> | 53 title="Requests"> |
| 52 </partial-line-chart> | 54 </partial-line-chart> |
| 53 | 55 |
| 54 </div> | 56 </div> |
| 55 </template> | 57 </template> |
| 56 <script> | 58 <script> |
| 57 Polymer({ | 59 Polymer({ |
| 58 is: 'stats-overview', | 60 is: 'stats-overview', |
| 59 properties: { | 61 properties: { |
| 60 // input | 62 // input |
| 63 // TODO(kjlubick): Update the stats endpoints to use | |
| 64 auth_headers: { | |
| 65 type: Object, | |
| 66 } | |
| 61 | 67 |
| 62 //output | 68 //output |
| 69 busy: { | |
| 70 type: Boolean, | |
| 71 value: false, | |
| 72 notify: true, | |
| 73 }, | |
| 63 data_table: { | 74 data_table: { |
| 64 type: Object, | 75 type: Object, |
| 65 computed: "_extractData(response,charts_api_loaded)", | 76 computed: "_extractData(response,charts_api_loaded)", |
| 66 notify: true, | 77 notify: true, |
| 67 }, | 78 }, |
| 68 | 79 |
| 69 //private | 80 //private |
| 70 charts_api_loaded: { | 81 charts_api_loaded: { |
| 71 type: Boolean, | 82 type: Boolean, |
| 72 }, | 83 }, |
| 73 _headers: { | 84 _headers: { |
| 74 type: Object, | 85 type: Object, |
| 75 value: { | 86 value: { |
| 76 "x-datasource-auth": "a", | 87 "x-datasource-auth": "a", |
| 77 }, | 88 }, |
| 78 }, | 89 }, |
| 79 params: { | 90 params: { |
| 80 type: Object, | 91 type: Object, |
| 81 value: { | 92 value: { |
| 82 duration: 20, | 93 duration: 20, |
| 83 }, | 94 }, |
| 84 }, | 95 }, |
| 85 response: { | 96 response: { |
| 86 type: Object, | 97 type: Object, |
| 87 }, | 98 }, |
| 88 }, | 99 }, |
| 89 | 100 |
| 90 _extractData: function (_response, ready) { | 101 _extractData: function (_response, ready) { |
| 102 // Times are coming in like Date(2016,4,13,12,10,0) which is supposed | |
| 103 // to be UTC but the browser interprets as browser local time. We fix | |
| 104 // the dates to be parsed as UTC and the partial-line-chart will show | |
| 105 // times in browser local time. | |
| 106 var table = _response.table; | |
|
stephana
2016/09/26 20:05:46
could you modify the backend to send the date/time
kjlubick
2016/09/27 12:17:18
I know the format seems fragile, but it's actually
stephana
2016/09/27 15:33:23
Acknowledged.
| |
| 107 // Our data looks like https://developers.google.com/chart/interactive/d ocs/datesandtimes#dates-and-times-using-the-date-string-representation | |
| 108 // i.e. | |
| 109 // rows: [ | |
| 110 // {c: [v: "Date(2016,8,23,14,35,0)", v: ...]} | |
| 111 // {c: ... } | |
| 112 // ] | |
| 113 // and we parse the first part of each datum, the Date. | |
| 114 table.rows.forEach(function(r) { | |
| 115 var time = r.c[0].v; | |
| 116 if (time.startsWith && time.startsWith("Date")) { | |
| 117 // Remove the Date() wrapper | |
| 118 time = time.substring(5, time.length-1); | |
| 119 // Split into an array of arguments | |
| 120 time = time.split(","); | |
| 121 // Parse and store. | |
| 122 r.c[0].v = new Date(Date.UTC(...time)) | |
| 123 } | |
| 124 }); | |
| 91 return _response.table; | 125 return _response.table; |
| 92 }, | 126 }, |
| 93 }); | 127 }); |
| 94 </script> | 128 </script> |
| 95 </dom-module> | 129 </dom-module> |
| OLD | NEW |