(function(){var i,r="#CPU-Usage",t="#Net-Usage",n="#NetPacket-Usage",a="#Temp-Stat",e=null;function o(e,t,i){return i.series.label+": "+i.datapoint[1].toFixed(2)}function l(e,t,i){return i.series.label+": "+d(i.datapoint[1].toFixed(2),true)}function s(e,t,i){return i.series.label+": "+App.formatBytes(i.datapoint[1])}function c(e,t,i){return i.series.label+": "+i.datapoint[1]+"℃"}function u(e,t){var i=new Date(e);if(t||i.getSeconds()%10==0){var r=i.getHours()<10?"0"+i.getHours():i.getHours();var n=i.getMinutes()<10?"0"+i.getMinutes():i.getMinutes();var a=i.getSeconds()<10?"0"+i.getSeconds():i.getSeconds();return r+":"+n+":"+a}return""}function d(e,t){if(t||e%10==0)return e+"%";return""}App.plotHover(r,l);App.plotHover(t,s);App.plotHover(n,o);App.plotHover(a,c);var f,p,h,g,v={series:{lines:{show:true,lineWidth:2,fill:true,fillColor:{colors:[{opacity:.25},{opacity:.25}]}},points:{show:false},shadowSize:2},legend:{show:true},grid:{labelMargin:10,axisMargin:500,hoverable:true,clickable:true,tickColor:"rgba(0,0,0,0.15)",borderWidth:0},colors:["#B450B2","#4A8CF7","#52e136"],xaxis:{mode:"time",tickSize:[2,"second"],tickFormatter:function(e,t){return u(e)}},yaxis:{min:0,max:100,tickSize:10,tickFormatter:function(e,t){return d(e)}}},m={series:{lines:{show:true,lineWidth:2,fill:true,fillColor:{colors:[{opacity:.25},{opacity:.25}]}},points:{show:false},shadowSize:2},legend:{show:true},grid:{labelMargin:10,axisMargin:500,hoverable:true,clickable:true,tickColor:"rgba(0,0,0,0.15)",borderWidth:0},colors:["#B450B2","#4A8CF7","#52e136"],xaxis:{mode:"time",tickSize:[2,"second"],tickFormatter:function(e,t){return u(e)}},yaxis:{tickFormatter:function(e,t){return App.formatBytes(e)}}},w={series:{lines:{show:true,lineWidth:2,fill:true,fillColor:{colors:[{opacity:.25},{opacity:.25}]}},points:{show:false},shadowSize:2},legend:{show:true},grid:{labelMargin:10,axisMargin:500,hoverable:true,clickable:true,tickColor:"rgba(0,0,0,0.15)",borderWidth:0},colors:["#B450B2","#4A8CF7","#52e136"],xaxis:{mode:"time",tickSize:[2,"second"],tickFormatter:function(e,t){return u(e)}}},b={series:{lines:{show:true,lineWidth:2,fill:true,fillColor:{colors:[{opacity:.25},{opacity:.25}]}},points:{show:false},shadowSize:2},legend:{show:true,noColumns:8,container:$("#Temp-Legend")[0]},grid:{labelMargin:10,axisMargin:500,hoverable:true,clickable:true,tickColor:"rgba(0,0,0,0.15)",borderWidth:0},colors:["#B450B2","#4A8CF7","#52e136"],xaxis:{mode:"time",tickSize:[2,"second"],tickFormatter:function(e,t){return u(e)}},yaxis:{min:0,max:100,tickSize:10,tickFormatter:function(e,t){return e+"℃"}}};function C(e){return[{data:e.Net.BytesRecv,label:App.i18n.chart.DOWNLOAD_SPEED},{data:e.Net.BytesSent,label:App.i18n.chart.UPLOAD_SPEED}]}function x(e){p.setData(e);p.setupGrid();p.draw()}function S(e){data=C(e);p=$(t).data("plot");if(!p)return k(data);x(data)}function k(e){$(t+"-Box").removeClass("hidden");p=$.plot($(t),e,m);$(t).data("plot",p)}function A(e){return[{data:e.Net.PacketsRecv,label:App.i18n.chart.RECV_PACKETS},{data:e.Net.PacketsSent,label:App.i18n.chart.SENT_PACKETS}]}function B(e){h.setData(e);h.setupGrid();h.draw()}function y(e){var t=A(e);h=$(n).data("plot");if(!h)return z(t);B(t)}function z(e){$(n+"-Box").removeClass("hidden");h=$.plot($(n),e,w);$(n).data("plot",h)}function M(e){var t=[];for(var i in e.Temp){t.push({data:e.Temp[i],label:i})}return t}function F(e){g.setData(e);g.setupGrid();g.draw()}function E(e){var t=M(e);if(t.length>0){g=$(a).data("plot");if(!g)return D(t);F(t)}}function D(e){b.legend.noColumns=e.length;b.series.lines.fill=b.legend.noColumns<=3;$(a+"-Box").removeClass("hidden");g=$.plot($(a),e,b);$(a).data("plot",g)}function P(e){return[{data:e.CPU,label:App.i18n.chart.CPU_USAGE},{data:e.Mem,label:App.i18n.chart.MEMORY_USAGE}]}function U(e){f.setData(e);f.setupGrid();f.draw()}function G(e){var t=P(e);f=$(r).data("plot");if(!f)return N(t);U(t)}function N(e){$(r+"-Box").removeClass("hidden");f=$.plot($(r),e,v);$(r).data("plot",f)}function W(){if(f){f.resize();f.setupGrid();f.draw()}if(g){g.resize();g.setupGrid();g.draw()}if(h){h.resize();h.setupGrid();h.draw()}if(p){p.resize();p.setupGrid();p.draw()}}function T(t){if(i){if(t!=null)t();return false}var e=App.wsURL(BACKEND_URL);i=new WebSocket(e+"/server/dynamic");i.onopen=function(e){if(t!=null)t();$(r+"-Box").removeClass("hidden")};i.onclose=function(e){i=null};i.onmessage=function(e){if($(r).length<1){i.close();L();return}var t=JSON.parse(e.data);G(t);S(t);y(t);E(t)};i.onerror=function(e){if(!$(r+"-Box").hasClass("hidden"))$(r+"-Box").addClass("hidden");if("data"in e)console.log(e.data);L()}}function H(){var t=$(r).width();T(function(){var e="ping";if(t<=260){e+=":10"}else if(t<=360){e+=":20"}else if(t<=500){e+=":30"}else if(t<=845){e+=":40"}try{i.send(e)}catch(e){L();console.error(e.message)}});if($(r).length<1)L()}function L(){if(e){clearInterval(e);e=null;try{if(i)i.close()}catch(e){}if(i)i=null}}var _=null;function R(){if($("#Temp-Legend").length>0){var e=$(window).width(),t=$(".cl-sidebar").width(),i=Math.abs(e-t)>=10;var r=e-(i?t:0)-85;if(r<200){r=200}if(_==null||_!=r){_=r;$("#Temp-Legend").css("width",i?r:"100%");var n=(r!="100%"?r:e)*2;$("canvas.flot-base,canvas.flot-overlay").css("width",r).attr("width",n);W()}}}$(function(){L();H();e=window.setInterval(H,2e3);R();$(window).on("resize",R)})})();