var w,h,ratio,i,s,el,g,div,dragQ,game,my={};function graphpaperMain(){var version='0.62';w=500;h=420;s="";s+='
';s+='
';s+='
';my.inps=[['From x','minx',0],['To x','maxx',10],['From y','min',0],['To y','maxy',10]];for(var i=0;i
';s+=''+inp[0]+':
';s+='';s+=' ';s+='
';s+=' ';}
s+='
';s+='
';s+='Equal Scales ';s+='Print ';s+='Save ';s+='
';s+='
';s+='Density: ';s+=' ';s+='Reset ';s+='
';s+='
';s+='';s+='
';s+=' ';s+='© 2018 MathsIsFun.com v'+version+'
';s+='';document.write(s);el=document.getElementById('can');ratio=2;el.width=w*ratio;el.height=h*ratio;el.style.width=w+"px";el.style.height=h+"px";g=el.getContext("2d");g.setTransform(ratio,0,0,ratio,0,0);el.addEventListener('touchmove',ontouchmove,false);el.addEventListener('mousemove',onmousemove,false);my.eqScaleQ=true;my.density=0.01;console.log("go");go(0);}
function chgVal(i,val){go(0);}
function densityChg(n,v){my.density=v/100;go(2);}
function densityReset(){my.density=0.01;go(2);}
function toggleScale(){my.eqScaleQ=!my.eqScaleQ;toggleBtn("scaleBtn",my.eqScaleQ);go(-1);}
function toggleBtn(btn,onq){if(onq){document.getElementById(btn).classList.add("hi");document.getElementById(btn).classList.remove("lo");}else{document.getElementById(btn).classList.add("lo");document.getElementById(btn).classList.remove("hi");}}
function go(n){var lims=[]
for(var i=0;i ';s+=val;s+='';break;case 'title':s+='
';s+=val;s+='';break;case 'in':s+=' ';break;case 'fix':s+='
';s+=fmt2(val);s+='';break;default:}
return s;}
function canvasSave(){var can=document.getElementById("can");var dataUrl=can.toDataURL('image/png');var win=window.open();var s=pageHTML(dataUrl);win.document.write(s);}
function canvasPrint(){var can=document.getElementById("can");var dataUrl=can.toDataURL('image/png');var win=window.open();var s=pageHTML(dataUrl);win.document.write(s);var isChrome=(window.navigator.userAgent.toLowerCase().indexOf("chrome")>-1);if(isChrome){win.focus();setTimeout(function(){win.print();},500);}else{win.focus();win.print();win.close();}}
function pageHTML(dataUrl){var s='Recent ';s+='';s+='';s+='';s+=' ';s+='';console.log("pageHTML",s);return s;}
function getPopHTML(){s='';s+='';s+='';inps=[['Investment','popInv',1000],['Income','popInc',200],['Number of Periods','popn',10],['Interest Rate (%)','popInt',5]];for(var i=0;i';s+=''+inp[0]+' ';s+=' ';s+='
'}
s+='';s+='✔ ';s+='✘ ';s+='
';s+='';return s;}
function doPop(){console.log("doPop");if(my.typNPVQ){document.getElementById('popInvLbl').innerHTML='Investment';document.getElementById('popIncLbl').innerHTML='Income';}else{document.getElementById('popInvLbl').innerHTML='Loan Amount';document.getElementById('popIncLbl').innerHTML='Payment Amount';}
var pop=document.getElementById('editpop');pop.style.transitionDuration="0.3s";pop.style.opacity=1;pop.style.zIndex=12;pop.style.left='50px';}
function editYes(){var pop=document.getElementById('editpop');pop.style.opacity=0;pop.style.zIndex=1;pop.style.left='-500px';console.log("editYes",my.fn);my.i=Number(document.getElementById('popInt').value)/100;var inv=Number(document.getElementById('popInv').value);var inc=Number(document.getElementById('popInc').value);var n=Number(document.getElementById('popn').value);var s=(-inv).toString();for(var i=0;ithis.xEnd){temp=this.xStt;this.xStt=this.xEnd;this.xEnd=temp;}
if(this.yStt>this.yEnd){temp=this.yStt;this.yStt=this.yEnd;this.yEnd=temp;}
var xSpan=this.xEnd-this.xStt;if(xSpan<=0)
xSpan=1e-9;this.xScale=xSpan/this.width;this.xLogScale=(Math.log(this.xEnd)-Math.log(this.xStt))/this.width;var ySpan=this.yEnd-this.yStt;if(ySpan<=0)
ySpan=1e-9;this.yScale=ySpan/this.height;this.yLogScale=(Math.log(this.yEnd)-Math.log(this.yStt))/this.height;var fromMidQ=false;if(this.uniScaleQ&&!this.xLogQ&&!this.yLogQ){var newScale=Math.max(this.xScale,this.yScale);this.xScale=newScale;xSpan=this.xScale*this.width;if(fromMidQ){var xMid=(this.xStt+this.xEnd)/2;this.xStt=xMid-xSpan/2;this.xEnd=xMid+xSpan/2;}else{this.xEnd=this.xStt+xSpan;}
this.yScale=newScale;ySpan=this.yScale*this.height;if(fromMidQ){var yMid=(this.yStt+this.yEnd)/2;this.yStt=yMid-ySpan/2;this.yEnd=yMid+ySpan/2;}else{this.yEnd=this.yStt+ySpan;}}};Coords.prototype.scale=function(factor,xMid,yMid){if(typeof xMid=='undefined')xMid=(this.xStt+this.xEnd)/2;this.xStt=xMid-(xMid-this.xStt)*factor;this.xEnd=xMid+(this.xEnd-xMid)*factor;if(typeof yMid=='undefined')yMid=(this.yStt+this.yEnd)/2;this.yStt=yMid-(yMid-this.yStt)*factor;this.yEnd=yMid+(this.yEnd-yMid)*factor;this.calcScale();};Coords.prototype.drag=function(xPix,yPix){this.xStt+=xPix*this.xScale;this.xEnd+=xPix*this.xScale;this.yStt+=yPix*this.yScale;this.yEnd+=yPix*this.yScale;this.calcScale();};Coords.prototype.newCenter=function(x,y){var xMid=this.xStt+x*this.xScale;var xhalfspan=(this.xEnd-this.xStt)/2;this.xStt=xMid-xhalfspan;this.xEnd=xMid+xhalfspan;var yMid=this.yEnd-y*this.yScale;var yhalfspan=(this.yEnd-this.yStt)/2;this.yStt=yMid-yhalfspan;this.yEnd=yMid+yhalfspan;this.calcScale();};Coords.prototype.fitToPts=function(pts,borderFactor){for(var i=0;i=5){if(majorQ){return(5*pow10);}else{return(1*pow10);}}
if(mantissa>=3){if(majorQ){return(2*pow10);}else{return(0.2*pow10);}}
if(mantissa>=1.4){if(majorQ){return(0.5*pow10);}else{return(0.2*pow10);}}
if(mantissa>=0.8){if(majorQ){return(0.5*pow10);}else{return(0.1*pow10);}}
if(majorQ){return(0.2*pow10);}else{return(0.1*pow10);}};function Graph(g,coords){this.g=g;this.coords=coords;this.xLinesQ=true;this.yLinesQ=true;this.xValsQ=true;this.yValsQ=true;this.style={border:{clr:'rgba(0,0,0,0.3)',thk:1},major:{clr:'rgba(0,0,256,0.3)',thk:1},minor:{clr:'rgba(0,0,256,0.1)',thk:1}};this.style={border:{clr:'rgba(0,0,0,0.3)',thk:1},major:{clr:'#000',thk:0.4},minor:{clr:'#000',thk:0.1}};this.skewQ=false;}
Graph.prototype.makeSVG=function(){this.hzAxisY=coords.toYPix(0);if(this.hzAxisY<0)this.hzAxisY=0;if(this.hzAxisY>coords.height)this.hzAxisY=coords.height;this.hzNumsY=this.hzAxisY+14;if(this.hzAxisY>coords.height-10)this.hzNumsY=coords.height-3;this.vtAxisX=coords.toXPix(0);if(this.vtAxisX<0)this.vtAxisX=0;if(this.vtAxisX>coords.width)this.vtAxisX=coords.width;this.vtNumsX=this.vtAxisX-5;if(this.vtAxisX<10)this.vtNumsX=20;my.svg.moveTo(coords.toXPix(coords.xStt,false),this.hzAxisY);my.svg.lineTo(coords.toXPix(coords.xEnd,false),this.hzAxisY);my.svg.moveTo(this.vtAxisX,coords.toYPix(coords.yStt,false));my.svg.lineTo(this.vtAxisX,coords.toYPix(coords.yEnd,false));}
Graph.prototype.drawGraph=function(){var coords=this.coords;this.hzAxisY=coords.toYPix(0);if(this.hzAxisYcoords.top+coords.height)this.hzAxisY=coords.top+coords.height;this.hzNumsY=this.hzAxisY+14;if(this.hzAxisY>coords.top+coords.height-10)this.hzNumsY=coords.top+coords.height-3;this.vtAxisX=coords.toXPix(0);if(this.vtAxisXcoords.left+coords.width)this.vtAxisX=coords.left+coords.width;this.vtNumsX=this.vtAxisX-5;this.vtNumsAlign='right';if(this.vtAxisX<30){this.vtNumsX=this.vtAxisX+4;this.vtNumsAlign='left';if(this.vtAxisX<0){this.vtNumsX=6;}}
g.strokeStyle=this.style.border.clr;g.lineWidth=this.style.border.thk;g.beginPath();g.moveTo(coords.toXPix(coords.xStt,false),coords.toYPix(coords.yStt,false));g.lineTo(coords.toXPix(coords.xStt,false),coords.toYPix(coords.yEnd,false));g.lineTo(coords.toXPix(coords.xEnd,false),coords.toYPix(coords.yEnd,false));g.lineTo(coords.toXPix(coords.xEnd,false),coords.toYPix(coords.yStt,false));g.closePath();g.stroke();if(coords.xLogQ){this.drawLinesLogX();}else{if(this.xLinesQ){this.drawHzLines();}}
if(coords.yLogQ){this.drawLinesLogY();}else{if(this.yLinesQ){this.drawVtLines();}}};Graph.prototype.drawVtLines=function(){var g=this.g;g.lineWidth=1;var coords=this.coords;var ticks=coords.getTicks(coords.xStt,coords.xEnd-coords.xStt,coords.width*coords.density);for(var i=0;i