UNPKG

bugle-reports

Version:
91 lines (83 loc) 2.79 kB
<link rel="import" href="../../bower_components/polymer/polymer.html" /> <link rel="import" href="../../bower_components/google-chart/google-chart.html" /> <link rel="import" href="../../bower_components/iron-ajax/iron-ajax.html" /> <dom-module id="bugl-base-chart"> <template> <div> <h2>{{title}}</h2> <google-chart type="{{type}}" cols='{{cols}}' options='{{options}}' rows='{{rows}}'> </google-chart> <iron-ajax auto url={{url}} handle-as="json" on-response="handleResponse" debounce-duration="300"> </iron-ajax> </div> </template> <script> /*global Polymer*/ Polymer({ is: "bugl-base-chart", properties: { title: { type: String, value: "Chart" }, cols: { type: Array, value: [] }, rows: { type: Array, value: [] }, url: { type: String, value: "" }, chartType: { type: String, value: "pie" }, options: { type: Object, value: { hAxis: { viewWindow: { min: 0, max: 20 } } } } }, ready: function() { this.set("options.title", this.title); }, handleResponse: function(e) { var data = e.detail.response; this.set('title', data.title); //data.rows = data.rows.map(function(item) { // return [item[1],item[0]] //}); this.set('rows', data.rows); if (data.cols.length !== data.colTypes.length) throw "Invalid columns"; var chartCols = []; for (var i=0; i<data.colTypes.length; i++) { var colType = data.cols[i].toString(); if (i == 0) { colType = "string"; } chartCols.push({ label: colType, type: data.colTypes[i]}) } this.set('cols', chartCols); } }); </script> </dom-module>