Skip to content
This repository has been archived by the owner on Sep 3, 2022. It is now read-only.

Support the new BigQuery types in charts #68

Merged
merged 3 commits into from Oct 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion datalab/notebook/static/charting.ts
Expand Up @@ -440,11 +440,20 @@ module Charting {
// Convert any string fields that are date type to JS Dates.
public static convertDates(data:any):void {
for (var i = 0; i < data.cols.length; i++) {
if (data.cols[i].type == 'datetime') {
if (data.cols[i].type == 'date' || data.cols[i].type == 'datetime') {
var rows = data.rows;
for (var j = 0; j < rows.length; j++) {
rows[j].c[i].v = new Date(rows[j].c[i].v);
}
} else if (data.cols[i].type == 'timeofday') {
var rows = data.rows;
for (var j = 0; j < rows.length; j++) {
var timeInSeconds = rows[j].c[i].v.split('.')[0];
rows[j].c[i].v = timeInSeconds.split(':').map(
function(n:string) {
return parseInt(n, 10);
});
}
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion datalab/utils/commands/_utils.py
Expand Up @@ -98,16 +98,23 @@ def _get_cols(fields, schema):
""" Get column metadata for Google Charts based on field list and schema. """
typemap = {
'STRING': 'string',
'INT64': 'number',
'INTEGER': 'number',
'FLOAT': 'number',
'FLOAT64': 'number',
'BOOL': 'boolean',
'BOOLEAN': 'boolean',
'DATE': 'date',
'TIME': 'timeofday',
'DATETIME': 'datetime',
'TIMESTAMP': 'datetime'
}
cols = []
for col in fields:
if schema:
f = schema[col]
cols.append({'id': f.name, 'label': f.name, 'type': typemap[f.data_type]})
t = typemap.get(f.data_type, 'string')
cols.append({'id': f.name, 'label': f.name, 'type': t})
else:
# This will only happen if we had no rows to infer a schema from, so the type
# is not really important, except that GCharts will choke if we pass such a schema
Expand Down