[#248,model][s]: normalize Field types where possible by mapping standard type aliases to default type name - fixes #248.

* view.graph.js improve graph view by making sure datetime for an axis is judged by whether it is date, datetime or time not just date!
* backend.ckan.js some type conversions now done in core model so can be removed
This commit is contained in:
Rufus Pollock
2012-10-12 22:06:56 +01:00
parent aaae34f91d
commit 7819b3b185
5 changed files with 45 additions and 10 deletions

View File

@@ -94,10 +94,7 @@ this.recline.Backend.Ckan = this.recline.Backend.Ckan || {};
var CKAN_TYPES_MAP = {
'int4': 'integer',
'int8': 'integer',
'float8': 'float',
'text': 'string',
'json': 'object',
'timestamp': 'date'
'float8': 'float'
};
}(jQuery, this.recline.Backend.Ckan));

View File

@@ -380,6 +380,9 @@ my.Field = Backbone.Model.extend({
if (this.attributes.label === null) {
this.set({label: this.id});
}
if (this.attributes.type.toLowerCase() in this._typeMap) {
this.attributes.type = this._typeMap[this.attributes.type.toLowerCase()];
}
if (options) {
this.renderer = options.renderer;
this.deriver = options.deriver;
@@ -389,6 +392,17 @@ my.Field = Backbone.Model.extend({
}
this.facets = new my.FacetList();
},
_typeMap: {
'text': 'string',
'double': 'number',
'float': 'number',
'numeric': 'number',
'int': 'integer',
'datetime': 'date-time',
'bool': 'boolean',
'timestamp': 'date-time',
'json': 'object'
},
defaultRenderers: {
object: function(val, field, doc) {
return JSON.stringify(val);
@@ -396,7 +410,7 @@ my.Field = Backbone.Model.extend({
geo_point: function(val, field, doc) {
return JSON.stringify(val);
},
'float': function(val, field, doc) {
'number': function(val, field, doc) {
var format = field.get('format');
if (format === 'percentage') {
return val + '%';

View File

@@ -145,7 +145,8 @@ my.Graph = Backbone.View.extend({
var xfield = self.model.fields.get(self.state.attributes.group);
// time series
var isDateTime = xfield.get('type') === 'date';
var xtype = xfield.get('type');
var isDateTime = (xtype === 'date' || xtype === 'date-time' || xtype === 'time');
if (self.model.records.models[parseInt(x)]) {
x = self.model.records.models[parseInt(x)].get(self.state.attributes.group);
@@ -259,7 +260,8 @@ my.Graph = Backbone.View.extend({
var x = doc.getFieldValue(xfield);
// time series
var isDateTime = xfield.get('type') === 'date';
var xtype = xfield.get('type');
var isDateTime = (xtype === 'date' || xtype === 'date-time' || xtype === 'time');
if (isDateTime) {
// datetime