diff --git a/oocharts.js b/oocharts.js index 045278a..d8b30bc 100644 --- a/oocharts.js +++ b/oocharts.js @@ -251,7 +251,11 @@ var oo = (function(document){ * @returns {Date} parsed Date */ var _parseDate = function(val){ - return new Date(val.substring(0, 4), parseInt(val.substring(5, 7)) - 1, val.substring(8, 10)); + val = val.split('-'); + var newDate = new Date(); + newDate.setFullYear(val[0], val[1]-1, val[2]); + newDate.setHours(0,0,0,0); + return newDate; }; /*------------------------------------------------------------ diff --git a/oocharts.min.js b/oocharts.min.js index 772f3be..611fb4a 100644 --- a/oocharts.min.js +++ b/oocharts.min.js @@ -1 +1,12 @@ -var oo=function(a){var b="https://api.oocharts.com/v1/dynamic.jsonp",c=void 0,d={},e={},f={},g={},h=function(){for(var b=function(b){for(var c=[],d=a.getElementsByTagName("*"),e=0;e0&&google.load("visualization","1",{packages:b,callback:a})}},e=a;b(function(){d(function(){e&&e(),h()})})},k=function(a){c=a},l=function(a){d=a},m=function(a){e=a},n=function(a){f=a},o=function(a){var b=a.getFullYear().toString(),c=(a.getMonth()+1).toString(),a=a.getDate().toString();return 1===c.length&&(c="0"+c),1===a.length&&(a="0"+a),b+"-"+c+"-"+a},p=function(a){return new Date(a.substring(0,4),parseInt(a.substring(5,7))-1,a.substring(8,10))},q=function(a,b,c){if(this.metrics=[],this.dimensions=[],!a)throw new Error("Profile argument required");this.profile=a,b=b||new Date,c=c||new Date,b instanceof Date&&(b=o(b)),c instanceof Date&&(c=o(c));var d=function(a){return/^[0-9]+(m|d|w|y)$/.test(a)},e=function(a){return/^([0-9]{4}-[0-9]{2}-[0-9]{2})$|^[0-9]+(m|d|w|y)$/.test(a)};if(!d(b)&&!e(b))throw new Error("startDate parameter invalid");if(!d(c)&&!e(c))throw new Error("endDate parameter invalid");if(d(b)&&d(c))throw new Error("startDate and endDate cannot both be relative dates");this.startDate=b,this.endDate=c};q.prototype.clearMetrics=function(){this.metrics=[]},q.prototype.clearDimensions=function(){this.dimensions=[]},q.prototype.addMetric=function(a){this.metrics.push(a)},q.prototype.addDimension=function(a){this.dimensions.push(a)},q.prototype.setFilter=function(a){this.filters=a},q.prototype.setSort=function(a){this.sort=a},q.prototype.setSegment=function(a){this.segment=a},q.prototype.setIndex=function(a){this.index=a},q.prototype.setMaxResults=function(a){this.maxResults=a},q.prototype.execute=function(a){var d={};if(d.key=c,d.profile=this.profile,0===this.metrics.length)throw new Error("At least one metric is required");d.metrics=this.metrics.toString(),d.start=this.startDate,d.end=this.endDate,this.dimensions.length>0&&(d.dimensions=this.dimensions.toString()),this.filters&&(d.filters=this.filters),this.sort&&(d.sort=this.sort),this.index&&(d.index=this.index),this.segment&&(d.segment=this.segment),this.maxResults&&(d.maxResults=this.maxResults),JSONP.get(b,d,function(b){0===b.rows.length&&(b.rows=[[]]),a(b)})};var r=function(a,b,c){this.query=new q(a,b,c)};r.prototype.setMetric=function(a){this.query.clearMetrics(),this.query.addMetric(a)},r.prototype.draw=function(b,c){this.query.execute(function(d){var e;e="string"==typeof b?a.getElementById(b):b,e.innerHTML="undefined"!=typeof d.rows[0][0]?d.rows[0][0].toString():"0","undefined"!=typeof c&&c()})};var s=function(a,b,c){this.query=new q(a,b,c),this.query.addDimension("ga:date"),this.labels=[],this.options=d};s.prototype.setOptions=function(a){this.options=a},s.prototype.addMetric=function(a,b){this.labels.push(b),this.query.addMetric(a)},s.prototype.draw=function(b,c){var d=this;this.query.execute(function(e){for(var f=e.rows,g=0;g