function chart(obj,title,labely,labelx){this.obj=obj;this.title=title;this.labely=labely;this.labelx=labelx;this.data=[];this.refreshWindow();this.addInfo="...";return this}chart.prototype.setMaxX=function setMaxX(maxX){this.maxX=maxX};chart.prototype.setMaxY=function setMaxY(maxY){this.maxY=maxY};
chart.prototype.refreshWindow=function refreshWindow(){this.obj.width=this.obj.clientWidth;this.obj.height=this.obj.clientHeight;this.width=this.obj.width;this.height=this.obj.height;this.context2D=this.obj.getContext("2d");this.paddingTop=this.obj.height*0.11;this.paddingRight=this.obj.width*0.05;this.paddingBottom=this.obj.height*0.16;this.paddingLeft=this.obj.width*0.09;this.textMargin=this.obj.width*0.01;this.labelMargin=this.obj.width*0.02;this.innerWidth=this.width-this.paddingLeft-this.paddingRight;
this.innerHeight=this.height-this.paddingTop-this.paddingBottom;this.minX=0;this.maxX=100;this.numXTicks=10;this.minY=0;this.numYTicks=Math.round(this.maxY/10);if(this.numYTicks<1)this.numYTicks=1;this.drawBG()};
chart.prototype.drawBG=function drawBG(){var context=this.context2D;var fontSize=Math.round(this.height/20);context.fillStyle="black";context.strokeStyle="rgba(0,0,0,.2)";context.font=fontSize+"px monospace";context.textAlign="center";context.textBaseline="top";context.lineWidth=this.width*0.003;for(var x=0;x<=this.numXTicks;x++){var label=Math.round(x*(this.maxX/this.numXTicks));var xs=this.innerWidth/this.numXTicks;context.fillText(label,Math.round(this.paddingLeft+x*xs),this.height-this.paddingBottom+
this.textMargin);context.beginPath();context.moveTo(Math.round(this.paddingLeft+x*xs),this.paddingTop);context.lineTo(Math.round(this.paddingLeft+x*xs),this.height-this.paddingBottom);context.stroke()}context.textAlign="center";context.textBaseline="top";context.fillText(this.title,Math.round(this.paddingLeft+this.innerWidth/2),this.labelMargin);context.textAlign="center";context.textBaseline="bottom";context.fillText(this.labelx,Math.round(this.paddingLeft+this.innerWidth/4),this.height-this.textMargin);
context.textAlign="right";context.textBaseline="bottom";context.fillText(this.addInfo,Math.round(this.width-this.paddingRight),this.height-this.textMargin);context.save();context.rotate(-Math.PI/2);context.textBaseline="top";context.textAlign="center";context.fillText(this.labely,-this.innerHeight/2-this.paddingTop,this.textMargin);context.restore();context.textBaseline="middle";context.textAlign="end";context.lineWidth=this.height*0.004;for(var y=0;y<=this.numYTicks;y++){var label=Math.round(y*(this.maxY/
this.numYTicks));var ys=this.innerHeight/this.numYTicks;context.fillText(label,this.paddingLeft-this.textMargin,Math.round(this.height-this.paddingBottom-y*ys));context.beginPath();context.moveTo(this.paddingLeft,Math.round(this.height-this.paddingBottom-y*ys));context.lineTo(this.width-this.paddingRight,Math.round(this.height-this.paddingBottom-y*ys));context.stroke()}};
chart.prototype.valToY=function valToY(val){var p=(val-this.minY)/(this.maxY-this.minY);var y=this.innerHeight*p;if(y>this.innerHeight)y=this.innerHeight;if(y<0)y=0;return y};
chart.prototype.drawData=function drawData(data){for(var i=0;i<data.length;i++)if(!this.data[i])this.data[i]=data[i];else this.data[i]=this.data[i]+(data[i]-this.data[i])*0.1;var context=this.context2D;context.beginPath();context.lineWidth=this.height*0.008;context.strokeStyle="rgba(200,0,0,.9)";var y=Math.round(this.paddingTop+this.innerHeight/2);context.lineTo(this.paddingLeft,data[0]);var x=0;var px=0;for(var i=1;i<this.data.length;i++){px=this.innerWidth*((i-1)/this.data.length);x=this.innerWidth*
(i/this.data.length);context.moveTo(this.paddingLeft+px,this.height-this.paddingBottom-this.valToY(this.data[i-1]));context.lineTo(this.paddingLeft+x,this.height-this.paddingBottom-this.valToY(this.data[i]))}context.stroke()};
