Skip to content

Commit

Permalink
Adds support for creating Query objects. (GoogleWebComponents#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
wesalvaro authored and ebidel committed Aug 4, 2016
1 parent 092cf73 commit 0bea10b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
19 changes: 19 additions & 0 deletions google-chart-loader.html
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@
* no arguments.
* - Anything else
*
* See <a href="https://developers.google.com/chart/interactive/docs/reference#datatable-class">the docs</a> for more details.
*
* @param {Array|{cols: !Array, rows: (!Array<!Array>|undefined)}|undefined} data
* the data with which we should use to construct the new DataTable object
* @return {!Promise<!google.visualization.DataTable>} promise for the created DataTable
Expand Down Expand Up @@ -295,6 +297,8 @@
/**
* Creates a DataView object from a DataTable for use with a chart.
*
* See <a href="https://developers.google.com/chart/interactive/docs/reference#dataview-class">the docs</a> for more details.
*
* @param {!google.visualization.DataTable} data the DataTable to use
* @return {!Promise<!google.visualization.DataView>} promise for the created DataView
*/
Expand All @@ -303,6 +307,21 @@
return new viz.DataView(data);
});
},

/**
* Creates a Query object to be sent to a DataSource protocol implementation.
*
* See <a href="https://developers.google.com/chart/interactive/docs/reference#query-classes">the docs</a> for more details.
*
* @param {string} url the URL of the DataSource protocol implementer
* @param {!Object=} opt_options options for the Query object
* @return {!Promise<!google.visualization.Query>} promise for the created DataView
*/
query: function(url, opt_options) {
return this._corePackage.then(function(viz) {
return new viz.Query(url, opt_options);
});
}
});
})();
</script>
12 changes: 12 additions & 0 deletions test/basic-tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,18 @@
chart.data = dataTable;
});
});
test('[data] is DataTable from DataSource Query', function(done) {
chart.addEventListener('google-chart-ready', function() {
done();
});
document.createElement('google-chart-loader')
.query('query.json')
.then(function(q) {
q.send(function(res) {
chart.data = res.getDataTable();
});
});
});
test('[data] is JSON URL for 2D Array', function(done) {
setDataAndWaitForRender('test-data-array.json', done);
});
Expand Down
13 changes: 13 additions & 0 deletions test/query.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
google.visualization.Query.setResponse({
"status":"ok",
"reqId":"0",
"table":{
"cols":[
{"label":"Data","type":"string"},
{"label":"Value","type":"number"}
],
"rows":[
{"c":[{"v":"Something"},{"v":1}]}
]
}
})

0 comments on commit 0bea10b

Please sign in to comment.