-
Notifications
You must be signed in to change notification settings - Fork 0
/
boxplot.min.js
1 lines (1 loc) · 8.28 KB
/
boxplot.min.js
1
"undefined"==typeof org&&(org={cityxdev:{}}),org.cityxdev||(org.cityxdev={boxplot:{}}),org.cityxdev.boxplot||(org.cityxdev.boxplot={}),org.cityxdev.boxplot.BoxPlot=function(o){let t=o;const i=t.$target;let e,l,s,d,a,n,r,c,v,m,p,b,x,g,h,u,y,w,f,k,R,q,C,B,z,E,P,O,W,A,F,I,M,j,L,Q,V;const _=function(o,t){let i=t/100*(o.length-1);if(Math.floor(i)===i)return o[i];{let t=Math.floor(i),e=i-t;return o[t]+(o[t+1]-o[t])*e}};let N;const U=function(){if(N=$('<div class="box-plot-container"> <div class="box-plot"> <div class="hor-line"></div> <div class="min"></div> <div class="max"></div> <div class="min-max"></div> <div class="box"></div> <div class="med"></div> </div></div>'),!t.hideLegend){function o(){$("div.box-plot-legend").remove()}function i(){const o=$('<div class="box-plot-legend" style="display: none;"></div>');o.css("position","absolute"),o.css("top",N.offset().top+"px"),o.css("left",N.offset().left+N.width()+2+"px"),o.css("z-index",1e4),o.css("padding","5px"),o.css("background-color",O),o.css("border",A+"px solid "+W),o.css("border-radius","4px"),o.append($('<table><tr class="min"><td><label>'+I+'</label></td><td class="min-val"></td></tr><tr><td><label>'+M+'</label></td><td class="q1-val"></td></tr><tr><td><label>'+j+'</label></td><td class="med-val"></td></tr><tr><td><label>'+L+'</label></td><td class="q3-val"></td></tr><tr class="max"><td><label>'+Q+'</label></td><td class="max-val"></td></tr><tr><td><label>'+V+'</label></td><td class="iqr-val"></td></tr></table>')),null==n?$("tr.min",o).hide():$("td.min-val",o).html(n.toFixed(u)),null==r?$("tr.max",o).hide():$("td.max-val",o).html(r.toFixed(u)),$("td.q1-val",o).html(l.toFixed(u)),$("td.med-val",o).html(a.toFixed(u)),$("td.q3-val",o).html(d.toFixed(u)),$("td.iqr-val",o).html(v.toFixed(u)),$("table td",o).css("vertical-align","middle"),$("table td label",o).css("margin","0").css("color",E),$("body").append(o),o.show()}e=!1,(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.substr(0,4)))&&(e=!0),e?($("body").click((function(t){0===$(t.target).parents(".box-plot-container").length&&o()})),N.click((function(){i()}))):N.on({mouseenter:i,mouseleave:o})}var e};this.redraw=function(o){F=!1,o&&(t=o),function(){if(u=void 0!==t.values.decimalPlaces?t.values.decimalPlaces:2,e=t.values.data,e){if(e.length<=1)return F=!0,void console.log("ERROR: wrong input data.");e.sort((function(o,t){return o-t})),l=_(e,25),s=_(e,50),d=_(e,75),n=e[0],r=e[e.length-1]}else{if(l=t.values.p25,s=t.values.p50,d=t.values.p75,n=t.values.min,r=t.values.max,null==l||null==s||null==d||l>s||s>d)return F=!0,void console.log("ERROR: wrong input data.");if(null!=n&&n>l)return F=!0,void console.log("ERROR: wrong input data.");if(null!=r&&r<d)return F=!0,void console.log("ERROR: wrong input data.")}a=s,x=l,g=d,h=g-x,v=d-l,m=Math.max(l-1.5*v,void 0!==n?n:Number.MIN_VALUE),p=Math.min(d+1.5*v,void 0!==r?r:Number.MAX_VALUE),b=p-m,c=(void 0!==r?r:p)-(void 0!==n?n:m)}(),y=t.style&&void 0!==t.style.height?t.style.height:"20px",w=t.style&&void 0!==t.style.width?t.style.width:"100%",f=t.style&&void 0!==t.style.borderWidthPx?t.style.borderWidthPx:1,k=t.style&&void 0!==t.style.borderColor?t.style.borderColor:"black",R=t.style&&void 0!==t.style.boxWidthPx?t.style.boxWidthPx:1,q=t.style&&void 0!==t.style.boxBorderColor?t.style.boxBorderColor:"blue",C=t.style&&void 0!==t.style.boxBackgroundColor?t.style.boxBackgroundColor:"white",B=t.style&&void 0!==t.style.medColor?t.style.medColor:"green",z=t.style&&void 0!==t.style.medBorderWidth?t.style.medBorderWidth:2,E=t.style&&void 0!==t.style.legendLabelColor?t.style.legendLabelColor:"black",P=t.style&&void 0!==t.style.legendValueColor?t.style.legendValueColor:"black",O=t.style&&void 0!==t.style.legendBackgroundColor?t.style.legendBackgroundColor:"white",W=t.style&&void 0!==t.style.legendBorderColor?t.style.legendBorderColor:"black",A=t.style&&void 0!==t.style.legendBorderWidthPx?t.style.legendBorderWidthPx:1,I=t.translation&&void 0!==t.translation.min?t.translation.min:"min",M=t.translation&&void 0!==t.translation.q1?t.translation.q1:"q1",j=t.translation&&void 0!==t.translation.med?t.translation.med:"med",L=t.translation&&void 0!==t.translation.q3?t.translation.q3:"q3",Q=t.translation&&void 0!==t.translation.max?t.translation.max:"max",V=t.translation&&void 0!==t.translation.iqr?t.translation.iqr:"IQR",$("div.box-plot-container",i).remove(),U(),$(N).css("height",y),$(N).css("width",w),$("div.box-plot",N).css("width","100%"),$("div.box-plot",N).css("height","100%"),$("div.box-plot",N).css("position","relative"),$("div.min,div.max",N).css("position","absolute"),$("div.min,div.max",N).css("width",f/2+"px"),$("div.min,div.max",N).css("height",f/2+"px"),$("div.min,div.max",N).css("top","calc(50% - "+f/2+"px)"),$("div.min,div.max",N).css("border-top",f+"px solid "+k),$("div.min,div.max",N).css("border-left",f+"px solid "+k),$("div.max",N).css("left","calc(100% - "+f+"px)"),$("div.min-max",N).css("position","absolute"),$("div.min-max",N).css("height","100%"),$("div.min-max",N).css("border-left",f+"px solid "+k),$("div.min-max",N).css("border-right",f+"px solid "+k),$("div.med",N).css("position","absolute"),$("div.med",N).css("border-left",z+"px solid "+B),$("div.med",N).css("height","calc(80% - "+2*R+"px)"),$("div.med",N).css("top","calc(10% + "+R+"px)"),$("div.box",N).css("position","absolute"),$("div.box",N).css("height","80%"),$("div.box",N).css("top","10%"),$("div.box",N).css("border",R+"px solid "+q),$("div.box",N).css("background-color",C),$("div.box",N).css("border-radius","2px"),$("div.hor-line",N).css("position","absolute"),$("div.hor-line",N).css("top","calc(50% - "+f/2+"px)"),$("div.hor-line",N).css("height",f+"px"),$("div.hor-line",N).css("border-top",+f+"px solid "+k),function(){let o=m,t=p,i=b;o<n&&(F=!0,console.log("ERROR: (p25 - IQR * 1.5) < min ")),o>x&&(F=!0,console.log("ERROR: (p25 - IQR * 1.5) > p25 ")),t>r&&(F=!0,console.log("ERROR: (p75 + IQR * 1.5) > max ")),t<g&&(F=!0,console.log("ERROR: (p75 + IQR * 1.5) < p75 ")),F&&(t=r,o=n,i=t-o,$("div.min",N).hide(),$("div.max",N).hide(),$("div.box",N).hide(),$("div.min-max",N).css("background-color","rgba(255,0,0,0.1)"));const e=i/c*100,l=(o-n)/c*100;$("div.min-max",N).css("width",e+"%"),$("div.min-max",N).css("left",l+"%"),$("div.hor-line",N).css("width",e+"%"),$("div.hor-line",N).css("left",l+"%");const s=(a-n)/c*100;$("div.med",N).css("left","calc("+s+"% - "+z/2+"px)"),$("div.box",N).css("left",(x-n)/c*100+"%"),$("div.box",N).css("width",h/c*100+"%")}(),i.append(N)},this.redraw()};