mirror of
https://github.com/YunoHost-Apps/linuxdash_ynh.git
synced 2024-09-03 19:36:07 +02:00
2 lines
8.8 KiB
JavaScript
2 lines
8.8 KiB
JavaScript
|
(function(e){function n(e){this.options=t.extend({},n.defaultOptions,e);this.clear()}function r(e){this.options=t.extend({},r.defaultChartOptions,e);this.seriesSet=[];this.currentValueRange=1;this.currentVisMinValue=0;this.lastRenderTimeMillis=0}var t={extend:function(){arguments[0]=arguments[0]||{};for(var e=1;e<arguments.length;e++){for(var n in arguments[e]){if(arguments[e].hasOwnProperty(n)){if(typeof arguments[e][n]==="object"){if(arguments[e][n]instanceof Array){arguments[0][n]=arguments[e][n]}else{arguments[0][n]=t.extend(arguments[0][n],arguments[e][n])}}else{arguments[0][n]=arguments[e][n]}}}}return arguments[0]}};n.defaultOptions={resetBoundsInterval:3e3,resetBounds:true};n.prototype.clear=function(){this.data=[];this.maxValue=Number.NaN;this.minValue=Number.NaN};n.prototype.resetBounds=function(){if(this.data.length){this.maxValue=this.data[0][1];this.minValue=this.data[0][1];for(var e=1;e<this.data.length;e++){var t=this.data[e][1];if(t>this.maxValue){this.maxValue=t}if(t<this.minValue){this.minValue=t}}}else{this.maxValue=Number.NaN;this.minValue=Number.NaN}};n.prototype.append=function(e,t,n){var r=this.data.length-1;while(r>=0&&this.data[r][0]>e){r--}if(r===-1){this.data.splice(0,0,[e,t])}else if(this.data.length>0&&this.data[r][0]===e){if(n){this.data[r][1]+=t;t=this.data[r][1]}else{this.data[r][1]=t}}else if(r<this.data.length-1){this.data.splice(r+1,0,[e,t])}else{this.data.push([e,t])}this.maxValue=isNaN(this.maxValue)?t:Math.max(this.maxValue,t);this.minValue=isNaN(this.minValue)?t:Math.min(this.minValue,t)};n.prototype.dropOldData=function(e,t){var n=0;while(this.data.length-n>=t&&this.data[n+1][0]<e){n++}if(n!==0){this.data.splice(0,n)}};r.defaultChartOptions={millisPerPixel:20,enableDpiScaling:true,yMinFormatter:function(e,t){return parseFloat(e).toFixed(t)},yMaxFormatter:function(e,t){return parseFloat(e).toFixed(t)},maxValueScale:1,minValueScale:1,interpolation:"bezier",scaleSmoothing:.125,maxDataSetLength:2,grid:{fillStyle:"#000000",strokeStyle:"#777777",lineWidth:1,sharpLines:false,millisPerLine:1e3,verticalSections:2,borderVisible:true},labels:{fillStyle:"#ffffff",disabled:false,fontSize:10,fontFamily:"monospace",precision:2},horizontalLines:[]};r.AnimateCompatibility=function(){var e=function(e,t){var n=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(e){return window.setTimeout(function(){e((new Date).getTime())},16)};return n.call(window,e,t)},t=function(e){var t=window.cancelAnimationFrame||function(e){clearTimeout(e)};return t.call(window,e)};return{requestAnimationFrame:e,cancelAnimationFrame:t}}();r.defaultSeriesPresentationOptions={lineWidth:1,strokeStyle:"#ffffff"};r.prototype.addTimeSeries=function(e,n){this.seriesSet.push({timeSeries:e,options:t.extend({},r.defaultSeriesPresentationOptions,n)});if(e.options.resetBounds&&e.options.resetBoundsInterval>0){e.resetBoundsTimerId=setInterval(function(){e.resetBounds()},e.options.resetBoundsInterval)}};r.prototype.removeTimeSeries=function(e){var t=this.seriesSet.length;for(var n=0;n<t;n++){if(this.seriesSet[n].timeSeries===e){this.seriesSet.splice(n,1);break}}if(e.resetBoundsTimerId){clearInterval(e.resetBoundsTimerId)}};r.prototype.getTimeSeriesOptions=function(e){var t=this.seriesSet.length;for(var n=0;n<t;n++){if(this.seriesSet[n].timeSeries===e){return this.seriesSet[n].options}}};r.prototype.bringToFront=function(e){var t=this.seriesSet.length;for(var n=0;n<t;n++){if(this.seriesSet[n].timeSeries===e){var r=this.seriesSet.splice(n,1);this.seriesSet.push(r[0]);break}}};r.prototype.streamTo=function(e,t){this.canvas=e;this.delay=t;this.start()};r.prototype.resize=function(){if(!this.options.enableDpiScaling||!window||window.devicePixelRatio===1)return;var e=window.devicePixelRatio;var t=parseInt(this.canvas.getAttribute("width"));var n=parseInt(this.canvas.getAttribute("height"));if(!this.originalWidth||Math.floor(this.originalWidth*e)!==t){this.originalWidth=t;this.canvas.setAttribute("width",Math.floor(t*e).toString
|