forked from tshaddix/oocharts-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oocharts.min.js
1 lines (1 loc) · 8.97 KB
/
oocharts.min.js
1
var oo=function(a){var b="https://api.oocharts.com/v1/dynamic.jsonp",c=void 0,d={},e={},f={},g={},h={},i=function(){for(var b=function(b){for(var c=[],d=a.getElementsByTagName("*"),e=0;e<d.length;e++)d[e].getAttribute(b)&&c.push(d[e]);return c},c=b("data-oochart"),d=0;d<c.length;d++){var e=c[d],f=e.getAttribute("data-oochart"),g=e.getAttribute("data-oochart-start-date"),h=e.getAttribute("data-oochart-end-date"),i=e.getAttribute("data-oochart-profile");if("metric"===f.toLowerCase()){var j=new u(i,g,h);j.setMetric(e.getAttribute("data-oochart-metric")),j.draw(e)}else if("column"===f.toLowerCase()){for(var k=new v(i,g,h),l=e.getAttribute("data-oochart-metrics"),m=l.split(","),n=0;n<m.length;n++)k.addMetric(m[n],m[n+1]),n+=1;var o=e.getAttribute("data-oochart-dimension");k.setDimension(o),k.draw(e)}else if("timeline"===f.toLowerCase()){for(var p=new w(i,g,h),l=e.getAttribute("data-oochart-metrics"),m=l.split(","),n=0;n<m.length;n++)p.addMetric(m[n],m[n+1]),n+=1;p.draw(e)}else if("bar"===f.toLowerCase()){for(var q=new x(i,g,h),l=e.getAttribute("data-oochart-metrics"),m=l.split(","),n=0;n<m.length;n++)q.addMetric(m[n],m[n+1]),n+=1;var o=e.getAttribute("data-oochart-dimension");q.setDimension(o),q.draw(e)}else if("pie"===f.toLowerCase()){var r=new y(i,g,h),s=e.getAttribute("data-oochart-metric"),o=e.getAttribute("data-oochart-dimension"),j=s.split(",");r.setMetric(j[0],j[1]),r.setDimension(o),r.draw(e)}else if("table"===f.toLowerCase()){for(var t=new z(i,g,h),s=e.getAttribute("data-oochart-metrics"),A=e.getAttribute("data-oochart-dimensions"),m=s.split(","),B=A.split(","),n=0;n<m.length;n++)t.addMetric(m[n],m[n+1]),n+=1;for(var C=0;C<B.length;C++)t.addDimension(B[C],B[C+1]),C+=1;t.draw(e)}}},j=function(b,c){var d=a.createElement("script");d.type="text/javascript",d.src=b,d.async=!1,d.onreadystatechange=d.onload=function(){var a=d.readyState;c.done||a&&!/loaded|complete/.test(a)||(c.done=!0,c())};var e=a.getElementsByTagName("script")[0];e.parentNode.insertBefore(d,e)},k=function(a){if(!c)throw"Set APIKey with oo.setAPIKey before calling load";var b=function(a){"undefined"==typeof google?j("https://www.google.com/jsapi",a):a()},d=function(a){if("undefined"==typeof google.visualization)google.load("visualization","1",{packages:["corechart","table"],callback:a});else{var b=[];"undefined"==typeof google.visualization.corechart&&b.push("corechart"),"undefined"==typeof google.visualization.table&&b.push("table"),b.length>0&&google.load("visualization","1",{packages:b,callback:a})}},e=a;b(function(){d(function(){e&&e(),i()})})},l=function(a){c=a},m=function(a){h=a},n=function(a){g=a},o=function(a){d=a},p=function(a){e=a},q=function(a){f=a},r=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},s=function(a){a=a.split("-");var b=new Date;return b.setFullYear(a[0],a[1]-1,a[2]),b.setHours(0,0,0,0),b},t=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=r(b)),c instanceof Date&&(c=r(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};t.prototype.clearMetrics=function(){this.metrics=[]},t.prototype.clearDimensions=function(){this.dimensions=[]},t.prototype.addMetric=function(a){this.metrics.push(a)},t.prototype.addDimension=function(a){this.dimensions.push(a)},t.prototype.setFilter=function(a){this.filters=a},t.prototype.setSort=function(a){this.sort=a},t.prototype.setSegment=function(a){this.segment=a},t.prototype.setIndex=function(a){this.index=a},t.prototype.setMaxResults=function(a){this.maxResults=a},t.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 u=function(a,b,c){this.query=new t(a,b,c)};u.prototype.setMetric=function(a){this.query.clearMetrics(),this.query.addMetric(a)},u.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 v=function(a,b,c){this.query=new t(a,b,c),this.metricLabels=[],this.options=h};v.prototype.setOptions=function(a){this.options=a},v.prototype.addMetric=function(a,b){this.metricLabels.push(b),this.query.addMetric(a)},v.prototype.setDimension=function(a){this.query.clearDimensions(),this.query.dimensions.push(a),this.dimensionLabel=a},v.prototype.draw=function(b,c){var d=this;this.query.execute(function(e){var f=e.rows,g=new google.visualization.DataTable;g.addColumn("string",d.dimensionLabel);for(var h=0;h<d.metricLabels.length;h++)g.addColumn("number",d.metricLabels[h]);g.addRows(f);var i;i="string"==typeof b?a.getElementById(b):b;var j=new google.visualization.ColumnChart(i);j.draw(g,d.options),"undefined"!=typeof c&&c()})};var w=function(a,b,c){this.query=new t(a,b,c),this.query.addDimension("ga:date"),this.labels=[],this.options=d};w.prototype.setOptions=function(a){this.options=a},w.prototype.addMetric=function(a,b){this.labels.push(b),this.query.addMetric(a)},w.prototype.draw=function(b,c){var d=this;this.query.execute(function(e){for(var f=e.rows,g=0;g<f.length;g++)f[g][0]=s(f[g][0]);var h=new google.visualization.DataTable;h.addColumn("date","Date");for(var i=0;i<d.labels.length;i++)h.addColumn("number",d.labels[i]);h.addRows(f);var j;j="string"==typeof b?a.getElementById(b):b;var k=new google.visualization.LineChart(j);k.draw(h,d.options),"undefined"!=typeof c&&c()})};var x=function(a,b,c){this.query=new t(a,b,c),this.metricLabels=[],this.options=g};x.prototype.setOptions=function(a){this.options=a},x.prototype.addMetric=function(a,b){this.metricLabels.push(b),this.query.addMetric(a)},x.prototype.setDimension=function(a){this.query.clearDimensions(),this.query.dimensions.push(a),this.dimensionLabel=a},x.prototype.draw=function(b,c){var d=this;this.query.execute(function(e){var f=e.rows,g=new google.visualization.DataTable;g.addColumn("string",d.dimensionLabel);for(var h=0;h<d.metricLabels.length;h++)g.addColumn("number",d.metricLabels[h]);g.addRows(f);var i;i="string"==typeof b?a.getElementById(b):b;var j=new google.visualization.BarChart(i);j.draw(g,d.options),"undefined"!=typeof c&&c()})};var y=function(a,b,c){this.query=new t(a,b,c),this.options=e};y.prototype.setMetric=function(a,b){this.metricLabel=b,this.query.clearMetrics(),this.query.addMetric(a)},y.prototype.setDimension=function(a){this.query.clearDimensions(),this.query.dimensionLabel=a,this.query.addDimension(a)},y.prototype.setOptions=function(a){this.options=a},y.prototype.draw=function(b,c){var d=this;this.query.execute(function(e){var f=e.rows,g=new google.visualization.DataTable;g.addColumn("string",d.dimensionLabel),g.addColumn("number",d.metricLabel),g.addRows(f);var h;h="string"==typeof b?a.getElementById(b):b;var i=new google.visualization.PieChart(h);i.draw(g,d.options),"undefined"!=typeof c&&c()})};var z=function(a,b,c){this.query=new t(a,b,c),this.metricLabels=[],this.dimensionLabels=[],this.options=f};return z.prototype.addMetric=function(a,b){this.query.addMetric(a),this.metricLabels.push(b)},z.prototype.addDimension=function(a,b){this.query.addDimension(a),this.dimensionLabels.push(b)},z.prototype.setOptions=function(a){this.options=a},z.prototype.draw=function(b,c){var d=this;this.query.execute(function(e){for(var f=e.rows,g=[],h=0;h<d.dimensionLabels.length;h++)g.push(d.dimensionLabels[h]);for(var i=0;i<d.metricLabels.length;i++)g.push(d.metricLabels[i]);f.splice(0,0,g);var k,j=google.visualization.arrayToDataTable(f);k="string"==typeof b?a.getElementById(b):b;var l=new google.visualization.Table(k);l.draw(j,d.options),"undefined"!=typeof c&&c()})},{Query:t,Timeline:w,Column:v,Bar:x,Metric:u,Pie:y,Table:z,load:k,formatDate:r,parseDate:s,setAPIKey:l,setBarDefaults:n,setColumnDefaults:m,setTimelineDefaults:o,setPieDefaults:p,setTableDefaults:q}}(document),JSONP=function(a){var b=0,c={};return{get:function(d,e,f){arguments[2]||(f=arguments[1],e={}),d+=d.indexOf("?")+1?"&":"?";var k,g=a.getElementsByTagName("head")[0],h=a.createElement("script"),i=[],j=b;b++,e.callback="JSONP.callbacks.request_"+j,c["request_"+j]=function(a){g.removeChild(h),delete c["request_"+j],f(a)};for(k in e)i.push(k+"="+encodeURIComponent(e[k]));d+=i.join("&"),h.type="text/javascript",h.src=d,g.appendChild(h)},callbacks:c}}(document);