fiatlux/firmware/webdir/js/smoothie_min.js

15 lines
14 KiB
JavaScript
Raw Normal View History

2021-07-18 23:25:27 +00:00
// MIT License:
//
// Copyright (c) 2010-2013, Joe Walnes
// 2013-2014, Drew Noakes
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
;(function(exports){var Util={extend:function(){arguments[0]=arguments[0]||{};for(var i=1;i<arguments.length;i+=1){for(var key in arguments[i]){if(arguments[i].hasOwnProperty(key)){if(typeof(arguments[i][key])==='object'){if(arguments[i][key]instanceof Array){arguments[0][key]=arguments[i][key]}else{arguments[0][key]=Util.extend(arguments[0][key],arguments[i][key])}}else{arguments[0][key]=arguments[i][key]}}}}return arguments[0]}};function TimeSeries(options){this.options=Util.extend({},TimeSeries.defaultOptions,options);this.clear()}TimeSeries.defaultOptions={resetBoundsInterval:3000,resetBounds:true};TimeSeries.prototype.clear=function(){this.data=[];this.maxValue=Number.NaN;this.minValue=Number.NaN;};TimeSeries.prototype.resetBounds=function(){if(this.data.length){this.maxValue=this.data[0][1];this.minValue=this.data[0][1];for(var i=1;i<this.data.length;i+=1){var value=this.data[i][1];if(value>this.maxValue){this.maxValue=value}if(value<this.minValue){this.minValue=value}}}else{this.maxValue=Number.NaN;this.minValue=Number.NaN}};TimeSeries.prototype.append=function(timestamp,value,sumRepeatedTimeStampValues){var i=this.data.length-1;while(i>=0&&this.data[i][0]>timestamp){i-=1}if(i===-1){this.data.splice(0,0,[timestamp,value])}else if(this.data.length>0&&this.data[i][0]===timestamp){if(sumRepeatedTimeStampValues){this.data[i][1]+=value;value=this.data[i][1]}else{this.data[i][1]=value}}else if(i<this.data.length-1){this.data.splice(i+1,0,[timestamp,value])}else{this.data.push([timestamp,value])}this.maxValue=isNaN(this.maxValue)?value:Math.max(this.maxValue,value);this.minValue=isNaN(this.minValue)?value:Math.min(this.minValue,value)};TimeSeries.prototype.dropOldData=function(oldestValidTime,maxDataSetLength){var removeCount=0;while(this.data.length-removeCount>=maxDataSetLength&&this.data[removeCount+1][0]<oldestValidTime){removeCount+=1}if(removeCount!==0){this.data.splice(0,removeCount)}};function SmoothieChart(options){this.options=Util.extend({},SmoothieChart.defaultChartOptions,options);this.seriesSet=[];this.currentValueRange=1;this.currentVisMinValue=0;this.lastRenderTimeMillis=0}SmoothieChart.defaultChartOptions={millisPerPixel:20,enableDpiScaling:true,yMinFormatter:function(min,precision){return parseFloat(min).toFixed(precision)},yMaxFormatter:function(max,precision){return parseFloat(max).toFixed(precision)},maxValueScale:1,minValueScale:1,interpolation:'bezier',scaleSmoothing:0.125,maxDataSetLength:2,scrollBackwards:false,grid:{fillStyle:'#000000',strokeStyle:'#777777',lineWidth:1,sharpLines:false,millisPerLine:1000,verticalSections:2,borderVisible:true},labels:{fillStyle:'#ffffff',disabled:false,fontSize:10,fontFamily:'monospace',precision:2},horizontalLines:[]};SmoothieChart.AnimateCompatibility=(function(){var requestAnimationFrame=function(callback,element){var requestAnimationFrame=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(callback){return window.setTimeout(function(){callback(new Date().getTime())},16)};return requestAnimationFrame.call(window,callback,element)},cancelAnimationFrame=function(id){var cancelAnimationFrame=window.cancelAnimationFrame||function(id){clearTimeout(id)};return cancelAnimationFrame.call(window,id)};return{requestAnimationFrame:requestAnimationFrame,cancelAnimationFrame:cancelAnimationFrame}})();SmoothieChart.defaultSeriesPresentationOptions={lineWidth:1,strokeStyle:'#ffffff'};SmoothieChart.prototype.addTimeSeries=function(timeSeries,options){this.seriesSet.push({timeSeries:timeSeries,options:Util.extend({},SmoothieChart.defaultSeriesPresentationOptions,options)});if(timeSeries.options.resetBounds&&timeSeries.options.resetBoundsInterval>0){timeSeries.resetBoundsTimerId=setInterval(function(){timeSeries.resetBounds()},timeSeries.options.resetBoundsInterval)}};SmoothieChart.prototype.removeTimeSeries=function(timeSeries){var numSeries=this.seriesSet.length;for(var i=0;i<numSeries;i+=1){if(this.seriesSet[i].timeSeries===timeSeries){this.seriesSet.splice