-
Notifications
You must be signed in to change notification settings - Fork 2
/
multibar.min.js
10 lines (10 loc) · 8.52 KB
/
multibar.min.js
1
2
3
4
5
6
7
8
9
10
/*!
* jquery-multibar v0.4.0 by @teorossi
* Copyright (c) 2015-2018 Matteo Rossi
*
* https://github.com/teorossi82/jquery-multi-bar
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/
!function(i){var l=function(i){var l='<div class="multi-bar-box';i.reverse&&(l+=" reverse "),l+='" ';var a=i.shadow&&n[i.shadow];a&&(l+=' style="'+n[i.shadow]+'"'),l+=">";for(var e=0;e<i.multiBarValue.length;e++){var t=(i.multiBarValue[e].val,0==e?"width:"+(i.multiBarValue[e].val-i.min)/(i.max-i.min)*100+"%":"width:"+(i.multiBarValue[e].val-i.multiBarValue[e-1].val)/(i.max-i.min)*100+"%"),r=i.multiBarValue[e].bgClass?'class="multi-bar-bar '+i.multiBarValue[e].bgClass+'" style="'+t+'"':i.multiBarValue[e].bgColor?'class="multi-bar-bar" style="background-color:'+i.multiBarValue[e].bgColor+";"+t+'"':'class="multi-bar-bar" style="'+t+'"';l+="<div "+r+"></div>"}l+="</div>";var s='<div class="multi-bar-value-content"><div class="multi-bar-initVal">'+i.min+"</div>";i.reverse&&(s='<div class="multi-bar-value-content reverse"><div class="multi-bar-initVal">'+i.min+"</div>");for(var o=0;o<i.multiBarValue.length;o++)if(i.multiBarValue[o].val==i.max)s+='<div class="multi-bar-value-box" style="width:'+(i.multiBarValue[o].val-i.multiBarValue[o-1].val)/(i.max-i.min)*100+'%"></div>';else if(0==o){var v=i.multiBarValue[o].visibility?i.multiBarValue[o].visibility:"visible";s+='<div class="multi-bar-value-box '+v+'" style="width:'+(i.multiBarValue[o].val-i.min)/(i.max-i.min)*100+'%;"><div class="multi-bar-value">'+i.multiBarValue[o].val+"</div></div>"}else{var v=i.multiBarValue[o].visibility?i.multiBarValue[o].visibility:"visible";s+='<div class="multi-bar-value-box '+v+'" style="width:'+(i.multiBarValue[o].val-i.multiBarValue[o-1].val)/(i.max-i.min)*100+'%;"><div class="multi-bar-value">'+i.multiBarValue[o].val+"</div></div>"}return s+='<div class="multi-bar-lastVal">'+i.max+"</div></div>",{mulBar:l,valBar:s}},a=function(i){var l='<div class="multi-bar-box';i.reverse&&(l+=" reverse "),i.size&&(l+=" multi-bar-"+i.size+" "),l+=' ">';for(var a=i.min,e=0;e<s.hot.length;e++)l+='<div class="multi-bar-bar" style="background-color:'+s.hot[e]+';width:10%"></div>';l+="</div>";var t='<div class="multi-bar-value-content"><div class="multi-bar-initVal">'+i.min+"</div>";i.reverse&&(t='<div class="multi-bar-value-content reverse"><div class="multi-bar-initVal">'+i.min+"</div>");for(var a=i.min,r=0;r<s.hot.length;r++)a+=(i.max-i.min)/10,t+=r==s.hot.length-1?'<div class="multi-bar-value-box" style="width:10%"></div>':'<div class="multi-bar-value-box" style="width:10%"><div class="multi-bar-value">'+a.toFixed(1)+"</div></div>";return t+='<div class="multi-bar-lastVal">'+i.max+"</div></div>",{mulBar:l,valBar:t}},e=function(i){var l='<div class="multi-bar-box';i.reverse&&(l+=" reverse "),i.size&&(l+=" multi-bar-"+i.size+" "),l+=' ">';for(var a=i.min,e=0;e<s.cold.length;e++)l+='<div class="multi-bar-bar" style="background-color:'+s.cold[e]+';width:10%"></div>';l+="</div>";var t='<div class="multi-bar-value-content"><div class="multi-bar-initVal">'+i.min+"</div>";i.reverse&&(t='<div class="multi-bar-value-content reverse"><div class="multi-bar-initVal">'+i.min+"</div>");for(var a=i.min,r=0;r<s.cold.length;r++)a+=(i.max-i.min)/10,t+=r==s.cold.length-1?'<div class="multi-bar-value-box" style="width:10%"></div>':'<div class="multi-bar-value-box" style="width:10%"><div class="multi-bar-value">'+a.toFixed(1)+"</div></div>";return t+='<div class="multi-bar-lastVal">'+i.max+"</div></div>",{mulBar:l,valBar:t}},t=function(i,l){var a='<div class="multi-bar-marker-content';l.posMarker&&"inside"===l.posMarker&&(a+=" inside ");var e="left";l.reverse&&(a+=" reverse ",e="right"),a+='">';var t="arrow-down";l.iconMarker&&(t=l.iconMarker);for(var r=0;r<i.length;r++){var s,n,o=i[r]&&"object"==typeof i[r];o?(s=i[r].value,n=i[r].color):(s=i[r],n="black");var v=(s-l.min)/(l.max-l.min)*100;s>l.max?v=100:s<l.min&&(v=0),a+='<div class="multi-bar-marker" style="'+e+":"+v+"%;color:"+n+'"><div class="multi-bar-marker-value">'+s+'</div><span class="icon-'+t+'"></span></div>'}return a+="</div>"},r=function(l,a,e){var t='<div class="multi-bar-legend-box">';if(a.legend.title){var r=a.legend.titleClass?'<div class="'+a.legend.titleClass+'">'+a.legend.title+"</div>":'<div class="multi-bar-legend-title">'+a.legend.title+"</div>";t+=r}for(var s=a.legend.itemClass?'class="multi-bar-legend-item '+a.legend.itemClass+'"':'class="multi-bar-legend-item"',n=0;n<l.length;n++){var o=l[n]&&"object"==typeof l[n]?l[n].value:l[n],v=l[n]&&"object"==typeof l[n]?l[n].label:"Item",u=l[n]&&"object"==typeof l[n]?l[n].color:"black";t+="<div "+s+'><span class="icon-circle" style="color:'+u+'"></span> <span class="multi-bar-legend-item-label">'+v+": "+o+"</span></div>"}t+="</div>";var m=a.legend.content;if(m)i(i(m).find(".multi-bar-legend-box")[0]).remove(),i(m).append(t),i(i(m).find(".multi-bar-legend-box")[0]).css("margin","0%");else if(i(e.find(".multi-bar-legend-box")[0]).remove(),i(e.find(".multi-bar")[0]).append(t),i(e.find(".multi-bar-content")[0]).removeClass("no-legend"),i(e.find(".multi-bar-content")[0]).addClass("yes-legend"),i(e.find(".multi-bar-legend-box")[0]).css("width","28%"),a.thermometer){var d=a.size&&"big"==a.size?parseFloat(i(e.find(".multi-bar")[0]).css("width"))/100*68-62:parseFloat(i(e.find(".multi-bar")[0]).css("width"))/100*68-51;i(e.find(".multi-bar-content")[0]).css("width",d+"px")}},s={defaults:["green","yellow","orange","red","purple","blue","black","white"],hot:["#F9F9BD","#F7F411","#ECD024","#FFA500","#E08E00","#FF350A","#E90000","#BE0028","#C10069","#8A0079"],cold:["#A4FCB7","#A4FCD6","#A4FCF5","#A4F2FC","#A4E1FC","#A4CDFC","#A4ACFC","#5479CE","#4759FF","#0019FF"]},n={center:"box-shadow:0 0px 4px 0 #666",top:"box-shadow:0px -2px 2px 0 #666",left:"box-shadow:-3px 0 2px 0 #666",right:"box-shadow:3px 0 2px 0 #666",bottom:"box-shadow:0px 2px 2px 0 #666",top_left:"box-shadow:-2px -2px 2px 0 #666",top_right:"box-shadow:2px -2px 2px 0 #666",bottom_left:"box-shadow:-2px 2px 2px 0 #666",bottom_right:"box-shadow:2px 2px 2px 0 #666"},o=function(t,r){this.element=i(t);var n='<div class="multi-bar';if(r.size&&(n+=" multi-bar-"+r.size+" "),r.multiBarValueVisibility&&"hidden"==r.multiBarValueVisibility&&(n+=" multi-bar-value-box-hidden "),r.thermometer){var o=r.reverse?r.type&&s[r.type]?s[r.type].length-1:r.multiBarValue.length-1:0,v=r.type&&s[r.type]?'class="thermometer_init" style="background-color:'+s[r.type][o]+';"':r.multiBarValue[o].bgClass?'class="thermometer_init '+r.multiBarValue[o].bgClass+'"':r.multiBarValue[o].bgColor?'class="thermometer_init" style="background-color:'+r.multiBarValue[o].bgColor+';"':'class="thermometer_init"';n+=' thermometer"><div class="multi-bar-content no-legend"><div '+v+'></div><div class="thermometer_end"></div><div class="multi-bar-marker-content"></div>'}else n+='"><div class="multi-bar-content no-legend"><div class="multi-bar-marker-content"></div>';var u;u=r.type&&"hot"==r.type?a(r):r.type&&"cold"==r.type?e(r):l(r),n+=u.mulBar+u.valBar,n+="</div></div>",this.element.html(n+'<div style="clear:both"></div>'),this.options=r,r.initValue&&"object"==typeof r.initValue&&this.setValue(r.initValue)};o.prototype={constructor:o,setValue:function(l){var a=t(l,this.options);i(i(this.element).find(".multi-bar-marker-content")[0]).replaceWith(a);var e=this.options.legend&&1==this.options.legend.show;if(e){r(l,this.options,this.element)}},destroy:function(){i(i(this.element).find(".multi-bar")[0]).remove();var l=this.options.legend&&1==this.options.legend.show;if(l){var a=this.options.legend.content;a&&i(i(a).find(".multi-bar-legend-box")[0]).remove()}}},i.fn.multibar=function(l){var a=Array.apply(null,arguments);return a.shift(),this.each(function(){var e,t=i(this),r=t.data("multibar");if(r)"string"==typeof l&&"function"==typeof r[l]&&r[l].apply(r,a);else{if(!l)return void t.data("multibar",new o(this,i.fn.multibar.defaults));if(l.min||0==l.min||(l.min=i.fn.multibar.defaults.min),l.max||0==l.max||(l.max=i.fn.multibar.defaults.max),!l.multiBarValue){l.multiBarValue=[];for(var n=(l.max-l.min)/5,v=l.min+n,u=0;5>u;u++)l.multiBarValue.push({visibility:"visible",val:parseInt(v),bgColor:s.defaults[u]}),v+=(l.max-l.min)/5}e=i.extend({},i.fn.multibar.defaults,l),t.data("multibar",new o(this,l))}})},i.fn.multibar.defaults={min:0,max:10,type:"normal",thermometer:!1,reverse:!1,posMarker:"outside",iconMarker:"arrow-down",multiBarValue:[{visibility:"visible",val:2,bgColor:"green"},{visibility:"visible",val:4,bgColor:"yellow"},{visibility:"visible",val:6,bgColor:"orange"},{visibility:"visible",val:8,bgColor:"red"},{visibility:"visible",val:10,bgColor:"purple"}],multiBarValueVisibility:"visible",shadow:!1}}(jQuery);