// 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;ithis.maxValue){this.maxValue=value}if(value=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=maxDataSetLength&&this.data[removeCount+1][0]0){timeSeries.resetBoundsTimerId=setInterval(function(){timeSeries.resetBounds()},timeSeries.options.resetBoundsInterval)}};SmoothieChart.prototype.removeTimeSeries=function(timeSeries){var numSeries=this.seriesSet.length;for(var i=0;i0.1||Math.abs(minValueDiff)>0.1;this.currentValueRange+=chartOptions.scaleSmoothing*valueRangeDiff;this.currentVisMinValue+=chartOptions.scaleSmoothing*minValueDiff}this.valueRange={min:chartMinValue,max:chartMaxValue}};SmoothieChart.prototype.render=function(canvas,time){var nowMillis=new Date().getTime();if(!this.isAnimatingScale){var maxIdleMillis=Math.min(1000/6,this.options.millisPerPixel);if(nowMillis-this.lastRenderTimeMillis0){context.beginPath();for(var t=time-(time%chartOptions.grid.millisPerLine);t>=oldestValidTime;t-=chartOptions.grid.millisPerLine){var gx=timeToXPixel(t);if(chartOptions.grid.sharpLines){gx-=0.5}context.moveTo(gx,0);context.lineTo(gx,dimensions.height)}context.stroke();context.closePath()}for(var v=1;v1){if(seriesOptions.fillStyle){context.lineTo(dimensions.width+seriesOptions.lineWidth+1,lastY);context.lineTo(dimensions.width+seriesOptions.lineWidth+1,dimensions.height+seriesOptions.lineWidth+1);context.lineTo(firstX,dimensions.height+seriesOptions.lineWidth);context.fillStyle=seriesOptions.fillStyle;context.fill()}if(seriesOptions.strokeStyle&&seriesOptions.strokeStyle!=='none'){context.stroke()}context.closePath()}context.restore()}if(!chartOptions.labels.disabled&&!isNaN(this.valueRange.min)&&!isNaN(this.valueRange.max)){var maxValueString=chartOptions.yMaxFormatter(this.valueRange.max,chartOptions.labels.precision),minValueString=chartOptions.yMinFormatter(this.valueRange.min,chartOptions.labels.precision),maxLabelPos=chartOptions.scrollBackwards?0:dimensions.width-context.measureText(maxValueString).width-2,minLabelPos=chartOptions.scrollBackwards?0:dimensions.width-context.measureText(minValueString).width-2;context.fillStyle=chartOptions.labels.fillStyle;context.fillText(maxValueString,maxLabelPos,chartOptions.labels.fontSize);context.fillText(minValueString,minLabelPos,dimensions.height-2)}if(chartOptions.timestampFormatter&&chartOptions.grid.millisPerLine>0){var textUntilX=chartOptions.scrollBackwards?context.measureText(minValueString).width:dimensions.width-context.measureText(minValueString).width+4;for(var t=time-(time%chartOptions.grid.millisPerLine);t>=oldestValidTime;t-=chartOptions.grid.millisPerLine){var gx=timeToXPixel(t);if((!chartOptions.scrollBackwards&&gxtextUntilX)){var tx=new Date(t),ts=chartOptions.timestampFormatter(tx),tsWidth=context.measureText(ts).width;textUntilX=chartOptions.scrollBackwards?gx+tsWidth+2:gx-tsWidth-2;context.fillStyle=chartOptions.labels.fillStyle;if(chartOptions.scrollBackwards){context.fillText(ts,gx,dimensions.height-2)}else{context.fillText(ts,gx-tsWidth,dimensions.height-2)}}}}context.restore();};SmoothieChart.timeFormatter=function(date){function pad2(number){return(number<10?'0':'')+number}return pad2(date.getHours())+':'+pad2(date.getMinutes())+':'+pad2(date.getSeconds())};exports.TimeSeries=TimeSeries;exports.SmoothieChart=SmoothieChart})(typeof exports==='undefined'?this:exports);