Skip to content
Browse files

Updated builds

  • Loading branch information...
1 parent 7a303c7 commit f918e64eb26a228f94ca1a4382c6a55978b20cbb @iros iros committed Apr 17, 2012
View
2 dist/LASTBUILD
@@ -1 +1 @@
-2012/04/17 04:27
+2012/04/17 11:19
View
5 dist/miso.ds.0.1.0.js
@@ -236,8 +236,8 @@
_.each(this.deltas, function(delta) {
cols = _.union(cols,
- _.keys(delta.old),
- _.keys(delta.changed)
+ ( _.isUndefined(delta.old) ? [] : _.keys(delta.old) ),
+ ( _.isUndefined(delta.changed) ? [] : _.keys(delta.changed) )
);
});
@@ -365,6 +365,7 @@
return new Miso.Event(delta);
};
}(this, _));
+
(function(global, _) {
var Miso = global.Miso || {};
View
5 dist/miso.ds.deps.0.1.0.js
@@ -2427,8 +2427,8 @@
_.each(this.deltas, function(delta) {
cols = _.union(cols,
- _.keys(delta.old),
- _.keys(delta.changed)
+ ( _.isUndefined(delta.old) ? [] : _.keys(delta.old) ),
+ ( _.isUndefined(delta.changed) ? [] : _.keys(delta.changed) )
);
});
@@ -2556,6 +2556,7 @@
return new Miso.Event(delta);
};
}(this, _));
+
(function(global, _) {
var Miso = global.Miso || {};
View
2 dist/miso.ds.deps.min.0.1.0.js
1 addition, 1 deletion not shown because the diff is too large. Please use a local Git client to view these changes.
View
BIN dist/miso.ds.dev.0.1.0.zip
Binary file not shown.
View
2 dist/miso.ds.min.0.1.0.js
@@ -6,4 +6,4 @@
* https://github.com/misoproject/dataset/blob/master/LICENSE-MIT
* https://github.com/misoproject/dataset/blob/master/LICENSE-GPL
*/
-(function(a,_){var b=a.Miso={};b.typeOf=function(a,c){var d=_.keys(b.types),e;return d.push(d.splice(_.indexOf(d,"string"),1)[0]),d.push(d.splice(_.indexOf(d,"mixed"),1)[0]),e=_.find(d,function(d){return b.types[d].test(a,c)}),e=_.isUndefined(e)?"string":e,e},b.types={mixed:{name:"mixed",coerce:function(a){return a},test:function(a){return!0},compare:function(a,b){return a<b?-1:a>b?1:0},numeric:function(a){return _.isNaN(Number(a))?0:Number(a)}},string:{name:"string",coerce:function(a){return a==null?null:a.toString()},test:function(a){return a===null||typeof a=="undefined"||typeof a=="string"},compare:function(a,b){return a==null&&b!=null?-1:a!=null&&b==null?1:a<b?-1:a>b?1:0},numeric:function(a,b){return b}},"boolean":{name:"boolean",regexp:/^(true|false)$/,coerce:function(a){return a==="false"?!1:Boolean(a)},test:function(a){return a===null||typeof a=="undefined"||typeof a=="boolean"||this.regexp.test(a)?!0:!1},compare:function(a,b){return a==null&&b!=null?-1:a!=null&&b==null?1:a==null&&b==null?0:a===b?0:a<b?-1:1},numeric:function(a){return a?1:0}},number:{name:"number",regexp:/^[\-\.]?[0-9]+([\.][0-9]+)?$/,coerce:function(a){return _.isNull(a)?null:_.isNaN(a)?null:+a},test:function(a){return a===null||typeof a=="undefined"||typeof a=="number"||this.regexp.test(a)?!0:!1},compare:function(a,b){return a==null&&b!=null?-1:a!=null&&b==null?1:a==null&&b==null?0:a===b?0:a<b?-1:1},numeric:function(a){return a}},time:{name:"time",format:"DD/MM/YYYY",_formatLookup:[["DD","\\d{2}"],["D","\\d{1}|\\d{2}"],["MM","\\d{2}"],["M","\\d{1}|\\d{2}"],["YYYY","\\d{4}"],["YY","\\d{2}"],["A","[AM|PM]"],["hh","\\d{2}"],["h","\\d{1}|\\d{2}"],["mm","\\d{2}"],["m","\\d{1}|\\d{2}"],["ss","\\d{2}"],["s","\\d{1}|\\d{2}"],["ZZ","[-|+]\\d{4}"],["Z","[-|+]\\d{2}:\\d{2}"]],_regexpTable:{},_regexp:function(a){if(this._regexpTable[a])return new RegExp(this._regexpTable[a],"g");var b=a;return _.each(this._formatLookup,function(a){b=b.replace(a[0],a[1])},this),b=b.split("/").join("\\/"),this._regexpTable[a]=b,new RegExp(this._regexpTable[a],"g")},coerce:function(a,b){b=b||{};if(_.isString(a)){var c=b.format||this.format;return moment(a,b.format)}return _.isNumber(a)?moment(a):a},test:function(a,b){b=b||{};if(a===null||typeof a=="undefined")return!0;if(_.isString(a)){var c=b.format||this.format,d=this._regexp(c);return d.test(a)}return!0},compare:function(a,b){return a<b?-1:a>b?1:0},numeric:function(a){return a.valueOf()}}}})(this,_),function(a,_){var b=a.Miso||(a.Miso={});b.Event=function(a){_.isArray(a)||(a=[a]),this.deltas=a},_.extend(b.Event.prototype,{affectedColumns:function(){var a=[];return _.each(this.deltas,function(b){a=_.union(a,_.keys(b.old),_.keys(b.changed))}),a}}),_.extend(b.Event,{isRemove:function(a){return _.isUndefined(a.changed)||_.keys(a.changed).length===0?!0:!1},isAdd:function(a){return _.isUndefined(a.old)||_.keys(a.old).length===0?!0:!1},isUpdate:function(a){return!this.isRemove(a)&&!this.isAdd(a)?!0:!1}}),b.Events={},b.Events.bind=function(a,b,c){var d=this._callbacks||(this._callbacks={}),e=d[a]||(d[a]={}),f=e.tail||(e.tail=e.next={});return f.callback=b,f.context=c,e.tail=f.next={},this},b.Events.unbind=function(a,b){var c,d,e;if(!a)this._callbacks=null;else if(c=this._callbacks)if(!b)c[a]={};else if(d=c[a])while((e=d)&&(d=d.next)){if(d.callback!==b)continue;e.next=d.next,d.context=d.callback=null;break}return this},b.Events.trigger=function(a){var b,c,d,e,f,g=["all",a];if(!(c=this._callbacks))return this;while(f=g.pop()){if(!(b=c[f]))continue;e=f==="all"?arguments:Array.prototype.slice.call(arguments,1);while(b=b.next)(d=b.callback)&&d.apply(b.context||this,e)}return this},b.Events._buildEvent=function(a){return new b.Event(a)}}(this,_),function(a,_){var b=a.Miso||{};b.Builder={detectColumnType:function(a,c){var d=_.inject(c.slice(0,5),function(a,c){var d=b.typeOf(c);return c!==""&&a.indexOf(d)===-1&&!_.isNull(c)&&a.push(d),a},[]);return d.length===1?a.type=d[0]:a.type="mixed",a},detectColumnTypes:function(a,c){_.each(c,function(c,d){var e=a.column(d);if(e.type){e.force=!0;return}b.Builder.detectColumnType(e,c)},this)},cacheRows:function(a){b.Builder.clearRowCache(a),_.each(a._columns[a._columnPositionByName._id].data,function(b,c){a._rowPositionById[b]=c,a._rowIdByPosition.push(b)},a);var c=_.uniq(_.map(a._columns,function(a){return a.data.length}));if(c.length>1)throw new Error("Row lengths need to be the same. Empty values should be set to null."+_.map(a._columns,function(a){return a.data+"|||"}));a.length=c[0]},clearRowCache:function(a){a._rowPositionById={},a._rowIdByPosition=[]},cacheColumns:function(a){a._columnPositionByName={},_.each(a._columns,function(b,c){a._columnPositionByName[b.name]=c})}},Array.prototype.indexOf||(Array.prototype.indexOf=function(a,b){for(var c=b||0,d=this.length;c<d;c++)if(this[c]===a)return c;return-1})}(this,_),function(a,_){var b=a.Miso;b.Column=function(a){return _.extend(this,a),this._id=a.id||_.uniqueId(),this.data=a.data||[],this},_.extend(b.Column.prototype,{toNumeric:function(a,c){return b.types[this.type].numeric(a,c)},numericAt:function(a){return this.toNumeric(this.data[a],a)},coerce:function(){this.data=_.map(this.data,function(a){return b.types[this.type].coerce(a,this)},this)},_sum:function(){return _.sum(this.data)},_mean:function(){var a=0;for(var c=0;c<this.data.length;c++)a+=this.numericAt(c);return a/=this.data.length,b.types[this.type].coerce(a,this)},_median:function(){return b.types[this.type].coerce(_.median(this.data),this)},_max:function(){var a=-Infinity;for(var c=0;c<this.data.length;c++)b.types[this.type].compare(this.data[c],a)>0&&(a=this.numericAt(c));return b.types[this.type].coerce(a,this)},_min:function(){var a=Infinity;for(var c=0;c<this.data.length;c++)b.types[this.type].compare(this.data[c],a)<0&&(a=this.numericAt(c));return b.types[this.type].coerce(a,this)}}),b.DataView=function(a){if(typeof a!="undefined"){a=a||(a={});if(_.isUndefined(a.parent))throw new Error("A view must have a parent specified.");this.parent=a.parent,this._initialize(a)}},_.extend(b.DataView.prototype,{_initialize:function(a){this.parent.syncable===!0&&(_.extend(this,b.Events),this.syncable=!0),this.filter={columns:this._columnFilter(a.filter.columns||undefined),rows:this._rowFilter(a.filter.rows||undefined)},this._columns=this._selectData(),b.Builder.cacheColumns(this),b.Builder.cacheRows(this),this.syncable&&this.parent.bind("change",this._sync,this)},_sync:function(a){var c=a.deltas,d=null;_.each(c,function(c,e){var f=this._rowPositionById[c._id];if(typeof f=="undefined"&&b.Event.isAdd(c))this.filter.rows&&this.filter.rows(c.changed)&&(this._add(c.changed),d="add");else{if(f==="undefined")return;_.each(c.changed,function(a,b){var c=this._columnPositionByName[b];if(_.isUndefined(c))return;this._columns[c].data[f]=a,d="update"},this)}var g=this.rowByPosition(f);if(b.Event.isRemove(c)||this.filter.row&&!this.filter.row(g)){var h={_id:c._id,old:this.rowByPosition(f),changed:{}};a.deltas.splice(e,1,h),this._remove(f),d="delete"}},this),this.syncable&&(this.trigger(d,a),this.trigger("change",a))},where:function(a,c){return c=c||{},c.parent=this,c.filter=a||{},new b.DataView(c)},_selectData:function(){var a=[];return _.each(this.parent._columns,function(c){this.filter.columns(c)&&a.push(new b.Column({name:c.name,data:[],type:c.type,_id:c._id}))},this),this.parent.each(function(b){if(!this.filter.rows(b))return;for(var c=0;c<a.length;c++)a[c].data.push(b[a[c].name])},this),a},_columnFilter:function(a){var b;return _.isUndefined(a)?b=function(){return!0}:(_.isString(a)&&(a=[a]),a.push("_id"),b=function(b){return _.indexOf(a,b.name)===-1?!1:!0}),b},_rowFilter:function(a){var b;return _.isNumber(a)&&(a=[a]),_.isUndefined(a)?b=function(){return!0}:_.isFunction(a)?b=a:b=function(b){return _.indexOf(a,b._id)===-1?!1:!0},b},column:function(a){return this._column(a)},_column:function(a){if(_.isUndefined(this._columnPositionByName))return undefined;var b=this._columnPositionByName[a];return this._columns[b]},columns:function(a){return new b.DataView({filter:{columns:a},parent:this})},columnNames:function(){var a=_.pluck(this._columns,"name");return _.reject(a,function(a){return a==="_id"||a==="_oids"})},hasColumn:function(a){return!_.isUndefined(this._columnPositionByName[a])},each:function(a,b){for(var c=0;c<this.length;c++)a.apply(b||this,[this.rowByPosition(c),c])},eachColumn:function(a,b){var c=this.columnNames();for(var d=0;d<c.length;d++)a.apply(b||this,[c[d],this.column(c[d]),d])},rowByPosition:function(a){return this._row(a)},rowById:function(a){return this._row(this._rowPositionById[a])},_row:function(a){var b={};return _.each(this._columns,function(c){b[c.name]=c.data[a]}),b},_remove:function(a){var b=this._rowPositionById[a];return _.each(this._columns,function(a){a.data.splice(b,1)}),delete this._rowPositionById[a],this._rowIdByPosition.splice(b,1),this.length--,this},_add:function(a,c){_.each(a,function(c,d){var e=this.column(d);if(typeof e!="undefined"){var f=b.types[e.type];if(e.force||f.test(a[e.name],e))_.isUndefined(e.before)||(a[e.name]=e.before(a[e.name])),a[e.name]=f.coerce(a[e.name],e);else throw"incorrect value '"+a[e.name]+"' of type "+b.typeOf(a[e.name],e)+" passed to column with type "+e.type}},this);if(_.isUndefined(this.comparator))_.each(this._columns,function(b){b.data.push(!_.isUndefined(a[b.name])&&!_.isNull(a[b.name])?a[b.name]:null)}),this.length++,this._rowIdByPosition=this._rowIdByPosition||(this._rowIdByPosition=[]),this._rowPositionById=this._rowPositionById||(this._rowPositionById={}),this._rowIdByPosition.push(a._id),this._rowPositionById[a._id]=this._rowIdByPosition.length;else{var d=function(a,b,c){Array.prototype.splice.apply(c,[a,0].concat(b))},e;this.length++;for(e=0;e<this.length;e++){var f=this.rowByPosition(e);if(_.isUndefined(f._id)||this.comparator(a,f)<0){_.each(this._columns,function(b){d(e,a[b.name]?a[b.name]:null,b.data)});break}}this._rowIdByPosition=[],this._rowPositionById={},this.each(function(a,b){this._rowIdByPosition.push(a._id),this._rowPositionById[a._id]=b})}return this},rows:function(a){return new b.DataView({filter:{rows:a},parent:this})},sort:function(a){a=a||{},a.comparator&&(this.comparator=a.comparator);if(_.isUndefined(this.comparator))throw new Error("Cannot sort without this.comparator.");var b=this.length,c;if(b===1)return;var d=_.bind(function(a,b){var c=this.rowByPosition(b);_.each(c,function(c,d){var e=this._columnPositionByName[d],f=this._columns[e].data[a];this._columns[e].data.splice(a,1,c),this._columns[e].data.splice(b,1,f)},this)},this),e=_.bind(function(a,b){var c=a,e;while(c*2<=b){e=c*2;var f=this.rowByPosition(c);e+1<b&&this.comparator(this.rowByPosition(e),this.rowByPosition(e+1))<0&&e++;if(this.comparator(f,this.rowByPosition(e))<0)d(c,e),c=e;else return}},this),f=function(a){var b=Math.round((a-2)/2);while(b>=0)e(b,a-1),b--};if(b>2){f(b),c=b-1;while(c>1)d(c,0),c--,e(0,c)}else this.comparator(this.rowByPosition(0),this.rowByPosition(1))>0&&d(0,1);return this.comparator(this.rowByPosition(this.length-2),this.rowByPosition(this.length-1))>0&&d(this.length-1,this.length-2),this.syncable&&a.silent&&this.trigger("sort"),this},toJSON:function(){var a=[];for(var b=0;b<this.length;b++)a.push(this.rowByPosition(b));return a}})}(this,_),function(a,_){var b=a.Miso;b.Product=b.Product||function(a){a=a||{},this.func=a.func;if(a.columns){var b=a.columns;_.isArray(a.columns)&&(b=a.columns[0]),this.valuetype=b.type,this.numeric=function(){return b.toNumeric(this.value)}}return this.func({silent:!0}),this},_.extend(b.Product.prototype,b.Events,{val:function(){return this.value},type:function(){return this.valuetype},_sync:function(a){this.func()},_buildDelta:function(a,b){return{old:a,changed:b}}}),_.extend(b.DataView.prototype,{_findColumns:function(a){var b=[];return _.isUndefined(a)&&(a=this.columnNames()),a=_.isArray(a)?a:[a],_.each(a,function(a){a=this._columns[this._columnPositionByName[a]],b.push(a)},this),b},sum:function(a,c){c=c||{};var d=this._findColumns(a),e=function(a){return function(){return _.each(a,function(a){if(a.type===b.types.time.name)throw new Error("Can't sum up time")}),_.sum(_.map(a,function(a){return a._sum()}))}}(d);return this._calculated(d,e)},max:function(a,c){c=c||{};var d=this._findColumns(a),e=function(a){return function(){var c=_.max(_.map(a,function(a){return a._max()})),d=a[0].type,e=a[0].typeOptions;return b.types[d].coerce(c,e)}}(d);return this._calculated(d,e)},min:function(a,c){c=c||{};var d=this._findColumns(a),e=function(a){return function(){var c=_.min(_.map(a,function(a){return a._min()})),d=a[0].type,e=a[0].typeOptions;return b.types[d].coerce(c,e)}}(d);return this._calculated(d,e)},mean:function(a,c){c=c||{};var d=this._findColumns(a),e=function(a){return function(){var c=[];_.each(a,function(a){c.push(a.data)}),c=_.flatten(c);var d=a[0].type,e=a[0].typeOptions;return c=_.map(c,function(a){return b.types[d].numeric(a)}),b.types[d].coerce(_.mean(c),e)}}(d);return this._calculated(d,e)},_calculated:function(a,c){var d=this,e=new b.Product({columns:a,func:function(a){a=a||{};var b=this._buildDelta(this.value,c.apply(d));this.value=b.changed;if(d.syncable){var e=this._buildEvent(b);!_.isUndefined(b.old)&&!a.silent&&b.old!==b.changed&&this.trigger("change",e)}}});return this.syncable?(this.bind("change",e._sync,e),e):c()}})}(this,_),function(a,_,moment){var b=a.Miso;b.Dataset=function(a){this.length=0,this._columns=[],this._columnPositionByName={},typeof a!="undefined"&&(a=a||{},this._initialize(a))},b.Dataset.prototype=new b.DataView,_.extend(b.Dataset.prototype,{_initialize:function(a){a.sync===!0&&(_.extend(this,b.Events),this.syncable=!0),this.importer=a.importer||null,this.parser=a.parser||b.Parsers.Obj,_.isUndefined(a.parser)&&(a.strict?this.parser=b.Parsers.Strict:a.delimiter&&(this.parser=b.Parsers.Delimited)),a.delimiter&&(a.dataType="text"),this.importer===null&&(a.url?a.interval?(this.importer=b.Importers.Polling,this.interval=a.interval):this.importer=b.Importers.Remote:this.importer=b.Importers.Local),this.parser=new this.parser(a),this.importer=new this.importer(a),a.comparator&&(this.comparator=a.comparator),a.ready&&(this.ready=a.ready),a.resetOnFetch&&(this.resetOnFetch=a.resetOnFetch),a.uniqueAgainst&&(this.uniqueAgainst=a.uniqueAgainst),_.isUndefined(a.data)&&_.isUndefined(a.url)&&this._addIdColumn(),a.deferred&&(this.deferred=a.deferred),a.columns&&this.addColumns(a.columns)},fetch:function(a){a=a||{};var b=this.deferred||new _.Deferred;if(_.isNull(this.importer))throw"No importer defined";return this.importer.fetch({success:_.bind(function(c){this.apply(c),this.comparator&&this.sort(),this.ready&&this.ready.call(this),a.success&&a.success.call(this),b.resolveWith(this,[this])},this),error:_.bind(function(c){a.error&&a.error.call(this),b.reject(c)},this)}),b.promise()},_applications:{againstColumn:function(a){var b=[],c=_.keys(a),d,e=this.column(this.uniqueAgainst),f=a[this._columns[1].name].length,g=_.max(_.map(c,function(b){return a[b].length},this)),h=[],i;for(i=0;i<f;i++){var j=a[this.uniqueAgainst][i];e.data.indexOf(j)!==-1&&h.push(i)}h.sort().reverse();for(i=0;i<g;i++)if(h.indexOf(i)===-1){d={};for(var k=0;k<c.length;k++)d[c[k]]=a[c[k]][i];b.push(d)}this.add(b)},blind:function(a){var b,c,d=[],e,f=_.keys(a),g=_.max(_.map(f,function(b){return a[b].length},this));for(var h=0;h<g;h++){e={};for(var i=0;i<f.length;i++)e[f[i]]=a[f[i]][h];d.push(e)}this.add(d)}},apply:function(a){var c=this.parser.parse(a);if(!this.fetched)this._addIdColumn(),this.addColumns(_.map(c.columns,function(a){return{name:a}})),b.Builder.detectColumnTypes(this,c.data),this._applications.blind.call(this,c.data),this.fetched=!0;else if(this.resetOnFetch)this.reset(),this._applications.blind.call(this,c.data);else if(this.uniqueAgainst){if(!this.hasColumn(this.uniqueAgainst))throw new Error("You requested a unique add against a column that doesn't exist.");this._applications.againstColumn.call(this,c.data)}else this._applications.blind.call(this,c.data);b.Builder.cacheRows(this)},addColumns:function(a){_.each(a,function(a){this.addColumn(a)},this)},addColumn:function(a){return _.isUndefined(this.column(a.name))?(a=new b.Column(a),this._columns.push(a),this._columnPositionByName[a.name]=this._columns.length-1,a):!1},_addIdColumn:function(a){if(!_.isUndefined(this.column("_id")))return;var b=[];a&&a>0&&_.times(a,function(){b.push(_.uniqueId())}),this.addColumn({name:"_id",type:"number",data:b});if(this._columnPositionByName._id!==0){var c=this._columns[this._columnPositionByName._id],d=this._columnPositionByName._id;this._columns.splice(d,1),this._columns.unshift(c),this._columnPositionByName._id=0,_.each(this._columnPositionByName,function(a,b){b!=="_id"&&this._columnPositionByName[b]<d&&this._columnPositionByName[b]++},this)}},add:function(a,b){b=b||{},_.isArray(a)||(a=[a]);var c=[];_.each(a,function(a){a._id||(a._id=_.uniqueId()),this._add(a,b),this.syncable&&!b.silent&&c.push({changed:a})},this);if(this.syncable&&!b.silent){var d=this._buildEvent(c);this.trigger("add",d),this.trigger("change",d)}return this},remove:function(a,b){a=this._rowFilter(a);var c=[],d=[];this.each(function(b,e){a(b)&&(d.push(b._id),c.push({old:b}))}),_.each(d,function(a){this._remove(a)},this);if(this.syncable&&(!b||!b.silent)){var e=this._buildEvent(c);this.trigger("remove",e),this.trigger("change",e)}},update:function(a,c,d){var e=_.keys(c),f=[],g=_.bind(function(a,d){var g;_.each(e,function(a){g=this.column(a);var e=b.types[g.type];if(e)if(b.typeOf(c[g.name],g)===g.type)_.isUndefined(g.before)||(c[g.name]=g.before(c[g.name])),c[g.name]=e.coerce(c[g.name],g);else throw"incorrect value '"+c[g.name]+"' of type "+b.typeOf(c[g.name],g)+" passed to column with type "+g.type;g.data[d]=c[g.name]},this),f.push({_id:a._id,old:a,changed:c})},this);_.isString(a)&&(a=[a]);if(_.isArray(a)){var h,i;_.each(a,function(a){h=this.rowById(a),i=this._rowPositionById[a],g(h,i)})}else a=this._rowFilter(a),this.each(function(b,c){a(b)&&g(b,c)},this);if(this.syncable&&(!d||!d.silent)){var j=this._buildEvent(f);this.trigger("update",j),this.trigger("change",j)}return this},reset:function(a){_.each(this._columns,function(a){a.data=[]}),this.length=0,this.syncable&&(!a||!a.silent)&&this.trigger("reset")}})}(this,_,moment),function(a,_){var b=a.Miso||(a.Miso={});b.Derived=function(a){a=a||{},b.Dataset.call(this),this.parent=a.parent,this.method=a.method,this._addIdColumn(),this.addColumn({name:"_oids",type:"mixed"}),this.parent.syncable&&(_.extend(this,b.Events),this.syncable=!0,this.parent.bind("change",this._sync,this))},b.Derived.prototype=new b.Dataset,_.extend(b.Derived.prototype,{_sync:function(a){this.func.call(this.args),this.trigger("change")}}),_.extend(b.DataView.prototype,{movingAverage:function(a,c,d){d=d||{};var e=new b.Derived({parent:this,method:d.method||_.mean,size:c,args:arguments});this.eachColumn(function(a){e.addColumn({name:a,type:this.column(a).type,data:[]})},this),b.Builder.cacheColumns(e);var f=function(){var d=[];typeof a=="string"&&(a=[a]),this.column("_id").data=this.parent.column("_id").data.slice(c-1,this.parent.length),this.eachColumn(function(b,d,e){a.indexOf(b)===-1&&b!=="_oids"?d.data=this.parent.column(b).data.slice(c-1,this.parent.length):d.data=_.movingAvg(this.parent.column(b).data,c,this.method)},this),this.length=this.parent.length-c+1;var e=this.column("_oids");e.data=[];for(var f=0;f<this.length;f++)e.data.push(this.parent.column("_id").data.slice(f,f+c));return b.Builder.cacheRows(this),this};return e.func=_.bind(f,e),e.func.call(e.args)},countBy:function(a,c){function j(a,c,d){var e;for(e=0;e<a.length;e++)if(b.types[d].compare(a[e],c)===0)return e;return-1}c=c||{};var d=new b.Derived({parent:this,method:_.sum,args:arguments}),e=this.column(a);d.addColumn({name:a,type:e.type}),d.addColumn({name:"count",type:"number"}),d.addColumn({name:"_oids",type:"mixed"}),b.Builder.cacheColumns(d);var f=d._column(a).data,g=d._column("count").data,h=d._column("_oids").data,i=d._column("_id").data;return this.each(function(b){var c=j(f,b[a],e.type);c===-1?(f.push(b[a]),i.push(_.uniqueId()),g.push(1),h.push([b._id])):(g[c]+=1,h[c].push(b._id))}),b.Builder.cacheRows(d),d},groupBy:function(a,c,d){d=d||{};var e=new b.Derived({parent:this,method:d.method||_.sum,args:arguments});d&&d.preprocess&&(e.preprocess=d.preprocess);var f=_.union([a],c);_.each(f,function(a){this.addColumn({name:a,type:this.parent.column(a).type})},e),b.Builder.cacheColumns(e);var g=function(){b.Builder.clearRowCache(this);var d={},e=0,f=this._columnPositionByName[a],g=this.parent.column(a);for(var h=0;h<this.parent.length;h++){var i=null;this.preprocess?i=this.preprocess(g.data[h]):i=g.data[h],_.isUndefined(d[i])&&(d[i]=e,_.each(c,function(a){var b=this.column(a),c=this.column("_id");b.data[e]=[],c.data[e]=_.uniqueId()},this),this.column(a).data[e]=i,e++),_.each(c,function(a){var b=this.column(a),c=this.parent.column(a).data[h],e=d[i];b.data[e].push(this.parent.rowByPosition(h))},this)}var j=this._columns[this._columnPositionByName._oids];return j.data=[],_.each(c,function(a){var b=this.column(a);_.each(b.data,function(c,d){_.isArray(c)&&(j.data[d]=j.data[d]||[],j.data[d].push(_.map(c,function(a){return a._id})),j.data[d]=_.flatten(j.data[d]),b.data[d]=this.method(_.map(c,function(b){return b[a]})),this.length++)},this)},this),b.Builder.cacheRows(this),this};return e.func=_.bind(g,e),e.func.call(e.args)}})}(this,_),function(a,_){var b=a.Miso||(a.Miso={});b.Importers=function(a,b){},b.Importers.prototype.extract=function(a){return a=_.clone(a),a}}(this,_),function(a,_){var b=a.Miso||(a.Miso={});b.Importers.Local=function(a){a=a||{},this.data=a.data||null,this.extract=a.extract||this.extract},_.extend(b.Importers.Local.prototype,b.Importers.prototype,{fetch:function(a){var b=a.data?a.data:this.data;a.success(this.extract(b))}})}(this,_),function(a,_){var b=a.Miso||(a.Miso={});b.Importers.Remote=function(a){a=a||{},this._url=a.url,this.extract=a.extract||this.extract,this.params={type:"GET",url:_.isFunction(this._url)?_.bind(this._url,this):this._url,dataType:a.dataType?a.dataType:a.jsonp?"jsonp":"json"}},_.extend(b.Importers.Remote.prototype,b.Importers.prototype,{fetch:function(a){var c=_.bind(function(b){a.success(this.extract(b))},this);b.Xhr(_.extend(this.params,{success:c,error:a.error}))}});var c={url:"",data:"",dataType:"",success:function(){},type:"GET",async:!0,xhr:function(){return new a.XMLHttpRequest}},d=/\?/;b.Xhr=function(a){a.dataType=a.dataType&&a.dataType.toLowerCase()||null;var e=_.isFunction(a.url)?a.url():a.url;if(!(!a.dataType||a.dataType!=="jsonp"&&a.dataType!=="script")){b.Xhr.getJSONP(e,a.success,a.dataType==="script",a.error);return}var f=_.extend({},c,a,{url:e});f.ajax=f.xhr();if(f.ajax)return f.type==="GET"&&f.data&&(f.url+=(d.test(f.url)?"&":"?")+f.data,f.data=null),f.ajax.open(f.type,f.url,f.async),f.ajax.send(f.data||null),b.Xhr.httpData(f)},b.Xhr.getJSONP=function(a,b,c,d){if(c){var e=document.querySelectorAll('script[src="'+a+'"]');if(e.length){b&&b(!0);return}}var f=document.head||document.getElementsByTagName("head")[0]||document.documentElement,g=document.createElement("script"),h=a.split("?")[1],i=!1,j=[],k,l,m;h&&!c&&(j=h.split("&")),j.length&&(l=j[j.length-1].split("=")),k=j.length?l[1]?l[1]:l[0]:"jsonp",!h&&!c&&(a+="?callback="+k),k&&!c&&(!window[k]||(k=k+ +(new Date)+_.uniqueId()),window[k]=function(a){b&&b(a),i=!0},a=a.replace(l.join("="),l[0]+"="+k)),g.onload=g.onreadystatechange=function(){if(!g.readyState||/loaded|complete/.test(g.readyState)){c&&b&&b();if(i){try{delete window[k]}catch(a){window[k]=void 0}f.removeChild(g)}}},g.onerror=function(a){d&&d.call(null)},g.src=a,f.insertBefore(g,f.firstChild);return},b.Xhr.httpData=function(a){var b,c=null;return a.ajax.onreadystatechange=function(){if(a.ajax.readyState===4){try{c=JSON.parse(a.ajax.responseText)}catch(d){}b={xml:a.ajax.responseXML,text:a.ajax.responseText,json:c},a.dataType&&(b=b[a.dataType]),/(2..)/.test(a.ajax.status)?a.success.call(a.ajax,b):a.error&&a.error.call(null,a.ajax.statusText)}},b}}(this,_),function(a,_){var b=a.Miso||(a.Miso={});b.Importers.Polling=function(a){a=a||{},this.interval=a.interval||1e3,this._def=null,b.Importers.Remote.apply(this,[a])},_.extend(b.Importers.Polling.prototype,b.Importers.Remote.prototype,{fetch:function(c){this._def===null&&(this._def=_.Deferred(),this.success_callback=_.bind(function(a){c.success(this.extract(a)),this._def.resolve(this)},this),this.error_callback=_.bind(function(a){c.error(a),this._def.reject(a)},this)),_.when(this._def.promise()).then(function(a){var b=_.bind(function(){this.fetch({success:this.success_callback,error:this.error_callback})},a);a._timeout=setTimeout(b,a.interval),a._def=_.Deferred()}),b.Xhr(_.extend(this.params,{success:this.success_callback,error:this.error_callback})),a.imp=this},stop:function(){this._def!==null&&this._def.reject(),typeof this._timeout!="undefined"&&clearTimeout(this._timeout)},start:function(){this._def!==null&&(this._def=_.Deferred(),this.fetch())}})}(this,_),function(a,_){var b=a.Miso||(a.Miso={});b.Importers.GoogleSpreadsheet=function(a){a=a||{};if(a.url)a.url=a.url;else{if(_.isUndefined(a.key))throw new Error("Set options 'key' properties to point to your google document.");a.worksheet=a.worksheet||1,a.url="https://spreadsheets.google.com/feeds/cells/"+a.key+"/"+a.worksheet+"/public/basic?alt=json-in-script&callback=",delete a.key,delete a.worksheet}return this.params={type:"GET",url:a.url,dataType:"jsonp"},this},_.extend(b.Importers.GoogleSpreadsheet.prototype,b.Importers.Remote.prototype)}(this,_),function(a,_){var b=a.Miso||(a.Miso={});b.Parsers=function(a){this.options=a||{}},_.extend(b.Parsers.prototype,{parse:function(){}})}(this,_),function(a,_){var b=a.Miso||(a.Miso={});b.Parsers.Strict=function(a){this.options=a||{}},_.extend(b.Parsers.Strict.prototype,b.Parsers.prototype,{parse:function(a){var b={},c=[];return _.each(a.columns,function(a){c.push(a.name),b[a.name]=a.data}),{columns:c,data:b}}})}(this,_),function(a,_){var b=a.Miso||(a.Miso={});b.Parsers.Obj=b.Parsers,_.extend(b.Parsers.Obj.prototype,b.Parsers.prototype,{parse:function(a){var b=_.keys(a[0]),c={};return _.each(b,function(a){c[a]=[]}),_.each(b,function(b){_.times(a.length,function(d){c[b].push(a[d][b])})}),{columns:b,data:c}}})}(this,_),function(a,_){var b=a.Miso||(a.Miso={});b.Parsers.GoogleSpreadsheet=function(a){},_.extend(b.Parsers.GoogleSpreadsheet.prototype,b.Parsers.prototype,{parse:function(a){var b=[],c=[],d=/([A-Z]+)(\d+)/,e={};_.each(a.feed.entry,function(a,f){var g=d.exec(a.title.$t),h=g[1],i=parseInt(g[2],10);if(_.isUndefined(e[h]))e[h]=c.length,b[e[h]]=a.content.$t,c[e[h]]=[];else{var j=e[h];c[j][i-1]=a.content.$t}},this),c.length=_.max(_.pluck(c,"length"))-1;var f={};return _.each(c,function(a,c){a.splice(0,1);for(var d=0;d<a.length;d++)if(_.isUndefined(a[d])||a[d]==="")a[d]=null;f[b[c]]=a}),{columns:b,data:f}}})}(this,_),function(a,_){var b=a.Miso||(a.Miso={});b.Parsers.Delimited=function(a){a=a||{},this.delimiter=a.delimiter||",",this.__delimiterPatterns=new RegExp("(\\"+this.delimiter+"|\\r?\\n|\\r|^)"+'(?:"([^"]*(?:""[^"]*)*)"|'+'([^"\\'+this.delimiter+"\\r\\n]*))","gi")},_.extend(b.Parsers.Delimited.prototype,b.Parsers.prototype,{parse:function(a){var b=[],c={},d=function(a,d,e){e=e||",";var f=null,g=0,h=!1,i=-1,j=0;try{while(f=a.exec(d)){var k=f[1];if(k.length&&k!==e){j++;if(i<g-1)throw j--,new Error("Not enough items in row");h=!0,i=0}else h||g++,i++;var l=null;f[2]?l=f[2].replace(new RegExp('""',"g"),'"'):l=f[3];if(h){l===""&&(l=null);if(typeof c[b[i]]=="undefined")throw new Error("Too many items in row");c[b[i]].push(l)}else b.push(l),c[l]=[]}}catch(m){throw new Error("Error while parsing delimited data on row "+j+". Message: "+m.message)}return{columns:b,data:c}};return d(this.__delimiterPatterns,a,this.delimiter)}})}(this,_)
+(function(a,_){var b=a.Miso={};b.typeOf=function(a,c){var d=_.keys(b.types),e;return d.push(d.splice(_.indexOf(d,"string"),1)[0]),d.push(d.splice(_.indexOf(d,"mixed"),1)[0]),e=_.find(d,function(d){return b.types[d].test(a,c)}),e=_.isUndefined(e)?"string":e,e},b.types={mixed:{name:"mixed",coerce:function(a){return a},test:function(a){return!0},compare:function(a,b){return a<b?-1:a>b?1:0},numeric:function(a){return _.isNaN(Number(a))?0:Number(a)}},string:{name:"string",coerce:function(a){return a==null?null:a.toString()},test:function(a){return a===null||typeof a=="undefined"||typeof a=="string"},compare:function(a,b){return a==null&&b!=null?-1:a!=null&&b==null?1:a<b?-1:a>b?1:0},numeric:function(a,b){return b}},"boolean":{name:"boolean",regexp:/^(true|false)$/,coerce:function(a){return a==="false"?!1:Boolean(a)},test:function(a){return a===null||typeof a=="undefined"||typeof a=="boolean"||this.regexp.test(a)?!0:!1},compare:function(a,b){return a==null&&b!=null?-1:a!=null&&b==null?1:a==null&&b==null?0:a===b?0:a<b?-1:1},numeric:function(a){return a?1:0}},number:{name:"number",regexp:/^[\-\.]?[0-9]+([\.][0-9]+)?$/,coerce:function(a){return _.isNull(a)?null:_.isNaN(a)?null:+a},test:function(a){return a===null||typeof a=="undefined"||typeof a=="number"||this.regexp.test(a)?!0:!1},compare:function(a,b){return a==null&&b!=null?-1:a!=null&&b==null?1:a==null&&b==null?0:a===b?0:a<b?-1:1},numeric:function(a){return a}},time:{name:"time",format:"DD/MM/YYYY",_formatLookup:[["DD","\\d{2}"],["D","\\d{1}|\\d{2}"],["MM","\\d{2}"],["M","\\d{1}|\\d{2}"],["YYYY","\\d{4}"],["YY","\\d{2}"],["A","[AM|PM]"],["hh","\\d{2}"],["h","\\d{1}|\\d{2}"],["mm","\\d{2}"],["m","\\d{1}|\\d{2}"],["ss","\\d{2}"],["s","\\d{1}|\\d{2}"],["ZZ","[-|+]\\d{4}"],["Z","[-|+]\\d{2}:\\d{2}"]],_regexpTable:{},_regexp:function(a){if(this._regexpTable[a])return new RegExp(this._regexpTable[a],"g");var b=a;return _.each(this._formatLookup,function(a){b=b.replace(a[0],a[1])},this),b=b.split("/").join("\\/"),this._regexpTable[a]=b,new RegExp(this._regexpTable[a],"g")},coerce:function(a,b){b=b||{};if(_.isString(a)){var c=b.format||this.format;return moment(a,b.format)}return _.isNumber(a)?moment(a):a},test:function(a,b){b=b||{};if(a===null||typeof a=="undefined")return!0;if(_.isString(a)){var c=b.format||this.format,d=this._regexp(c);return d.test(a)}return!0},compare:function(a,b){return a<b?-1:a>b?1:0},numeric:function(a){return a.valueOf()}}}})(this,_),function(a,_){var b=a.Miso||(a.Miso={});b.Event=function(a){_.isArray(a)||(a=[a]),this.deltas=a},_.extend(b.Event.prototype,{affectedColumns:function(){var a=[];return _.each(this.deltas,function(b){a=_.union(a,_.isUndefined(b.old)?[]:_.keys(b.old),_.isUndefined(b.changed)?[]:_.keys(b.changed))}),a}}),_.extend(b.Event,{isRemove:function(a){return _.isUndefined(a.changed)||_.keys(a.changed).length===0?!0:!1},isAdd:function(a){return _.isUndefined(a.old)||_.keys(a.old).length===0?!0:!1},isUpdate:function(a){return!this.isRemove(a)&&!this.isAdd(a)?!0:!1}}),b.Events={},b.Events.bind=function(a,b,c){var d=this._callbacks||(this._callbacks={}),e=d[a]||(d[a]={}),f=e.tail||(e.tail=e.next={});return f.callback=b,f.context=c,e.tail=f.next={},this},b.Events.unbind=function(a,b){var c,d,e;if(!a)this._callbacks=null;else if(c=this._callbacks)if(!b)c[a]={};else if(d=c[a])while((e=d)&&(d=d.next)){if(d.callback!==b)continue;e.next=d.next,d.context=d.callback=null;break}return this},b.Events.trigger=function(a){var b,c,d,e,f,g=["all",a];if(!(c=this._callbacks))return this;while(f=g.pop()){if(!(b=c[f]))continue;e=f==="all"?arguments:Array.prototype.slice.call(arguments,1);while(b=b.next)(d=b.callback)&&d.apply(b.context||this,e)}return this},b.Events._buildEvent=function(a){return new b.Event(a)}}(this,_),function(a,_){var b=a.Miso||{};b.Builder={detectColumnType:function(a,c){var d=_.inject(c.slice(0,5),function(a,c){var d=b.typeOf(c);return c!==""&&a.indexOf(d)===-1&&!_.isNull(c)&&a.push(d),a},[]);return d.length===1?a.type=d[0]:a.type="mixed",a},detectColumnTypes:function(a,c){_.each(c,function(c,d){var e=a.column(d);if(e.type){e.force=!0;return}b.Builder.detectColumnType(e,c)},this)},cacheRows:function(a){b.Builder.clearRowCache(a),_.each(a._columns[a._columnPositionByName._id].data,function(b,c){a._rowPositionById[b]=c,a._rowIdByPosition.push(b)},a);var c=_.uniq(_.map(a._columns,function(a){return a.data.length}));if(c.length>1)throw new Error("Row lengths need to be the same. Empty values should be set to null."+_.map(a._columns,function(a){return a.data+"|||"}));a.length=c[0]},clearRowCache:function(a){a._rowPositionById={},a._rowIdByPosition=[]},cacheColumns:function(a){a._columnPositionByName={},_.each(a._columns,function(b,c){a._columnPositionByName[b.name]=c})}},Array.prototype.indexOf||(Array.prototype.indexOf=function(a,b){for(var c=b||0,d=this.length;c<d;c++)if(this[c]===a)return c;return-1})}(this,_),function(a,_){var b=a.Miso;b.Column=function(a){return _.extend(this,a),this._id=a.id||_.uniqueId(),this.data=a.data||[],this},_.extend(b.Column.prototype,{toNumeric:function(a,c){return b.types[this.type].numeric(a,c)},numericAt:function(a){return this.toNumeric(this.data[a],a)},coerce:function(){this.data=_.map(this.data,function(a){return b.types[this.type].coerce(a,this)},this)},_sum:function(){return _.sum(this.data)},_mean:function(){var a=0;for(var c=0;c<this.data.length;c++)a+=this.numericAt(c);return a/=this.data.length,b.types[this.type].coerce(a,this)},_median:function(){return b.types[this.type].coerce(_.median(this.data),this)},_max:function(){var a=-Infinity;for(var c=0;c<this.data.length;c++)b.types[this.type].compare(this.data[c],a)>0&&(a=this.numericAt(c));return b.types[this.type].coerce(a,this)},_min:function(){var a=Infinity;for(var c=0;c<this.data.length;c++)b.types[this.type].compare(this.data[c],a)<0&&(a=this.numericAt(c));return b.types[this.type].coerce(a,this)}}),b.DataView=function(a){if(typeof a!="undefined"){a=a||(a={});if(_.isUndefined(a.parent))throw new Error("A view must have a parent specified.");this.parent=a.parent,this._initialize(a)}},_.extend(b.DataView.prototype,{_initialize:function(a){this.parent.syncable===!0&&(_.extend(this,b.Events),this.syncable=!0),this.filter={columns:this._columnFilter(a.filter.columns||undefined),rows:this._rowFilter(a.filter.rows||undefined)},this._columns=this._selectData(),b.Builder.cacheColumns(this),b.Builder.cacheRows(this),this.syncable&&this.parent.bind("change",this._sync,this)},_sync:function(a){var c=a.deltas,d=null;_.each(c,function(c,e){var f=this._rowPositionById[c._id];if(typeof f=="undefined"&&b.Event.isAdd(c))this.filter.rows&&this.filter.rows(c.changed)&&(this._add(c.changed),d="add");else{if(f==="undefined")return;_.each(c.changed,function(a,b){var c=this._columnPositionByName[b];if(_.isUndefined(c))return;this._columns[c].data[f]=a,d="update"},this)}var g=this.rowByPosition(f);if(b.Event.isRemove(c)||this.filter.row&&!this.filter.row(g)){var h={_id:c._id,old:this.rowByPosition(f),changed:{}};a.deltas.splice(e,1,h),this._remove(f),d="delete"}},this),this.syncable&&(this.trigger(d,a),this.trigger("change",a))},where:function(a,c){return c=c||{},c.parent=this,c.filter=a||{},new b.DataView(c)},_selectData:function(){var a=[];return _.each(this.parent._columns,function(c){this.filter.columns(c)&&a.push(new b.Column({name:c.name,data:[],type:c.type,_id:c._id}))},this),this.parent.each(function(b){if(!this.filter.rows(b))return;for(var c=0;c<a.length;c++)a[c].data.push(b[a[c].name])},this),a},_columnFilter:function(a){var b;return _.isUndefined(a)?b=function(){return!0}:(_.isString(a)&&(a=[a]),a.push("_id"),b=function(b){return _.indexOf(a,b.name)===-1?!1:!0}),b},_rowFilter:function(a){var b;return _.isNumber(a)&&(a=[a]),_.isUndefined(a)?b=function(){return!0}:_.isFunction(a)?b=a:b=function(b){return _.indexOf(a,b._id)===-1?!1:!0},b},column:function(a){return this._column(a)},_column:function(a){if(_.isUndefined(this._columnPositionByName))return undefined;var b=this._columnPositionByName[a];return this._columns[b]},columns:function(a){return new b.DataView({filter:{columns:a},parent:this})},columnNames:function(){var a=_.pluck(this._columns,"name");return _.reject(a,function(a){return a==="_id"||a==="_oids"})},hasColumn:function(a){return!_.isUndefined(this._columnPositionByName[a])},each:function(a,b){for(var c=0;c<this.length;c++)a.apply(b||this,[this.rowByPosition(c),c])},eachColumn:function(a,b){var c=this.columnNames();for(var d=0;d<c.length;d++)a.apply(b||this,[c[d],this.column(c[d]),d])},rowByPosition:function(a){return this._row(a)},rowById:function(a){return this._row(this._rowPositionById[a])},_row:function(a){var b={};return _.each(this._columns,function(c){b[c.name]=c.data[a]}),b},_remove:function(a){var b=this._rowPositionById[a];return _.each(this._columns,function(a){a.data.splice(b,1)}),delete this._rowPositionById[a],this._rowIdByPosition.splice(b,1),this.length--,this},_add:function(a,c){_.each(a,function(c,d){var e=this.column(d);if(typeof e!="undefined"){var f=b.types[e.type];if(e.force||f.test(a[e.name],e))_.isUndefined(e.before)||(a[e.name]=e.before(a[e.name])),a[e.name]=f.coerce(a[e.name],e);else throw"incorrect value '"+a[e.name]+"' of type "+b.typeOf(a[e.name],e)+" passed to column with type "+e.type}},this);if(_.isUndefined(this.comparator))_.each(this._columns,function(b){b.data.push(!_.isUndefined(a[b.name])&&!_.isNull(a[b.name])?a[b.name]:null)}),this.length++,this._rowIdByPosition=this._rowIdByPosition||(this._rowIdByPosition=[]),this._rowPositionById=this._rowPositionById||(this._rowPositionById={}),this._rowIdByPosition.push(a._id),this._rowPositionById[a._id]=this._rowIdByPosition.length;else{var d=function(a,b,c){Array.prototype.splice.apply(c,[a,0].concat(b))},e;this.length++;for(e=0;e<this.length;e++){var f=this.rowByPosition(e);if(_.isUndefined(f._id)||this.comparator(a,f)<0){_.each(this._columns,function(b){d(e,a[b.name]?a[b.name]:null,b.data)});break}}this._rowIdByPosition=[],this._rowPositionById={},this.each(function(a,b){this._rowIdByPosition.push(a._id),this._rowPositionById[a._id]=b})}return this},rows:function(a){return new b.DataView({filter:{rows:a},parent:this})},sort:function(a){a=a||{},a.comparator&&(this.comparator=a.comparator);if(_.isUndefined(this.comparator))throw new Error("Cannot sort without this.comparator.");var b=this.length,c;if(b===1)return;var d=_.bind(function(a,b){var c=this.rowByPosition(b);_.each(c,function(c,d){var e=this._columnPositionByName[d],f=this._columns[e].data[a];this._columns[e].data.splice(a,1,c),this._columns[e].data.splice(b,1,f)},this)},this),e=_.bind(function(a,b){var c=a,e;while(c*2<=b){e=c*2;var f=this.rowByPosition(c);e+1<b&&this.comparator(this.rowByPosition(e),this.rowByPosition(e+1))<0&&e++;if(this.comparator(f,this.rowByPosition(e))<0)d(c,e),c=e;else return}},this),f=function(a){var b=Math.round((a-2)/2);while(b>=0)e(b,a-1),b--};if(b>2){f(b),c=b-1;while(c>1)d(c,0),c--,e(0,c)}else this.comparator(this.rowByPosition(0),this.rowByPosition(1))>0&&d(0,1);return this.comparator(this.rowByPosition(this.length-2),this.rowByPosition(this.length-1))>0&&d(this.length-1,this.length-2),this.syncable&&a.silent&&this.trigger("sort"),this},toJSON:function(){var a=[];for(var b=0;b<this.length;b++)a.push(this.rowByPosition(b));return a}})}(this,_),function(a,_){var b=a.Miso;b.Product=b.Product||function(a){a=a||{},this.func=a.func;if(a.columns){var b=a.columns;_.isArray(a.columns)&&(b=a.columns[0]),this.valuetype=b.type,this.numeric=function(){return b.toNumeric(this.value)}}return this.func({silent:!0}),this},_.extend(b.Product.prototype,b.Events,{val:function(){return this.value},type:function(){return this.valuetype},_sync:function(a){this.func()},_buildDelta:function(a,b){return{old:a,changed:b}}}),_.extend(b.DataView.prototype,{_findColumns:function(a){var b=[];return _.isUndefined(a)&&(a=this.columnNames()),a=_.isArray(a)?a:[a],_.each(a,function(a){a=this._columns[this._columnPositionByName[a]],b.push(a)},this),b},sum:function(a,c){c=c||{};var d=this._findColumns(a),e=function(a){return function(){return _.each(a,function(a){if(a.type===b.types.time.name)throw new Error("Can't sum up time")}),_.sum(_.map(a,function(a){return a._sum()}))}}(d);return this._calculated(d,e)},max:function(a,c){c=c||{};var d=this._findColumns(a),e=function(a){return function(){var c=_.max(_.map(a,function(a){return a._max()})),d=a[0].type,e=a[0].typeOptions;return b.types[d].coerce(c,e)}}(d);return this._calculated(d,e)},min:function(a,c){c=c||{};var d=this._findColumns(a),e=function(a){return function(){var c=_.min(_.map(a,function(a){return a._min()})),d=a[0].type,e=a[0].typeOptions;return b.types[d].coerce(c,e)}}(d);return this._calculated(d,e)},mean:function(a,c){c=c||{};var d=this._findColumns(a),e=function(a){return function(){var c=[];_.each(a,function(a){c.push(a.data)}),c=_.flatten(c);var d=a[0].type,e=a[0].typeOptions;return c=_.map(c,function(a){return b.types[d].numeric(a)}),b.types[d].coerce(_.mean(c),e)}}(d);return this._calculated(d,e)},_calculated:function(a,c){var d=this,e=new b.Product({columns:a,func:function(a){a=a||{};var b=this._buildDelta(this.value,c.apply(d));this.value=b.changed;if(d.syncable){var e=this._buildEvent(b);!_.isUndefined(b.old)&&!a.silent&&b.old!==b.changed&&this.trigger("change",e)}}});return this.syncable?(this.bind("change",e._sync,e),e):c()}})}(this,_),function(a,_,moment){var b=a.Miso;b.Dataset=function(a){this.length=0,this._columns=[],this._columnPositionByName={},typeof a!="undefined"&&(a=a||{},this._initialize(a))},b.Dataset.prototype=new b.DataView,_.extend(b.Dataset.prototype,{_initialize:function(a){a.sync===!0&&(_.extend(this,b.Events),this.syncable=!0),this.importer=a.importer||null,this.parser=a.parser||b.Parsers.Obj,_.isUndefined(a.parser)&&(a.strict?this.parser=b.Parsers.Strict:a.delimiter&&(this.parser=b.Parsers.Delimited)),a.delimiter&&(a.dataType="text"),this.importer===null&&(a.url?a.interval?(this.importer=b.Importers.Polling,this.interval=a.interval):this.importer=b.Importers.Remote:this.importer=b.Importers.Local),this.parser=new this.parser(a),this.importer=new this.importer(a),a.comparator&&(this.comparator=a.comparator),a.ready&&(this.ready=a.ready),a.resetOnFetch&&(this.resetOnFetch=a.resetOnFetch),a.uniqueAgainst&&(this.uniqueAgainst=a.uniqueAgainst),_.isUndefined(a.data)&&_.isUndefined(a.url)&&this._addIdColumn(),a.deferred&&(this.deferred=a.deferred),a.columns&&this.addColumns(a.columns)},fetch:function(a){a=a||{};var b=this.deferred||new _.Deferred;if(_.isNull(this.importer))throw"No importer defined";return this.importer.fetch({success:_.bind(function(c){this.apply(c),this.comparator&&this.sort(),this.ready&&this.ready.call(this),a.success&&a.success.call(this),b.resolveWith(this,[this])},this),error:_.bind(function(c){a.error&&a.error.call(this),b.reject(c)},this)}),b.promise()},_applications:{againstColumn:function(a){var b=[],c=_.keys(a),d,e=this.column(this.uniqueAgainst),f=a[this._columns[1].name].length,g=_.max(_.map(c,function(b){return a[b].length},this)),h=[],i;for(i=0;i<f;i++){var j=a[this.uniqueAgainst][i];e.data.indexOf(j)!==-1&&h.push(i)}h.sort().reverse();for(i=0;i<g;i++)if(h.indexOf(i)===-1){d={};for(var k=0;k<c.length;k++)d[c[k]]=a[c[k]][i];b.push(d)}this.add(b)},blind:function(a){var b,c,d=[],e,f=_.keys(a),g=_.max(_.map(f,function(b){return a[b].length},this));for(var h=0;h<g;h++){e={};for(var i=0;i<f.length;i++)e[f[i]]=a[f[i]][h];d.push(e)}this.add(d)}},apply:function(a){var c=this.parser.parse(a);if(!this.fetched)this._addIdColumn(),this.addColumns(_.map(c.columns,function(a){return{name:a}})),b.Builder.detectColumnTypes(this,c.data),this._applications.blind.call(this,c.data),this.fetched=!0;else if(this.resetOnFetch)this.reset(),this._applications.blind.call(this,c.data);else if(this.uniqueAgainst){if(!this.hasColumn(this.uniqueAgainst))throw new Error("You requested a unique add against a column that doesn't exist.");this._applications.againstColumn.call(this,c.data)}else this._applications.blind.call(this,c.data);b.Builder.cacheRows(this)},addColumns:function(a){_.each(a,function(a){this.addColumn(a)},this)},addColumn:function(a){return _.isUndefined(this.column(a.name))?(a=new b.Column(a),this._columns.push(a),this._columnPositionByName[a.name]=this._columns.length-1,a):!1},_addIdColumn:function(a){if(!_.isUndefined(this.column("_id")))return;var b=[];a&&a>0&&_.times(a,function(){b.push(_.uniqueId())}),this.addColumn({name:"_id",type:"number",data:b});if(this._columnPositionByName._id!==0){var c=this._columns[this._columnPositionByName._id],d=this._columnPositionByName._id;this._columns.splice(d,1),this._columns.unshift(c),this._columnPositionByName._id=0,_.each(this._columnPositionByName,function(a,b){b!=="_id"&&this._columnPositionByName[b]<d&&this._columnPositionByName[b]++},this)}},add:function(a,b){b=b||{},_.isArray(a)||(a=[a]);var c=[];_.each(a,function(a){a._id||(a._id=_.uniqueId()),this._add(a,b),this.syncable&&!b.silent&&c.push({changed:a})},this);if(this.syncable&&!b.silent){var d=this._buildEvent(c);this.trigger("add",d),this.trigger("change",d)}return this},remove:function(a,b){a=this._rowFilter(a);var c=[],d=[];this.each(function(b,e){a(b)&&(d.push(b._id),c.push({old:b}))}),_.each(d,function(a){this._remove(a)},this);if(this.syncable&&(!b||!b.silent)){var e=this._buildEvent(c);this.trigger("remove",e),this.trigger("change",e)}},update:function(a,c,d){var e=_.keys(c),f=[],g=_.bind(function(a,d){var g;_.each(e,function(a){g=this.column(a);var e=b.types[g.type];if(e)if(b.typeOf(c[g.name],g)===g.type)_.isUndefined(g.before)||(c[g.name]=g.before(c[g.name])),c[g.name]=e.coerce(c[g.name],g);else throw"incorrect value '"+c[g.name]+"' of type "+b.typeOf(c[g.name],g)+" passed to column with type "+g.type;g.data[d]=c[g.name]},this),f.push({_id:a._id,old:a,changed:c})},this);_.isString(a)&&(a=[a]);if(_.isArray(a)){var h,i;_.each(a,function(a){h=this.rowById(a),i=this._rowPositionById[a],g(h,i)})}else a=this._rowFilter(a),this.each(function(b,c){a(b)&&g(b,c)},this);if(this.syncable&&(!d||!d.silent)){var j=this._buildEvent(f);this.trigger("update",j),this.trigger("change",j)}return this},reset:function(a){_.each(this._columns,function(a){a.data=[]}),this.length=0,this.syncable&&(!a||!a.silent)&&this.trigger("reset")}})}(this,_,moment),function(a,_){var b=a.Miso||(a.Miso={});b.Derived=function(a){a=a||{},b.Dataset.call(this),this.parent=a.parent,this.method=a.method,this._addIdColumn(),this.addColumn({name:"_oids",type:"mixed"}),this.parent.syncable&&(_.extend(this,b.Events),this.syncable=!0,this.parent.bind("change",this._sync,this))},b.Derived.prototype=new b.Dataset,_.extend(b.Derived.prototype,{_sync:function(a){this.func.call(this.args),this.trigger("change")}}),_.extend(b.DataView.prototype,{movingAverage:function(a,c,d){d=d||{};var e=new b.Derived({parent:this,method:d.method||_.mean,size:c,args:arguments});this.eachColumn(function(a){e.addColumn({name:a,type:this.column(a).type,data:[]})},this),b.Builder.cacheColumns(e);var f=function(){var d=[];typeof a=="string"&&(a=[a]),this.column("_id").data=this.parent.column("_id").data.slice(c-1,this.parent.length),this.eachColumn(function(b,d,e){a.indexOf(b)===-1&&b!=="_oids"?d.data=this.parent.column(b).data.slice(c-1,this.parent.length):d.data=_.movingAvg(this.parent.column(b).data,c,this.method)},this),this.length=this.parent.length-c+1;var e=this.column("_oids");e.data=[];for(var f=0;f<this.length;f++)e.data.push(this.parent.column("_id").data.slice(f,f+c));return b.Builder.cacheRows(this),this};return e.func=_.bind(f,e),e.func.call(e.args)},countBy:function(a,c){function j(a,c,d){var e;for(e=0;e<a.length;e++)if(b.types[d].compare(a[e],c)===0)return e;return-1}c=c||{};var d=new b.Derived({parent:this,method:_.sum,args:arguments}),e=this.column(a);d.addColumn({name:a,type:e.type}),d.addColumn({name:"count",type:"number"}),d.addColumn({name:"_oids",type:"mixed"}),b.Builder.cacheColumns(d);var f=d._column(a).data,g=d._column("count").data,h=d._column("_oids").data,i=d._column("_id").data;return this.each(function(b){var c=j(f,b[a],e.type);c===-1?(f.push(b[a]),i.push(_.uniqueId()),g.push(1),h.push([b._id])):(g[c]+=1,h[c].push(b._id))}),b.Builder.cacheRows(d),d},groupBy:function(a,c,d){d=d||{};var e=new b.Derived({parent:this,method:d.method||_.sum,args:arguments});d&&d.preprocess&&(e.preprocess=d.preprocess);var f=_.union([a],c);_.each(f,function(a){this.addColumn({name:a,type:this.parent.column(a).type})},e),b.Builder.cacheColumns(e);var g=function(){b.Builder.clearRowCache(this);var d={},e=0,f=this._columnPositionByName[a],g=this.parent.column(a);for(var h=0;h<this.parent.length;h++){var i=null;this.preprocess?i=this.preprocess(g.data[h]):i=g.data[h],_.isUndefined(d[i])&&(d[i]=e,_.each(c,function(a){var b=this.column(a),c=this.column("_id");b.data[e]=[],c.data[e]=_.uniqueId()},this),this.column(a).data[e]=i,e++),_.each(c,function(a){var b=this.column(a),c=this.parent.column(a).data[h],e=d[i];b.data[e].push(this.parent.rowByPosition(h))},this)}var j=this._columns[this._columnPositionByName._oids];return j.data=[],_.each(c,function(a){var b=this.column(a);_.each(b.data,function(c,d){_.isArray(c)&&(j.data[d]=j.data[d]||[],j.data[d].push(_.map(c,function(a){return a._id})),j.data[d]=_.flatten(j.data[d]),b.data[d]=this.method(_.map(c,function(b){return b[a]})),this.length++)},this)},this),b.Builder.cacheRows(this),this};return e.func=_.bind(g,e),e.func.call(e.args)}})}(this,_),function(a,_){var b=a.Miso||(a.Miso={});b.Importers=function(a,b){},b.Importers.prototype.extract=function(a){return a=_.clone(a),a}}(this,_),function(a,_){var b=a.Miso||(a.Miso={});b.Importers.Local=function(a){a=a||{},this.data=a.data||null,this.extract=a.extract||this.extract},_.extend(b.Importers.Local.prototype,b.Importers.prototype,{fetch:function(a){var b=a.data?a.data:this.data;a.success(this.extract(b))}})}(this,_),function(a,_){var b=a.Miso||(a.Miso={});b.Importers.Remote=function(a){a=a||{},this._url=a.url,this.extract=a.extract||this.extract,this.params={type:"GET",url:_.isFunction(this._url)?_.bind(this._url,this):this._url,dataType:a.dataType?a.dataType:a.jsonp?"jsonp":"json"}},_.extend(b.Importers.Remote.prototype,b.Importers.prototype,{fetch:function(a){var c=_.bind(function(b){a.success(this.extract(b))},this);b.Xhr(_.extend(this.params,{success:c,error:a.error}))}});var c={url:"",data:"",dataType:"",success:function(){},type:"GET",async:!0,xhr:function(){return new a.XMLHttpRequest}},d=/\?/;b.Xhr=function(a){a.dataType=a.dataType&&a.dataType.toLowerCase()||null;var e=_.isFunction(a.url)?a.url():a.url;if(!(!a.dataType||a.dataType!=="jsonp"&&a.dataType!=="script")){b.Xhr.getJSONP(e,a.success,a.dataType==="script",a.error);return}var f=_.extend({},c,a,{url:e});f.ajax=f.xhr();if(f.ajax)return f.type==="GET"&&f.data&&(f.url+=(d.test(f.url)?"&":"?")+f.data,f.data=null),f.ajax.open(f.type,f.url,f.async),f.ajax.send(f.data||null),b.Xhr.httpData(f)},b.Xhr.getJSONP=function(a,b,c,d){if(c){var e=document.querySelectorAll('script[src="'+a+'"]');if(e.length){b&&b(!0);return}}var f=document.head||document.getElementsByTagName("head")[0]||document.documentElement,g=document.createElement("script"),h=a.split("?")[1],i=!1,j=[],k,l,m;h&&!c&&(j=h.split("&")),j.length&&(l=j[j.length-1].split("=")),k=j.length?l[1]?l[1]:l[0]:"jsonp",!h&&!c&&(a+="?callback="+k),k&&!c&&(!window[k]||(k=k+ +(new Date)+_.uniqueId()),window[k]=function(a){b&&b(a),i=!0},a=a.replace(l.join("="),l[0]+"="+k)),g.onload=g.onreadystatechange=function(){if(!g.readyState||/loaded|complete/.test(g.readyState)){c&&b&&b();if(i){try{delete window[k]}catch(a){window[k]=void 0}f.removeChild(g)}}},g.onerror=function(a){d&&d.call(null)},g.src=a,f.insertBefore(g,f.firstChild);return},b.Xhr.httpData=function(a){var b,c=null;return a.ajax.onreadystatechange=function(){if(a.ajax.readyState===4){try{c=JSON.parse(a.ajax.responseText)}catch(d){}b={xml:a.ajax.responseXML,text:a.ajax.responseText,json:c},a.dataType&&(b=b[a.dataType]),/(2..)/.test(a.ajax.status)?a.success.call(a.ajax,b):a.error&&a.error.call(null,a.ajax.statusText)}},b}}(this,_),function(a,_){var b=a.Miso||(a.Miso={});b.Importers.Polling=function(a){a=a||{},this.interval=a.interval||1e3,this._def=null,b.Importers.Remote.apply(this,[a])},_.extend(b.Importers.Polling.prototype,b.Importers.Remote.prototype,{fetch:function(c){this._def===null&&(this._def=_.Deferred(),this.success_callback=_.bind(function(a){c.success(this.extract(a)),this._def.resolve(this)},this),this.error_callback=_.bind(function(a){c.error(a),this._def.reject(a)},this)),_.when(this._def.promise()).then(function(a){var b=_.bind(function(){this.fetch({success:this.success_callback,error:this.error_callback})},a);a._timeout=setTimeout(b,a.interval),a._def=_.Deferred()}),b.Xhr(_.extend(this.params,{success:this.success_callback,error:this.error_callback})),a.imp=this},stop:function(){this._def!==null&&this._def.reject(),typeof this._timeout!="undefined"&&clearTimeout(this._timeout)},start:function(){this._def!==null&&(this._def=_.Deferred(),this.fetch())}})}(this,_),function(a,_){var b=a.Miso||(a.Miso={});b.Importers.GoogleSpreadsheet=function(a){a=a||{};if(a.url)a.url=a.url;else{if(_.isUndefined(a.key))throw new Error("Set options 'key' properties to point to your google document.");a.worksheet=a.worksheet||1,a.url="https://spreadsheets.google.com/feeds/cells/"+a.key+"/"+a.worksheet+"/public/basic?alt=json-in-script&callback=",delete a.key,delete a.worksheet}return this.params={type:"GET",url:a.url,dataType:"jsonp"},this},_.extend(b.Importers.GoogleSpreadsheet.prototype,b.Importers.Remote.prototype)}(this,_),function(a,_){var b=a.Miso||(a.Miso={});b.Parsers=function(a){this.options=a||{}},_.extend(b.Parsers.prototype,{parse:function(){}})}(this,_),function(a,_){var b=a.Miso||(a.Miso={});b.Parsers.Strict=function(a){this.options=a||{}},_.extend(b.Parsers.Strict.prototype,b.Parsers.prototype,{parse:function(a){var b={},c=[];return _.each(a.columns,function(a){c.push(a.name),b[a.name]=a.data}),{columns:c,data:b}}})}(this,_),function(a,_){var b=a.Miso||(a.Miso={});b.Parsers.Obj=b.Parsers,_.extend(b.Parsers.Obj.prototype,b.Parsers.prototype,{parse:function(a){var b=_.keys(a[0]),c={};return _.each(b,function(a){c[a]=[]}),_.each(b,function(b){_.times(a.length,function(d){c[b].push(a[d][b])})}),{columns:b,data:c}}})}(this,_),function(a,_){var b=a.Miso||(a.Miso={});b.Parsers.GoogleSpreadsheet=function(a){},_.extend(b.Parsers.GoogleSpreadsheet.prototype,b.Parsers.prototype,{parse:function(a){var b=[],c=[],d=/([A-Z]+)(\d+)/,e={};_.each(a.feed.entry,function(a,f){var g=d.exec(a.title.$t),h=g[1],i=parseInt(g[2],10);if(_.isUndefined(e[h]))e[h]=c.length,b[e[h]]=a.content.$t,c[e[h]]=[];else{var j=e[h];c[j][i-1]=a.content.$t}},this),c.length=_.max(_.pluck(c,"length"))-1;var f={};return _.each(c,function(a,c){a.splice(0,1);for(var d=0;d<a.length;d++)if(_.isUndefined(a[d])||a[d]==="")a[d]=null;f[b[c]]=a}),{columns:b,data:f}}})}(this,_),function(a,_){var b=a.Miso||(a.Miso={});b.Parsers.Delimited=function(a){a=a||{},this.delimiter=a.delimiter||",",this.__delimiterPatterns=new RegExp("(\\"+this.delimiter+"|\\r?\\n|\\r|^)"+'(?:"([^"]*(?:""[^"]*)*)"|'+'([^"\\'+this.delimiter+"\\r\\n]*))","gi")},_.extend(b.Parsers.Delimited.prototype,b.Parsers.prototype,{parse:function(a){var b=[],c={},d=function(a,d,e){e=e||",";var f=null,g=0,h=!1,i=-1,j=0;try{while(f=a.exec(d)){var k=f[1];if(k.length&&k!==e){j++;if(i<g-1)throw j--,new Error("Not enough items in row");h=!0,i=0}else h||g++,i++;var l=null;f[2]?l=f[2].replace(new RegExp('""',"g"),'"'):l=f[3];if(h){l===""&&(l=null);if(typeof c[b[i]]=="undefined")throw new Error("Too many items in row");c[b[i]].push(l)}else b.push(l),c[l]=[]}}catch(m){throw new Error("Error while parsing delimited data on row "+j+". Message: "+m.message)}return{columns:b,data:c}};return d(this.__delimiterPatterns,a,this.delimiter)}})}(this,_)
View
5 dist/node/miso.ds.deps.0.1.0.js
@@ -349,8 +349,8 @@ var request = require("request");
_.each(this.deltas, function(delta) {
cols = _.union(cols,
- _.keys(delta.old),
- _.keys(delta.changed)
+ ( _.isUndefined(delta.old) ? [] : _.keys(delta.old) ),
+ ( _.isUndefined(delta.changed) ? [] : _.keys(delta.changed) )
);
});
@@ -478,6 +478,7 @@ var request = require("request");
return new Miso.Event(delta);
};
}(this, _));
+
(function(global, _) {
var Miso = global.Miso || {};
View
6 test/unit/events.js
@@ -56,7 +56,7 @@
});
ds.fetch({ success: function() {
this.bind('add', function(event) {
- equals( event.affectedColumns().length, 2)
+ equals( event.affectedColumns().length, 2);
});
}
});
@@ -74,7 +74,7 @@
});
ds.fetch({ success: function() {
this.bind('remove', function(event) {
- equals( event.affectedColumns().length, 2)
+ equals( event.affectedColumns().length, 2);
});
}
});
@@ -92,7 +92,7 @@
});
ds.fetch({ success: function() {
this.bind('change', function(event) {
- equals( event.affectedColumns().length, 2)
+ equals( event.affectedColumns().length, 2);
});
}
});

0 comments on commit f918e64

Please sign in to comment.
Something went wrong with that request. Please try again.