Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updating builds

  • Loading branch information...
commit e0f2f611e6b4b42dfadb8096741f0aa9f2d8cc5f 1 parent 578ea7e
@iros iros authored
View
2  dist/LASTBUILD
@@ -1 +1 @@
-2012/10/26 02:13
+2012/10/27 04:34
View
110 dist/miso.ds.0.3.0.js
@@ -1,5 +1,5 @@
/**
-* Miso.Dataset - v0.3.0 - 10/26/2012
+* Miso.Dataset - v0.3.0 - 10/27/2012
* http://github.com/misoproject/dataset
* Copyright (c) 2012 Alex Graul, Irene Ros;
* Dual Licensed: MIT, GPL
@@ -695,114 +695,52 @@
* Parameters:
* options - Optional
*/
- sort : function(args) {
- var options = {};
+ sort : function(args) {
+ var options = {}, cachedRows = [];
//If the first param is the comparator, set it as such.
if ( _.isFunction(args) ) {
options.comparator = args;
} else {
- options = args || options;
+ options = args || {};
}
if (options.comparator) {
this.comparator = options.comparator;
- }
-
- if (_.isUndefined(this.comparator)) {
+ } else if (_.isUndefined(this.comparator)) {
throw new Error("Cannot sort without this.comparator.");
- }
-
- var count = this.length, end;
-
- if (count === 1) {
- // we're done. only one item, all sorted.
- return;
}
- var swap = _.bind(function(from, to) {
-
- // move second row over to first
- var row = this.rowByPosition(to);
-
- _.each(row, function(value, column) {
- var colPosition = this._columnPositionByName[column],
- value2 = this._columns[colPosition].data[from];
- this._columns[colPosition].data.splice(from, 1, value);
- this._columns[colPosition].data.splice(to, 1, value2);
- }, this);
- }, this);
-
- var siftDown = _.bind(function(start, end) {
- var root = start, child;
- while (root * 2 <= end) {
- child = root * 2;
- var root_node = this.rowByPosition(root);
-
- if ((child + 1 < end) &&
- this.comparator(
- this.rowByPosition(child),
- this.rowByPosition(child+1)
- ) < 0) {
- child++;
- }
-
- if (this.comparator(
- root_node,
- this.rowByPosition(child)) < 0) {
-
- swap(root, child);
- root = child;
- } else {
- return;
- }
-
- }
-
- }, this);
-
+ // cache rows
+ var i, j, row;
+ for(i = 0; i < this.length; i++) {
+ cachedRows[i] = this._row(i);
+ }
- // puts data in max-heap order
- var heapify = function(count) {
- var start = Math.round((count - 2) / 2);
- while (start >= 0) {
- siftDown(start, count - 1);
- start--;
- }
- };
+ cachedRows.sort( this.comparator );
- if (count > 2) {
- heapify(count);
+ // iterate through cached rows, overwriting data in columns
+ i = cachedRows.length;
+ while ( i-- ) {
+ row = cachedRows[i];
- end = count - 1;
- while (end > 1) {
-
- swap(end, 0);
- end--;
- siftDown(0, end);
+ this._rowIdByPosition[i] = row[ this.idAttribute ];
+ this._rowPositionById[ row[ this.idAttribute ] ] = i;
+ j = this._columns.length;
+ while ( j-- ) {
+ var col = this._columns[j];
+ col.data[i] = row[ col.name ];
}
- } else {
- if (this.comparator(
- this.rowByPosition(0),
- this.rowByPosition(1)) > 0) {
- swap(0,1);
- }
- }
-
- // check last two rows, they seem to always be off sync.
- if (this.comparator(
- this.rowByPosition(this.length - 2),
- this.rowByPosition(this.length - 1)) > 0) {
- swap(this.length - 1,this.length - 2);
}
- if (this.syncable && options.silent) {
+ if (this.syncable && !options.silent) {
this.trigger("sort");
}
+
return this;
},
-
+
/**
* Exports a version of the dataset in json format.
* Returns:
View
110 dist/miso.ds.0.3.0.m.js
@@ -1,5 +1,5 @@
/**
-* Miso.Dataset - v0.3.0 - 10/26/2012
+* Miso.Dataset - v0.3.0 - 10/27/2012
* http://github.com/misoproject/dataset
* Copyright (c) 2012 Alex Graul, Irene Ros;
* Dual Licensed: MIT, GPL
@@ -695,114 +695,52 @@
* Parameters:
* options - Optional
*/
- sort : function(args) {
- var options = {};
+ sort : function(args) {
+ var options = {}, cachedRows = [];
//If the first param is the comparator, set it as such.
if ( _.isFunction(args) ) {
options.comparator = args;
} else {
- options = args || options;
+ options = args || {};
}
if (options.comparator) {
this.comparator = options.comparator;
- }
-
- if (_.isUndefined(this.comparator)) {
+ } else if (_.isUndefined(this.comparator)) {
throw new Error("Cannot sort without this.comparator.");
- }
-
- var count = this.length, end;
-
- if (count === 1) {
- // we're done. only one item, all sorted.
- return;
}
- var swap = _.bind(function(from, to) {
-
- // move second row over to first
- var row = this.rowByPosition(to);
-
- _.each(row, function(value, column) {
- var colPosition = this._columnPositionByName[column],
- value2 = this._columns[colPosition].data[from];
- this._columns[colPosition].data.splice(from, 1, value);
- this._columns[colPosition].data.splice(to, 1, value2);
- }, this);
- }, this);
-
- var siftDown = _.bind(function(start, end) {
- var root = start, child;
- while (root * 2 <= end) {
- child = root * 2;
- var root_node = this.rowByPosition(root);
-
- if ((child + 1 < end) &&
- this.comparator(
- this.rowByPosition(child),
- this.rowByPosition(child+1)
- ) < 0) {
- child++;
- }
-
- if (this.comparator(
- root_node,
- this.rowByPosition(child)) < 0) {
-
- swap(root, child);
- root = child;
- } else {
- return;
- }
-
- }
-
- }, this);
-
+ // cache rows
+ var i, j, row;
+ for(i = 0; i < this.length; i++) {
+ cachedRows[i] = this._row(i);
+ }
- // puts data in max-heap order
- var heapify = function(count) {
- var start = Math.round((count - 2) / 2);
- while (start >= 0) {
- siftDown(start, count - 1);
- start--;
- }
- };
+ cachedRows.sort( this.comparator );
- if (count > 2) {
- heapify(count);
+ // iterate through cached rows, overwriting data in columns
+ i = cachedRows.length;
+ while ( i-- ) {
+ row = cachedRows[i];
- end = count - 1;
- while (end > 1) {
-
- swap(end, 0);
- end--;
- siftDown(0, end);
+ this._rowIdByPosition[i] = row[ this.idAttribute ];
+ this._rowPositionById[ row[ this.idAttribute ] ] = i;
+ j = this._columns.length;
+ while ( j-- ) {
+ var col = this._columns[j];
+ col.data[i] = row[ col.name ];
}
- } else {
- if (this.comparator(
- this.rowByPosition(0),
- this.rowByPosition(1)) > 0) {
- swap(0,1);
- }
- }
-
- // check last two rows, they seem to always be off sync.
- if (this.comparator(
- this.rowByPosition(this.length - 2),
- this.rowByPosition(this.length - 1)) > 0) {
- swap(this.length - 1,this.length - 2);
}
- if (this.syncable && options.silent) {
+ if (this.syncable && !options.silent) {
this.trigger("sort");
}
+
return this;
},
-
+
/**
* Exports a version of the dataset in json format.
* Returns:
View
112 dist/miso.ds.deps.0.3.0.js
@@ -1,5 +1,5 @@
/**
-* Miso.Dataset - v0.3.0 - 10/26/2012
+* Miso.Dataset - v0.3.0 - 10/27/2012
* http://github.com/misoproject/dataset
* Copyright (c) 2012 Alex Graul, Irene Ros;
* Dual Licensed: MIT, GPL
@@ -5933,7 +5933,7 @@
})(this);
/**
-* Miso.Dataset - v0.3.0 - 10/26/2012
+* Miso.Dataset - v0.3.0 - 10/27/2012
* http://github.com/misoproject/dataset
* Copyright (c) 2012 Alex Graul, Irene Ros;
* Dual Licensed: MIT, GPL
@@ -6629,114 +6629,52 @@
* Parameters:
* options - Optional
*/
- sort : function(args) {
- var options = {};
+ sort : function(args) {
+ var options = {}, cachedRows = [];
//If the first param is the comparator, set it as such.
if ( _.isFunction(args) ) {
options.comparator = args;
} else {
- options = args || options;
+ options = args || {};
}
if (options.comparator) {
this.comparator = options.comparator;
- }
-
- if (_.isUndefined(this.comparator)) {
+ } else if (_.isUndefined(this.comparator)) {
throw new Error("Cannot sort without this.comparator.");
- }
-
- var count = this.length, end;
-
- if (count === 1) {
- // we're done. only one item, all sorted.
- return;
}
- var swap = _.bind(function(from, to) {
-
- // move second row over to first
- var row = this.rowByPosition(to);
-
- _.each(row, function(value, column) {
- var colPosition = this._columnPositionByName[column],
- value2 = this._columns[colPosition].data[from];
- this._columns[colPosition].data.splice(from, 1, value);
- this._columns[colPosition].data.splice(to, 1, value2);
- }, this);
- }, this);
-
- var siftDown = _.bind(function(start, end) {
- var root = start, child;
- while (root * 2 <= end) {
- child = root * 2;
- var root_node = this.rowByPosition(root);
-
- if ((child + 1 < end) &&
- this.comparator(
- this.rowByPosition(child),
- this.rowByPosition(child+1)
- ) < 0) {
- child++;
- }
-
- if (this.comparator(
- root_node,
- this.rowByPosition(child)) < 0) {
-
- swap(root, child);
- root = child;
- } else {
- return;
- }
-
- }
-
- }, this);
-
+ // cache rows
+ var i, j, row;
+ for(i = 0; i < this.length; i++) {
+ cachedRows[i] = this._row(i);
+ }
- // puts data in max-heap order
- var heapify = function(count) {
- var start = Math.round((count - 2) / 2);
- while (start >= 0) {
- siftDown(start, count - 1);
- start--;
- }
- };
+ cachedRows.sort( this.comparator );
- if (count > 2) {
- heapify(count);
+ // iterate through cached rows, overwriting data in columns
+ i = cachedRows.length;
+ while ( i-- ) {
+ row = cachedRows[i];
- end = count - 1;
- while (end > 1) {
-
- swap(end, 0);
- end--;
- siftDown(0, end);
+ this._rowIdByPosition[i] = row[ this.idAttribute ];
+ this._rowPositionById[ row[ this.idAttribute ] ] = i;
+ j = this._columns.length;
+ while ( j-- ) {
+ var col = this._columns[j];
+ col.data[i] = row[ col.name ];
}
- } else {
- if (this.comparator(
- this.rowByPosition(0),
- this.rowByPosition(1)) > 0) {
- swap(0,1);
- }
- }
-
- // check last two rows, they seem to always be off sync.
- if (this.comparator(
- this.rowByPosition(this.length - 2),
- this.rowByPosition(this.length - 1)) > 0) {
- swap(this.length - 1,this.length - 2);
}
- if (this.syncable && options.silent) {
+ if (this.syncable && !options.silent) {
this.trigger("sort");
}
+
return this;
},
-
+
/**
* Exports a version of the dataset in json format.
* Returns:
View
112 dist/miso.ds.deps.ie.0.3.0.js
@@ -1,5 +1,5 @@
/**
-* Miso.Dataset - v0.3.0 - 10/26/2012
+* Miso.Dataset - v0.3.0 - 10/27/2012
* http://github.com/misoproject/dataset
* Copyright (c) 2012 Alex Graul, Irene Ros;
* Dual Licensed: MIT, GPL
@@ -6421,7 +6421,7 @@ if (!JSON) {
})(this);
/**
-* Miso.Dataset - v0.3.0 - 10/26/2012
+* Miso.Dataset - v0.3.0 - 10/27/2012
* http://github.com/misoproject/dataset
* Copyright (c) 2012 Alex Graul, Irene Ros;
* Dual Licensed: MIT, GPL
@@ -7117,114 +7117,52 @@ if (!JSON) {
* Parameters:
* options - Optional
*/
- sort : function(args) {
- var options = {};
+ sort : function(args) {
+ var options = {}, cachedRows = [];
//If the first param is the comparator, set it as such.
if ( _.isFunction(args) ) {
options.comparator = args;
} else {
- options = args || options;
+ options = args || {};
}
if (options.comparator) {
this.comparator = options.comparator;
- }
-
- if (_.isUndefined(this.comparator)) {
+ } else if (_.isUndefined(this.comparator)) {
throw new Error("Cannot sort without this.comparator.");
- }
-
- var count = this.length, end;
-
- if (count === 1) {
- // we're done. only one item, all sorted.
- return;
}
- var swap = _.bind(function(from, to) {
-
- // move second row over to first
- var row = this.rowByPosition(to);
-
- _.each(row, function(value, column) {
- var colPosition = this._columnPositionByName[column],
- value2 = this._columns[colPosition].data[from];
- this._columns[colPosition].data.splice(from, 1, value);
- this._columns[colPosition].data.splice(to, 1, value2);
- }, this);
- }, this);
-
- var siftDown = _.bind(function(start, end) {
- var root = start, child;
- while (root * 2 <= end) {
- child = root * 2;
- var root_node = this.rowByPosition(root);
-
- if ((child + 1 < end) &&
- this.comparator(
- this.rowByPosition(child),
- this.rowByPosition(child+1)
- ) < 0) {
- child++;
- }
-
- if (this.comparator(
- root_node,
- this.rowByPosition(child)) < 0) {
-
- swap(root, child);
- root = child;
- } else {
- return;
- }
-
- }
-
- }, this);
-
+ // cache rows
+ var i, j, row;
+ for(i = 0; i < this.length; i++) {
+ cachedRows[i] = this._row(i);
+ }
- // puts data in max-heap order
- var heapify = function(count) {
- var start = Math.round((count - 2) / 2);
- while (start >= 0) {
- siftDown(start, count - 1);
- start--;
- }
- };
+ cachedRows.sort( this.comparator );
- if (count > 2) {
- heapify(count);
+ // iterate through cached rows, overwriting data in columns
+ i = cachedRows.length;
+ while ( i-- ) {
+ row = cachedRows[i];
- end = count - 1;
- while (end > 1) {
-
- swap(end, 0);
- end--;
- siftDown(0, end);
+ this._rowIdByPosition[i] = row[ this.idAttribute ];
+ this._rowPositionById[ row[ this.idAttribute ] ] = i;
+ j = this._columns.length;
+ while ( j-- ) {
+ var col = this._columns[j];
+ col.data[i] = row[ col.name ];
}
- } else {
- if (this.comparator(
- this.rowByPosition(0),
- this.rowByPosition(1)) > 0) {
- swap(0,1);
- }
- }
-
- // check last two rows, they seem to always be off sync.
- if (this.comparator(
- this.rowByPosition(this.length - 2),
- this.rowByPosition(this.length - 1)) > 0) {
- swap(this.length - 1,this.length - 2);
}
- if (this.syncable && options.silent) {
+ if (this.syncable && !options.silent) {
this.trigger("sort");
}
+
return this;
},
-
+
/**
* Exports a version of the dataset in json format.
* Returns:
View
4 dist/miso.ds.deps.ie.min.0.3.0.js
2 additions, 2 deletions not shown
View
4 dist/miso.ds.deps.min.0.3.0.js
2 additions, 2 deletions not shown
View
BIN  dist/miso.ds.dev.0.3.0.zip
Binary file not shown
View
4 dist/miso.ds.min.0.3.0.js
@@ -1,9 +1,9 @@
/**
-* Miso.Dataset - v0.3.0 - 10/26/2012
+* Miso.Dataset - v0.3.0 - 10/27/2012
* http://github.com/misoproject/dataset
* Copyright (c) 2012 Alex Graul, Irene Ros;
* Dual Licensed: MIT, GPL
* https://github.com/misoproject/dataset/blob/master/LICENSE-MIT
* https://github.com/misoproject/dataset/blob/master/LICENSE-GPL
*/
-(function(a){a.Miso=a.Miso||{},a.Miso.Dataset=function(a){a=a||{},this.length=0,this._columns=[],this._columnPositionByName={},this._computedColumns=[],this._initialize(a)}})(this),function(a,_){var b=a.Miso.Dataset;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){return b.types[this.type].numeric(a)},numericAt:function(a){return this.toNumeric(this.data[a])},coerce:function(){this.data=_.map(this.data,function(a){return b.types[this.type].coerce(a,this)},this)},compute:function(a,b){if(this.func){var c=this.func(a);return typeof b!="undefined"?this.data[b]=c:this.data.push(c),c}},isComputed:function(){return!_.isUndefined(this.func)},_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++)this.data[c]!==null&&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++)this.data[c]!==null&&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.idAttribute=this.parent.idAttribute,this.filter={},this.filter.columns=_.bind(this._columnFilter(a.filter.columns||undefined),this),this.filter.rows=_.bind(this._rowFilter(a.filter.rows||undefined),this),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[this.idAttribute]];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={old:this.rowByPosition(f),changed:{}};h[this.idAttribute]=c[this.idAttribute],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.filter=c.filter||{},_.isFunction(a)?c.filter.rows=a:c.filter=a,c.parent=this,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(this.idAttribute),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=_.bind(function(b){return _.indexOf(a,b[this.idAttribute])===-1?!1:!0},this),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===this.idAttribute||a==="_oids"},this)},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])},reverseEach:function(a,b){for(var c=this.length-1;c>=0;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(e.isComputed())throw"You're trying to update a computed column. Those get computed!";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 '"+e.name+"' with type "+e.type}},this),this._computedColumns&&_.each(this._computedColumns,function(b){var c=b.compute(a);a[b.name]=c});if(_.isUndefined(this.comparator)){_.each(this._columns,function(b){b.isComputed()||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={});if(typeof this._rowPositionById[a[this.idAttribute]]!="undefined")throw"The id "+a[this.idAttribute]+" is not unique. The "+this.idAttribute+" column must be unique";this._rowPositionById[a[this.idAttribute]]=this._rowIdByPosition.length,this._rowIdByPosition.push(a[this.idAttribute])}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[this.idAttribute])||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[this.idAttribute]),this._rowPositionById[a[this.idAttribute]]=b},this)}return this},rows:function(a){return new b.DataView({filter:{rows:a},parent:this})},sort:function(a){var b={};_.isFunction(a)?b.comparator=a:b=a||b,b.comparator&&(this.comparator=b.comparator);if(_.isUndefined(this.comparator))throw new Error("Cannot sort without this.comparator.");var c=this.length,d;if(c===1)return;var e=_.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),f=_.bind(function(a,b){var c=a,d;while(c*2<=b){d=c*2;var f=this.rowByPosition(c);d+1<b&&this.comparator(this.rowByPosition(d),this.rowByPosition(d+1))<0&&d++;if(this.comparator(f,this.rowByPosition(d))<0)e(c,d),c=d;else return}},this),g=function(a){var b=Math.round((a-2)/2);while(b>=0)f(b,a-1),b--};if(c>2){g(c),d=c-1;while(d>1)e(d,0),d--,f(0,d)}else this.comparator(this.rowByPosition(0),this.rowByPosition(1))>0&&e(0,1);return this.comparator(this.rowByPosition(this.length-2),this.rowByPosition(this.length-1))>0&&e(this.length-1,this.length-2),this.syncable&&b.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,_,moment){var b=a.Miso.Dataset;b.prototype=new b.DataView,_.extend(b.prototype,{_initialize:function(a){a.sync===!0&&(_.extend(this,b.Events),this.syncable=!0),this.idAttribute=a.idAttribute||"_id",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)),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.parser instanceof b.Parsers.Delimited&&(a.dataType="text"),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:this.deferred=new _.Deferred,a.columns&&this.addColumns(a.columns)},fetch:function(a){a=a||{};var b=this.deferred;if(_.isNull(this.importer))throw"No importer defined";return this.importer.fetch({success:_.bind(function(c){try{this._apply(c)}catch(d){if(a.error)a.error.call(this,d);else throw d}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,c),b.reject(c)},this)}),b.promise()},_applications:{againstColumn:function(a){var c=[],d=_.keys(a),e,f=this.uniqueAgainst,g=this.column(f),h=[],i=[],j=[];_.each(a[f],function(c,d){var e=g.data.indexOf(b.types[g.type].coerce(c)),f={};_.each(a,function(a,b){f[b]=a[d]}),e===-1?h.push(f):(i.push(f),f[this.idAttribute]=this.rowById(this.column(this.idAttribute).data[e])[this.idAttribute],this.update(f))},this),h.length>0&&this.add(h)},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)},addComputedColumn:function(a,c,d){if(!_.isUndefined(this.column(a)))throw"There is already a column by this name.";if(typeof b.types[c]=="undefined")throw"The type "+c+" doesn't exist";var e=new b.Column({name:a,type:c,func:_.bind(d,this)});return this._columns.push(e),this._computedColumns.push(e),this._columnPositionByName[e.name]=this._columns.length-1,this.length>0&&this.each(function(a,b){e.compute(a,b)},this),e},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(this.idAttribute)))return;var b=[];a&&a>0&&_.times(a,function(){b.push(_.uniqueId())});var c=this.addColumn({name:this.idAttribute,data:b});this.idAttribute==="_id"&&(c.type="number");if(this._columnPositionByName[this.idAttribute]!==0){var d=this._columnPositionByName[this.idAttribute];this._columns.splice(d,1),this._columns.unshift(c),this._columnPositionByName[this.idAttribute]=0,_.each(this._columnPositionByName,function(a,b){b!==this.idAttribute&&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[this.idAttribute]||(a[this.idAttribute]=_.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);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[this.idAttribute]),c.push({old:b}))}),_.each(d,function(a){this._remove(a)},this);if(this.syncable&&(!b||!b.silent)){var e=this._buildEvent(c,this);this.trigger("remove",e),this.trigger("change",e)}},_arrayUpdate:function(a){var c=[];return _.each(a,function(a){var d={old:{},changed:{}};d[this.idAttribute]=a[this.idAttribute];var e=this._rowPositionById[a[this.idAttribute]];_.each(a,function(a,c){var f=this._columns[this._columnPositionByName[c]],g=b.types[f.type];if(f.name===this.idAttribute&&f.data[e]!==a)throw"You can't update the id column";if(typeof f=="undefined")throw"column "+c+" not found!";if(!g.test(a,f))throw"Value is incorrect type";if(this._computedColumns[f.name])return;a=g.coerce(a,f),_.isUndefined(f.before)||(a=f.before(a)),f.data[e]!==a&&(d.old[c]=f.data[e],f.data[e]=a,d.changed[c]=a)},this),typeof this._computedColumns!="undefined"&&_.each(this._computedColumns,function(a){var b=_.extend({},this._row(e)),c=b[a.name],f=a.compute(b,e);c!==f&&(d.old[a.name]=c,a.data[e]=f,d.changed[a.name]=f)},this),_.keys(d.changed).length>0&&c.push(d)},this),c},_functionUpdate:function(a){var b=[];for(var c=0;c<this.length;c++){var d=a(this.rowByPosition(c));d!==!1&&b.push(d)}return this._arrayUpdate(b)},update:function(a,b){var c;if(_.isFunction(a))c=this._functionUpdate(a);else{var d=_.isArray(a)?a:[a];c=this._arrayUpdate(d)}if(this.syncable&&(!b||!b.silent)){var e=this._buildEvent(c,this);this.trigger("update",e),this.trigger("change",e)}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.Dataset;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 _.isNull(a)||typeof a=="undefined"||_.isNaN(a)?null:a},test:function(a){return!0},compare:function(a,b){if(_.isEqual(a,b))return 0;if(a<b)return-1;if(a>b)return 1},numeric:function(a){return a===null||_.isNaN(+a)?null:+a}},string:{name:"string",coerce:function(a){return _.isNaN(a)||a===null||typeof a=="undefined"?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){return _.isNaN(+a)||a===null?null:_.isNumber(+a)?+a:null}},"boolean":{name:"boolean",regexp:/^(true|false)$/,coerce:function(a){return _.isNaN(a)||a===null||typeof a=="undefined"?null: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===null||_.isNaN(a)?null:a?1:0}},number:{name:"number",regexp:/^\s*[\-\.]?[0-9]+([\.][0-9]+)?\s*$/,coerce:function(a){var b=+a;return _.isNull(a)||typeof a=="undefined"||_.isNaN(b)?null:b},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 _.isNaN(a)||a===null?null: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(_.isNull(a)||typeof a=="undefined"||_.isNaN(a))return null;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 _.isNaN(a)||a===null?null:a.valueOf()}}}}(this,_),function(a,_){var b=a.Miso.Dataset;b.Event=function(a,b){_.isArray(a)||(a=[a]),this.deltas=a,this.dataset=b||null},_.extend(b.Event.prototype,{affectedColumns:function(){var a=[];return _.each(this.deltas,function(b){b.old=b.old||[],b.changed=b.changed||[],a=_.chain(a).union(_.keys(b.old),_.keys(b.changed)).reject(function(a){return a===this.dataset.idAttribute},this).value()},this),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,c){return new b.Event(a,c)}}(this,_),function(a,_){var b=a.Miso.Dataset;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[a.idAttribute]].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.Dataset;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}}}),b.Product.define=function(a){return function(c,d){d=d||{};var e=this._findColumns(c),f=this;d.type=d.type||e[0].type,d.typeOptions=d.typeOptions||e[0].typeOptions;var g=function(){var c=a.call(f,e,d);return b.types[d.type].coerce(c,d.typeOptions)};if(this.syncable){var h=new b.Product({columns:e,func:function(a){a=a||{};var b=this._buildDelta(this.value,g.call(f));this.value=b.changed;if(f.syncable){var c=this._buildEvent(b,this);!_.isUndefined(b.old)&&!a.silent&&b.old!==b.changed&&this.trigger("change",c)}}});return this.bind("change",h._sync,h),h}return g.call(f)}},_.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:b.Product.define(function(a,c){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()}))}),max:b.Product.define(function(a,b){return _.max(_.map(a,function(a){return a._max()}))}),min:b.Product.define(function(a,b){return _.min(_.map(a,function(a){return a._min()}))}),mean:b.Product.define(function(a,c){var d=[];_.each(a,function(a){d.push(a.data)}),d=_.flatten(d);var e=a[0].type;return d=_.map(d,function(a){return b.types[e].numeric(a)}),_.mean(d)})})}(this,_),function(a,_){var b=a.Miso.Dataset;b.Importers=function(a,b){},b.Importers.prototype.extract=function(a){return a=_.clone(a),a}}(this,_),function(a,_){var b=a.Miso.Dataset;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.Dataset;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",callback:a.callback}},_.extend(b.Importers.Remote.prototype,b.Importers.prototype,{fetch:function(a){var c=_.bind(function(b){a.success(this.extract(b))},this);this.callback&&(window[this.callback]=c),b.Xhr(_.extend(this.params,{success:this.callback?this.callback:c,error:a.error}))}});var c={url:"",data:"",dataType:"",success:function(){},type:"GET",async:!0,xhr:function(){return a.ActiveXObject?new a.ActiveXObject("Microsoft.XMLHTTP"):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,a.callback);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,e){if(c){var f=document.querySelectorAll('script[src="'+a+'"]');if(f.length){b&&b(!0);return}}var g=document.head||document.getElementsByTagName("head")[0]||document.documentElement,h=document.createElement("script"),i=a.split("?")[1],j=!1,k=[],l;i&&!c&&(k=i.split("&")),k.length&&(l=k[k.length-1].split("="));if(!e){var m=_.uniqueId("callback");e=k.length?l[1]?l[1]:m:m}!i&&!c&&(a+="?");if(!i||!/callback/.test(i))i&&(a+="&"),a+="callback="+e;e&&!c&&(!window[e]||(e=e+ +(new Date)+_.uniqueId()),window[e]=function(a){b&&b(a),j=!0},l&&(a=a.replace(l.join("="),l[0]+"="+e))),h.onload=h.onreadystatechange=function(){if(!h.readyState||/loaded|complete/.test(h.readyState)){c&&b&&b();if(j){try{delete window[e]}catch(a){window[e]=void 0}g.removeChild(h)}}},h.onerror=function(a){d&&d.call(null,a)},h.src=a,g.insertBefore(h,g.firstChild);return},b.Xhr.httpData=function(a){var b,c=null,d;return d=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)}},a.ajax.readyState===4?d():a.ajax.onreadystatechange=d,b}}(this,_),function(a,_){var b=a.Miso.Dataset;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.Dataset;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.fast?(a.url="https://spreadsheets.google.com/tq?key="+a.key,typeof a.sheetName=="undefined"&&(a.sheetName="Sheet1"),a.url+="&sheet="+a.sheetName,this.callback="misodsgs"+(new Date).getTime(),a.url+="&tqx=version:0.6;responseHandler:"+this.callback,a.url+=";reqId:0;out:json&tq&_=1335871249558#",delete a.sheetName):a.url="https://spreadsheets.google.com/feeds/cells/"+a.key+"/"+a.worksheet+"/public/basic?alt=json-in-script&callback=",delete a.key}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.Dataset;b.Parsers=function(a){this.options=a||{}},_.extend(b.Parsers.prototype,{parse:function(){}})}(this,_),function(a,_){var b=a.Miso.Dataset;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){if(c.indexOf(a.name)!==-1)throw new Error('You have more than one column named "'+a.name+'"');c.push(a.name),b[a.name]=a.data}),{columns:c,data:b}}})}(this,_),function(a,_){var b=a.Miso.Dataset;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.Dataset;b.Parsers.GoogleSpreadsheet=function(a){this.fast=a.fast||!1},_.extend(b.Parsers.GoogleSpreadsheet.prototype,b.Parsers.prototype,{parse:function(a){var b=[],c=[],d={},e;if(typeof a.status!="undefined"&&a.status==="error")throw new Error("You can't use the fast importer for this url. Disable the fast flag");if(this.fast){b=_.pluck(a.table.cols,"label");if(_.unique(b).length<b.length){var f="";throw _.inject(b,function(a,b){return a[b]=a[b]+1||1,a[b]>1&&(f=b),a},{}),new Error('You have more than one column named "'+f+'"')}_.each(a.table.rows,function(a){a=a.c;for(e=0;e<a.length;e++)c[e]=c[e]||[],a[e].v===""?c[e].push(null):c[e].push(a[e].v)}),_.each(b,function(a,b){d[a]=c[b]})}else{var g=/([A-Z]+)(\d+)/,h={};_.each(a.feed.entry,function(a,d){var e=g.exec(a.title.$t),f=e[1],i=parseInt(e[2],10);if(i===1){if(b.indexOf(a.content.$t)!==-1)throw new Error('You have more than one column named "'+a.content.$t+'"');h[f]=c.length,b[h[f]]=a.content.$t,c[h[f]]=[]}else{var j=h[f];c[j][i-1]=a.content.$t}},this),_.each(c,function(a,e){a.length=_.max(_.pluck(c,"length")),a.splice(0,1);for(var f=0;f<a.length;f++)if(_.isUndefined(a[f])||a[f]==="")a[f]=null;d[b[e]]=a})}return{columns:b,data:d}}})}(this,_),function(a,_){var b=a.Miso.Dataset;b.Parsers.Delimited=function(a){a=a||{},this.delimiter=a.delimiter||",",this.skipRows=a.skipRows||0,this.emptyValue=a.emptyValue||null,this.__delimiterPatterns=new RegExp("(\\"+this.delimiter+"|\\r?\\n|\\r|^)"+'(?:"([^"]*(?:""[^"]*)*)"|'+'([^"\\'+this.delimiter+"\\r\\n]*))","gi")},typeof String.prototype.trim!="function"&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),_.extend(b.Parsers.Delimited.prototype,b.Parsers.prototype,{parse:function(a){var b=[],c={},d={},e=function(a){d[a]||(d[a]=0);var b=a+d[a];return d[a]+=1,b},f=function(a,d,f,g,h){f=f||",";var i=null,j=0,k=!1,l=-1,m=0;try{d=d.replace(/\s+$/,"").replace(/^[\r|\n|\s]+[\r|\n]/,"\n");if(g>0){var n=0,o=0,p=d.length;while(n<g&&o<p)/\n|\r|\r\n/.test(d.charAt(o))&&n++,o++;d=d.slice(o,p)}function q(a){var d=a[1];if(d.length&&d!==f){m++;if(l<j-1)throw m--,new Error("Not enough items in row");k=!0,l=0}else k||j++,l++;var g=null;a[2]?g=a[2].replace(new RegExp('""',"g"),'"'):g=a[3];if(k){g===""&&(g=h);if(typeof c[b[l]]=="undefined")throw new Error("Too many items in row");c[b[l]].push(g)}else{var i=function(a){var c=e(a);while(b.indexOf(c)!==-1)c=e(a);return c};if(_.isUndefined(g)||g==="")g="X";b.indexOf(g)!==-1&&(g=i(g)),b.push(g),c[g]=[]}}(new RegExp("^"+f)).test(d)&&q(["","",undefined,""]);while(i=a.exec(d))q(i)}catch(r){throw new Error("Error while parsing delimited data on row "+m+". Message: "+r.message)}return{columns:b,data:c}};return f(this.__delimiterPatterns,a,this.delimiter,this.skipRows,this.emptyValue)}})}(this,_),function(a,_){var b=a.Miso.Dataset;b.Derived=function(a){a=a||{},b.call(this),this.parent=a.parent,this.idAttribute="_id",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,_.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){if(a===this.idAttribute)throw"You can't compute a moving average on the id column";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(this.idAttribute).data=this.parent.column(this.parent.idAttribute).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(this.parent.idAttribute).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(d.idAttribute).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[this.parent.idAttribute]])):(g[c]+=1,h[c].push(b[this.parent.idAttribute]))},d),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(){var d=this;b.Builder.clearRowCache(this);var e={},f=0,g=this._columnPositionByName[a],h=this.parent.column(a);for(var i=0;i<this.parent.length;i++){var j=null;this.preprocess?j=this.preprocess(h.data[i]):j=h.data[i],_.isUndefined(e[j])&&(e[j]=f,_.each(c,function(a){var b=this.column(a),c=this.column(this.idAttribute);b.data[f]=[],c.data[f]=_.uniqueId()},this),this.column(a).data[f]=j,f++),_.each(c,function(a){var b=this.column(a),c=this.parent.column(a).data[i],d=e[j];b.data[d].push(this.parent.rowByPosition(i))},this)}var k=this._columns[this._columnPositionByName._oids];return k.data=[],_.each(c,function(a){var b=this.column(a);_.each(b.data,function(c,e){_.isArray(c)&&(k.data[e]=k.data[e]||[],k.data[e].push(_.map(c,function(a){return a[d.parent.idAttribute]})),k.data[e]=_.flatten(k.data[e]),b.data[e]=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){a.Miso=a.Miso||{},a.Miso.Dataset=function(a){a=a||{},this.length=0,this._columns=[],this._columnPositionByName={},this._computedColumns=[],this._initialize(a)}})(this),function(a,_){var b=a.Miso.Dataset;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){return b.types[this.type].numeric(a)},numericAt:function(a){return this.toNumeric(this.data[a])},coerce:function(){this.data=_.map(this.data,function(a){return b.types[this.type].coerce(a,this)},this)},compute:function(a,b){if(this.func){var c=this.func(a);return typeof b!="undefined"?this.data[b]=c:this.data.push(c),c}},isComputed:function(){return!_.isUndefined(this.func)},_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++)this.data[c]!==null&&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++)this.data[c]!==null&&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.idAttribute=this.parent.idAttribute,this.filter={},this.filter.columns=_.bind(this._columnFilter(a.filter.columns||undefined),this),this.filter.rows=_.bind(this._rowFilter(a.filter.rows||undefined),this),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[this.idAttribute]];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={old:this.rowByPosition(f),changed:{}};h[this.idAttribute]=c[this.idAttribute],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.filter=c.filter||{},_.isFunction(a)?c.filter.rows=a:c.filter=a,c.parent=this,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(this.idAttribute),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=_.bind(function(b){return _.indexOf(a,b[this.idAttribute])===-1?!1:!0},this),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===this.idAttribute||a==="_oids"},this)},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])},reverseEach:function(a,b){for(var c=this.length-1;c>=0;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(e.isComputed())throw"You're trying to update a computed column. Those get computed!";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 '"+e.name+"' with type "+e.type}},this),this._computedColumns&&_.each(this._computedColumns,function(b){var c=b.compute(a);a[b.name]=c});if(_.isUndefined(this.comparator)){_.each(this._columns,function(b){b.isComputed()||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={});if(typeof this._rowPositionById[a[this.idAttribute]]!="undefined")throw"The id "+a[this.idAttribute]+" is not unique. The "+this.idAttribute+" column must be unique";this._rowPositionById[a[this.idAttribute]]=this._rowIdByPosition.length,this._rowIdByPosition.push(a[this.idAttribute])}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[this.idAttribute])||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[this.idAttribute]),this._rowPositionById[a[this.idAttribute]]=b},this)}return this},rows:function(a){return new b.DataView({filter:{rows:a},parent:this})},sort:function(a){var b={},c=[];_.isFunction(a)?b.comparator=a:b=a||{};if(b.comparator)this.comparator=b.comparator;else if(_.isUndefined(this.comparator))throw new Error("Cannot sort without this.comparator.");var d,e,f;for(d=0;d<this.length;d++)c[d]=this._row(d);c.sort(this.comparator),d=c.length;while(d--){f=c[d],this._rowIdByPosition[d]=f[this.idAttribute],this._rowPositionById[f[this.idAttribute]]=d,e=this._columns.length;while(e--){var g=this._columns[e];g.data[d]=f[g.name]}}return this.syncable&&!b.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,_,moment){var b=a.Miso.Dataset;b.prototype=new b.DataView,_.extend(b.prototype,{_initialize:function(a){a.sync===!0&&(_.extend(this,b.Events),this.syncable=!0),this.idAttribute=a.idAttribute||"_id",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)),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.parser instanceof b.Parsers.Delimited&&(a.dataType="text"),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:this.deferred=new _.Deferred,a.columns&&this.addColumns(a.columns)},fetch:function(a){a=a||{};var b=this.deferred;if(_.isNull(this.importer))throw"No importer defined";return this.importer.fetch({success:_.bind(function(c){try{this._apply(c)}catch(d){if(a.error)a.error.call(this,d);else throw d}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,c),b.reject(c)},this)}),b.promise()},_applications:{againstColumn:function(a){var c=[],d=_.keys(a),e,f=this.uniqueAgainst,g=this.column(f),h=[],i=[],j=[];_.each(a[f],function(c,d){var e=g.data.indexOf(b.types[g.type].coerce(c)),f={};_.each(a,function(a,b){f[b]=a[d]}),e===-1?h.push(f):(i.push(f),f[this.idAttribute]=this.rowById(this.column(this.idAttribute).data[e])[this.idAttribute],this.update(f))},this),h.length>0&&this.add(h)},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)},addComputedColumn:function(a,c,d){if(!_.isUndefined(this.column(a)))throw"There is already a column by this name.";if(typeof b.types[c]=="undefined")throw"The type "+c+" doesn't exist";var e=new b.Column({name:a,type:c,func:_.bind(d,this)});return this._columns.push(e),this._computedColumns.push(e),this._columnPositionByName[e.name]=this._columns.length-1,this.length>0&&this.each(function(a,b){e.compute(a,b)},this),e},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(this.idAttribute)))return;var b=[];a&&a>0&&_.times(a,function(){b.push(_.uniqueId())});var c=this.addColumn({name:this.idAttribute,data:b});this.idAttribute==="_id"&&(c.type="number");if(this._columnPositionByName[this.idAttribute]!==0){var d=this._columnPositionByName[this.idAttribute];this._columns.splice(d,1),this._columns.unshift(c),this._columnPositionByName[this.idAttribute]=0,_.each(this._columnPositionByName,function(a,b){b!==this.idAttribute&&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[this.idAttribute]||(a[this.idAttribute]=_.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);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[this.idAttribute]),c.push({old:b}))}),_.each(d,function(a){this._remove(a)},this);if(this.syncable&&(!b||!b.silent)){var e=this._buildEvent(c,this);this.trigger("remove",e),this.trigger("change",e)}},_arrayUpdate:function(a){var c=[];return _.each(a,function(a){var d={old:{},changed:{}};d[this.idAttribute]=a[this.idAttribute];var e=this._rowPositionById[a[this.idAttribute]];_.each(a,function(a,c){var f=this._columns[this._columnPositionByName[c]],g=b.types[f.type];if(f.name===this.idAttribute&&f.data[e]!==a)throw"You can't update the id column";if(typeof f=="undefined")throw"column "+c+" not found!";if(!g.test(a,f))throw"Value is incorrect type";if(this._computedColumns[f.name])return;a=g.coerce(a,f),_.isUndefined(f.before)||(a=f.before(a)),f.data[e]!==a&&(d.old[c]=f.data[e],f.data[e]=a,d.changed[c]=a)},this),typeof this._computedColumns!="undefined"&&_.each(this._computedColumns,function(a){var b=_.extend({},this._row(e)),c=b[a.name],f=a.compute(b,e);c!==f&&(d.old[a.name]=c,a.data[e]=f,d.changed[a.name]=f)},this),_.keys(d.changed).length>0&&c.push(d)},this),c},_functionUpdate:function(a){var b=[];for(var c=0;c<this.length;c++){var d=a(this.rowByPosition(c));d!==!1&&b.push(d)}return this._arrayUpdate(b)},update:function(a,b){var c;if(_.isFunction(a))c=this._functionUpdate(a);else{var d=_.isArray(a)?a:[a];c=this._arrayUpdate(d)}if(this.syncable&&(!b||!b.silent)){var e=this._buildEvent(c,this);this.trigger("update",e),this.trigger("change",e)}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.Dataset;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 _.isNull(a)||typeof a=="undefined"||_.isNaN(a)?null:a},test:function(a){return!0},compare:function(a,b){if(_.isEqual(a,b))return 0;if(a<b)return-1;if(a>b)return 1},numeric:function(a){return a===null||_.isNaN(+a)?null:+a}},string:{name:"string",coerce:function(a){return _.isNaN(a)||a===null||typeof a=="undefined"?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){return _.isNaN(+a)||a===null?null:_.isNumber(+a)?+a:null}},"boolean":{name:"boolean",regexp:/^(true|false)$/,coerce:function(a){return _.isNaN(a)||a===null||typeof a=="undefined"?null: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===null||_.isNaN(a)?null:a?1:0}},number:{name:"number",regexp:/^\s*[\-\.]?[0-9]+([\.][0-9]+)?\s*$/,coerce:function(a){var b=+a;return _.isNull(a)||typeof a=="undefined"||_.isNaN(b)?null:b},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 _.isNaN(a)||a===null?null: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(_.isNull(a)||typeof a=="undefined"||_.isNaN(a))return null;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 _.isNaN(a)||a===null?null:a.valueOf()}}}}(this,_),function(a,_){var b=a.Miso.Dataset;b.Event=function(a,b){_.isArray(a)||(a=[a]),this.deltas=a,this.dataset=b||null},_.extend(b.Event.prototype,{affectedColumns:function(){var a=[];return _.each(this.deltas,function(b){b.old=b.old||[],b.changed=b.changed||[],a=_.chain(a).union(_.keys(b.old),_.keys(b.changed)).reject(function(a){return a===this.dataset.idAttribute},this).value()},this),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,c){return new b.Event(a,c)}}(this,_),function(a,_){var b=a.Miso.Dataset;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[a.idAttribute]].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.Dataset;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}}}),b.Product.define=function(a){return function(c,d){d=d||{};var e=this._findColumns(c),f=this;d.type=d.type||e[0].type,d.typeOptions=d.typeOptions||e[0].typeOptions;var g=function(){var c=a.call(f,e,d);return b.types[d.type].coerce(c,d.typeOptions)};if(this.syncable){var h=new b.Product({columns:e,func:function(a){a=a||{};var b=this._buildDelta(this.value,g.call(f));this.value=b.changed;if(f.syncable){var c=this._buildEvent(b,this);!_.isUndefined(b.old)&&!a.silent&&b.old!==b.changed&&this.trigger("change",c)}}});return this.bind("change",h._sync,h),h}return g.call(f)}},_.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:b.Product.define(function(a,c){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()}))}),max:b.Product.define(function(a,b){return _.max(_.map(a,function(a){return a._max()}))}),min:b.Product.define(function(a,b){return _.min(_.map(a,function(a){return a._min()}))}),mean:b.Product.define(function(a,c){var d=[];_.each(a,function(a){d.push(a.data)}),d=_.flatten(d);var e=a[0].type;return d=_.map(d,function(a){return b.types[e].numeric(a)}),_.mean(d)})})}(this,_),function(a,_){var b=a.Miso.Dataset;b.Importers=function(a,b){},b.Importers.prototype.extract=function(a){return a=_.clone(a),a}}(this,_),function(a,_){var b=a.Miso.Dataset;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.Dataset;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",callback:a.callback}},_.extend(b.Importers.Remote.prototype,b.Importers.prototype,{fetch:function(a){var c=_.bind(function(b){a.success(this.extract(b))},this);this.callback&&(window[this.callback]=c),b.Xhr(_.extend(this.params,{success:this.callback?this.callback:c,error:a.error}))}});var c={url:"",data:"",dataType:"",success:function(){},type:"GET",async:!0,xhr:function(){return a.ActiveXObject?new a.ActiveXObject("Microsoft.XMLHTTP"):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,a.callback);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,e){if(c){var f=document.querySelectorAll('script[src="'+a+'"]');if(f.length){b&&b(!0);return}}var g=document.head||document.getElementsByTagName("head")[0]||document.documentElement,h=document.createElement("script"),i=a.split("?")[1],j=!1,k=[],l;i&&!c&&(k=i.split("&")),k.length&&(l=k[k.length-1].split("="));if(!e){var m=_.uniqueId("callback");e=k.length?l[1]?l[1]:m:m}!i&&!c&&(a+="?");if(!i||!/callback/.test(i))i&&(a+="&"),a+="callback="+e;e&&!c&&(!window[e]||(e=e+ +(new Date)+_.uniqueId()),window[e]=function(a){b&&b(a),j=!0},l&&(a=a.replace(l.join("="),l[0]+"="+e))),h.onload=h.onreadystatechange=function(){if(!h.readyState||/loaded|complete/.test(h.readyState)){c&&b&&b();if(j){try{delete window[e]}catch(a){window[e]=void 0}g.removeChild(h)}}},h.onerror=function(a){d&&d.call(null,a)},h.src=a,g.insertBefore(h,g.firstChild);return},b.Xhr.httpData=function(a){var b,c=null,d;return d=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)}},a.ajax.readyState===4?d():a.ajax.onreadystatechange=d,b}}(this,_),function(a,_){var b=a.Miso.Dataset;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.Dataset;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.fast?(a.url="https://spreadsheets.google.com/tq?key="+a.key,typeof a.sheetName=="undefined"&&(a.sheetName="Sheet1"),a.url+="&sheet="+a.sheetName,this.callback="misodsgs"+(new Date).getTime(),a.url+="&tqx=version:0.6;responseHandler:"+this.callback,a.url+=";reqId:0;out:json&tq&_=1335871249558#",delete a.sheetName):a.url="https://spreadsheets.google.com/feeds/cells/"+a.key+"/"+a.worksheet+"/public/basic?alt=json-in-script&callback=",delete a.key}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.Dataset;b.Parsers=function(a){this.options=a||{}},_.extend(b.Parsers.prototype,{parse:function(){}})}(this,_),function(a,_){var b=a.Miso.Dataset;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){if(c.indexOf(a.name)!==-1)throw new Error('You have more than one column named "'+a.name+'"');c.push(a.name),b[a.name]=a.data}),{columns:c,data:b}}})}(this,_),function(a,_){var b=a.Miso.Dataset;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.Dataset;b.Parsers.GoogleSpreadsheet=function(a){this.fast=a.fast||!1},_.extend(b.Parsers.GoogleSpreadsheet.prototype,b.Parsers.prototype,{parse:function(a){var b=[],c=[],d={},e;if(typeof a.status!="undefined"&&a.status==="error")throw new Error("You can't use the fast importer for this url. Disable the fast flag");if(this.fast){b=_.pluck(a.table.cols,"label");if(_.unique(b).length<b.length){var f="";throw _.inject(b,function(a,b){return a[b]=a[b]+1||1,a[b]>1&&(f=b),a},{}),new Error('You have more than one column named "'+f+'"')}_.each(a.table.rows,function(a){a=a.c;for(e=0;e<a.length;e++)c[e]=c[e]||[],a[e].v===""?c[e].push(null):c[e].push(a[e].v)}),_.each(b,function(a,b){d[a]=c[b]})}else{var g=/([A-Z]+)(\d+)/,h={};_.each(a.feed.entry,function(a,d){var e=g.exec(a.title.$t),f=e[1],i=parseInt(e[2],10);if(i===1){if(b.indexOf(a.content.$t)!==-1)throw new Error('You have more than one column named "'+a.content.$t+'"');h[f]=c.length,b[h[f]]=a.content.$t,c[h[f]]=[]}else{var j=h[f];c[j][i-1]=a.content.$t}},this),_.each(c,function(a,e){a.length=_.max(_.pluck(c,"length")),a.splice(0,1);for(var f=0;f<a.length;f++)if(_.isUndefined(a[f])||a[f]==="")a[f]=null;d[b[e]]=a})}return{columns:b,data:d}}})}(this,_),function(a,_){var b=a.Miso.Dataset;b.Parsers.Delimited=function(a){a=a||{},this.delimiter=a.delimiter||",",this.skipRows=a.skipRows||0,this.emptyValue=a.emptyValue||null,this.__delimiterPatterns=new RegExp("(\\"+this.delimiter+"|\\r?\\n|\\r|^)"+'(?:"([^"]*(?:""[^"]*)*)"|'+'([^"\\'+this.delimiter+"\\r\\n]*))","gi")},typeof String.prototype.trim!="function"&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),_.extend(b.Parsers.Delimited.prototype,b.Parsers.prototype,{parse:function(a){var b=[],c={},d={},e=function(a){d[a]||(d[a]=0);var b=a+d[a];return d[a]+=1,b},f=function(a,d,f,g,h){f=f||",";var i=null,j=0,k=!1,l=-1,m=0;try{d=d.replace(/\s+$/,"").replace(/^[\r|\n|\s]+[\r|\n]/,"\n");if(g>0){var n=0,o=0,p=d.length;while(n<g&&o<p)/\n|\r|\r\n/.test(d.charAt(o))&&n++,o++;d=d.slice(o,p)}function q(a){var d=a[1];if(d.length&&d!==f){m++;if(l<j-1)throw m--,new Error("Not enough items in row");k=!0,l=0}else k||j++,l++;var g=null;a[2]?g=a[2].replace(new RegExp('""',"g"),'"'):g=a[3];if(k){g===""&&(g=h);if(typeof c[b[l]]=="undefined")throw new Error("Too many items in row");c[b[l]].push(g)}else{var i=function(a){var c=e(a);while(b.indexOf(c)!==-1)c=e(a);return c};if(_.isUndefined(g)||g==="")g="X";b.indexOf(g)!==-1&&(g=i(g)),b.push(g),c[g]=[]}}(new RegExp("^"+f)).test(d)&&q(["","",undefined,""]);while(i=a.exec(d))q(i)}catch(r){throw new Error("Error while parsing delimited data on row "+m+". Message: "+r.message)}return{columns:b,data:c}};return f(this.__delimiterPatterns,a,this.delimiter,this.skipRows,this.emptyValue)}})}(this,_),function(a,_){var b=a.Miso.Dataset;b.Derived=function(a){a=a||{},b.call(this),this.parent=a.parent,this.idAttribute="_id",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,_.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){if(a===this.idAttribute)throw"You can't compute a moving average on the id column";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(this.idAttribute).data=this.parent.column(this.parent.idAttribute).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(this.parent.idAttribute).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(d.idAttribute).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[this.parent.idAttribute]])):(g[c]+=1,h[c].push(b[this.parent.idAttribute]))},d),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(){var d=this;b.Builder.clearRowCache(this);var e={},f=0,g=this._columnPositionByName[a],h=this.parent.column(a);for(var i=0;i<this.parent.length;i++){var j=null;this.preprocess?j=this.preprocess(h.data[i]):j=h.data[i],_.isUndefined(e[j])&&(e[j]=f,_.each(c,function(a){var b=this.column(a),c=this.column(this.idAttribute);b.data[f]=[],c.data[f]=_.uniqueId()},this),this.column(a).data[f]=j,f++),_.each(c,function(a){var b=this.column(a),c=this.parent.column(a).data[i],d=e[j];b.data[d].push(this.parent.rowByPosition(i))},this)}var k=this._columns[this._columnPositionByName._oids];return k.data=[],_.each(c,function(a){var b=this.column(a);_.each(b.data,function(c,e){_.isArray(c)&&(k.data[e]=k.data[e]||[],k.data[e].push(_.map(c,function(a){return a[d.parent.idAttribute]})),k.data[e]=_.flatten(k.data[e]),b.data[e]=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,_)
View
4 dist/miso.ds.min.0.3.0.m.js
@@ -1,9 +1,9 @@
/**
-* Miso.Dataset - v0.3.0 - 10/26/2012
+* Miso.Dataset - v0.3.0 - 10/27/2012
* http://github.com/misoproject/dataset
* Copyright (c) 2012 Alex Graul, Irene Ros;
* Dual Licensed: MIT, GPL
* https://github.com/misoproject/dataset/blob/master/LICENSE-MIT
* https://github.com/misoproject/dataset/blob/master/LICENSE-GPL
*/
-(function(a){a.Miso=a.Miso||{},a.Miso.Dataset=function(a){a=a||{},this.length=0,this._columns=[],this._columnPositionByName={},this._computedColumns=[],this._initialize(a)}})(this),function(a,_){var b=a.Miso.Dataset;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){return b.types[this.type].numeric(a)},numericAt:function(a){return this.toNumeric(this.data[a])},coerce:function(){this.data=_.map(this.data,function(a){return b.types[this.type].coerce(a,this)},this)},compute:function(a,b){if(this.func){var c=this.func(a);return typeof b!="undefined"?this.data[b]=c:this.data.push(c),c}},isComputed:function(){return!_.isUndefined(this.func)},_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++)this.data[c]!==null&&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++)this.data[c]!==null&&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.idAttribute=this.parent.idAttribute,this.filter={},this.filter.columns=_.bind(this._columnFilter(a.filter.columns||undefined),this),this.filter.rows=_.bind(this._rowFilter(a.filter.rows||undefined),this),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[this.idAttribute]];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={old:this.rowByPosition(f),changed:{}};h[this.idAttribute]=c[this.idAttribute],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.filter=c.filter||{},_.isFunction(a)?c.filter.rows=a:c.filter=a,c.parent=this,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(this.idAttribute),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=_.bind(function(b){return _.indexOf(a,b[this.idAttribute])===-1?!1:!0},this),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===this.idAttribute||a==="_oids"},this)},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])},reverseEach:function(a,b){for(var c=this.length-1;c>=0;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(e.isComputed())throw"You're trying to update a computed column. Those get computed!";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 '"+e.name+"' with type "+e.type}},this),this._computedColumns&&_.each(this._computedColumns,function(b){var c=b.compute(a);a[b.name]=c});if(_.isUndefined(this.comparator)){_.each(this._columns,function(b){b.isComputed()||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={});if(typeof this._rowPositionById[a[this.idAttribute]]!="undefined")throw"The id "+a[this.idAttribute]+" is not unique. The "+this.idAttribute+" column must be unique";this._rowPositionById[a[this.idAttribute]]=this._rowIdByPosition.length,this._rowIdByPosition.push(a[this.idAttribute])}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[this.idAttribute])||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[this.idAttribute]),this._rowPositionById[a[this.idAttribute]]=b},this)}return this},rows:function(a){return new b.DataView({filter:{rows:a},parent:this})},sort:function(a){var b={};_.isFunction(a)?b.comparator=a:b=a||b,b.comparator&&(this.comparator=b.comparator);if(_.isUndefined(this.comparator))throw new Error("Cannot sort without this.comparator.");var c=this.length,d;if(c===1)return;var e=_.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),f=_.bind(function(a,b){var c=a,d;while(c*2<=b){d=c*2;var f=this.rowByPosition(c);d+1<b&&this.comparator(this.rowByPosition(d),this.rowByPosition(d+1))<0&&d++;if(this.comparator(f,this.rowByPosition(d))<0)e(c,d),c=d;else return}},this),g=function(a){var b=Math.round((a-2)/2);while(b>=0)f(b,a-1),b--};if(c>2){g(c),d=c-1;while(d>1)e(d,0),d--,f(0,d)}else this.comparator(this.rowByPosition(0),this.rowByPosition(1))>0&&e(0,1);return this.comparator(this.rowByPosition(this.length-2),this.rowByPosition(this.length-1))>0&&e(this.length-1,this.length-2),this.syncable&&b.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,_,moment){var b=a.Miso.Dataset;b.prototype=new b.DataView,_.extend(b.prototype,{_initialize:function(a){a.sync===!0&&(_.extend(this,b.Events),this.syncable=!0),this.idAttribute=a.idAttribute||"_id",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)),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.parser instanceof b.Parsers.Delimited&&(a.dataType="text"),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:this.deferred=new _.Deferred,a.columns&&this.addColumns(a.columns)},fetch:function(a){a=a||{};var b=this.deferred;if(_.isNull(this.importer))throw"No importer defined";return this.importer.fetch({success:_.bind(function(c){try{this._apply(c)}catch(d){if(a.error)a.error.call(this,d);else throw d}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,c),b.reject(c)},this)}),b.promise()},_applications:{againstColumn:function(a){var c=[],d=_.keys(a),e,f=this.uniqueAgainst,g=this.column(f),h=[],i=[],j=[];_.each(a[f],function(c,d){var e=g.data.indexOf(b.types[g.type].coerce(c)),f={};_.each(a,function(a,b){f[b]=a[d]}),e===-1?h.push(f):(i.push(f),f[this.idAttribute]=this.rowById(this.column(this.idAttribute).data[e])[this.idAttribute],this.update(f))},this),h.length>0&&this.add(h)},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)},addComputedColumn:function(a,c,d){if(!_.isUndefined(this.column(a)))throw"There is already a column by this name.";if(typeof b.types[c]=="undefined")throw"The type "+c+" doesn't exist";var e=new b.Column({name:a,type:c,func:_.bind(d,this)});return this._columns.push(e),this._computedColumns.push(e),this._columnPositionByName[e.name]=this._columns.length-1,this.length>0&&this.each(function(a,b){e.compute(a,b)},this),e},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(this.idAttribute)))return;var b=[];a&&a>0&&_.times(a,function(){b.push(_.uniqueId())});var c=this.addColumn({name:this.idAttribute,data:b});this.idAttribute==="_id"&&(c.type="number");if(this._columnPositionByName[this.idAttribute]!==0){var d=this._columnPositionByName[this.idAttribute];this._columns.splice(d,1),this._columns.unshift(c),this._columnPositionByName[this.idAttribute]=0,_.each(this._columnPositionByName,function(a,b){b!==this.idAttribute&&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[this.idAttribute]||(a[this.idAttribute]=_.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);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[this.idAttribute]),c.push({old:b}))}),_.each(d,function(a){this._remove(a)},this);if(this.syncable&&(!b||!b.silent)){var e=this._buildEvent(c,this);this.trigger("remove",e),this.trigger("change",e)}},_arrayUpdate:function(a){var c=[];return _.each(a,function(a){var d={old:{},changed:{}};d[this.idAttribute]=a[this.idAttribute];var e=this._rowPositionById[a[this.idAttribute]];_.each(a,function(a,c){var f=this._columns[this._columnPositionByName[c]],g=b.types[f.type];if(f.name===this.idAttribute&&f.data[e]!==a)throw"You can't update the id column";if(typeof f=="undefined")throw"column "+c+" not found!";if(!g.test(a,f))throw"Value is incorrect type";if(this._computedColumns[f.name])return;a=g.coerce(a,f),_.isUndefined(f.before)||(a=f.before(a)),f.data[e]!==a&&(d.old[c]=f.data[e],f.data[e]=a,d.changed[c]=a)},this),typeof this._computedColumns!="undefined"&&_.each(this._computedColumns,function(a){var b=_.extend({},this._row(e)),c=b[a.name],f=a.compute(b,e);c!==f&&(d.old[a.name]=c,a.data[e]=f,d.changed[a.name]=f)},this),_.keys(d.changed).length>0&&c.push(d)},this),c},_functionUpdate:function(a){var b=[];for(var c=0;c<this.length;c++){var d=a(this.rowByPosition(c));d!==!1&&b.push(d)}return this._arrayUpdate(b)},update:function(a,b){var c;if(_.isFunction(a))c=this._functionUpdate(a);else{var d=_.isArray(a)?a:[a];c=this._arrayUpdate(d)}if(this.syncable&&(!b||!b.silent)){var e=this._buildEvent(c,this);this.trigger("update",e),this.trigger("change",e)}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.Dataset;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 _.isNull(a)||typeof a=="undefined"||_.isNaN(a)?null:a},test:function(a){return!0},compare:function(a,b){if(_.isEqual(a,b))return 0;if(a<b)return-1;if(a>b)return 1},numeric:function(a){return a===null||_.isNaN(+a)?null:+a}},string:{name:"string",coerce:function(a){return _.isNaN(a)||a===null||typeof a=="undefined"?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){return _.isNaN(+a)||a===null?null:_.isNumber(+a)?+a:null}},"boolean":{name:"boolean",regexp:/^(true|false)$/,coerce:function(a){return _.isNaN(a)||a===null||typeof a=="undefined"?null: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===null||_.isNaN(a)?null:a?1:0}},number:{name:"number",regexp:/^\s*[\-\.]?[0-9]+([\.][0-9]+)?\s*$/,coerce:function(a){var b=+a;return _.isNull(a)||typeof a=="undefined"||_.isNaN(b)?null:b},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 _.isNaN(a)||a===null?null: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(_.isNull(a)||typeof a=="undefined"||_.isNaN(a))return null;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 _.isNaN(a)||a===null?null:a.valueOf()}}}}(this,_),function(a,_){var b=a.Miso.Dataset;b.Event=function(a,b){_.isArray(a)||(a=[a]),this.deltas=a,this.dataset=b||null},_.extend(b.Event.prototype,{affectedColumns:function(){var a=[];return _.each(this.deltas,function(b){b.old=b.old||[],b.changed=b.changed||[],a=_.chain(a).union(_.keys(b.old),_.keys(b.changed)).reject(function(a){return a===this.dataset.idAttribute},this).value()},this),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,c){return new b.Event(a,c)}}(this,_),function(a,_){var b=a.Miso.Dataset;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[a.idAttribute]].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.Dataset;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}}}),b.Product.define=function(a){return function(c,d){d=d||{};var e=this._findColumns(c),f=this;d.type=d.type||e[0].type,d.typeOptions=d.typeOptions||e[0].typeOptions;var g=function(){var c=a.call(f,e,d);return b.types[d.type].coerce(c,d.typeOptions)};if(this.syncable){var h=new b.Product({columns:e,func:function(a){a=a||{};var b=this._buildDelta(this.value,g.call(f));this.value=b.changed;if(f.syncable){var c=this._buildEvent(b,this);!_.isUndefined(b.old)&&!a.silent&&b.old!==b.changed&&this.trigger("change",c)}}});return this.bind("change",h._sync,h),h}return g.call(f)}},_.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:b.Product.define(function(a,c){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()}))}),max:b.Product.define(function(a,b){return _.max(_.map(a,function(a){return a._max()}))}),min:b.Product.define(function(a,b){return _.min(_.map(a,function(a){return a._min()}))}),mean:b.Product.define(function(a,c){var d=[];_.each(a,function(a){d.push(a.data)}),d=_.flatten(d);var e=a[0].type;return d=_.map(d,function(a){return b.types[e].numeric(a)}),_.mean(d)})})}(this,_),function(a,_){var b=a.Miso.Dataset;b.Importers=function(a,b){},b.Importers.prototype.extract=function(a){return a=_.clone(a),a}}(this,_),function(a,_){var b=a.Miso.Dataset;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.Dataset;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",callback:a.callback}},_.extend(b.Importers.Remote.prototype,b.Importers.prototype,{fetch:function(a){var c=_.bind(function(b){a.success(this.extract(b))},this);this.callback&&(window[this.callback]=c),b.Xhr(_.extend(this.params,{success:this.callback?this.callback:c,error:a.error}))}});var c={url:"",data:"",dataType:"",success:function(){},type:"GET",async:!0,xhr:function(){return a.ActiveXObject?new a.ActiveXObject("Microsoft.XMLHTTP"):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,a.callback);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,e){if(c){var f=document.querySelectorAll('script[src="'+a+'"]');if(f.length){b&&b(!0);return}}var g=document.head||document.getElementsByTagName("head")[0]||document.documentElement,h=document.createElement("script"),i=a.split("?")[1],j=!1,k=[],l;i&&!c&&(k=i.split("&")),k.length&&(l=k[k.length-1].split("="));if(!e){var m=_.uniqueId("callback");e=k.length?l[1]?l[1]:m:m}!i&&!c&&(a+="?");if(!i||!/callback/.test(i))i&&(a+="&"),a+="callback="+e;e&&!c&&(!window[e]||(e=e+ +(new Date)+_.uniqueId()),window[e]=function(a){b&&b(a),j=!0},l&&(a=a.replace(l.join("="),l[0]+"="+e))),h.onload=h.onreadystatechange=function(){if(!h.readyState||/loaded|complete/.test(h.readyState)){c&&b&&b();if(j){try{delete window[e]}catch(a){window[e]=void 0}g.removeChild(h)}}},h.onerror=function(a){d&&d.call(null,a)},h.src=a,g.insertBefore(h,g.firstChild);return},b.Xhr.httpData=function(a){var b,c=null,d;return d=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)}},a.ajax.readyState===4?d():a.ajax.onreadystatechange=d,b}}(this,_),function(a,_){var b=a.Miso.Dataset;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.Dataset;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.fast?(a.url="https://spreadsheets.google.com/tq?key="+a.key,typeof a.sheetName=="undefined"&&(a.sheetName="Sheet1"),a.url+="&sheet="+a.sheetName,this.callback="misodsgs"+(new Date).getTime(),a.url+="&tqx=version:0.6;responseHandler:"+this.callback,a.url+=";reqId:0;out:json&tq&_=1335871249558#",delete a.sheetName):a.url="https://spreadsheets.google.com/feeds/cells/"+a.key+"/"+a.worksheet+"/public/basic?alt=json-in-script&callback=",delete a.key}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.Dataset;b.Parsers=function(a){this.options=a||{}},_.extend(b.Parsers.prototype,{parse:function(){}})}(this,_),function(a,_){var b=a.Miso.Dataset;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){if(c.indexOf(a.name)!==-1)throw new Error('You have more than one column named "'+a.name+'"');c.push(a.name),b[a.name]=a.data}),{columns:c,data:b}}})}(this,_),function(a,_){var b=a.Miso.Dataset;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.Dataset;b.Parsers.GoogleSpreadsheet=function(a){this.fast=a.fast||!1},_.extend(b.Parsers.GoogleSpreadsheet.prototype,b.Parsers.prototype,{parse:function(a){var b=[],c=[],d={},e;if(typeof a.status!="undefined"&&a.status==="error")throw new Error("You can't use the fast importer for this url. Disable the fast flag");if(this.fast){b=_.pluck(a.table.cols,"label");if(_.unique(b).length<b.length){var f="";throw _.inject(b,function(a,b){return a[b]=a[b]+1||1,a[b]>1&&(f=b),a},{}),new Error('You have more than one column named "'+f+'"')}_.each(a.table.rows,function(a){a=a.c;for(e=0;e<a.length;e++)c[e]=c[e]||[],a[e].v===""?c[e].push(null):c[e].push(a[e].v)}),_.each(b,function(a,b){d[a]=c[b]})}else{var g=/([A-Z]+)(\d+)/,h={};_.each(a.feed.entry,function(a,d){var e=g.exec(a.title.$t),f=e[1],i=parseInt(e[2],10);if(i===1){if(b.indexOf(a.content.$t)!==-1)throw new Error('You have more than one column named "'+a.content.$t+'"');h[f]=c.length,b[h[f]]=a.content.$t,c[h[f]]=[]}else{var j=h[f];c[j][i-1]=a.content.$t}},this),_.each(c,function(a,e){a.length=_.max(_.pluck(c,"length")),a.splice(0,1);for(var f=0;f<a.length;f++)if(_.isUndefined(a[f])||a[f]==="")a[f]=null;d[b[e]]=a})}return{columns:b,data:d}}})}(this,_),function(a,_){var b=a.Miso.Dataset;b.Parsers.Delimited=function(a){a=a||{},this.delimiter=a.delimiter||",",this.skipRows=a.skipRows||0,this.emptyValue=a.emptyValue||null,this.__delimiterPatterns=new RegExp("(\\"+this.delimiter+"|\\r?\\n|\\r|^)"+'(?:"([^"]*(?:""[^"]*)*)"|'+'([^"\\'+this.delimiter+"\\r\\n]*))","gi")},typeof String.prototype.trim!="function"&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),_.extend(b.Parsers.Delimited.prototype,b.Parsers.prototype,{parse:function(a){var b=[],c={},d={},e=function(a){d[a]||(d[a]=0);var b=a+d[a];return d[a]+=1,b},f=function(a,d,f,g,h){f=f||",";var i=null,j=0,k=!1,l=-1,m=0;try{d=d.replace(/\s+$/,"").replace(/^[\r|\n|\s]+[\r|\n]/,"\n");if(g>0){var n=0,o=0,p=d.length;while(n<g&&o<p)/\n|\r|\r\n/.test(d.charAt(o))&&n++,o++;d=d.slice(o,p)}function q(a){var d=a[1];if(d.length&&d!==f){m++;if(l<j-1)throw m--,new Error("Not enough items in row");k=!0,l=0}else k||j++,l++;var g=null;a[2]?g=a[2].replace(new RegExp('""',"g"),'"'):g=a[3];if(k){g===""&&(g=h);if(typeof c[b[l]]=="undefined")throw new Error("Too many items in row");c[b[l]].push(g)}else{var i=function(a){var c=e(a);while(b.indexOf(c)!==-1)c=e(a);return c};if(_.isUndefined(g)||g==="")g="X";b.indexOf(g)!==-1&&(g=i(g)),b.push(g),c[g]=[]}}(new RegExp("^"+f)).test(d)&&q(["","",undefined,""]);while(i=a.exec(d))q(i)}catch(r){throw new Error("Error while parsing delimited data on row "+m+". Message: "+r.message)}return{columns:b,data:c}};return f(this.__delimiterPatterns,a,this.delimiter,this.skipRows,this.emptyValue)}})}(this,_),function(a,_){var b=a.Miso.Dataset;b.Derived=function(a){a=a||{},b.call(this),this.parent=a.parent,this.idAttribute="_id",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,_.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){if(a===this.idAttribute)throw"You can't compute a moving average on the id column";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(this.idAttribute).data=this.parent.column(this.parent.idAttribute).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(this.parent.idAttribute).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(d.idAttribute).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[this.parent.idAttribute]])):(g[c]+=1,h[c].push(b[this.parent.idAttribute]))},d),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(){var d=this;b.Builder.clearRowCache(this);var e={},f=0,g=this._columnPositionByName[a],h=this.parent.column(a);for(var i=0;i<this.parent.length;i++){var j=null;this.preprocess?j=this.preprocess(h.data[i]):j=h.data[i],_.isUndefined(e[j])&&(e[j]=f,_.each(c,function(a){var b=this.column(a),c=this.column(this.idAttribute);b.data[f]=[],c.data[f]=_.uniqueId()},this),this.column(a).data[f]=j,f++),_.each(c,function(a){var b=this.column(a),c=this.parent.column(a).data[i],d=e[j];b.data[d].push(this.parent.rowByPosition(i))},this)}var k=this._columns[this._columnPositionByName._oids];return k.data=[],_.each(c,function(a){var b=this.column(a);_.each(b.data,function(c,e){_.isArray(c)&&(k.data[e]=k.data[e]||[],k.data[e].push(_.map(c,function(a){return a[d.parent.idAttribute]})),k.data[e]=_.flatten(k.data[e]),b.data[e]=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||{};delete window.Miso,typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(module.exports=b),exports.miso=b):typeof define=="function"&&define.amd&&define("miso",[],function(){return b})}(this)
+(function(a){a.Miso=a.Miso||{},a.Miso.Dataset=function(a){a=a||{},this.length=0,this._columns=[],this._columnPositionByName={},this._computedColumns=[],this._initialize(a)}})(this),function(a,_){var b=a.Miso.Dataset;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){return b.types[this.type].numeric(a)},numericAt:function(a){return this.toNumeric(this.data[a])},coerce:function(){this.data=_.map(this.data,function(a){return b.types[this.type].coerce(a,this)},this)},compute:function(a,b){if(this.func){var c=this.func(a);return typeof b!="undefined"?this.data[b]=c:this.data.push(c),c}},isComputed:function(){return!_.isUndefined(this.func)},_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++)this.data[c]!==null&&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++)this.data[c]!==null&&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.idAttribute=this.parent.idAttribute,this.filter={},this.filter.columns=_.bind(this._columnFilter(a.filter.columns||undefined),this),this.filter.rows=_.bind(this._rowFilter(a.filter.rows||undefined),this),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[this.idAttribute]];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={old:this.rowByPosition(f),changed:{}};h[this.idAttribute]=c[this.idAttribute],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.filter=c.filter||{},_.isFunction(a)?c.filter.rows=a:c.filter=a,c.parent=this,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(this.idAttribute),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=_.bind(function(b){return _.indexOf(a,b[this.idAttribute])===-1?!1:!0},this),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===this.idAttribute||a==="_oids"},this)},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])},reverseEach:function(a,b){for(var c=this.length-1;c>=0;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(e.isComputed())throw"You're trying to update a computed column. Those get computed!";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 '"+e.name+"' with type "+e.type}},this),this._computedColumns&&_.each(this._computedColumns,function(b){var c=b.compute(a);a[b.name]=c});if(_.isUndefined(this.comparator)){_.each(this._columns,function(b){b.isComputed()||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={});if(typeof this._rowPositionById[a[this.idAttribute]]!="undefined")throw"The id "+a[this.idAttribute]+" is not unique. The "+this.idAttribute+" column must be unique";this._rowPositionById[a[this.idAttribute]]=this._rowIdByPosition.length,this._rowIdByPosition.push(a[this.idAttribute])}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[this.idAttribute])||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[this.idAttribute]),this._rowPositionById[a[this.idAttribute]]=b},this)}return this},rows:function(a){return new b.DataView({filter:{rows:a},parent:this})},sort:function(a){var b={},c=[];_.isFunction(a)?b.comparator=a:b=a||{};if(b.comparator)this.comparator=b.comparator;else if(_.isUndefined(this.comparator))throw new Error("Cannot sort without this.comparator.");var d,e,f;for(d=0;d<this.length;d++)c[d]=this._row(d);c.sort(this.comparator),d=c.length;while(d--){f=c[d],this._rowIdByPosition[d]=f[this.idAttribute],this._rowPositionById[f[this.idAttribute]]=d,e=this._columns.length;while(e--){var g=this._columns[e];g.data[d]=f[g.name]}}return this.syncable&&!b.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,_,moment){var b=a.Miso.Dataset;b.prototype=new b.DataView,_.extend(b.prototype,{_initialize:function(a){a.sync===!0&&(_.extend(this,b.Events),this.syncable=!0),this.idAttribute=a.idAttribute||"_id",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)),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.parser instanceof b.Parsers.Delimited&&(a.dataType="text"),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:this.deferred=new _.Deferred,a.columns&&this.addColumns(a.columns)},fetch:function(a){a=a||{};var b=this.deferred;if(_.isNull(this.importer))throw"No importer defined";return this.importer.fetch({success:_.bind(function(c){try{this._apply(c)}catch(d){if(a.error)a.error.call(this,d);else throw d}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,c),b.reject(c)},this)}),b.promise()},_applications:{againstColumn:function(a){var c=[],d=_.keys(a),e,f=this.uniqueAgainst,g=this.column(f),h=[],i=[],j=[];_.each(a[f],function(c,d){var e=g.data.indexOf(b.types[g.type].coerce(c)),f={};_.each(a,function(a,b){f[b]=a[d]}),e===-1?h.push(f):(i.push(f),f[this.idAttribute]=this.rowById(this.column(this.idAttribute).data[e])[this.idAttribute],this.update(f))},this),h.length>0&&this.add(h)},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)},addComputedColumn:function(a,c,d){if(!_.isUndefined(this.column(a)))throw"There is already a column by this name.";if(typeof b.types[c]=="undefined")throw"The type "+c+" doesn't exist";var e=new b.Column({name:a,type:c,func:_.bind(d,this)});return this._columns.push(e),this._computedColumns.push(e),this._columnPositionByName[e.name]=this._columns.length-1,this.length>0&&this.each(function(a,b){e.compute(a,b)},this),e},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(this.idAttribute)))return;var b=[];a&&a>0&&_.times(a,function(){b.push(_.uniqueId())});var c=this.addColumn({name:this.idAttribute,data:b});this.idAttribute==="_id"&&(c.type="number");if(this._columnPositionByName[this.idAttribute]!==0){var d=this._columnPositionByName[this.idAttribute];this._columns.splice(d,1),this._columns.unshift(c),this._columnPositionByName[this.idAttribute]=0,_.each(this._columnPositionByName,function(a,b){b!==this.idAttribute&&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[this.idAttribute]||(a[this.idAttribute]=_.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);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[this.idAttribute]),c.push({old:b}))}),_.each(d,function(a){this._remove(a)},this);if(this.syncable&&(!b||!b.silent)){var e=this._buildEvent(c,this);this.trigger("remove",e),this.trigger("change",e)}},_arrayUpdate:function(a){var c=[];return _.each(a,function(a){var d={old:{},changed:{}};d[this.idAttribute]=a[this.idAttribute];var e=this._rowPositionById[a[this.idAttribute]];_.each(a,function(a,c){var f=this._columns[this._columnPositionByName[c]],g=b.types[f.type];if(f.name===this.idAttribute&&f.data[e]!==a)throw"You can't update the id column";if(typeof f=="undefined")throw"column "+c+" not found!";if(!g.test(a,f))throw"Value is incorrect type";if(this._computedColumns[f.name])return;a=g.coerce(a,f),_.isUndefined(f.before)||(a=f.before(a)),f.data[e]!==a&&(d.old[c]=f.data[e],f.data[e]=a,d.changed[c]=a)},this),typeof this._computedColumns!="undefined"&&_.each(this._computedColumns,function(a){var b=_.extend({},this._row(e)),c=b[a.name],f=a.compute(b,e);c!==f&&(d.old[a.name]=c,a.data[e]=f,d.changed[a.name]=f)},this),_.keys(d.changed).length>0&&c.push(d)},this),c},_functionUpdate:function(a){var b=[];for(var c=0;c<this.length;c++){var d=a(this.rowByPosition(c));d!==!1&&b.push(d)}return this._arrayUpdate(b)},update:function(a,b){var c;if(_.isFunction(a))c=this._functionUpdate(a);else{var d=_.isArray(a)?a:[a];c=this._arrayUpdate(d)}if(this.syncable&&(!b||!b.silent)){var e=this._buildEvent(c,this);this.trigger("update",e),this.trigger("change",e)}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.Dataset;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 _.isNull(a)||typeof a=="undefined"||_.isNaN(a)?null:a},test:function(a){return!0},compare:function(a,b){if(_.isEqual(a,b))return 0;if(a<b)return-1;if(a>b)return 1},numeric:function(a){return a===null||_.isNaN(+a)?null:+a}},string:{name:"string",coerce:function(a){return _.isNaN(a)||a===null||typeof a=="undefined"?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){return _.isNaN(+a)||a===null?null:_.isNumber(+a)?+a:null}},"boolean":{name:"boolean",regexp:/^(true|false)$/,coerce:function(a){return _.isNaN(a)||a===null||typeof a=="undefined"?null: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===null||_.isNaN(a)?null:a?1:0}},number:{name:"number",regexp:/^\s*[\-\.]?[0-9]+([\.][0-9]+)?\s*$/,coerce:function(a){var b=+a;return _.isNull(a)||typeof a=="undefined"||_.isNaN(b)?null:b},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 _.isNaN(a)||a===null?null: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(_.isNull(a)||typeof a=="undefined"||_.isNaN(a))return null;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 _.isNaN(a)||a===null?null:a.valueOf()}}}}(this,_),function(a,_){var b=a.Miso.Dataset;b.Event=function(a,b){_.isArray(a)||(a=[a]),this.deltas=a,this.dataset=b||null},_.extend(b.Event.prototype,{affectedColumns:function(){var a=[];return _.each(this.deltas,function(b){b.old=b.old||[],b.changed=b.changed||[],a=_.chain(a).union(_.keys(b.old),_.keys(b.changed)).reject(function(a){return a===this.dataset.idAttribute},this).value()},this),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,c){return new b.Event(a,c)}}(this,_),function(a,_){var b=a.Miso.Dataset;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[a.idAttribute]].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.Dataset;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}}}),b.Product.define=function(a){return function(c,d){d=d||{};var e=this._findColumns(c),f=this;d.type=d.type||e[0].type,d.typeOptions=d.typeOptions||e[0].typeOptions;var g=function(){var c=a.call(f,e,d);return b.types[d.type].coerce(c,d.typeOptions)};if(this.syncable){var h=new b.Product({columns:e,func:function(a){a=a||{};var b=this._buildDelta(this.value,g.call(f));this.value=b.changed;if(f.syncable){var c=this._buildEvent(b,this);!_.isUndefined(b.old)&&!a.silent&&b.old!==b.changed&&this.trigger("change",c)}}});return this.bind("change",h._sync,h),h}return g.call(f)}},_.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:b.Product.define(function(a,c){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()}))}),max:b.Product.define(function(a,b){return _.max(_.map(a,function(a){return a._max()}))}),min:b.Product.define(function(a,b){return _.min(_.map(a,function(a){return a._min()}))}),mean:b.Product.define(function(a,c){var d=[];_.each(a,function(a){d.push(a.data)}),d=_.flatten(d);var e=a[0].type;return d=_.map(d,function(a){return b.types[e].numeric(a)}),_.mean(d)})})}(this,_),function(a,_){var b=a.Miso.Dataset;b.Importers=function(a,b){},b.Importers.prototype.extract=function(a){return a=_.clone(a),a}}(this,_),function(a,_){var b=a.Miso.Dataset;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.Dataset;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",callback:a.callback}},_.extend(b.Importers.Remote.prototype,b.Importers.prototype,{fetch:function(a){var c=_.bind(function(b){a.success(this.extract(b))},this);this.callback&&(window[this.callback]=c),b.Xhr(_.extend(this.params,{success:this.callback?this.callback:c,error:a.error}))}});var c={url:"",data:"",dataType:"",success:function(){},type:"GET",async:!0,xhr:function(){return a.ActiveXObject?new a.ActiveXObject("Microsoft.XMLHTTP"):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,a.callback);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,e){if(c){var f=document.querySelectorAll('script[src="'+a+'"]');if(f.length){b&&b(!0);return}}var g=document.head||document.getElementsByTagName("head")[0]||document.documentElement,h=document.createElement("script"),i=a.split("?")[1],j=!1,k=[],l;i&&!c&&(k=i.split("&")),k.length&&(l=k[k.length-1].split("="));if(!e){var m=_.uniqueId("callback");e=k.length?l[1]?l[1]:m:m}!i&&!c&&(a+="?");if(!i||!/callback/.test(i))i&&(a+="&"),a+="callback="+e;e&&!c&&(!window[e]||(e=e+ +(new Date)+_.uniqueId()),window[e]=function(a){b&&b(a),j=!0},l&&(a=a.replace(l.join("="),l[0]+"="+e))),h.onload=h.onreadystatechange=function(){if(!h.readyState||/loaded|complete/.test(h.readyState)){c&&b&&b();if(j){try{delete window[e]}catch(a){window[e]=void 0}g.removeChild(h)}}},h.onerror=function(a){d&&d.call(null,a)},h.src=a,g.insertBefore(h,g.firstChild);return},b.Xhr.httpData=function(a){var b,c=null,d;return d=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)}},a.ajax.readyState===4?d():a.ajax.onreadystatechange=d,b}}(this,_),function(a,_){var b=a.Miso.Dataset;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.Dataset;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.fast?(a.url="https://spreadsheets.google.com/tq?key="+a.key,typeof a.sheetName=="undefined"&&(a.sheetName="Sheet1"),a.url+="&sheet="+a.sheetName,this.callback="misodsgs"+(new Date).getTime(),a.url+="&tqx=version:0.6;responseHandler:"+this.callback,a.url+=";reqId:0;out:json&tq&_=1335871249558#",delete a.sheetName):a.url="https://spreadsheets.google.com/feeds/cells/"+a.key+"/"+a.worksheet+"/public/basic?alt=json-in-script&callback=",delete a.key}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.Dataset;b.Parsers=function(a){this.options=a||{}},_.extend(b.Parsers.prototype,{parse:function(){}})}(this,_),function(a,_){var b=a.Miso.Dataset;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){if(c.indexOf(a.name)!==-1)throw new Error('You have more than one column named "'+a.name+'"');c.push(a.name),b[a.name]=a.data}),{columns:c,data:b}}})}(this,_),function(a,_){var b=a.Miso.Dataset;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.Dataset;b.Parsers.GoogleSpreadsheet=function(a){this.fast=a.fast||!1},_.extend(b.Parsers.GoogleSpreadsheet.prototype,b.Parsers.prototype,{parse:function(a){var b=[],c=[],d={},e;if(typeof a.status!="undefined"&&a.status==="error")throw new Error("You can't use the fast importer for this url. Disable the fast flag");if(this.fast){b=_.pluck(a.table.cols,"label");if(_.unique(b).length<b.length){var f="";throw _.inject(b,function(a,b){return a[b]=a[b]+1||1,a[b]>1&&(f=b),a},{}),new Error('You have more than one column named "'+f+'"')}_.each(a.table.rows,function(a){a=a.c;for(e=0;e<a.length;e++)c[e]=c[e]||[],a[e].v===""?c[e].push(null):c[e].push(a[e].v)}),_.each(b,function(a,b){d[a]=c[b]})}else{var g=/([A-Z]+)(\d+)/,h={};_.each(a.feed.entry,function(a,d){var e=g.exec(a.title.$t),f=e[1],i=parseInt(e[2],10);if(i===1){if(b.indexOf(a.content.$t)!==-1)throw new Error('You have more than one column named "'+a.content.$t+'"');h[f]=c.length,b[h[f]]=a.content.$t,c[h[f]]=[]}else{var j=h[f];c[j][i-1]=a.content.$t}},this),_.each(c,function(a,e){a.length=_.max(_.pluck(c,"length")),a.splice(0,1);for(var f=0;f<a.length;f++)if(_.isUndefined(a[f])||a[f]==="")a[f]=null;d[b[e]]=a})}return{columns:b,data:d}}})}(this,_),function(a,_){var b=a.Miso.Dataset;b.Parsers.Delimited=function(a){a=a||{},this.delimiter=a.delimiter||",",this.skipRows=a.skipRows||0,this.emptyValue=a.emptyValue||null,this.__delimiterPatterns=new RegExp("(\\"+this.delimiter+"|\\r?\\n|\\r|^)"+'(?:"([^"]*(?:""[^"]*)*)"|'+'([^"\\'+this.delimiter+"\\r\\n]*))","gi")},typeof String.prototype.trim!="function"&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),_.extend(b.Parsers.Delimited.prototype,b.Parsers.prototype,{parse:function(a){var b=[],c={},d={},e=function(a){d[a]||(d[a]=0);var b=a+d[a];return d[a]+=1,b},f=function(a,d,f,g,h){f=f||",";var i=null,j=0,k=!1,l=-1,m=0;try{d=d.replace(/\s+$/,"").replace(/^[\r|\n|\s]+[\r|\n]/,"\n");if(g>0){var n=0,o=0,p=d.length;while(n<g&&o<p)/\n|\r|\r\n/.test(d.charAt(o))&&n++,o++;d=d.slice(o,p)}function q(a){var d=a[1];if(d.length&&d!==f){m++;if(l<j-1)throw m--,new Error("Not enough items in row");k=!0,l=0}else k||j++,l++;var g=null;a[2]?g=a[2].replace(new RegExp('""',"g"),'"'):g=a[3];if(k){g===""&&(g=h);if(typeof c[b[l]]=="undefined")throw new Error("Too many items in row");c[b[l]].push(g)}else{var i=function(a){var c=e(a);while(b.indexOf(c)!==-1)c=e(a);return c};if(_.isUndefined(g)||g==="")g="X";b.indexOf(g)!==-1&&(g=i(g)),b.push(g),c[g]=[]}}(new RegExp("^"+f)).test(d)&&q(["","",undefined,""]);while(i=a.exec(d))q(i)}catch(r){throw new Error("Error while parsing delimited data on row "+m+". Message: "+r.message)}return{columns:b,data:c}};return f(this.__delimiterPatterns,a,this.delimiter,this.skipRows,this.emptyValue)}})}(this,_),function(a,_){var b=a.Miso.Dataset;b.Derived=function(a){a=a||{},b.call(this),this.parent=a.parent,this.idAttribute="_id",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,_.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){if(a===this.idAttribute)throw"You can't compute a moving average on the id column";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(this.idAttribute).data=this.parent.column(this.parent.idAttribute).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(this.parent.idAttribute).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(d.idAttribute).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[this.parent.idAttribute]])):(g[c]+=1,h[c].push(b[this.parent.idAttribute]))},d),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(){var d=this;b.Builder.clearRowCache(this);var e={},f=0,g=this._columnPositionByName[a],h=this.parent.column(a);for(var i=0;i<this.parent.length;i++){var j=null;this.preprocess?j=this.preprocess(h.data[i]):j=h.data[i],_.isUndefined(e[j])&&(e[j]=f,_.each(c,function(a){var b=this.column(a),c=this.column(this.idAttribute);b.data[f]=[],c.data[f]=_.uniqueId()},this),this.column(a).data[f]=j,f++),_.each(c,function(a){var b=this.column(a),c=this.parent.column(a).data[i],d=e[j];b.data[d].push(this.parent.rowByPosition(i))},this)}var k=this._columns[this._columnPositionByName._oids];return k.data=[],_.each(c,function(a){var b=this.column(a);_.each(b.data,function(c,e){_.isArray(c)&&(k.data[e]=k.data[e]||[],k.data[e].push(_.map(c,function(a){return a[d.parent.idAttribute]})),k.data[e]=_.flatten(k.data[e]),b.data[e]=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||{};delete window.Miso,typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(module.exports=b),exports.miso=b):typeof define=="function"&&define.amd&&define("miso",[],function(){return b})}(this)
View
110 dist/node/miso.ds.deps.0.3.0.js
@@ -112,7 +112,7 @@ var request = require("request");
// Include Miso Dataset lib
/**
-* Miso.Dataset - v0.3.0 - 10/26/2012
+* Miso.Dataset - v0.3.0 - 10/27/2012
* http://github.com/misoproject/dataset
* Copyright (c) 2012 Alex Graul, Irene Ros;
* Dual Licensed: MIT, GPL
@@ -808,114 +808,52 @@ var request = require("request");
* Parameters:
* options - Optional
*/
- sort : function(args) {
- var options = {};
+ sort : function(args) {
+ var options = {}, cachedRows = [];
//If the first param is the comparator, set it as such.
if ( _.isFunction(args) ) {
options.comparator = args;
} else {
- options = args || options;
+ options = args || {};
}
if (options.comparator) {
this.comparator = options.comparator;
- }
-
- if (_.isUndefined(this.comparator)) {
+ } else if (_.isUndefined(this.comparator)) {
throw new Error("Cannot sort without this.comparator.");
- }
-
- var count = this.length, end;
-
- if (count === 1) {
- // we're done. only one item, all sorted.
- return;
}
- var swap = _.bind(function(from, to) {
-
- // move second row over to first
- var row = this.rowByPosition(to);
-
- _.each(row, function(value, column) {
- var colPosition = this._columnPositionByName[column],
- value2 = this._columns[colPosition].data[from];
- this._columns[colPosition].data.splice(from, 1, value);
- this._columns[colPosition].data.splice(to, 1, value2);
- }, this);
- }, this);
-
- var siftDown = _.bind(function(start, end) {
- var root = start, child;
- while (root * 2 <= end) {
- child = root * 2;
- var root_node = this.rowByPosition(root);
-
- if ((child + 1 < end) &&
- this.comparator(
- this.rowByPosition(child),
- this.rowByPosition(child+1)
- ) < 0) {
- child++;
- }
-
- if (this.comparator(
- root_node,
- this.rowByPosition(child)) < 0) {
-
- swap(root, child);
- root = child;
- } else {
- return;
- }
-
- }
-
- }, this);
-
+ // cache rows
+ var i, j, row;
+ for(i = 0; i < this.length; i++) {
+ cachedRows[i] = this._row(i);
+ }
- // puts data in max-heap order
- var heapify = function(count) {
- var start = Math.round((count - 2) / 2);
- while (start >= 0) {
- siftDown(start, count - 1);
- start--;
- }
- };
+ cachedRows.sort( this.comparator );
- if (count > 2) {
- heapify(count);
+ // iterate through cached rows, overwriting data in columns
+ i = cachedRows.length;
+ while ( i-- ) {
+ row = cachedRows[i];
- end = count - 1;
- while (end > 1) {
-
- swap(end, 0);
- end--;
- siftDown(0, end);
+ this._rowIdByPosition[i] = row[ this.idAttribute ];
+ this._rowPositionById[ row[ this.idAttribute ] ] = i;
+ j = this._columns.length;
+ while ( j-- ) {
+ var col = this._columns[j];
+ col.data[i] = row[ col.name ];
}
- } else {
- if (this.comparator(
- this.rowByPosition(0),
- this.rowByPosition(1)) > 0) {
- swap(0,1);
- }
- }
-
- // check last two rows, they seem to always be off sync.
- if (this.comparator(
- this.rowByPosition(this.length - 2),
- this.rowByPosition(this.length - 1)) > 0) {
- swap(this.length - 1,this.length - 2);
}
- if (this.syncable && options.silent) {
+ if (this.syncable && !options.silent) {
this.trigger("sort");
}
+
return this;
},
-
+
/**
* Exports a version of the dataset in json format.
* Returns:
Please sign in to comment.
Something went wrong with that request. Please try again.