-
Notifications
You must be signed in to change notification settings - Fork 2
/
mta.min.js
6 lines (6 loc) · 2.4 KB
/
mta.min.js
1
2
3
4
5
6
/**
* Created by Vladi on 3/7/2015.
* wrapper for http://morrisjs.github.io/morris.js/
* version 1.2
*/
!function(){function b(a,b,c){function d(a,b){this.container=document.querySelector("#"+b.element),this.origData=b.data,this.xkey=b.xkey,this.origYKeys=b.ykeys,this.displayedYKeys=b.ykeys,this.labels=b.labels,this.morris=Morris[a](b)}if(!a||!b)return void console.log("Please make sure morris obj is correct");if(!Morris)return void console.log("Missing morris.js");var e=new d(a,b);return d.prototype.initSelectYKeys=function(){var a=e.origYKeys,b=document.createElement("div"),c=this.container.parentNode;b.className="buttonsContainer",b.setAttribute("data-parent-graph",this.container.id);for(var d in a){var f=document.createElement("input"),g=document.createElement("span");g.className="yKeyButton",a.hasOwnProperty(d)&&(f.setAttribute("type","checkbox"),f.checked=!0,f.style.cursor="pointer",g.style.cursor="pointer",f.setAttribute("data-key-name",a[d]),f.addEventListener("change",function(){var a=this;a.checked=!a.checked}),g.addEventListener("click",function(){var a=this.childNodes[0],b=a.getAttribute("data-key-name");b&&(e.toggleYKeys(new Array(b)),a.checked=!a.checked)}),g.appendChild(f),g.appendChild(document.createTextNode("Display "+a[d])),b.appendChild(g))}c.insertBefore(b,this.container.nextSibling),this.buttonsContainer=b},d.prototype.show=function(){this.container.style.display="inline-block"},d.prototype.hide=function(){this.container.style.display="none"},d.prototype.getMorrisObj=function(){return this.morris},d.prototype.setData=function(a){a&&a.length>0&&(this.morris.setData(a),this.origData=a,this.setYKeys(this.origYKeys))},d.prototype.toggleYKeys=function(a){for(var b=this.displayedYKeys,c=[],d=0,e=b.length;d<e;d++)c.push(b[d]);for(var f=0,g=a.length;f<g;f++){var h=c.indexOf(a[f]);h>-1?delete c[h]:c.push(a[f])}this.displayedYKeys=c,this.setYKeys(c)},d.prototype.setYKeys=function(a){var b=this.filterData(this.origData,a);b&&b.length>0&&this.morris.setData(b)},d.prototype.filterData=function(a,b){var c=[];for(var d in a)if(a.hasOwnProperty(d)){var e=a[d],f={},g=!1;for(var h in e)if(e.hasOwnProperty(h))for(var i=0,j=b.length;i<j;i++)if(this.xkey===h||h===b[i]){f[h]=a[d][h],g=!0;break}g&&c.push(f)}return c},c&&e.initSelectYKeys(),e}var a={};window.MTA||(window.MTA=a),a.Line=function(a,c){return b("Line",a,c)},a.Bar=function(a,c){return b("Bar",a,c)},a.Donut=function(a){return b("Donut",a,!1)}}();