text: var graph=function(w,x){var y=this.options={size:{width:function(){return window.innerHeight<window.innerWidth?window.innerHeight-20:window.innerWidth-20},height:function(){return window.innerHeight<window.innerWidth?window.innerHeight-20:window.innerWidth-20}},gridSettings:{range:{xM:-10,xP:10,yM:-10,yP:10},colors:{axes:"#E4EDF0",temLines:"#7f8c8d",text:"#7f8c8d"},referenceLines:!0,text:!0},toolTips:{enable:!0,roundEdges:!0,width:140,fontColor:"#e3f2fd",template:"P(<x(1)>, <y(1)>)<br>f(x) = <formula>"},
  fontType:"Arial",changeOnResize:!0,randomColors:!0,moveEnable:!0,zoomEnable:!0,colors:"rgb(26, 188, 156);rgb(46, 204, 113);rgb(52, 152, 219);rgb(155, 89, 182);rgb(52, 73, 94);rgb(22, 160, 133);rgb(39, 174, 96);rgb(41, 128, 185);rgb(142, 68, 173);rgb(44, 62, 80);rgb(241, 196, 15);rgb(230, 126, 34);rgb(231, 76, 60);rgb(243, 156, 18);rgb(211, 84, 0);rgb(192, 57, 43)".split(";")},l={},z=l.merge=function(a,b){"object"!==typeof a&&(a={});for(var c in b)if(b.hasOwnProperty(c)){var d=b[c];a[c]="object"===
  typeof d?l.merge(a[c],d):d}c=2;for(d=arguments.length;c<d;c++)z(a,arguments[c]);return a};l.getRandomArbitrary=function(a,b){return Math.random()*(b-a)+a};l.complileTemplate=function(a){var b=[];a=a.split("<br>");for(var c=0;c<a.length;c++){var d="return '"+a[c].split("<").join("'+ dataset.").split(">").join("+'")+"'";b.push(new Function("dataset",d))}return b};var A=l.decimalAdjust=function(a,b,c){if("undefined"===typeof c||0===+c)return Math[a](b);b=+b;c=+c;if(isNaN(b)||"number"!==typeof c||0!==
  c%1)return NaN;b=b.toString().split("e");b=Math[a](+(b[0]+"e"+(b[1]?+b[1]-c:-c)));b=b.toString().split("e");return+(b[0]+"e"+(b[1]?+b[1]+c:c))};Math.round10||(Math.round10=function(a,b){return A("round",a,b)});CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,d,r,f,e){"undefined"==typeof e&&(e=!0);"undefined"===typeof r&&(r=5);this.beginPath();this.moveTo(a+r,b);this.lineTo(a+c-r,b);this.quadraticCurveTo(a+c,b,a+c,b+r);this.lineTo(a+c,b+d-r);this.quadraticCurveTo(a+c,b+d,a+c-r,b+d);this.lineTo(a+
  r,b+d);this.quadraticCurveTo(a,b+d,a,b+d-r);this.lineTo(a,b+r);this.quadraticCurveTo(a,b,a+r,b);this.closePath();e&&this.stroke();f&&this.fill()};this.canvas=w.canvas;this.ctx=w;this.initialized=!1;this.functions=[];this.offset={x:0,y:0};this.zoom=0;this.options=l.merge(y,x);this.functionsComp=l.complileTemplate(this.options.toolTips.template);this.canvasWidth=this.canvas.width=this.options.size.width();this.canvasHeight=this.canvas.height=this.options.size.height();(this.dynamicZoom=-1*this.options.gridSettings.range.xM+
  this.options.gridSettings.range.xP+1==-1*this.options.gridSettings.range.yM+this.options.gridSettings.range.yP+1)||console.warn("Dynamic zoom was turned off due to the fact that the scale is stretched!");this.drawGrid=function(){this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height);var a=this.canvasWidth=this.canvas.width,b=this.canvasHeight=this.canvas.height,c=this.options.gridSettings.range.xM+this.zoom,d=this.options.gridSettings.range.xP-this.zoom,f=this.options.gridSettings.range.yM+
  this.zoom,g=this.options.gridSettings.range.yP-this.zoom,e=-1*c+d+1,h=a/e,m=b/(-1*f+g+1),p=a/2,n=b/2,t=this.offset.x/h,q=-1*this.offset.y/m,l=this.offset.x>a/2?0:-1*this.offset.x>a/2?a:p-this.offset.x,u=this.offset.y>b/2?0:-1*this.offset.y>b/2?b:n-this.offset.y,k=1;this.dynamicZoom&&(k=this.getIncrement(e));this.initialized&&this.ctx.restore();this.ctx.save();if(this.options.gridSettings.referenceLines){for(e=this.offset.x>p?Math.floor(t-d):k;e<=d+Math.floor(t+.5);e+=k)this.drawRefLinieX(h*e+p-this.offset.x);
  for(e=-1*this.offset.y>n?Math.floor(q-g):k;e<=g+Math.floor(q+.5);e+=k)this.drawRefLinieY(b-(m*e+n+this.offset.y));for(e=-1*this.offset.x>p?Math.ceil(t-c):-1*k;e>=c+Math.floor(t);e-=k)this.drawRefLinieX(h*e+p-this.offset.x);for(e=this.offset.y>n?Math.ceil(q-f):-1*k;e>=f+Math.floor(q);e-=k)this.drawRefLinieY(b-(m*e+n+this.offset.y))}this.ctx.lineWidth=2;this.ctx.strokeStyle="#7f8c8d";this.offset.y<b/2&&-1*this.offset.y<b/2&&(this.ctx.beginPath(),this.ctx.moveTo(0,n-this.offset.y),this.ctx.lineTo(a,
  n-this.offset.y),this.ctx.stroke());this.offset.x<a/2&&-1*this.offset.x<a/2&&(this.ctx.beginPath(),this.ctx.moveTo(p-this.offset.x,0),this.ctx.lineTo(p-this.offset.x,b),this.ctx.stroke());for(e=this.offset.x>p?Math.floor(t-d):k;e<=d+Math.floor(t+.5);e+=k)this.drawUnitX(h*e+p-this.offset.x,u,e,this.offset.y+20<b/2?-10:20);for(e=-1*this.offset.y>n?Math.floor(q-g):k;e<=g+Math.floor(q+.5);e+=k)this.drawUnitY(l,b-(m*e+n+this.offset.y),e,-1*this.offset.x+20>a/2?-10:10);for(e=-1*this.offset.x>p?Math.ceil(t-
  c):-1*k;e>=c+Math.floor(t);e-=k)this.drawUnitX(h*e+p-this.offset.x,u,e,this.offset.y+20<b/2?-10:20);for(e=this.offset.y>n?Math.ceil(q-f):-1*k;e>=f+Math.floor(q);e-=k)this.drawUnitY(l,b-(m*e+n+this.offset.y),e,-1*this.offset.x+20>a/2?-10:10);this.initialized=!0;this.middleX=p;this.middleY=n;this.unitsGapX=h;this.unitsGapY=m};this.getIncrement=function(a,b){"undefined"===typeof b&&(b=1);35<a/b&&(b=this.getIncrement(a,b+1));return b};this.drawRefLinieX=function(a){this.ctx.lineWidth=2;this.ctx.strokeStyle=
  this.options.gridSettings.colors.axes;this.ctx.beginPath();this.ctx.moveTo(a,0);this.ctx.lineTo(a,this.canvasHeight);this.ctx.stroke()};this.drawRefLinieY=function(a){this.ctx.lineWidth=2;this.ctx.strokeStyle=this.options.gridSettings.colors.axes;this.ctx.beginPath();this.ctx.moveTo(0,a);this.ctx.lineTo(this.canvasWidth,a);this.ctx.stroke()};this.drawUnitX=function(a,b,c,d){this.ctx.lineWidth=2;this.ctx.strokeStyle=this.options.gridSettings.colors.temLines;this.ctx.beginPath();this.ctx.moveTo(a,b-
  5);this.ctx.lineTo(a,b+5);this.ctx.stroke();this.options.gridSettings.text&&(this.ctx.textAlign="left",this.ctx.font="14px "+this.options.fontType,this.ctx.fillStyle=this.options.gridSettings.colors.text,this.ctx.fillText(c,a-this.ctx.measureText(c.toString()).width/2,b+d))};this.drawUnitY=function(a,b,c,d){this.ctx.lineWidth=2;this.ctx.strokeStyle=this.options.gridSettings.colors.temLines;this.ctx.beginPath();this.ctx.moveTo(a-5,b);this.ctx.lineTo(a+5,b);this.ctx.stroke();this.options.gridSettings.text&&
  (this.ctx.textAlign=0>d?"right":"left",this.ctx.font="14px "+this.options.fontType,this.ctx.fillStyle=this.options.gridSettings.colors.text,this.ctx.fillText(c,a+d,b+5))};this.funGraph=function(a,b){var c,d,f=0,g=0,e=[],h=this.middleX,m=this.middleY,p=Math.round((this.canvasWidth-h)/4),n=Math.round(-h/4),l=math.compile(a);this.ctx.beginPath();this.ctx.lineWidth=2;this.ctx.strokeStyle=b;for(var q=n;q<=p;q++){c=4*q;d=this.unitsGapY*l.eval({x:c/this.unitsGapX});if(0<=m-d)g>d&&0>m-g&&(e.push({x:h+f,y:m-
  g}),this.ctx.moveTo(h+f-this.offset.x,m-g-this.offset.y)),e.push({x:h+c,y:m-d}),this.ctx.lineTo(h+c-this.offset.x,m-d-this.offset.y);else if(q!=n&&g<d&&0<m-g){c+=4;d=this.unitsGapY*l.eval({x:c/this.unitsGapX});this.ctx.lineTo(h+c-this.offset.x,m-d-this.offset.y);e.push({x:h+c,y:m-d});break}f=c;g=d}this.ctx.stroke();return{compFunction:l,points:e}};this.drawGraphs=function(a){this.drawGrid();this.functions=[];for(var b,c=0;c<a.length;c++){this.functions.push({formula:a[c]});try{this.options.randomColors?
  (this.functions[c].color=this.options.colors[Math.round(l.getRandomArbitrary(0,this.options.colors.length-1))],b=this.funGraph(a[c],this.functions[c].color)):(this.functions[c].color=this.options.colors[c],b=this.funGraph(a[c],this.options.colors[c])),this.functions[c].points=b.points,this.functions[c].compiled=b.compFunction}catch(d){"undefined"!==typeof this.errorElem?this.errorElem.innerHTML="<p>"+d.message+"</p>":console.log(d.message)}}};this.addGraphs=function(a){this.initialized||this.drawGrid();
  for(var b,c=this.functions.length,d=0;d<a.length;d++)this.functions.push({formula:a[d]});for(d=0;d<a.length;d++)try{this.options.randomColors?(this.functions[d+c].color=this.options.colors[Math.round(l.getRandomArbitrary(0,this.options.colors.length-1))],b=this.funGraph(a[d],this.functions[d+c].color)):(this.functions[d+c].color=this.options.colors[d+c],b=this.funGraph(a[d],this.options.colors[d+c])),this.functions[d+c].points=b.points,this.functions[d+c].compiled=b.compFunction}catch(f){"undefined"!==
  typeof this.errorElem?this.errorElem.innerHTML="<p>"+f.message+"</p>":console.log(f.message)}};this.addMissingPoints=function(){for(var a,b,c,d=0;d<this.functions.length;d++){a=this.functions[d].points;if(0<a[0].x-this.offset.x&&a[0].x-this.offset.x<this.canvasWidth&&0<a[0].y-this.offset.y&&a[0].y-this.offset.y<this.canvasHeight){this.ctx.beginPath();this.ctx.lineWidth=2;this.ctx.strokeStyle=this.functions[d].color;for(this.ctx.moveTo(a[0].x-this.offset.x,a[0].y-this.offset.y);0<a[0].x-this.offset.x&&
  a[0].x-this.offset.x<this.canvasWidth&&0<a[0].y-this.offset.y&&a[0].y-this.offset.y<this.canvasHeight;)b=a[0].x-this.middleX-4,c=this.unitsGapY*this.functions[d].compiled.eval({x:b/this.unitsGapX}),this.ctx.lineTo(this.middleX+b-this.offset.x,this.middleY-c-this.offset.y),a.unshift({x:this.middleX+b,y:this.middleY-c});this.ctx.stroke()}if(0<a[a.length-1].x-this.offset.x&&a[a.length-1].x-this.offset.x<this.canvasWidth&&0<a[a.length-1].y-this.offset.y&&a[a.length-1].y-this.offset.y<this.canvasHeight){this.ctx.beginPath();
  this.ctx.lineWidth=2;this.ctx.strokeStyle=this.functions[d].color;for(this.ctx.moveTo(a[a.length-1].x-this.offset.x,a[a.length-1].y-this.offset.y);0<a[a.length-1].x-this.offset.x&&a[a.length-1].x-this.offset.x<this.canvasWidth&&0<a[a.length-1].y-this.offset.y&&a[a.length-1].y-this.offset.y<this.canvasHeight;)b=a[a.length-1].x-this.middleX+4,c=this.unitsGapY*this.functions[d].compiled.eval({x:b/this.unitsGapX}),this.ctx.lineTo(this.middleX+b-this.offset.x,this.middleY-c-this.offset.y),a.push({x:this.middleX+
  b,y:this.middleY-c});this.ctx.stroke()}}};this.updateGraphs=function(){this.drawGrid();for(var a=0;a<this.functions.length;a++){var b=this.functions[a].points;this.ctx.beginPath();this.ctx.lineWidth=2;this.ctx.strokeStyle=this.functions[a].color;this.ctx.moveTo(b[0].x-this.offset.x,b[0].y-this.offset.y);for(var c=1;c<b.length;c++)this.ctx.lineTo(b[c].x-this.offset.x,b[c].y-this.offset.y);this.ctx.stroke()}};this.updateHover=function(a){a.preventDefault();a.stopPropagation();for(var b=parseInt(a.clientX-
  this.canvas.offsetLeft),c=parseInt(a.clientY-this.canvas.offsetTop),d,f,g=0;g<this.functions.length;g++){f=this.functions[g].points;for(var e=0;e<f.length;e++){a=f[e].x-this.offset.x;d=f[e].y-this.offset.y;if(12>b-a&&-12<b-a&&12>c-d&&-12<c-d){var h=this,b={x:function(a){return Math.round10((f[e].x-h.middleX)/h.unitsGapX,-1*a)},y:function(a){return Math.round10((f[e].y-h.middleY)/h.unitsGapY*-1,-1*a)},formula:this.functions[g].formula};this.updateGraphs();this.ctx.restore();this.ctx.beginPath();this.ctx.fillStyle=
  this.functions[g].color;this.ctx.arc(a,d,3,0,2*Math.PI);this.ctx.fill();a=160>this.canvasWidth-a?a-160:a+5;d=90>d?d+5:d-85;this.ctx.shadowBlur=2;this.ctx.shadowColor="black";this.ctx.fillStyle=this.functions[g].color;this.options.toolTips.roundEdges?this.ctx.roundRect(a,d,150,35*this.functionsComp.length+5,5,!0,!1):this.ctx.fillRect(a,d,150,35*this.functionsComp.length+5);this.ctx.shadowBlur=0;this.ctx.fillStyle=this.options.toolTips.fontColor;this.ctx.font="30px "+this.options.fontType;for(g=0;g<
  this.functionsComp.length;g++)this.ctx.fillText(this.functionsComp[g](b),a+5,d+25+35*g,140);this.hoverMenu=!0;return}this.hoverMenu&&(this.updateGraphs(),this.hoverMenu=!1)}}};this.updateOffset=function(a,b){"undefined"!==a&&"undefined"!==b&&(this.offset.x=parseInt(b.mouseX-(a.clientX-this.canvas.offsetLeft)),this.offset.y=parseInt(b.mouseY-(a.clientY-this.canvas.offsetTop)));this.updateGraphs();this.addMissingPoints()};this.updateZoom=function(a){a=window.event||a;this.zoom+=Math.max(-1,Math.min(1,
  a.wheelDelta||-a.detail));if(-1<this.options.gridSettings.range.xM+this.zoom||1>this.options.gridSettings.range.xP-this.zoom||-1<this.options.gridSettings.range.yM+this.zoom||1>this.options.gridSettings.range.yP-this.zoom)--this.zoom;else{this.drawGrid();for(var b=0;b<this.functions.length;b++)a=this.funGraph(this.functions[b].formula,this.functions[b].color),this.functions[b].points=a.points,this.functions[b].compiled=a.compFunction;this.addMissingPoints()}};this.resizeGraphs=function(){this.drawGrid();
  for(var a,b=0;b<this.functions.length;b++)a=this.funGraph(this.functions[b].formula,this.functions[b].color),this.functions[b].points=a.points,this.functions[b].compiled=a.compFunction;this.addMissingPoints()};var v=!1,u=0,f=this;f.mouseState={};(this.options.toolTips.enable||this.options.moveEnable)&&this.canvas.addEventListener("mousemove",function(a){0!=u||v||(f.options.moveEnable&&f.mouseState.down?f.updateOffset(a,f.mouseState):f.options.toolTips.enable&&f.updateHover(a),u+=1,window.setTimeout(function(){--u},
  33))});this.options.moveEnable&&(this.canvas.addEventListener("mousedown",function(a){f.mouseState={down:!0,mouseX:parseInt(a.clientX-f.canvas.offsetLeft)+f.offset.x,mouseY:parseInt(a.clientY-f.canvas.offsetTop)+f.offset.y};f.canvas.style.cursor="move"}),this.canvas.addEventListener("mouseup",function(){f.canvas.style.cursor="auto";f.mouseState.down=!1}),this.canvas.addEventListener("mouseout",function(){f.canvas.style.cursor="auto";f.mouseState.down=!1}));this.options.zoomEnable&&(this.canvas.addEventListener("DOMMouseScroll",
  function(a){f.updateZoom(a);a=a||window.event;a.preventDefault&&a.preventDefault();a.returnValue=!1},!1),this.canvas.addEventListener("mousewheel",function(a){f.updateZoom(a);a=a||window.event;a.preventDefault&&a.preventDefault();a.returnValue=!1},!1),this.canvas.addEventListener("mouseover",function(){},!1));this.options.changeOnResize&&(window.onresize=function(){if(f.canvasWidth!=f.options.size.width()||f.canvasHeight!=f.options.size.height())v=!0,f.canvasWidth=f.canvas.width=f.options.size.width(),
  f.canvasHeight=f.canvas.height=f.options.size.height(),f.resizeGraphs(),v=!1});return this};
  