From 08c6a145842f6d933c8e451f771cd2319887de4b Mon Sep 17 00:00:00 2001 From: Javier Gracia Carpio Date: Thu, 27 Sep 2018 22:31:24 +0200 Subject: [PATCH] Fixes some small bugs --- lib/grafica.js | 8 +++++--- lib/grafica.min.js | 6 +++--- releases/grafica.js | 8 +++++--- releases/grafica.min.js | 6 +++--- src/GAxis.js | 4 ++-- src/GLayer.js | 2 +- src/GPlot.js | 2 ++ 7 files changed, 21 insertions(+), 15 deletions(-) diff --git a/lib/grafica.js b/lib/grafica.js index 364db4e..35f8fdd 100644 --- a/lib/grafica.js +++ b/lib/grafica.js @@ -1131,9 +1131,9 @@ GAxis.prototype.setNTicks = function(nTicks) { if (nTicks >= 0) { this.nTicks = nTicks; this.ticksSeparation = -1; + this.fixedTicks = false; if (!this.log) { - this.fixedTicks = false; this.updateTicks(); this.updatePlotTicks(); this.updateTicksInside(); @@ -1144,9 +1144,9 @@ GAxis.prototype.setNTicks = function(nTicks) { GAxis.prototype.setTicksSeparation = function(ticksSeparation) { this.ticksSeparation = ticksSeparation; + this.fixedTicks = false; if (!this.log) { - this.fixedTicks = false; this.updateTicks(); this.updatePlotTicks(); this.updateTicksInside(); @@ -3254,7 +3254,7 @@ GLayer.prototype.addPointAtIndexPos = function() { if (index <= this.points.length) { this.points.splice(index, 0, new GPoint(x, y, label)); this.plotPoints.splice(index, 0, new GPoint(this.valueToXPlot(x), this.valueToYPlot(y), label)); - this.inside.splice(index, 0, this.isInside(this.plotPoints[0])); + this.inside.splice(index, 0, this.isInside(this.plotPoints[index])); if ( typeof this.hist !== "undefined") { this.hist.setPlotPoints(this.plotPoints); @@ -3944,6 +3944,7 @@ GPlot.prototype.moveHorizontalAxesLim = function(delta) { // Fix the limits this.fixedXLim = true; + this.fixedYLim = true; // Move the horizontal axes this.xAxis.moveLim(this.xLim); @@ -3968,6 +3969,7 @@ GPlot.prototype.moveVerticalAxesLim = function(delta) { } // Fix the limits + this.fixedXLim = true; this.fixedYLim = true; // Move the vertical axes diff --git a/lib/grafica.min.js b/lib/grafica.min.js index 72dbf0c..ae54087 100644 --- a/lib/grafica.min.js +++ b/lib/grafica.min.js @@ -1,4 +1,4 @@ -/*! grafica.js (0.3.1): a library for p5.js. Author: Javier GraciĆ” Carpio, license: LGPL-3.0, 2018-09-26 */ function GPoint(){var a,b,c;if(3===arguments.length)a=arguments[0],b=arguments[1],c=arguments[2];else if(2===arguments.length&&arguments[0]instanceof p5.Vector)a=arguments[0].x,b=arguments[0].y,c=arguments[1];else if(2===arguments.length)a=arguments[0],b=arguments[1],c="";else if(1===arguments.length&&arguments[0]instanceof GPoint)a=arguments[0].getX(),b=arguments[0].getY(),c=arguments[0].getLabel();else if(1===arguments.length&&arguments[0]instanceof p5.Vector)a=arguments[0].x,b=arguments[0].y,c="";else{if(0!==arguments.length)throw new Error("GPoint constructor: signature not supported");a=0,b=0,c=""}this.x=a,this.y=b,this.label=c,this.valid=this.isValidNumber(this.x)&&this.isValidNumber(this.y)}function GTitle(a,b){this.parent=a,this.dim=b.slice(),this.relativePos=.5,this.plotPos=this.relativePos*this.dim[0],this.offset=10,this.text="",this.textAlignment=this.parent.CENTER,this.fontName="Helvetica",this.fontColor=this.parent.color(100),this.fontStyle=this.parent.BOLD,this.fontSize=13}function GAxisLabel(a,b,c){this.parent=a,this.type=b===this.parent.BOTTOM||b===this.parent.TOP||b===this.parent.LEFT||b===this.parent.RIGHT?b:this.parent.BOTTOM,this.dim=c.slice(),this.relativePos=.5,this.plotPos=this.type===this.parent.BOTTOM||this.type===this.parent.TOP?this.relativePos*this.dim[0]:-this.relativePos*this.dim[1],this.offset=35,this.rotate=this.type!==this.parent.BOTTOM&&this.type!==this.parent.TOP,this.text="",this.textAlignment=this.parent.CENTER,this.fontName="Helvetica",this.fontColor=this.parent.color(0),this.fontSize=13}function GAxis(a,b,c,d,e){this.parent=a,this.type=b===this.parent.BOTTOM||b===this.parent.TOP||b===this.parent.LEFT||b===this.parent.RIGHT?b:this.parent.BOTTOM,this.dim=c.slice(),this.lim=d.slice(),this.log=e,this.log&&(this.lim[0]<=0||this.lim[1]<=0)&&(console.log("The limits are negative. This is not allowed in logarithmic scale."),console.log("Will set them to (0.1, 10)"),this.lim[1]>this.lim[0]?(this.lim[0]=.1,this.lim[1]=10):(this.lim[0]=10,this.lim[1]=.1)),this.offset=5,this.lineColor=this.parent.color(0),this.lineWidth=1,this.nTicks=5,this.ticksSeparation=-1,this.ticks=[],this.plotTicks=[],this.ticksInside=[],this.tickLabels=[],this.fixedTicks=!1,this.tickLength=3,this.smallTickLength=2,this.expTickLabels=!1,this.rotateTickLabels=this.type!==this.parent.BOTTOM&&this.type!==this.parent.TOP,this.drawTickLabels=this.type===this.parent.BOTTOM||this.type===this.parent.LEFT,this.tickLabelOffset=7,this.ticksPrecision=void 0,this.lab=new GAxisLabel(this.parent,this.type,this.dim),this.drawAxisLabel=!0,this.fontName="Helvetica",this.fontColor=this.parent.color(0),this.fontSize=11,this.updateTicks(),this.updatePlotTicks(),this.updateTicksInside(),this.updateTickLabels()}function GHistogram(a,b,c,d){this.parent=a,this.type=b===GPlot.VERTICAL||b===GPlot.HORIZONTAL?b:GPlot.VERTICAL,this.dim=c.slice(),this.plotPoints=[];for(var e=0;e0&&b>0&&(this.dim[0]=a,this.dim[1]=b,this.plotPos=this.relativePos*this.dim[0])},GTitle.prototype.setRelativePos=function(a){this.relativePos=a,this.plotPos=this.relativePos*this.dim[0]},GTitle.prototype.setOffset=function(a){this.offset=a},GTitle.prototype.setText=function(a){this.text=a},GTitle.prototype.setTextAlignment=function(a){a!==this.parent.CENTER&&a!==this.parent.LEFT&&a!==this.parent.RIGHT||(this.textAlignment=a)},GTitle.prototype.setFontName=function(a){this.fontName=a},GTitle.prototype.setFontColor=function(a){this.fontColor=a},GTitle.prototype.setFontStyle=function(a){this.fontStyle=a},GTitle.prototype.setFontSize=function(a){a>0&&(this.fontSize=a)},GTitle.prototype.setFontProperties=function(a,b,c){c>0&&(this.fontName=a,this.fontColor=b,this.fontSize=c)},GAxisLabel.prototype.draw=function(){switch(this.type){case this.parent.BOTTOM:this.drawAsXLabel();break;case this.parent.LEFT:this.drawAsYLabel();break;case this.parent.TOP:this.drawAsTopLabel();break;case this.parent.RIGHT:this.drawAsRightLabel()}},GAxisLabel.prototype.drawAsXLabel=function(){this.parent.push(),this.parent.textFont(this.fontName),this.parent.textSize(this.fontSize),this.parent.fill(this.fontColor),this.parent.noStroke(),this.rotate?(this.parent.textAlign(this.parent.RIGHT,this.parent.CENTER),this.parent.translate(this.plotPos,this.offset),this.parent.rotate(-.5*Math.PI),this.parent.text(this.text,0,0)):(this.parent.textAlign(this.textAlignment,this.parent.TOP),this.parent.text(this.text,this.plotPos,this.offset)),this.parent.pop()},GAxisLabel.prototype.drawAsYLabel=function(){this.parent.push(),this.parent.textFont(this.fontName),this.parent.textSize(this.fontSize),this.parent.fill(this.fontColor),this.parent.noStroke(),this.rotate?(this.parent.textAlign(this.textAlignment,this.parent.BOTTOM),this.parent.translate(-this.offset,this.plotPos),this.parent.rotate(-.5*Math.PI),this.parent.text(this.text,0,0)):(this.parent.textAlign(this.parent.RIGHT,this.parent.CENTER),this.parent.text(this.text,-this.offset,this.plotPos)),this.parent.pop()},GAxisLabel.prototype.drawAsTopLabel=function(){this.parent.push(),this.parent.textFont(this.fontName),this.parent.textSize(this.fontSize),this.parent.fill(this.fontColor),this.parent.noStroke(),this.rotate?(this.parent.textAlign(this.parent.LEFT,this.parent.CENTER),this.parent.translate(this.plotPos,-this.offset-this.dim[1]),this.parent.rotate(-.5*Math.PI),this.parent.text(this.text,0,0)):(this.parent.textAlign(this.textAlignment,this.parent.BOTTOM),this.parent.text(this.text,this.plotPos,-this.offset-this.dim[1])),this.parent.pop()},GAxisLabel.prototype.drawAsRightLabel=function(){this.parent.push(),this.parent.textFont(this.fontName),this.parent.textSize(this.fontSize),this.parent.fill(this.fontColor),this.parent.noStroke(),this.rotate?(this.parent.textAlign(this.textAlignment,this.parent.TOP),this.parent.translate(this.offset+this.dim[0],this.plotPos),this.parent.rotate(-.5*Math.PI),this.parent.text(this.text,0,0)):(this.parent.textAlign(this.parent.LEFT,this.parent.CENTER),this.parent.text(this.text,this.offset+this.dim[0],this.plotPos)),this.parent.pop()},GAxisLabel.prototype.setDim=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(1!==arguments.length)throw new Error("GAxisLabel.setDim(): signature not supported");a=arguments[0][0],b=arguments[0][1]}a>0&&b>0&&(this.dim[0]=a,this.dim[1]=b,this.plotPos=this.type===this.parent.BOTTOM||this.type===this.parent.TOP?this.relativePos*this.dim[0]:-this.relativePos*this.dim[1])},GAxisLabel.prototype.setRelativePos=function(a){this.relativePos=a,this.plotPos=this.type===this.parent.BOTTOM||this.type===this.parent.TOP?this.relativePos*this.dim[0]:-this.relativePos*this.dim[1]},GAxisLabel.prototype.setOffset=function(a){this.offset=a},GAxisLabel.prototype.setRotate=function(a){this.rotate=a},GAxisLabel.prototype.setText=function(a){this.text=a},GAxisLabel.prototype.setTextAlignment=function(a){a!==this.parent.CENTER&&a!==this.parent.LEFT&&a!==this.parent.RIGHT||(this.textAlignment=a)},GAxisLabel.prototype.setFontName=function(a){this.fontName=a},GAxisLabel.prototype.setFontColor=function(a){this.fontColor=a},GAxisLabel.prototype.setFontSize=function(a){a>0&&(this.fontSize=a)},GAxisLabel.prototype.setFontProperties=function(a,b,c){c>0&&(this.fontName=a,this.fontColor=b,this.fontSize=c)},GAxis.prototype.obtainSigDigits=function(a){return Math.round(-Math.log(.5*Math.abs(a))/Math.LN10)},GAxis.prototype.roundPlus=function(a,b){return a=Math.round(a*Math.pow(10,b))/Math.pow(10,b),b<=0&&(a=Math.round(a)),a},GAxis.prototype.adaptSize=function(a,b){bthis.lim[0]?(a=Math.floor(Math.log(this.lim[0])/Math.LN10),b=Math.ceil(Math.log(this.lim[1])/Math.LN10)):(a=Math.floor(Math.log(this.lim[1])/Math.LN10),b=Math.ceil(Math.log(this.lim[0])/Math.LN10));var c=9*(b-a)+1;this.adaptSize(this.ticks,c);for(var d=a;d0){for(a=this.lim[1]>this.lim[0]?this.ticksSeparation:-this.ticksSeparation,c=this.obtainSigDigits(a);this.roundPlus(a,c)-a!=0;)c++;b=Math.floor((this.lim[1]-this.lim[0])/a)}else this.nTicks>0&&(a=(this.lim[1]-this.lim[0])/this.nTicks,c=this.obtainSigDigits(a),a=this.roundPlus(a,c),(0===a||Math.abs(a)>Math.abs(this.lim[1]-this.lim[0]))&&(c++,a=this.roundPlus((this.lim[1]-this.lim[0])/this.nTicks,c)),b=Math.floor((this.lim[1]-this.lim[0])/a));if(b>0){var d=this.lim[0]+(this.lim[1]-this.lim[0]-b*a)/2;for(d=this.roundPlus(d-2*a,c);(this.lim[1]-d)*(this.lim[0]-d)>0;)d=this.roundPlus(d+a,c);var e=Math.floor(Math.abs((this.lim[1]-d)/a))+1;this.adaptSize(this.ticks,e),this.ticks[0]=d;for(var f=1;f=0&&this.plotTicks[a]<=this.dim[0];else for(a=0;a=0&&-this.plotTicks[a]<=this.dim[1]},GAxis.prototype.updateTickLabels=function(){var a,b,c,d,e=this.ticks.length;if(this.adaptSize(this.tickLabels,e),this.log)for(d=0;d0?(b=Math.log(a)/Math.LN10,c=Math.abs(b-Math.round(b))<1e-4,c?(b=Math.round(b),this.expTickLabels?this.tickLabels[d]="1e"+b:this.tickLabels[d]=b>-3.1&&b<3.1?b>=0?""+Math.round(a):""+a:"1e"+b):this.tickLabels[d]=""):this.tickLabels[d]="";else for(d=0;d=0?this.tickLabels[d]=""+parseFloat(a).toFixed(this.ticksPrecision):this.tickLabels[d]=""+a},GAxis.prototype.moveLim=function(a){if(a[1]!==a[0])if(this.log&&(a[0]<=0||a[1]<=0))console.log("The limits are negative. This is not allowed in logarithmic scale.");else{if(this.lim[0]=a[0],this.lim[1]=a[1],!this.fixedTicks){var b=this.ticks.length;if(this.log)this.obtainLogarithmicTicks();else if(b>0){var c=0,d=0;if(this.ticksSeparation>0)for(c=this.lim[1]>this.lim[0]?this.ticksSeparation:-this.ticksSeparation,d=this.obtainSigDigits(c);this.roundPlus(c,d)-c!=0;)d++;else c=1===b?this.lim[1]-this.lim[0]:this.ticks[1]-this.ticks[0],d=this.obtainSigDigits(c),c=this.roundPlus(c,d),(0===c||Math.abs(c)>Math.abs(this.lim[1]-this.lim[0]))&&(d++,c=1===b?this.lim[1]-this.lim[0]:this.ticks[1]-this.ticks[0],c=this.roundPlus(c,d)),c=this.lim[1]>this.lim[0]?Math.abs(c):-Math.abs(c);var e=this.ticks[0]+c*Math.ceil((this.lim[0]-this.ticks[0])/c);e=this.roundPlus(e,d),(this.lim[1]-e)*(this.lim[0]-e)>0&&(e=this.ticks[0]+c*Math.floor((this.lim[0]-this.ticks[0])/c),e=this.roundPlus(e,d)),b=Math.floor(Math.abs((this.lim[1]-e)/c))+1,this.adaptSize(this.ticks,b),this.ticks[0]=e;for(var f=1;f0&&b>0&&(this.dim[0]=a,this.dim[1]=b,this.updatePlotTicks(),this.lab.setDim(this.dim))},GAxis.prototype.setLim=function(a){a[1]!==a[0]&&(this.log&&(a[0]<=0||a[1]<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.lim[0]=a[0],this.lim[1]=a[1],this.fixedTicks||(this.updateTicks(),this.updateTickLabels()),this.updatePlotTicks(),this.updateTicksInside()))},GAxis.prototype.setLimAndLog=function(a,b){a[1]!==a[0]&&(b&&(a[0]<=0||a[1]<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.lim[0]=a[0],this.lim[1]=a[1],this.log=b,this.fixedTicks||(this.updateTicks(),this.updateTickLabels()),this.updatePlotTicks(),this.updateTicksInside()))},GAxis.prototype.setLog=function(a){a!==this.log&&(this.log=a,this.log&&(this.lim[0]<=0||this.lim[1]<=0)&&(console.log("The limits are negative. This is not allowed in logarithmic scale."),console.log("Will set them to (0.1, 10)"),this.lim[1]>this.lim[0]?(this.lim[0]=.1,this.lim[1]=10):(this.lim[0]=10,this.lim[1]=.1)),this.fixedTicks||(this.updateTicks(),this.updateTickLabels()),this.updatePlotTicks(),this.updateTicksInside())},GAxis.prototype.setOffset=function(a){this.offset=a},GAxis.prototype.setLineColor=function(a){this.lineColor=a},GAxis.prototype.setLineWidth=function(a){a>0&&(this.lineWidth=a)},GAxis.prototype.setNTicks=function(a){a>=0&&(this.nTicks=a,this.ticksSeparation=-1,this.log||(this.fixedTicks=!1,this.updateTicks(),this.updatePlotTicks(),this.updateTicksInside(),this.updateTickLabels()))},GAxis.prototype.setTicksSeparation=function(a){this.ticksSeparation=a,this.log||(this.fixedTicks=!1,this.updateTicks(),this.updatePlotTicks(),this.updateTicksInside(),this.updateTickLabels())},GAxis.prototype.setTicks=function(a){var b=a.length;this.adaptSize(this.ticks,b);for(var c=0;c0&&(this.fontSize=a)},GAxis.prototype.setFontProperties=function(a,b,c){c>0&&(this.fontName=a,this.fontColor=b,this.fontSize=c)},GAxis.prototype.setAllFontProperties=function(a,b,c){this.setFontProperties(a,b,c),this.lab.setFontProperties(a,b,c)},GAxis.prototype.getTicks=function(){if(this.fixedTicks)return this.ticks.slice();for(var a=[],b=0,c=0;cb&&(this.differences.splice(b,Number.MAX_VALUE),this.leftSides.splice(b,Number.MAX_VALUE),this.rightSides.splice(b,Number.MAX_VALUE)),1===b)this.leftSides[0]=this.type===GPlot.VERTICAL?.2*this.dim[0]:.2*this.dim[1],this.rightSides[0]=this.leftSides[0];else if(b>1){for(a=0;a0?(c-d)/2:(c+d)/2}else this.differences[a]=0;for(this.leftSides[0]=this.differences[0],this.rightSides[0]=this.differences[0],a=1;athis.dim[0]&&(d=this.dim[0]),-f<0?f=0:-f>this.dim[1]&&(f=-this.dim[1]),e<0?e=0:e>this.dim[0]&&(e=this.dim[0]),-g<0?g=0:-g>this.dim[1]&&(g=-this.dim[1]),h=this.lineWidths[j%this.lineWidths.length],this.parent.fill(this.bgColors[j%this.bgColors.length]),this.parent.stroke(this.lineColors[j%this.lineColors.length]),this.parent.strokeWeight(h),Math.abs(e-d)>2*h&&Math.abs(g-f)>2*h?this.parent.rect(d,f,e,g):(this.type===GPlot.VERTICAL&&e!==d&&(f!==g||0!==f&&f!==-this.dim[1])||this.type===GPlot.HORIZONTAL&&g!==f&&(d!==e||0!==d&&d!==this.dim[0]))&&(this.parent.rect(d,f,e,g),this.parent.line(d,f,d,g),this.parent.line(e,f,e,g),this.parent.line(d,f,e,f),this.parent.line(d,g,e,g)));this.parent.pop(),this.drawLabels&&this.drawHistLabels()}},GHistogram.prototype.drawHistLabels=function(){var a,b,c=this.plotPoints.length,d=.5*Math.PI;if(this.parent.push(),this.parent.textFont(this.fontName),this.parent.textSize(this.fontSize),this.parent.fill(this.fontColor),this.parent.noStroke(),this.type===GPlot.VERTICAL)if(this.rotateLabels)for(this.parent.textAlign(this.parent.RIGHT,this.parent.CENTER),b=0;b=0&&a.getX()<=this.dim[0]&&(this.parent.push(),this.parent.translate(a.getX(),this.labelsOffset),this.parent.rotate(-d),this.parent.text(a.getLabel(),0,0),this.parent.pop());else for(this.parent.textAlign(this.parent.CENTER,this.parent.TOP),b=0;b=0&&a.getX()<=this.dim[0]&&this.parent.text(a.getLabel(),a.getX(),this.labelsOffset);else if(this.rotateLabels)for(this.parent.textAlign(this.parent.CENTER,this.parent.BOTTOM),b=0;b=0&&-a.getY()<=this.dim[1]&&(this.parent.push(),this.parent.translate(-this.labelsOffset,a.getY()),this.parent.rotate(-d),this.parent.text(a.getLabel(),0,0),this.parent.pop());else for(this.parent.textAlign(this.parent.RIGHT,this.parent.CENTER),b=0;b=0&&-a.getY()<=this.dim[1]&&this.parent.text(a.getLabel(),-this.labelsOffset,a.getY());this.parent.pop()},GHistogram.prototype.setType=function(a){a===this.type||a!==GPlot.VERTICAL&&a!==GPlot.HORIZONTAL||(this.type=a,this.updateArrays())},GHistogram.prototype.setDim=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(1!==arguments.length)throw new Error("GHistogram.setDim(): signature not supported");a=arguments[0][0],b=arguments[0][1]}a>0&&b>0&&(this.dim[0]=a,this.dim[1]=b,this.updateArrays())},GHistogram.prototype.setPlotPoints=function(a){var b,c=a.length;if(this.plotPoints.length===c)for(b=0;bc){for(b=0;b0&&(this.fontSize=a)},GHistogram.prototype.setFontProperties=function(a,b,c){c>0&&(this.fontName=a,this.fontColor=b,this.fontSize=c)},GLayer.prototype.isValidNumber=function(a){return!isNaN(a)&&isFinite(a)},GLayer.prototype.isId=function(a){return this.id===a},GLayer.prototype.valueToXPlot=function(a){return this.xLog?this.dim[0]*Math.log(a/this.xLim[0])/Math.log(this.xLim[1]/this.xLim[0]):this.dim[0]*(a-this.xLim[0])/(this.xLim[1]-this.xLim[0])},GLayer.prototype.valueToYPlot=function(a){return this.yLog?-this.dim[1]*Math.log(a/this.yLim[0])/Math.log(this.yLim[1]/this.yLim[0]):-this.dim[1]*(a-this.yLim[0])/(this.yLim[1]-this.yLim[0])},GLayer.prototype.valueToPlot=function(){if(2===arguments.length)return[this.valueToXPlot(arguments[0]),this.valueToYPlot(arguments[1])];if(1===arguments.length&&arguments[0]instanceof GPoint)return new GPoint(this.valueToXPlot(arguments[0].getX()),this.valueToYPlot(arguments[0].getY()),arguments[0].getLabel());if(1===arguments.length&&arguments[0]instanceof Array&&arguments[0][0]instanceof GPoint){var a,b,c,d,e,f,g=arguments[0].length,h=[];if(this.xLog&&this.yLog)for(a=this.dim[0]/Math.log(this.xLim[1]/this.xLim[0]),b=-this.dim[1]/Math.log(this.yLim[1]/this.yLim[0]),f=0;fg&&this.plotPoints.splice(g,Number.MAX_VALUE);if(this.xLog&&this.yLog)for(a=this.dim[0]/Math.log(this.xLim[1]/this.xLim[0]),b=-this.dim[1]/Math.log(this.yLim[1]/this.yLim[0]),f=0;f=0&&a<=this.dim[0]&&-b>=0&&-b<=this.dim[1])},GLayer.prototype.updateInsideList=function(){for(var a,b=this.plotPoints.length,c=0;c=0&&a.getX()<=this.dim[0]&&-a.getY()>=0&&-a.getY()<=this.dim[1]);this.inside.length>b&&this.inside.splice(b,Number.MAX_VALUE)},GLayer.prototype.getPointIndexAtPlotPos=function(a,b){var c;if(this.isInside(a,b))for(var d,e,f=Number.MAX_VALUE,g=this.plotPoints.length,h=this.pointSizes.length,i=0;ithis.dim[0]&&f>this.dim[0]||-e<0&&-g<0||-e>this.dim[1]&&-g>this.dim[1])){var j=f-d,k=g-e;if(0===j)c=2,this.cuts[0][0]=d,this.cuts[0][1]=0,this.cuts[1][0]=d,this.cuts[1][1]=-this.dim[1];else if(0===k)c=2,this.cuts[0][0]=0,this.cuts[0][1]=e,this.cuts[1][0]=this.dim[0],this.cuts[1][1]=e;else{var l=k/j,m=e-l*d;c=4,this.cuts[0][0]=-m/l,this.cuts[0][1]=0,this.cuts[1][0]=(-this.dim[1]-m)/l,this.cuts[1][1]=-this.dim[1],this.cuts[2][0]=0,this.cuts[2][1]=m,this.cuts[3][0]=this.dim[0],this.cuts[3][1]=m+l*this.dim[0]}if(c=this.getValidCuts(this.cuts,c,a,b),h||i){if(1!==c){var n=h?a:b;c>1&&(c=this.removeDuplicatedCuts(this.cuts,c,0))>1&&(c=this.removePointFromCuts(this.cuts,c,n,0))>1&&(c=this.removeDuplicatedCuts(this.cuts,c,.001))>1&&(c=this.removePointFromCuts(this.cuts,c,n,.001)),0===c&&(c=1,this.cuts[0][0]=n.getX(),this.cuts[0][1]=n.getY())}}else c>2&&(c=this.removeDuplicatedCuts(this.cuts,c,0))>2&&(c=this.removeDuplicatedCuts(this.cuts,c,.001)),2===c&&(Math.pow(this.cuts[0][0]-d,2),Math.pow(this.cuts[0][1]-e),2>Math.pow(this.cuts[1][0]-d,2)+Math.pow(this.cuts[1][1]-e,2)&&(this.cuts[2][0]=this.cuts[0][0],this.cuts[2][1]=this.cuts[0][1],this.cuts[0][0]=this.cuts[1][0],this.cuts[0][1]=this.cuts[1][1],this.cuts[1][0]=this.cuts[2][0],this.cuts[1][1]=this.cuts[2][1])),1===c&&(c=2,this.cuts[1][0]=this.cuts[0][0],this.cuts[1][1]=this.cuts[0][1]);(h||i)&&1!==c?console.log("There should be one cut!!!"):h||i||0===c||2===c||console.log("There should be either 0 or 2 cuts!!! "+c+" were found")}}return c},GLayer.prototype.getValidCuts=function(a,b,c,d){for(var e=c.getX(),f=c.getY(),g=d.getX(),h=d.getY(),i=Math.abs(g-e),j=Math.abs(h-f),k=0,l=0;ld||Math.abs(a[h][1]-f)>d)&&(a[g][0]=a[h][0],a[g][1]=a[h][1],g++);return g},GLayer.prototype.startHistogram=function(a){this.hist=new GHistogram(this.parent,a,this.dim,this.plotPoints)},GLayer.prototype.drawPoints=function(){var a,b;if(0===arguments.length){a=this.plotPoints.length;var c=this.pointColors.length,d=this.pointSizes.length;if(this.parent.push(),this.parent.ellipseMode(this.parent.CENTER),this.parent.noStroke(),1===c&&1===d)for(this.parent.fill(this.pointColors[0]),b=0;b=2&&this.parent.line(this.cuts[0][0],this.cuts[0][1],this.cuts[1][0],this.cuts[1][1])}this.parent.pop()},GLayer.prototype.drawLine=function(){var a,b,c,d,e,f;if(4===arguments.length&&arguments[0]instanceof GPoint)a=arguments[0],b=arguments[1],c=arguments[2],d=arguments[3];else if(4===arguments.length)e=arguments[0],f=arguments[1],c=arguments[2],d=arguments[3];else if(2===arguments.length&&arguments[0]instanceof GPoint)a=arguments[0],b=arguments[1],c=this.lineColor,d=this.lineWidth;else{if(2!==arguments.length)throw new Error("GLayer.drawLine(): signature not supported");e=arguments[0],f=arguments[1],c=this.lineColor,d=this.lineWidth}void 0!==e&&(this.xLog&&this.yLog?(a=new GPoint(this.xLim[0],Math.pow(10,e*Math.log(this.xLim[0])/Math.LN10+f)),b=new GPoint(this.xLim[1],Math.pow(10,e*Math.log(this.xLim[1])/Math.LN10+f))):this.xLog?(a=new GPoint(this.xLim[0],e*Math.log(this.xLim[0])/Math.LN10+f),b=new GPoint(this.xLim[1],e*Math.log(this.xLim[1])/Math.LN10+f)):this.yLog?(a=new GPoint(this.xLim[0],Math.pow(10,e*this.xLim[0]+f)),b=new GPoint(this.xLim[1],Math.pow(10,e*this.xLim[1]+f))):(a=new GPoint(this.xLim[0],e*this.xLim[0]+f),b=new GPoint(this.xLim[1],e*this.xLim[1]+f)));var g=this.valueToPlot(a),h=this.valueToPlot(b);if(g.isValid()&&h.isValid()){var i=this.isInside(g),j=this.isInside(h);if(this.parent.push(),this.parent.noFill(),this.parent.stroke(c),this.parent.strokeWeight(d),this.parent.strokeCap(this.parent.SQUARE),i&&j)this.parent.line(g.getX(),g.getY(),h.getX(),h.getY());else{var k=this.obtainBoxIntersections(g,h);i?this.parent.line(g.getX(),g.getY(),this.cuts[0][0],this.cuts[0][1]):j?this.parent.line(this.cuts[0][0],this.cuts[0][1],h.getX(),h.getY()):k>=2&&this.parent.line(this.cuts[0][0],this.cuts[0][1],this.cuts[1][0],this.cuts[1][1])}this.parent.pop()}},GLayer.prototype.drawHorizontalLine=function(){var a,b,c;if(3===arguments.length)a=arguments[0],b=arguments[1],c=arguments[2];else{if(1!==arguments.length)throw new Error("GLayer.drawHorizontalLine(): signature not supported");a=arguments[0],b=this.lineColor,c=this.lineWidth}var d=this.valueToYPlot(a);this.isValidNumber(d)&&-d>=0&&-d<=this.dim[1]&&(this.parent.push(),this.parent.noFill(),this.parent.stroke(b),this.parent.strokeWeight(c),this.parent.strokeCap(this.parent.SQUARE),this.parent.line(0,d,this.dim[0],d),this.parent.pop())},GLayer.prototype.drawVerticalLine=function(){var a,b,c;if(3===arguments.length)a=arguments[0],b=arguments[1],c=arguments[2];else{if(1!==arguments.length)throw new Error("GLayer.drawVerticalLine(): signature not supported");a=arguments[0],b=this.lineColor,c=this.lineWidth}var d=this.valueToXPlot(a);this.isValidNumber(d)&&d>=0&&d<=this.dim[0]&&(this.parent.push(),this.parent.noFill(),this.parent.stroke(b),this.parent.strokeWeight(c),this.parent.strokeCap(this.parent.SQUARE),this.parent.line(d,0,d,-this.dim[1]),this.parent.pop())},GLayer.prototype.drawFilledContour=function(a,b){var c;if(a===GPlot.HORIZONTAL?c=this.getHorizontalShape(b):a===GPlot.VERTICAL&&(c=this.getVerticalShape(b)),void 0!==c&&c.length>0){this.parent.push(),this.parent.fill(this.lineColor),this.parent.noStroke(),this.parent.beginShape();for(var d=0;d=0&&b.getX()<=this.dim[0]&&(-b.getY()<0?(f.push(new GPoint(b.getX(),0,"projection")),c=!0):(f.push(new GPoint(b.getX(),-this.dim[1],"projection")),c=!0)),d=i+1;d0){var l=new GPoint(f[0]);if(0!==l.getX()&&l.getX()!==this.dim[0])if("cut"===l.getLabel())this.plotPoints[g].getX()<0?(l.setX(0),l.setLabel("extreme")):(l.setX(this.dim[0]),l.setLabel("extreme"));else if(0!==g){for(var m=g-1;m>0&&!this.plotPoints[m].isValid();)m--;this.plotPoints[m].isValid()&&(this.plotPoints[m].getX()<0?(l.setX(0),l.setLabel("extreme")):(l.setX(this.dim[0]),l.setLabel("extreme")))}var n=new GPoint(f[f.length-1]);if(0!==n.getX()&&n.getX()!==this.dim[0]&&h!==e-1){for(d=h+1;dthis.dim[1]?(f.push(new GPoint(n.getX(),-this.dim[1])),f.push(new GPoint(l.getX(),-this.dim[1]))):(f.push(new GPoint(n.getX(),o[1])),f.push(new GPoint(l.getX(),o[1]))),"extreme"===l.getLabel()&&f.push(l)}return f},GLayer.prototype.getVerticalShape=function(a){for(var b,c,d,e=this.plotPoints.length,f=[],g=-1,h=-1,i=0;i=0&&-b.getY()<=this.dim[1]&&(b.getX()<0?(f.push(new GPoint(0,b.getY(),"projection")),c=!0):(f.push(new GPoint(this.dim[0],b.getY(),"projection")),c=!0)),d=i+1;d0){var l=new GPoint(f[0]);if(0!==l.getY()&&l.getY()!==-this.dim[1])if("cut"===l.getLabel())-this.plotPoints[g].getY()<0?(l.setY(0),l.setLabel("extreme")):(l.setY(-this.dim[1]),l.setLabel("extreme"));else if(0!==g){for(var m=g-1;m>0&&!this.plotPoints[m].isValid();)m--;this.plotPoints[m].isValid()&&(-this.plotPoints[m].getY()<0?(l.setY(0),l.setLabel("extreme")):(l.setY(-this.dim[1]),l.setLabel("extreme")))}var n=new GPoint(f[f.length-1]);if(0!==n.getY()&&n.getY()!==-this.dim[1]&&h!==e-1){for(d=h+1;dthis.dim[0]?(f.push(new GPoint(this.dim[0],n.getY())),f.push(new GPoint(this.dim[0],l.getY()))):(f.push(new GPoint(o[0],n.getY())),f.push(new GPoint(o[0],l.getY()))),"extreme"===l.getLabel()&&f.push(l)}return f},GLayer.prototype.drawLabel=function(a){var b=this.valueToXPlot(a.getX()),c=this.valueToYPlot(a.getY());if(this.isValidNumber(b)&&this.isValidNumber(c)){var d=b+this.labelSeparation[0],e=c-this.labelSeparation[1],f=this.fontSize/4;this.parent.push(),this.parent.rectMode(this.parent.CORNER),this.parent.noStroke(),this.parent.textFont(this.fontName),this.parent.textSize(this.fontSize),this.parent.textAlign(this.parent.LEFT,this.parent.BOTTOM),this.parent.fill(this.labelBgColor),this.parent.rect(d-f,e-this.fontSize-f,this.parent.textWidth(a.getLabel())+2*f,this.fontSize+2*f),this.parent.fill(this.fontColor),this.parent.text(a.getLabel(),d,e),this.parent.pop()}},GLayer.prototype.drawLabelAtPlotPos=function(a,b){var c=this.getPointAtPlotPos(a,b);void 0!==c&&this.drawLabel(c)},GLayer.prototype.drawHistogram=function(){void 0!==this.hist&&this.hist.draw(this.valueToPlot(this.histBasePoint))},GLayer.prototype.drawPolygon=function(a,b){var c;if(a.length>2){var d=this.valueToPlot(a),e=0;for(c=0;c1&&(h.push(new GPoint(this.cuts[0][0],this.cuts[0][1],"double cut")),h.push(new GPoint(this.cuts[1][0],this.cuts[1][1],"double cut")))}g=h.length;var k=[];for(c=0;c0&&t>0&&s!==this.dim[0]&&t!==this.dim[1]){var u=0===o||o===this.dim[0]?o:q,v=0===p||p===-this.dim[1]?p:r;k.push(new GPoint(u,v,"special cut"))}}}if(k.length>2){for(this.parent.push(),this.parent.fill(b),this.parent.noStroke(),this.parent.beginShape(),c=0;c0&&b>0&&(this.dim[0]=a,this.dim[1]=b,this.updatePlotPoints(),void 0!==this.hist&&(this.hist.setDim(this.dim),this.hist.setPlotPoints(this.plotPoints)))},GLayer.prototype.setXLim=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(1!==arguments.length)throw new Error("GLayer.setXLim(): signature not supported");a=arguments[0][0],b=arguments[0][1]}a!==b&&this.isValidNumber(a)&&this.isValidNumber(b)&&(this.xLog&&(a<=0||b<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.xLim[0]=a,this.xLim[1]=b,this.updatePlotPoints(),this.updateInsideList(),void 0!==this.hist&&this.hist.setPlotPoints(this.plotPoints)))},GLayer.prototype.setYLim=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(1!==arguments.length)throw new Error("GLayer.setYLim(): signature not supported");a=arguments[0][0],b=arguments[0][1]}a!==b&&this.isValidNumber(a)&&this.isValidNumber(b)&&(this.yLog&&(a<=0||b<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.yLim[0]=a,this.yLim[1]=b,this.updatePlotPoints(),this.updateInsideList(),void 0!==this.hist&&this.hist.setPlotPoints(this.plotPoints)))},GLayer.prototype.setXYLim=function(){var a,b,c,d;if(4===arguments.length)a=arguments[0],b=arguments[1],c=arguments[2],d=arguments[3];else{if(2!==arguments.length)throw new Error("GLayer.setXYLim(): signature not supported");a=arguments[0][0],b=arguments[0][1],c=arguments[1][0],d=arguments[1][1]}a!==b&&c!==d&&this.isValidNumber(a)&&this.isValidNumber(b)&&this.isValidNumber(c)&&this.isValidNumber(d)&&(this.xLog&&(a<=0||b<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.xLim[0]=a,this.xLim[1]=b),this.yLog&&(c<=0||d<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.yLim[0]=c,this.yLim[1]=d),this.updatePlotPoints(),this.updateInsideList(),void 0!==this.hist&&this.hist.setPlotPoints(this.plotPoints))},GLayer.prototype.setLimAndLog=function(){var a,b,c,d,e,f;if(6===arguments.length)a=arguments[0],b=arguments[1],c=arguments[2],d=arguments[3],e=arguments[4],f=arguments[5];else{if(4!==arguments.length)throw new Error("GLayer.setLimAndLog(): signature not supported");a=arguments[0][0],b=arguments[0][1],c=arguments[1][0],d=arguments[1][1],e=arguments[2],f=arguments[3]}a!==b&&c!==d&&this.isValidNumber(a)&&this.isValidNumber(b)&&this.isValidNumber(c)&&this.isValidNumber(d)&&(e&&(a<=0||b<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.xLim[0]=a,this.yLim[1]=b,this.xLog=e),f&&(c<=0||d<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.yLim[0]=c,this.yLim[1]=d,this.yLog=f),this.updatePlotPoints(),this.updateInsideList(),void 0!==this.hist&&this.hist.setPlotPoints(this.plotPoints))},GLayer.prototype.setXLog=function(a){a!==this.xLog&&(a&&(this.xLim[0]<=0||this.xLim[1]<=0)&&(console.log("One of the limits is negative. This is not allowed in logarithmic scale."),console.log("Will set horizontal limits to (0.1, 10)"),this.xLim[0]=.1,this.xLim[1]=10),this.xLog=a,this.updatePlotPoints(),this.updateInsideList(),void 0!==this.hist&&this.hist.setPlotPoints(this.plotPoints))},GLayer.prototype.setYLog=function(a){a!==this.yLog&&(a&&(this.yLim[0]<=0||this.yLim[1]<=0)&&(console.log("One of the limits is negative. This is not allowed in logarithmic scale."),console.log("Will set horizontal limits to (0.1, 10)"),this.yLim[0]=.1,this.yLim[1]=10),this.yLog=a,this.updatePlotPoints(),this.updateInsideList(),void 0!==this.hist&&this.hist.setPlotPoints(this.plotPoints))},GLayer.prototype.setPoints=function(a){var b,c=a.length;if(this.points.length>c)this.points.splice(c,Number.MAX_VALUE);else for(b=this.points.length;b0&&(this.pointColors=a.slice())},GLayer.prototype.setPointColor=function(a){this.pointColors=[a]},GLayer.prototype.setPointSizes=function(a){a.length>0&&(this.pointSizes=a.slice())},GLayer.prototype.setPointSize=function(a){this.pointSizes=[a]},GLayer.prototype.setLineColor=function(a){this.lineColor=a},GLayer.prototype.setLineWidth=function(a){a>0&&(this.lineWidth=a)},GLayer.prototype.setHistBasePoint=function(a){this.histBasePoint.set(a)},GLayer.prototype.setHistType=function(a){void 0!==this.hist&&this.hist.setType(a)},GLayer.prototype.setHistVisible=function(a){void 0!==this.hist&&this.hist.setVisible(a)},GLayer.prototype.setDrawHistLabels=function(a){void 0!==this.hist&&this.hist.setDrawLabels(a)},GLayer.prototype.setLabelBgColor=function(a){this.labelBgColor=a},GLayer.prototype.setLabelSeparation=function(a){this.labelSeparation[0]=a[0],this.labelSeparation[1]=a[1]},GLayer.prototype.setFontName=function(a){this.fontName=a},GLayer.prototype.setFontColor=function(a){this.fontColor=a},GLayer.prototype.setFontSize=function(a){a>0&&(this.fontSize=a)},GLayer.prototype.setFontProperties=function(a,b,c){c>0&&(this.fontName=a,this.fontColor=b,this.fontSize=c)},GLayer.prototype.setAllFontProperties=function(a,b,c){this.setFontProperties(a,b,c),void 0!==this.hist&&this.hist.setFontProperties(a,b,c)},GLayer.prototype.getId=function(){return this.id},GLayer.prototype.getDim=function(){return this.dim.slice()},GLayer.prototype.getXLim=function(){return this.xLim.slice()},GLayer.prototype.getYLim=function(){return this.yLim.slice()},GLayer.prototype.getXLog=function(){return this.xLog},GLayer.prototype.getYLog=function(){return this.yLog},GLayer.prototype.getPoints=function(){for(var a=[],b=0;b=this.pos[0]&&a<=this.pos[0]+this.outerDim[0]&&b>=this.pos[1]&&b<=this.pos[1]+this.outerDim[1]},GPlot.prototype.isOverBox=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(0!==arguments.length)throw new Error("GPlot.isOverBox(): signature not supported");a=this.parent.mouseX,b=this.parent.mouseY}return a>=this.pos[0]+this.mar[1]&&a<=this.pos[0]+this.outerDim[0]-this.mar[3]&&b>=this.pos[1]+this.mar[2]&&b<=this.pos[1]+this.outerDim[1]-this.mar[0]},GPlot.prototype.updateLimits=function(){this.fixedXLim||(this.xLim=this.calculatePlotXLim(),this.xAxis.setLim(this.xLim),this.topAxis.setLim(this.xLim)),this.fixedYLim||(this.yLim=this.calculatePlotYLim(),this.yAxis.setLim(this.yLim),this.rightAxis.setLim(this.yLim)),this.mainLayer.setXYLim(this.xLim,this.yLim);for(var a=0;a=this.yLim[0]&&e>=this.yLim[0]&&e<=this.yLim[1]||this.yLim[1]=this.yLim[1]),!f||this.xLog&&d<=0||(db[1]&&(b[1]=d))}return b[1]=this.xLim[0]&&d>=this.xLim[0]&&d<=this.xLim[1]||this.xLim[1]=this.xLim[1]),!f||this.yLog&&e<=0||(eb[1]&&(b[1]=e))}return b[1]=0&&c[b]<=this.dim[0]&&this.parent.line(c[b],0,c[b],-this.dim[1])}if(a===GPlot.BOTH||a===GPlot.HORIZONTAL){var d=this.yAxis.getPlotTicksRef();for(b=0;b=0&&-d[b]<=this.dim[1]&&this.parent.line(0,d[b],this.dim[0],d[b])}this.parent.pop()},GPlot.prototype.drawHistograms=function(){this.mainLayer.drawHistogram();for(var a=0;a0&&b>0){var c=a-this.mar[1]-this.mar[3],d=b-this.mar[0]-this.mar[2];if(c>0&&d>0){this.outerDim[0]=a,this.outerDim[1]=b,this.dim[0]=c,this.dim[1]=d,this.xAxis.setDim(this.dim),this.topAxis.setDim(this.dim),this.yAxis.setDim(this.dim),this.rightAxis.setDim(this.dim),this.title.setDim(this.dim),this.mainLayer.setDim(this.dim);for(var e=0;e0&&f>0&&(this.mar[0]=a,this.mar[1]=b,this.mar[2]=c,this.mar[3]=d,this.outerDim[0]=e,this.outerDim[1]=f)},GPlot.prototype.setDim=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(1!==arguments.length)throw new Error("GPlot.setDim(): signature not supported");a=arguments[0][0],b=arguments[0][1]}if(a>0&&b>0){var c=a+this.mar[1]+this.mar[3],d=b+this.mar[0]+this.mar[2];if(c>0&&d>0){this.outerDim[0]=c,this.outerDim[1]=d,this.dim[0]=a,this.dim[1]=b,this.xAxis.setDim(this.dim),this.topAxis.setDim(this.dim),this.yAxis.setDim(this.dim),this.rightAxis.setDim(this.dim),this.title.setDim(this.dim),this.mainLayer.setDim(this.dim);for(var e=0;ethis.xLim[1],this.fixedXLim=!0,this.xAxis.setLim(this.xLim),this.topAxis.setLim(this.xLim),this.updateLimits()))},GPlot.prototype.setYLim=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(1!==arguments.length)throw new Error("GPlot.setYLim(): signature not supported");a=arguments[0][0],b=arguments[0][1]}a!==b&&(this.yLog&&(a<=0||b<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.yLim[0]=a,this.yLim[1]=b,this.invertedYScale=this.yLim[0]>this.yLim[1],this.fixedYLim=!0,this.yAxis.setLim(this.yLim),this.rightAxis.setLim(this.yLim),this.updateLimits()))},GPlot.prototype.setFixedXLim=function(a){this.fixedXLim=a,this.updateLimits()},GPlot.prototype.setFixedYLim=function(a){this.fixedYLim=a,this.updateLimits()},GPlot.prototype.setLogScale=function(a){var b=this.xLog,c=this.yLog;if("xy"===a||"yx"===a?(b=!0,c=!0):"x"===a?(b=!0,c=!1):"y"===a?(b=!1,c=!0):""===a&&(b=!1,c=!1),b!==this.xLog||c!==this.yLog){this.xLog=b,this.yLog=c,this.xLog&&this.fixedXLim&&(this.xLim[0]<=0||this.xLim[1]<=0)&&(this.fixedXLim=!1),this.yLog&&this.fixedYLim&&(this.yLim[0]<=0||this.yLim[1]<=0)&&(this.fixedYLim=!1),this.fixedXLim||(this.xLim=this.calculatePlotXLim()),this.fixedYLim||(this.yLim=this.calculatePlotYLim()),this.xAxis.setLimAndLog(this.xLim,this.xLog),this.topAxis.setLimAndLog(this.xLim,this.xLog),this.yAxis.setLimAndLog(this.yLim,this.yLog),this.rightAxis.setLimAndLog(this.yLim,this.yLog),this.mainLayer.setLimAndLog(this.xLim,this.yLim,this.xLog,this.yLog);for(var d=0;d=0&&a!==this.expandLimFactor&&(this.expandLimFactor=a,this.updateLimits())},GPlot.prototype.setBgColor=function(a){this.bgColor=a},GPlot.prototype.setBoxBgColor=function(a){this.boxBgColor=a},GPlot.prototype.setBoxLineColor=function(a){this.boxLineColor=a},GPlot.prototype.setBoxLineWidth=function(a){a>0&&(this.boxLineWidth=a)},GPlot.prototype.setGridLineColor=function(a){this.gridLineColor=a},GPlot.prototype.setGridLineWidth=function(a){a>0&&(this.gridLineWidth=a)},GPlot.prototype.setPoints=function(){if(2===arguments.length)this.getLayer(arguments[1]).setPoints(arguments[0]);else{if(1!==arguments.length)throw new Error("GPlot.setPoints(): signature not supported");this.mainLayer.setPoints(arguments[0])}this.updateLimits()},GPlot.prototype.setPoint=function(){if(5===arguments.length)this.getLayer(arguments[4]).setPoint(arguments[0],arguments[1],arguments[2],arguments[3]);else if(4===arguments.length)this.mainLayer.setPoint(arguments[0],arguments[1],arguments[2],arguments[3]);else if(3===arguments.length&&arguments[1]instanceof GPoint)this.getLayer(arguments[2]).setPoint(arguments[0],arguments[1]);else if(3===arguments.length)this.mainLayer.setPoint(arguments[0],arguments[1],arguments[2]);else{if(2!==arguments.length)throw new Error("GPlot.setPoint(): signature not supported");this.mainLayer.setPoint(arguments[0],arguments[1])}this.updateLimits()},GPlot.prototype.addPoint=function(){if(4===arguments.length)this.getLayer(arguments[3]).addPoint(arguments[0],arguments[1],arguments[2]);else if(3===arguments.length)this.mainLayer.addPoint(arguments[0],arguments[1],arguments[2]);else if(2===arguments.length&&arguments[0]instanceof GPoint)this.getLayer(arguments[1]).addPoint(arguments[0]);else if(2===arguments.length)this.mainLayer.addPoint(arguments[0],arguments[1]);else{if(1!==arguments.length)throw new Error("GPlot.addPoint(): signature not supported");this.mainLayer.addPoint(arguments[0])}this.updateLimits()},GPlot.prototype.addPoints=function(){if(2===arguments.length)this.getLayer(arguments[1]).addPoints(arguments[0]);else{if(1!==arguments.length)throw new Error("GPlot.addPoints(): signature not supported");this.mainLayer.addPoints(arguments[0])}this.updateLimits()},GPlot.prototype.removePoint=function(){if(2===arguments.length)this.getLayer(arguments[1]).removePoint(arguments[0]);else{if(1!==arguments.length)throw new Error("GPlot.removePoint(): signature not supported");this.mainLayer.removePoint(arguments[0])}this.updateLimits()},GPlot.prototype.addPointAtIndexPos=function(){if(5===arguments.length)this.getLayer(arguments[4]).addPointAtIndexPos(arguments[0],arguments[1],arguments[2],arguments[3]);else if(4===arguments.length)this.mainLayer.addPointAtIndexPos(arguments[0],arguments[1],arguments[2],arguments[3]);else if(3===arguments.length&&arguments[1]instanceof GPoint)this.getLayer(arguments[2]).addPointAtIndexPos(arguments[0],arguments[1]);else if(3===arguments.length)this.mainLayer.addPointAtIndexPos(arguments[0],arguments[1],arguments[2]);else{if(2!==arguments.length)throw new Error("GPlot.addPointAtIndexPos(): signature not supported");this.mainLayer.addPointAtIndexPos(arguments[0],arguments[1])}this.updateLimits()},GPlot.prototype.setPointColors=function(a){this.mainLayer.setPointColors(a)},GPlot.prototype.setPointColor=function(a){this.mainLayer.setPointColor(a)},GPlot.prototype.setPointSizes=function(a){this.mainLayer.setPointSizes(a)},GPlot.prototype.setPointSize=function(a){this.mainLayer.setPointSize(a)},GPlot.prototype.setLineColor=function(a){this.mainLayer.setLineColor(a)},GPlot.prototype.setLineWidth=function(a){this.mainLayer.setLineWidth(a)},GPlot.prototype.setHistBasePoint=function(a){this.mainLayer.setHistBasePoint(a)},GPlot.prototype.setHistType=function(a){this.mainLayer.setHistType(a)},GPlot.prototype.setHistVisible=function(a){this.mainLayer.setHistVisible(a)},GPlot.prototype.setDrawHistLabels=function(a){this.mainLayer.setDrawHistLabels(a)},GPlot.prototype.setLabelBgColor=function(a){this.mainLayer.setLabelBgColor(a)},GPlot.prototype.setLabelSeparation=function(a){this.mainLayer.setLabelSeparation(a)},GPlot.prototype.setTitleText=function(a){this.title.setText(a)},GPlot.prototype.setAxesOffset=function(a){this.xAxis.setOffset(a),this.topAxis.setOffset(a),this.yAxis.setOffset(a),this.rightAxis.setOffset(a)},GPlot.prototype.setTicksLength=function(a){this.xAxis.setTickLength(a),this.topAxis.setTickLength(a),this.yAxis.setTickLength(a),this.rightAxis.setTickLength(a)},GPlot.prototype.setHorizontalAxesNTicks=function(a){this.xAxis.setNTicks(a),this.topAxis.setNTicks(a)},GPlot.prototype.setHorizontalAxesTicksSeparation=function(a){this.xAxis.setTicksSeparation(a),this.topAxis.setTicksSeparation(a)},GPlot.prototype.setHorizontalAxesTicks=function(a){this.xAxis.setTicks(a),this.topAxis.setTicks(a)},GPlot.prototype.setVerticalAxesNTicks=function(a){this.yAxis.setNTicks(a),this.rightAxis.setNTicks(a)},GPlot.prototype.setVerticalAxesTicksSeparation=function(a){this.yAxis.setTicksSeparation(a),this.rightAxis.setTicksSeparation(a)},GPlot.prototype.setVerticalAxesTicks=function(a){this.yAxis.setTicks(a),this.rightAxis.setTicks(a)},GPlot.prototype.setFontName=function(a){this.mainLayer.setFontName(a)},GPlot.prototype.setFontColor=function(a){this.mainLayer.setFontColor(a)},GPlot.prototype.setFontSize=function(a){this.mainLayer.setFontSize(a)},GPlot.prototype.setFontProperties=function(a,b,c){this.mainLayer.setFontProperties(a,b,c)},GPlot.prototype.setAllFontProperties=function(a,b,c){this.xAxis.setAllFontProperties(a,b,c),this.topAxis.setAllFontProperties(a,b,c),this.yAxis.setAllFontProperties(a,b,c),this.rightAxis.setAllFontProperties(a,b,c),this.title.setFontProperties(a,b,c),this.mainLayer.setAllFontProperties(a,b,c);for(var d=0;d0&&(this.zoomFactor=a),b!==this.parent.LEFT&&b!==this.parent.RIGHT&&b!==this.parent.CENTER||(this.increaseZoomButton=b),c!==this.parent.LEFT&&c!==this.parent.RIGHT&&c!==this.parent.CENTER||(this.decreaseZoomButton=c),d!==this.parent.SHIFT&&d!==this.parent.CONTROL&&d!==this.parent.ALT&&d!==GPlot.NONE||(this.increaseZoomKeyModifier=d),e!==this.parent.SHIFT&&e!==this.parent.CONTROL&&e!==this.parent.ALT&&e!==GPlot.NONE||(this.decreaseZoomKeyModifier=e)},GPlot.prototype.deactivateZooming=function(){this.zoomingIsActive=!1},GPlot.prototype.activateCentering=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else if(1===arguments.length)a=arguments[0],b=GPlot.NONE;else{if(0!==arguments.length)throw new Error("GPlot.activateCentering(): signature not supported");a=this.parent.LEFT,b=GPlot.NONE}this.centeringIsActive=!0,a!==this.parent.LEFT&&a!==this.parent.RIGHT&&a!==this.parent.CENTER||(this.centeringButton=a),b!==this.parent.SHIFT&&b!==this.parent.CONTROL&&b!==this.parent.ALT&&b!==GPlot.NONE||(this.centeringKeyModifier=b)},GPlot.prototype.deactivateCentering=function(){this.centeringIsActive=!1},GPlot.prototype.activatePanning=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else if(1===arguments.length)a=arguments[0],b=GPlot.NONE;else{if(0!==arguments.length)throw new Error("GPlot.activatePanning(): signature not supported");a=this.parent.LEFT,b=GPlot.NONE}this.panningIsActive=!0,a!==this.parent.LEFT&&a!==this.parent.RIGHT&&a!==this.parent.CENTER||(this.panningButton=a),b!==this.parent.SHIFT&&b!==this.parent.CONTROL&&b!==this.parent.ALT&&b!==GPlot.NONE||(this.panningKeyModifier=b)},GPlot.prototype.deactivatePanning=function(){this.panningIsActive=!1,this.panningReferencePoint=void 0},GPlot.prototype.activatePointLabels=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else if(1===arguments.length)a=arguments[0],b=GPlot.NONE;else{if(0!==arguments.length)throw new Error("GPlot.activatePointLabels(): signature not supported");a=this.parent.LEFT,b=GPlot.NONE}this.labelingIsActive=!0,a!==this.parent.LEFT&&a!==this.parent.RIGHT&&a!==this.parent.CENTER||(this.labelingButton=a),b!==this.parent.SHIFT&&b!==this.parent.CONTROL&&b!==this.parent.ALT&&b!==GPlot.NONE||(this.labelingKeyModifier=b)},GPlot.prototype.deactivatePointLabels=function(){this.labelingIsActive=!1,this.mousePos=void 0},GPlot.prototype.activateReset=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else if(1===arguments.length)a=arguments[0],b=GPlot.NONE;else{if(0!==arguments.length)throw new Error("GPlot.activateReset(): signature not supported");a=this.parent.RIGHT,b=GPlot.NONE}this.resetIsActive=!0,this.xLimReset=void 0,this.yLimReset=void 0,a!==this.parent.LEFT&&a!==this.parent.RIGHT&&a!==this.parent.CENTER||(this.resetButton=a),b!==this.parent.SHIFT&&b!==this.parent.CONTROL&&b!==this.parent.ALT&&b!==GPlot.NONE||(this.resetKeyModifier=b)},GPlot.prototype.deactivateReset=function(){this.resetIsActive=!1,this.xLimReset=void 0,this.yLimReset=void 0},GPlot.prototype.getButton=function(a){var b;return 0===a.button?b=this.parent.LEFT:1===a.button?b=this.parent.CENTER:2===a.button?b=this.parent.RIGHT:void 0===a.button&&(b=this.parent.LEFT),b},GPlot.prototype.getModifier=function(a){return a.altKey?this.parent.ALT:a.ctrlKey?this.parent.CONTROL:a.shiftKey?this.parent.SHIFT:GPlot.NONE},GPlot.prototype.saveResetLimits=function(){void 0!==this.xLimReset&&void 0!==this.yLimReset||(this.xLimReset=this.xLim.slice(),this.yLimReset=this.yLim.slice())},GPlot.prototype.clickEvent=function(a){var b=a||window.event;if(this.isOverBox()){var c=this.getButton(b),d=this.getModifier(b);this.zoomingIsActive&&(c===this.increaseZoomButton&&d===this.increaseZoomKeyModifier?(this.resetIsActive&&this.saveResetLimits(),this.zoom(this.zoomFactor,this.parent.mouseX,this.parent.mouseY)):c===this.decreaseZoomButton&&d===this.decreaseZoomKeyModifier&&(this.resetIsActive&&this.saveResetLimits(),this.zoom(1/this.zoomFactor,this.parent.mouseX,this.parent.mouseY))), +/*! grafica.js (0.3.1): a library for p5.js. Author: Javier GraciĆ” Carpio, license: LGPL-3.0, 2018-09-27 */ function GPoint(){var a,b,c;if(3===arguments.length)a=arguments[0],b=arguments[1],c=arguments[2];else if(2===arguments.length&&arguments[0]instanceof p5.Vector)a=arguments[0].x,b=arguments[0].y,c=arguments[1];else if(2===arguments.length)a=arguments[0],b=arguments[1],c="";else if(1===arguments.length&&arguments[0]instanceof GPoint)a=arguments[0].getX(),b=arguments[0].getY(),c=arguments[0].getLabel();else if(1===arguments.length&&arguments[0]instanceof p5.Vector)a=arguments[0].x,b=arguments[0].y,c="";else{if(0!==arguments.length)throw new Error("GPoint constructor: signature not supported");a=0,b=0,c=""}this.x=a,this.y=b,this.label=c,this.valid=this.isValidNumber(this.x)&&this.isValidNumber(this.y)}function GTitle(a,b){this.parent=a,this.dim=b.slice(),this.relativePos=.5,this.plotPos=this.relativePos*this.dim[0],this.offset=10,this.text="",this.textAlignment=this.parent.CENTER,this.fontName="Helvetica",this.fontColor=this.parent.color(100),this.fontStyle=this.parent.BOLD,this.fontSize=13}function GAxisLabel(a,b,c){this.parent=a,this.type=b===this.parent.BOTTOM||b===this.parent.TOP||b===this.parent.LEFT||b===this.parent.RIGHT?b:this.parent.BOTTOM,this.dim=c.slice(),this.relativePos=.5,this.plotPos=this.type===this.parent.BOTTOM||this.type===this.parent.TOP?this.relativePos*this.dim[0]:-this.relativePos*this.dim[1],this.offset=35,this.rotate=this.type!==this.parent.BOTTOM&&this.type!==this.parent.TOP,this.text="",this.textAlignment=this.parent.CENTER,this.fontName="Helvetica",this.fontColor=this.parent.color(0),this.fontSize=13}function GAxis(a,b,c,d,e){this.parent=a,this.type=b===this.parent.BOTTOM||b===this.parent.TOP||b===this.parent.LEFT||b===this.parent.RIGHT?b:this.parent.BOTTOM,this.dim=c.slice(),this.lim=d.slice(),this.log=e,this.log&&(this.lim[0]<=0||this.lim[1]<=0)&&(console.log("The limits are negative. This is not allowed in logarithmic scale."),console.log("Will set them to (0.1, 10)"),this.lim[1]>this.lim[0]?(this.lim[0]=.1,this.lim[1]=10):(this.lim[0]=10,this.lim[1]=.1)),this.offset=5,this.lineColor=this.parent.color(0),this.lineWidth=1,this.nTicks=5,this.ticksSeparation=-1,this.ticks=[],this.plotTicks=[],this.ticksInside=[],this.tickLabels=[],this.fixedTicks=!1,this.tickLength=3,this.smallTickLength=2,this.expTickLabels=!1,this.rotateTickLabels=this.type!==this.parent.BOTTOM&&this.type!==this.parent.TOP,this.drawTickLabels=this.type===this.parent.BOTTOM||this.type===this.parent.LEFT,this.tickLabelOffset=7,this.ticksPrecision=void 0,this.lab=new GAxisLabel(this.parent,this.type,this.dim),this.drawAxisLabel=!0,this.fontName="Helvetica",this.fontColor=this.parent.color(0),this.fontSize=11,this.updateTicks(),this.updatePlotTicks(),this.updateTicksInside(),this.updateTickLabels()}function GHistogram(a,b,c,d){this.parent=a,this.type=b===GPlot.VERTICAL||b===GPlot.HORIZONTAL?b:GPlot.VERTICAL,this.dim=c.slice(),this.plotPoints=[];for(var e=0;e0&&b>0&&(this.dim[0]=a,this.dim[1]=b,this.plotPos=this.relativePos*this.dim[0])},GTitle.prototype.setRelativePos=function(a){this.relativePos=a,this.plotPos=this.relativePos*this.dim[0]},GTitle.prototype.setOffset=function(a){this.offset=a},GTitle.prototype.setText=function(a){this.text=a},GTitle.prototype.setTextAlignment=function(a){a!==this.parent.CENTER&&a!==this.parent.LEFT&&a!==this.parent.RIGHT||(this.textAlignment=a)},GTitle.prototype.setFontName=function(a){this.fontName=a},GTitle.prototype.setFontColor=function(a){this.fontColor=a},GTitle.prototype.setFontStyle=function(a){this.fontStyle=a},GTitle.prototype.setFontSize=function(a){a>0&&(this.fontSize=a)},GTitle.prototype.setFontProperties=function(a,b,c){c>0&&(this.fontName=a,this.fontColor=b,this.fontSize=c)},GAxisLabel.prototype.draw=function(){switch(this.type){case this.parent.BOTTOM:this.drawAsXLabel();break;case this.parent.LEFT:this.drawAsYLabel();break;case this.parent.TOP:this.drawAsTopLabel();break;case this.parent.RIGHT:this.drawAsRightLabel()}},GAxisLabel.prototype.drawAsXLabel=function(){this.parent.push(),this.parent.textFont(this.fontName),this.parent.textSize(this.fontSize),this.parent.fill(this.fontColor),this.parent.noStroke(),this.rotate?(this.parent.textAlign(this.parent.RIGHT,this.parent.CENTER),this.parent.translate(this.plotPos,this.offset),this.parent.rotate(-.5*Math.PI),this.parent.text(this.text,0,0)):(this.parent.textAlign(this.textAlignment,this.parent.TOP),this.parent.text(this.text,this.plotPos,this.offset)),this.parent.pop()},GAxisLabel.prototype.drawAsYLabel=function(){this.parent.push(),this.parent.textFont(this.fontName),this.parent.textSize(this.fontSize),this.parent.fill(this.fontColor),this.parent.noStroke(),this.rotate?(this.parent.textAlign(this.textAlignment,this.parent.BOTTOM),this.parent.translate(-this.offset,this.plotPos),this.parent.rotate(-.5*Math.PI),this.parent.text(this.text,0,0)):(this.parent.textAlign(this.parent.RIGHT,this.parent.CENTER),this.parent.text(this.text,-this.offset,this.plotPos)),this.parent.pop()},GAxisLabel.prototype.drawAsTopLabel=function(){this.parent.push(),this.parent.textFont(this.fontName),this.parent.textSize(this.fontSize),this.parent.fill(this.fontColor),this.parent.noStroke(),this.rotate?(this.parent.textAlign(this.parent.LEFT,this.parent.CENTER),this.parent.translate(this.plotPos,-this.offset-this.dim[1]),this.parent.rotate(-.5*Math.PI),this.parent.text(this.text,0,0)):(this.parent.textAlign(this.textAlignment,this.parent.BOTTOM),this.parent.text(this.text,this.plotPos,-this.offset-this.dim[1])),this.parent.pop()},GAxisLabel.prototype.drawAsRightLabel=function(){this.parent.push(),this.parent.textFont(this.fontName),this.parent.textSize(this.fontSize),this.parent.fill(this.fontColor),this.parent.noStroke(),this.rotate?(this.parent.textAlign(this.textAlignment,this.parent.TOP),this.parent.translate(this.offset+this.dim[0],this.plotPos),this.parent.rotate(-.5*Math.PI),this.parent.text(this.text,0,0)):(this.parent.textAlign(this.parent.LEFT,this.parent.CENTER),this.parent.text(this.text,this.offset+this.dim[0],this.plotPos)),this.parent.pop()},GAxisLabel.prototype.setDim=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(1!==arguments.length)throw new Error("GAxisLabel.setDim(): signature not supported");a=arguments[0][0],b=arguments[0][1]}a>0&&b>0&&(this.dim[0]=a,this.dim[1]=b,this.plotPos=this.type===this.parent.BOTTOM||this.type===this.parent.TOP?this.relativePos*this.dim[0]:-this.relativePos*this.dim[1])},GAxisLabel.prototype.setRelativePos=function(a){this.relativePos=a,this.plotPos=this.type===this.parent.BOTTOM||this.type===this.parent.TOP?this.relativePos*this.dim[0]:-this.relativePos*this.dim[1]},GAxisLabel.prototype.setOffset=function(a){this.offset=a},GAxisLabel.prototype.setRotate=function(a){this.rotate=a},GAxisLabel.prototype.setText=function(a){this.text=a},GAxisLabel.prototype.setTextAlignment=function(a){a!==this.parent.CENTER&&a!==this.parent.LEFT&&a!==this.parent.RIGHT||(this.textAlignment=a)},GAxisLabel.prototype.setFontName=function(a){this.fontName=a},GAxisLabel.prototype.setFontColor=function(a){this.fontColor=a},GAxisLabel.prototype.setFontSize=function(a){a>0&&(this.fontSize=a)},GAxisLabel.prototype.setFontProperties=function(a,b,c){c>0&&(this.fontName=a,this.fontColor=b,this.fontSize=c)},GAxis.prototype.obtainSigDigits=function(a){return Math.round(-Math.log(.5*Math.abs(a))/Math.LN10)},GAxis.prototype.roundPlus=function(a,b){return a=Math.round(a*Math.pow(10,b))/Math.pow(10,b),b<=0&&(a=Math.round(a)),a},GAxis.prototype.adaptSize=function(a,b){bthis.lim[0]?(a=Math.floor(Math.log(this.lim[0])/Math.LN10),b=Math.ceil(Math.log(this.lim[1])/Math.LN10)):(a=Math.floor(Math.log(this.lim[1])/Math.LN10),b=Math.ceil(Math.log(this.lim[0])/Math.LN10));var c=9*(b-a)+1;this.adaptSize(this.ticks,c);for(var d=a;d0){for(a=this.lim[1]>this.lim[0]?this.ticksSeparation:-this.ticksSeparation,c=this.obtainSigDigits(a);this.roundPlus(a,c)-a!=0;)c++;b=Math.floor((this.lim[1]-this.lim[0])/a)}else this.nTicks>0&&(a=(this.lim[1]-this.lim[0])/this.nTicks,c=this.obtainSigDigits(a),a=this.roundPlus(a,c),(0===a||Math.abs(a)>Math.abs(this.lim[1]-this.lim[0]))&&(c++,a=this.roundPlus((this.lim[1]-this.lim[0])/this.nTicks,c)),b=Math.floor((this.lim[1]-this.lim[0])/a));if(b>0){var d=this.lim[0]+(this.lim[1]-this.lim[0]-b*a)/2;for(d=this.roundPlus(d-2*a,c);(this.lim[1]-d)*(this.lim[0]-d)>0;)d=this.roundPlus(d+a,c);var e=Math.floor(Math.abs((this.lim[1]-d)/a))+1;this.adaptSize(this.ticks,e),this.ticks[0]=d;for(var f=1;f=0&&this.plotTicks[a]<=this.dim[0];else for(a=0;a=0&&-this.plotTicks[a]<=this.dim[1]},GAxis.prototype.updateTickLabels=function(){var a,b,c,d,e=this.ticks.length;if(this.adaptSize(this.tickLabels,e),this.log)for(d=0;d0?(b=Math.log(a)/Math.LN10,c=Math.abs(b-Math.round(b))<1e-4,c?(b=Math.round(b),this.expTickLabels?this.tickLabels[d]="1e"+b:this.tickLabels[d]=b>-3.1&&b<3.1?b>=0?""+Math.round(a):""+a:"1e"+b):this.tickLabels[d]=""):this.tickLabels[d]="";else for(d=0;d=0?this.tickLabels[d]=""+parseFloat(a).toFixed(this.ticksPrecision):this.tickLabels[d]=""+a},GAxis.prototype.moveLim=function(a){if(a[1]!==a[0])if(this.log&&(a[0]<=0||a[1]<=0))console.log("The limits are negative. This is not allowed in logarithmic scale.");else{if(this.lim[0]=a[0],this.lim[1]=a[1],!this.fixedTicks){var b=this.ticks.length;if(this.log)this.obtainLogarithmicTicks();else if(b>0){var c=0,d=0;if(this.ticksSeparation>0)for(c=this.lim[1]>this.lim[0]?this.ticksSeparation:-this.ticksSeparation,d=this.obtainSigDigits(c);this.roundPlus(c,d)-c!=0;)d++;else c=1===b?this.lim[1]-this.lim[0]:this.ticks[1]-this.ticks[0],d=this.obtainSigDigits(c),c=this.roundPlus(c,d),(0===c||Math.abs(c)>Math.abs(this.lim[1]-this.lim[0]))&&(d++,c=1===b?this.lim[1]-this.lim[0]:this.ticks[1]-this.ticks[0],c=this.roundPlus(c,d)),c=this.lim[1]>this.lim[0]?Math.abs(c):-Math.abs(c);var e=this.ticks[0]+c*Math.ceil((this.lim[0]-this.ticks[0])/c);e=this.roundPlus(e,d),(this.lim[1]-e)*(this.lim[0]-e)>0&&(e=this.ticks[0]+c*Math.floor((this.lim[0]-this.ticks[0])/c),e=this.roundPlus(e,d)),b=Math.floor(Math.abs((this.lim[1]-e)/c))+1,this.adaptSize(this.ticks,b),this.ticks[0]=e;for(var f=1;f0&&b>0&&(this.dim[0]=a,this.dim[1]=b,this.updatePlotTicks(),this.lab.setDim(this.dim))},GAxis.prototype.setLim=function(a){a[1]!==a[0]&&(this.log&&(a[0]<=0||a[1]<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.lim[0]=a[0],this.lim[1]=a[1],this.fixedTicks||(this.updateTicks(),this.updateTickLabels()),this.updatePlotTicks(),this.updateTicksInside()))},GAxis.prototype.setLimAndLog=function(a,b){a[1]!==a[0]&&(b&&(a[0]<=0||a[1]<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.lim[0]=a[0],this.lim[1]=a[1],this.log=b,this.fixedTicks||(this.updateTicks(),this.updateTickLabels()),this.updatePlotTicks(),this.updateTicksInside()))},GAxis.prototype.setLog=function(a){a!==this.log&&(this.log=a,this.log&&(this.lim[0]<=0||this.lim[1]<=0)&&(console.log("The limits are negative. This is not allowed in logarithmic scale."),console.log("Will set them to (0.1, 10)"),this.lim[1]>this.lim[0]?(this.lim[0]=.1,this.lim[1]=10):(this.lim[0]=10,this.lim[1]=.1)),this.fixedTicks||(this.updateTicks(),this.updateTickLabels()),this.updatePlotTicks(),this.updateTicksInside())},GAxis.prototype.setOffset=function(a){this.offset=a},GAxis.prototype.setLineColor=function(a){this.lineColor=a},GAxis.prototype.setLineWidth=function(a){a>0&&(this.lineWidth=a)},GAxis.prototype.setNTicks=function(a){a>=0&&(this.nTicks=a,this.ticksSeparation=-1,this.fixedTicks=!1,this.log||(this.updateTicks(),this.updatePlotTicks(),this.updateTicksInside(),this.updateTickLabels()))},GAxis.prototype.setTicksSeparation=function(a){this.ticksSeparation=a,this.fixedTicks=!1,this.log||(this.updateTicks(),this.updatePlotTicks(),this.updateTicksInside(),this.updateTickLabels())},GAxis.prototype.setTicks=function(a){var b=a.length;this.adaptSize(this.ticks,b);for(var c=0;c0&&(this.fontSize=a)},GAxis.prototype.setFontProperties=function(a,b,c){c>0&&(this.fontName=a,this.fontColor=b,this.fontSize=c)},GAxis.prototype.setAllFontProperties=function(a,b,c){this.setFontProperties(a,b,c),this.lab.setFontProperties(a,b,c)},GAxis.prototype.getTicks=function(){if(this.fixedTicks)return this.ticks.slice();for(var a=[],b=0,c=0;cb&&(this.differences.splice(b,Number.MAX_VALUE),this.leftSides.splice(b,Number.MAX_VALUE),this.rightSides.splice(b,Number.MAX_VALUE)),1===b)this.leftSides[0]=this.type===GPlot.VERTICAL?.2*this.dim[0]:.2*this.dim[1],this.rightSides[0]=this.leftSides[0];else if(b>1){for(a=0;a0?(c-d)/2:(c+d)/2}else this.differences[a]=0;for(this.leftSides[0]=this.differences[0],this.rightSides[0]=this.differences[0],a=1;athis.dim[0]&&(d=this.dim[0]),-f<0?f=0:-f>this.dim[1]&&(f=-this.dim[1]),e<0?e=0:e>this.dim[0]&&(e=this.dim[0]),-g<0?g=0:-g>this.dim[1]&&(g=-this.dim[1]),h=this.lineWidths[j%this.lineWidths.length],this.parent.fill(this.bgColors[j%this.bgColors.length]),this.parent.stroke(this.lineColors[j%this.lineColors.length]),this.parent.strokeWeight(h),Math.abs(e-d)>2*h&&Math.abs(g-f)>2*h?this.parent.rect(d,f,e,g):(this.type===GPlot.VERTICAL&&e!==d&&(f!==g||0!==f&&f!==-this.dim[1])||this.type===GPlot.HORIZONTAL&&g!==f&&(d!==e||0!==d&&d!==this.dim[0]))&&(this.parent.rect(d,f,e,g),this.parent.line(d,f,d,g),this.parent.line(e,f,e,g),this.parent.line(d,f,e,f),this.parent.line(d,g,e,g)));this.parent.pop(),this.drawLabels&&this.drawHistLabels()}},GHistogram.prototype.drawHistLabels=function(){var a,b,c=this.plotPoints.length,d=.5*Math.PI;if(this.parent.push(),this.parent.textFont(this.fontName),this.parent.textSize(this.fontSize),this.parent.fill(this.fontColor),this.parent.noStroke(),this.type===GPlot.VERTICAL)if(this.rotateLabels)for(this.parent.textAlign(this.parent.RIGHT,this.parent.CENTER),b=0;b=0&&a.getX()<=this.dim[0]&&(this.parent.push(),this.parent.translate(a.getX(),this.labelsOffset),this.parent.rotate(-d),this.parent.text(a.getLabel(),0,0),this.parent.pop());else for(this.parent.textAlign(this.parent.CENTER,this.parent.TOP),b=0;b=0&&a.getX()<=this.dim[0]&&this.parent.text(a.getLabel(),a.getX(),this.labelsOffset);else if(this.rotateLabels)for(this.parent.textAlign(this.parent.CENTER,this.parent.BOTTOM),b=0;b=0&&-a.getY()<=this.dim[1]&&(this.parent.push(),this.parent.translate(-this.labelsOffset,a.getY()),this.parent.rotate(-d),this.parent.text(a.getLabel(),0,0),this.parent.pop());else for(this.parent.textAlign(this.parent.RIGHT,this.parent.CENTER),b=0;b=0&&-a.getY()<=this.dim[1]&&this.parent.text(a.getLabel(),-this.labelsOffset,a.getY());this.parent.pop()},GHistogram.prototype.setType=function(a){a===this.type||a!==GPlot.VERTICAL&&a!==GPlot.HORIZONTAL||(this.type=a,this.updateArrays())},GHistogram.prototype.setDim=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(1!==arguments.length)throw new Error("GHistogram.setDim(): signature not supported");a=arguments[0][0],b=arguments[0][1]}a>0&&b>0&&(this.dim[0]=a,this.dim[1]=b,this.updateArrays())},GHistogram.prototype.setPlotPoints=function(a){var b,c=a.length;if(this.plotPoints.length===c)for(b=0;bc){for(b=0;b0&&(this.fontSize=a)},GHistogram.prototype.setFontProperties=function(a,b,c){c>0&&(this.fontName=a,this.fontColor=b,this.fontSize=c)},GLayer.prototype.isValidNumber=function(a){return!isNaN(a)&&isFinite(a)},GLayer.prototype.isId=function(a){return this.id===a},GLayer.prototype.valueToXPlot=function(a){return this.xLog?this.dim[0]*Math.log(a/this.xLim[0])/Math.log(this.xLim[1]/this.xLim[0]):this.dim[0]*(a-this.xLim[0])/(this.xLim[1]-this.xLim[0])},GLayer.prototype.valueToYPlot=function(a){return this.yLog?-this.dim[1]*Math.log(a/this.yLim[0])/Math.log(this.yLim[1]/this.yLim[0]):-this.dim[1]*(a-this.yLim[0])/(this.yLim[1]-this.yLim[0])},GLayer.prototype.valueToPlot=function(){if(2===arguments.length)return[this.valueToXPlot(arguments[0]),this.valueToYPlot(arguments[1])];if(1===arguments.length&&arguments[0]instanceof GPoint)return new GPoint(this.valueToXPlot(arguments[0].getX()),this.valueToYPlot(arguments[0].getY()),arguments[0].getLabel());if(1===arguments.length&&arguments[0]instanceof Array&&arguments[0][0]instanceof GPoint){var a,b,c,d,e,f,g=arguments[0].length,h=[];if(this.xLog&&this.yLog)for(a=this.dim[0]/Math.log(this.xLim[1]/this.xLim[0]),b=-this.dim[1]/Math.log(this.yLim[1]/this.yLim[0]),f=0;fg&&this.plotPoints.splice(g,Number.MAX_VALUE);if(this.xLog&&this.yLog)for(a=this.dim[0]/Math.log(this.xLim[1]/this.xLim[0]),b=-this.dim[1]/Math.log(this.yLim[1]/this.yLim[0]),f=0;f=0&&a<=this.dim[0]&&-b>=0&&-b<=this.dim[1])},GLayer.prototype.updateInsideList=function(){for(var a,b=this.plotPoints.length,c=0;c=0&&a.getX()<=this.dim[0]&&-a.getY()>=0&&-a.getY()<=this.dim[1]);this.inside.length>b&&this.inside.splice(b,Number.MAX_VALUE)},GLayer.prototype.getPointIndexAtPlotPos=function(a,b){var c;if(this.isInside(a,b))for(var d,e,f=Number.MAX_VALUE,g=this.plotPoints.length,h=this.pointSizes.length,i=0;ithis.dim[0]&&f>this.dim[0]||-e<0&&-g<0||-e>this.dim[1]&&-g>this.dim[1])){var j=f-d,k=g-e;if(0===j)c=2,this.cuts[0][0]=d,this.cuts[0][1]=0,this.cuts[1][0]=d,this.cuts[1][1]=-this.dim[1];else if(0===k)c=2,this.cuts[0][0]=0,this.cuts[0][1]=e,this.cuts[1][0]=this.dim[0],this.cuts[1][1]=e;else{var l=k/j,m=e-l*d;c=4,this.cuts[0][0]=-m/l,this.cuts[0][1]=0,this.cuts[1][0]=(-this.dim[1]-m)/l,this.cuts[1][1]=-this.dim[1],this.cuts[2][0]=0,this.cuts[2][1]=m,this.cuts[3][0]=this.dim[0],this.cuts[3][1]=m+l*this.dim[0]}if(c=this.getValidCuts(this.cuts,c,a,b),h||i){if(1!==c){var n=h?a:b;c>1&&(c=this.removeDuplicatedCuts(this.cuts,c,0))>1&&(c=this.removePointFromCuts(this.cuts,c,n,0))>1&&(c=this.removeDuplicatedCuts(this.cuts,c,.001))>1&&(c=this.removePointFromCuts(this.cuts,c,n,.001)),0===c&&(c=1,this.cuts[0][0]=n.getX(),this.cuts[0][1]=n.getY())}}else c>2&&(c=this.removeDuplicatedCuts(this.cuts,c,0))>2&&(c=this.removeDuplicatedCuts(this.cuts,c,.001)),2===c&&(Math.pow(this.cuts[0][0]-d,2),Math.pow(this.cuts[0][1]-e),2>Math.pow(this.cuts[1][0]-d,2)+Math.pow(this.cuts[1][1]-e,2)&&(this.cuts[2][0]=this.cuts[0][0],this.cuts[2][1]=this.cuts[0][1],this.cuts[0][0]=this.cuts[1][0],this.cuts[0][1]=this.cuts[1][1],this.cuts[1][0]=this.cuts[2][0],this.cuts[1][1]=this.cuts[2][1])),1===c&&(c=2,this.cuts[1][0]=this.cuts[0][0],this.cuts[1][1]=this.cuts[0][1]);(h||i)&&1!==c?console.log("There should be one cut!!!"):h||i||0===c||2===c||console.log("There should be either 0 or 2 cuts!!! "+c+" were found")}}return c},GLayer.prototype.getValidCuts=function(a,b,c,d){for(var e=c.getX(),f=c.getY(),g=d.getX(),h=d.getY(),i=Math.abs(g-e),j=Math.abs(h-f),k=0,l=0;ld||Math.abs(a[h][1]-f)>d)&&(a[g][0]=a[h][0],a[g][1]=a[h][1],g++);return g},GLayer.prototype.startHistogram=function(a){this.hist=new GHistogram(this.parent,a,this.dim,this.plotPoints)},GLayer.prototype.drawPoints=function(){var a,b;if(0===arguments.length){a=this.plotPoints.length;var c=this.pointColors.length,d=this.pointSizes.length;if(this.parent.push(),this.parent.ellipseMode(this.parent.CENTER),this.parent.noStroke(),1===c&&1===d)for(this.parent.fill(this.pointColors[0]),b=0;b=2&&this.parent.line(this.cuts[0][0],this.cuts[0][1],this.cuts[1][0],this.cuts[1][1])}this.parent.pop()},GLayer.prototype.drawLine=function(){var a,b,c,d,e,f;if(4===arguments.length&&arguments[0]instanceof GPoint)a=arguments[0],b=arguments[1],c=arguments[2],d=arguments[3];else if(4===arguments.length)e=arguments[0],f=arguments[1],c=arguments[2],d=arguments[3];else if(2===arguments.length&&arguments[0]instanceof GPoint)a=arguments[0],b=arguments[1],c=this.lineColor,d=this.lineWidth;else{if(2!==arguments.length)throw new Error("GLayer.drawLine(): signature not supported");e=arguments[0],f=arguments[1],c=this.lineColor,d=this.lineWidth}void 0!==e&&(this.xLog&&this.yLog?(a=new GPoint(this.xLim[0],Math.pow(10,e*Math.log(this.xLim[0])/Math.LN10+f)),b=new GPoint(this.xLim[1],Math.pow(10,e*Math.log(this.xLim[1])/Math.LN10+f))):this.xLog?(a=new GPoint(this.xLim[0],e*Math.log(this.xLim[0])/Math.LN10+f),b=new GPoint(this.xLim[1],e*Math.log(this.xLim[1])/Math.LN10+f)):this.yLog?(a=new GPoint(this.xLim[0],Math.pow(10,e*this.xLim[0]+f)),b=new GPoint(this.xLim[1],Math.pow(10,e*this.xLim[1]+f))):(a=new GPoint(this.xLim[0],e*this.xLim[0]+f),b=new GPoint(this.xLim[1],e*this.xLim[1]+f)));var g=this.valueToPlot(a),h=this.valueToPlot(b);if(g.isValid()&&h.isValid()){var i=this.isInside(g),j=this.isInside(h);if(this.parent.push(),this.parent.noFill(),this.parent.stroke(c),this.parent.strokeWeight(d),this.parent.strokeCap(this.parent.SQUARE),i&&j)this.parent.line(g.getX(),g.getY(),h.getX(),h.getY());else{var k=this.obtainBoxIntersections(g,h);i?this.parent.line(g.getX(),g.getY(),this.cuts[0][0],this.cuts[0][1]):j?this.parent.line(this.cuts[0][0],this.cuts[0][1],h.getX(),h.getY()):k>=2&&this.parent.line(this.cuts[0][0],this.cuts[0][1],this.cuts[1][0],this.cuts[1][1])}this.parent.pop()}},GLayer.prototype.drawHorizontalLine=function(){var a,b,c;if(3===arguments.length)a=arguments[0],b=arguments[1],c=arguments[2];else{if(1!==arguments.length)throw new Error("GLayer.drawHorizontalLine(): signature not supported");a=arguments[0],b=this.lineColor,c=this.lineWidth}var d=this.valueToYPlot(a);this.isValidNumber(d)&&-d>=0&&-d<=this.dim[1]&&(this.parent.push(),this.parent.noFill(),this.parent.stroke(b),this.parent.strokeWeight(c),this.parent.strokeCap(this.parent.SQUARE),this.parent.line(0,d,this.dim[0],d),this.parent.pop())},GLayer.prototype.drawVerticalLine=function(){var a,b,c;if(3===arguments.length)a=arguments[0],b=arguments[1],c=arguments[2];else{if(1!==arguments.length)throw new Error("GLayer.drawVerticalLine(): signature not supported");a=arguments[0],b=this.lineColor,c=this.lineWidth}var d=this.valueToXPlot(a);this.isValidNumber(d)&&d>=0&&d<=this.dim[0]&&(this.parent.push(),this.parent.noFill(),this.parent.stroke(b),this.parent.strokeWeight(c),this.parent.strokeCap(this.parent.SQUARE),this.parent.line(d,0,d,-this.dim[1]),this.parent.pop())},GLayer.prototype.drawFilledContour=function(a,b){var c;if(a===GPlot.HORIZONTAL?c=this.getHorizontalShape(b):a===GPlot.VERTICAL&&(c=this.getVerticalShape(b)),void 0!==c&&c.length>0){this.parent.push(),this.parent.fill(this.lineColor),this.parent.noStroke(),this.parent.beginShape();for(var d=0;d=0&&b.getX()<=this.dim[0]&&(-b.getY()<0?(f.push(new GPoint(b.getX(),0,"projection")),c=!0):(f.push(new GPoint(b.getX(),-this.dim[1],"projection")),c=!0)),d=i+1;d0){var l=new GPoint(f[0]);if(0!==l.getX()&&l.getX()!==this.dim[0])if("cut"===l.getLabel())this.plotPoints[g].getX()<0?(l.setX(0),l.setLabel("extreme")):(l.setX(this.dim[0]),l.setLabel("extreme"));else if(0!==g){for(var m=g-1;m>0&&!this.plotPoints[m].isValid();)m--;this.plotPoints[m].isValid()&&(this.plotPoints[m].getX()<0?(l.setX(0),l.setLabel("extreme")):(l.setX(this.dim[0]),l.setLabel("extreme")))}var n=new GPoint(f[f.length-1]);if(0!==n.getX()&&n.getX()!==this.dim[0]&&h!==e-1){for(d=h+1;dthis.dim[1]?(f.push(new GPoint(n.getX(),-this.dim[1])),f.push(new GPoint(l.getX(),-this.dim[1]))):(f.push(new GPoint(n.getX(),o[1])),f.push(new GPoint(l.getX(),o[1]))),"extreme"===l.getLabel()&&f.push(l)}return f},GLayer.prototype.getVerticalShape=function(a){for(var b,c,d,e=this.plotPoints.length,f=[],g=-1,h=-1,i=0;i=0&&-b.getY()<=this.dim[1]&&(b.getX()<0?(f.push(new GPoint(0,b.getY(),"projection")),c=!0):(f.push(new GPoint(this.dim[0],b.getY(),"projection")),c=!0)),d=i+1;d0){var l=new GPoint(f[0]);if(0!==l.getY()&&l.getY()!==-this.dim[1])if("cut"===l.getLabel())-this.plotPoints[g].getY()<0?(l.setY(0),l.setLabel("extreme")):(l.setY(-this.dim[1]),l.setLabel("extreme"));else if(0!==g){for(var m=g-1;m>0&&!this.plotPoints[m].isValid();)m--;this.plotPoints[m].isValid()&&(-this.plotPoints[m].getY()<0?(l.setY(0),l.setLabel("extreme")):(l.setY(-this.dim[1]),l.setLabel("extreme")))}var n=new GPoint(f[f.length-1]);if(0!==n.getY()&&n.getY()!==-this.dim[1]&&h!==e-1){for(d=h+1;dthis.dim[0]?(f.push(new GPoint(this.dim[0],n.getY())),f.push(new GPoint(this.dim[0],l.getY()))):(f.push(new GPoint(o[0],n.getY())),f.push(new GPoint(o[0],l.getY()))),"extreme"===l.getLabel()&&f.push(l)}return f},GLayer.prototype.drawLabel=function(a){var b=this.valueToXPlot(a.getX()),c=this.valueToYPlot(a.getY());if(this.isValidNumber(b)&&this.isValidNumber(c)){var d=b+this.labelSeparation[0],e=c-this.labelSeparation[1],f=this.fontSize/4;this.parent.push(),this.parent.rectMode(this.parent.CORNER),this.parent.noStroke(),this.parent.textFont(this.fontName),this.parent.textSize(this.fontSize),this.parent.textAlign(this.parent.LEFT,this.parent.BOTTOM),this.parent.fill(this.labelBgColor),this.parent.rect(d-f,e-this.fontSize-f,this.parent.textWidth(a.getLabel())+2*f,this.fontSize+2*f),this.parent.fill(this.fontColor),this.parent.text(a.getLabel(),d,e),this.parent.pop()}},GLayer.prototype.drawLabelAtPlotPos=function(a,b){var c=this.getPointAtPlotPos(a,b);void 0!==c&&this.drawLabel(c)},GLayer.prototype.drawHistogram=function(){void 0!==this.hist&&this.hist.draw(this.valueToPlot(this.histBasePoint))},GLayer.prototype.drawPolygon=function(a,b){var c;if(a.length>2){var d=this.valueToPlot(a),e=0;for(c=0;c1&&(h.push(new GPoint(this.cuts[0][0],this.cuts[0][1],"double cut")),h.push(new GPoint(this.cuts[1][0],this.cuts[1][1],"double cut")))}g=h.length;var k=[];for(c=0;c0&&t>0&&s!==this.dim[0]&&t!==this.dim[1]){var u=0===o||o===this.dim[0]?o:q,v=0===p||p===-this.dim[1]?p:r;k.push(new GPoint(u,v,"special cut"))}}}if(k.length>2){for(this.parent.push(),this.parent.fill(b),this.parent.noStroke(),this.parent.beginShape(),c=0;c0&&b>0&&(this.dim[0]=a,this.dim[1]=b,this.updatePlotPoints(),void 0!==this.hist&&(this.hist.setDim(this.dim),this.hist.setPlotPoints(this.plotPoints)))},GLayer.prototype.setXLim=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(1!==arguments.length)throw new Error("GLayer.setXLim(): signature not supported");a=arguments[0][0],b=arguments[0][1]}a!==b&&this.isValidNumber(a)&&this.isValidNumber(b)&&(this.xLog&&(a<=0||b<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.xLim[0]=a,this.xLim[1]=b,this.updatePlotPoints(),this.updateInsideList(),void 0!==this.hist&&this.hist.setPlotPoints(this.plotPoints)))},GLayer.prototype.setYLim=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(1!==arguments.length)throw new Error("GLayer.setYLim(): signature not supported");a=arguments[0][0],b=arguments[0][1]}a!==b&&this.isValidNumber(a)&&this.isValidNumber(b)&&(this.yLog&&(a<=0||b<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.yLim[0]=a,this.yLim[1]=b,this.updatePlotPoints(),this.updateInsideList(),void 0!==this.hist&&this.hist.setPlotPoints(this.plotPoints)))},GLayer.prototype.setXYLim=function(){var a,b,c,d;if(4===arguments.length)a=arguments[0],b=arguments[1],c=arguments[2],d=arguments[3];else{if(2!==arguments.length)throw new Error("GLayer.setXYLim(): signature not supported");a=arguments[0][0],b=arguments[0][1],c=arguments[1][0],d=arguments[1][1]}a!==b&&c!==d&&this.isValidNumber(a)&&this.isValidNumber(b)&&this.isValidNumber(c)&&this.isValidNumber(d)&&(this.xLog&&(a<=0||b<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.xLim[0]=a,this.xLim[1]=b),this.yLog&&(c<=0||d<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.yLim[0]=c,this.yLim[1]=d),this.updatePlotPoints(),this.updateInsideList(),void 0!==this.hist&&this.hist.setPlotPoints(this.plotPoints))},GLayer.prototype.setLimAndLog=function(){var a,b,c,d,e,f;if(6===arguments.length)a=arguments[0],b=arguments[1],c=arguments[2],d=arguments[3],e=arguments[4],f=arguments[5];else{if(4!==arguments.length)throw new Error("GLayer.setLimAndLog(): signature not supported");a=arguments[0][0],b=arguments[0][1],c=arguments[1][0],d=arguments[1][1],e=arguments[2],f=arguments[3]}a!==b&&c!==d&&this.isValidNumber(a)&&this.isValidNumber(b)&&this.isValidNumber(c)&&this.isValidNumber(d)&&(e&&(a<=0||b<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.xLim[0]=a,this.yLim[1]=b,this.xLog=e),f&&(c<=0||d<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.yLim[0]=c,this.yLim[1]=d,this.yLog=f),this.updatePlotPoints(),this.updateInsideList(),void 0!==this.hist&&this.hist.setPlotPoints(this.plotPoints))},GLayer.prototype.setXLog=function(a){a!==this.xLog&&(a&&(this.xLim[0]<=0||this.xLim[1]<=0)&&(console.log("One of the limits is negative. This is not allowed in logarithmic scale."),console.log("Will set horizontal limits to (0.1, 10)"),this.xLim[0]=.1,this.xLim[1]=10),this.xLog=a,this.updatePlotPoints(),this.updateInsideList(),void 0!==this.hist&&this.hist.setPlotPoints(this.plotPoints))},GLayer.prototype.setYLog=function(a){a!==this.yLog&&(a&&(this.yLim[0]<=0||this.yLim[1]<=0)&&(console.log("One of the limits is negative. This is not allowed in logarithmic scale."),console.log("Will set horizontal limits to (0.1, 10)"),this.yLim[0]=.1,this.yLim[1]=10),this.yLog=a,this.updatePlotPoints(),this.updateInsideList(),void 0!==this.hist&&this.hist.setPlotPoints(this.plotPoints))},GLayer.prototype.setPoints=function(a){var b,c=a.length;if(this.points.length>c)this.points.splice(c,Number.MAX_VALUE);else for(b=this.points.length;b0&&(this.pointColors=a.slice())},GLayer.prototype.setPointColor=function(a){this.pointColors=[a]},GLayer.prototype.setPointSizes=function(a){a.length>0&&(this.pointSizes=a.slice())},GLayer.prototype.setPointSize=function(a){this.pointSizes=[a]},GLayer.prototype.setLineColor=function(a){this.lineColor=a},GLayer.prototype.setLineWidth=function(a){a>0&&(this.lineWidth=a)},GLayer.prototype.setHistBasePoint=function(a){this.histBasePoint.set(a)},GLayer.prototype.setHistType=function(a){void 0!==this.hist&&this.hist.setType(a)},GLayer.prototype.setHistVisible=function(a){void 0!==this.hist&&this.hist.setVisible(a)},GLayer.prototype.setDrawHistLabels=function(a){void 0!==this.hist&&this.hist.setDrawLabels(a)},GLayer.prototype.setLabelBgColor=function(a){this.labelBgColor=a},GLayer.prototype.setLabelSeparation=function(a){this.labelSeparation[0]=a[0],this.labelSeparation[1]=a[1]},GLayer.prototype.setFontName=function(a){this.fontName=a},GLayer.prototype.setFontColor=function(a){this.fontColor=a},GLayer.prototype.setFontSize=function(a){a>0&&(this.fontSize=a)},GLayer.prototype.setFontProperties=function(a,b,c){c>0&&(this.fontName=a,this.fontColor=b,this.fontSize=c)},GLayer.prototype.setAllFontProperties=function(a,b,c){this.setFontProperties(a,b,c),void 0!==this.hist&&this.hist.setFontProperties(a,b,c)},GLayer.prototype.getId=function(){return this.id},GLayer.prototype.getDim=function(){return this.dim.slice()},GLayer.prototype.getXLim=function(){return this.xLim.slice()},GLayer.prototype.getYLim=function(){return this.yLim.slice()},GLayer.prototype.getXLog=function(){return this.xLog},GLayer.prototype.getYLog=function(){return this.yLog},GLayer.prototype.getPoints=function(){for(var a=[],b=0;b=this.pos[0]&&a<=this.pos[0]+this.outerDim[0]&&b>=this.pos[1]&&b<=this.pos[1]+this.outerDim[1]},GPlot.prototype.isOverBox=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(0!==arguments.length)throw new Error("GPlot.isOverBox(): signature not supported");a=this.parent.mouseX,b=this.parent.mouseY}return a>=this.pos[0]+this.mar[1]&&a<=this.pos[0]+this.outerDim[0]-this.mar[3]&&b>=this.pos[1]+this.mar[2]&&b<=this.pos[1]+this.outerDim[1]-this.mar[0]},GPlot.prototype.updateLimits=function(){this.fixedXLim||(this.xLim=this.calculatePlotXLim(),this.xAxis.setLim(this.xLim),this.topAxis.setLim(this.xLim)),this.fixedYLim||(this.yLim=this.calculatePlotYLim(),this.yAxis.setLim(this.yLim),this.rightAxis.setLim(this.yLim)),this.mainLayer.setXYLim(this.xLim,this.yLim);for(var a=0;a=this.yLim[0]&&e>=this.yLim[0]&&e<=this.yLim[1]||this.yLim[1]=this.yLim[1]),!f||this.xLog&&d<=0||(db[1]&&(b[1]=d))}return b[1]=this.xLim[0]&&d>=this.xLim[0]&&d<=this.xLim[1]||this.xLim[1]=this.xLim[1]),!f||this.yLog&&e<=0||(eb[1]&&(b[1]=e))}return b[1]=0&&c[b]<=this.dim[0]&&this.parent.line(c[b],0,c[b],-this.dim[1])}if(a===GPlot.BOTH||a===GPlot.HORIZONTAL){var d=this.yAxis.getPlotTicksRef();for(b=0;b=0&&-d[b]<=this.dim[1]&&this.parent.line(0,d[b],this.dim[0],d[b])}this.parent.pop()},GPlot.prototype.drawHistograms=function(){this.mainLayer.drawHistogram();for(var a=0;a0&&b>0){var c=a-this.mar[1]-this.mar[3],d=b-this.mar[0]-this.mar[2];if(c>0&&d>0){this.outerDim[0]=a,this.outerDim[1]=b,this.dim[0]=c,this.dim[1]=d,this.xAxis.setDim(this.dim),this.topAxis.setDim(this.dim),this.yAxis.setDim(this.dim),this.rightAxis.setDim(this.dim),this.title.setDim(this.dim),this.mainLayer.setDim(this.dim);for(var e=0;e0&&f>0&&(this.mar[0]=a,this.mar[1]=b,this.mar[2]=c,this.mar[3]=d,this.outerDim[0]=e,this.outerDim[1]=f)},GPlot.prototype.setDim=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(1!==arguments.length)throw new Error("GPlot.setDim(): signature not supported");a=arguments[0][0],b=arguments[0][1]}if(a>0&&b>0){var c=a+this.mar[1]+this.mar[3],d=b+this.mar[0]+this.mar[2];if(c>0&&d>0){this.outerDim[0]=c,this.outerDim[1]=d,this.dim[0]=a,this.dim[1]=b,this.xAxis.setDim(this.dim),this.topAxis.setDim(this.dim),this.yAxis.setDim(this.dim),this.rightAxis.setDim(this.dim),this.title.setDim(this.dim),this.mainLayer.setDim(this.dim);for(var e=0;ethis.xLim[1],this.fixedXLim=!0,this.xAxis.setLim(this.xLim),this.topAxis.setLim(this.xLim),this.updateLimits()))},GPlot.prototype.setYLim=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(1!==arguments.length)throw new Error("GPlot.setYLim(): signature not supported");a=arguments[0][0],b=arguments[0][1]}a!==b&&(this.yLog&&(a<=0||b<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.yLim[0]=a,this.yLim[1]=b,this.invertedYScale=this.yLim[0]>this.yLim[1],this.fixedYLim=!0,this.yAxis.setLim(this.yLim),this.rightAxis.setLim(this.yLim),this.updateLimits()))},GPlot.prototype.setFixedXLim=function(a){this.fixedXLim=a,this.updateLimits()},GPlot.prototype.setFixedYLim=function(a){this.fixedYLim=a,this.updateLimits()},GPlot.prototype.setLogScale=function(a){var b=this.xLog,c=this.yLog;if("xy"===a||"yx"===a?(b=!0,c=!0):"x"===a?(b=!0,c=!1):"y"===a?(b=!1,c=!0):""===a&&(b=!1,c=!1),b!==this.xLog||c!==this.yLog){this.xLog=b,this.yLog=c,this.xLog&&this.fixedXLim&&(this.xLim[0]<=0||this.xLim[1]<=0)&&(this.fixedXLim=!1),this.yLog&&this.fixedYLim&&(this.yLim[0]<=0||this.yLim[1]<=0)&&(this.fixedYLim=!1),this.fixedXLim||(this.xLim=this.calculatePlotXLim()),this.fixedYLim||(this.yLim=this.calculatePlotYLim()),this.xAxis.setLimAndLog(this.xLim,this.xLog),this.topAxis.setLimAndLog(this.xLim,this.xLog),this.yAxis.setLimAndLog(this.yLim,this.yLog),this.rightAxis.setLimAndLog(this.yLim,this.yLog),this.mainLayer.setLimAndLog(this.xLim,this.yLim,this.xLog,this.yLog);for(var d=0;d=0&&a!==this.expandLimFactor&&(this.expandLimFactor=a,this.updateLimits())},GPlot.prototype.setBgColor=function(a){this.bgColor=a},GPlot.prototype.setBoxBgColor=function(a){this.boxBgColor=a},GPlot.prototype.setBoxLineColor=function(a){this.boxLineColor=a},GPlot.prototype.setBoxLineWidth=function(a){a>0&&(this.boxLineWidth=a)},GPlot.prototype.setGridLineColor=function(a){this.gridLineColor=a},GPlot.prototype.setGridLineWidth=function(a){a>0&&(this.gridLineWidth=a)},GPlot.prototype.setPoints=function(){if(2===arguments.length)this.getLayer(arguments[1]).setPoints(arguments[0]);else{if(1!==arguments.length)throw new Error("GPlot.setPoints(): signature not supported");this.mainLayer.setPoints(arguments[0])}this.updateLimits()},GPlot.prototype.setPoint=function(){if(5===arguments.length)this.getLayer(arguments[4]).setPoint(arguments[0],arguments[1],arguments[2],arguments[3]);else if(4===arguments.length)this.mainLayer.setPoint(arguments[0],arguments[1],arguments[2],arguments[3]);else if(3===arguments.length&&arguments[1]instanceof GPoint)this.getLayer(arguments[2]).setPoint(arguments[0],arguments[1]);else if(3===arguments.length)this.mainLayer.setPoint(arguments[0],arguments[1],arguments[2]);else{if(2!==arguments.length)throw new Error("GPlot.setPoint(): signature not supported");this.mainLayer.setPoint(arguments[0],arguments[1])}this.updateLimits()},GPlot.prototype.addPoint=function(){if(4===arguments.length)this.getLayer(arguments[3]).addPoint(arguments[0],arguments[1],arguments[2]);else if(3===arguments.length)this.mainLayer.addPoint(arguments[0],arguments[1],arguments[2]);else if(2===arguments.length&&arguments[0]instanceof GPoint)this.getLayer(arguments[1]).addPoint(arguments[0]);else if(2===arguments.length)this.mainLayer.addPoint(arguments[0],arguments[1]);else{if(1!==arguments.length)throw new Error("GPlot.addPoint(): signature not supported");this.mainLayer.addPoint(arguments[0])}this.updateLimits()},GPlot.prototype.addPoints=function(){if(2===arguments.length)this.getLayer(arguments[1]).addPoints(arguments[0]);else{if(1!==arguments.length)throw new Error("GPlot.addPoints(): signature not supported");this.mainLayer.addPoints(arguments[0])}this.updateLimits()},GPlot.prototype.removePoint=function(){if(2===arguments.length)this.getLayer(arguments[1]).removePoint(arguments[0]);else{if(1!==arguments.length)throw new Error("GPlot.removePoint(): signature not supported");this.mainLayer.removePoint(arguments[0])}this.updateLimits()},GPlot.prototype.addPointAtIndexPos=function(){if(5===arguments.length)this.getLayer(arguments[4]).addPointAtIndexPos(arguments[0],arguments[1],arguments[2],arguments[3]);else if(4===arguments.length)this.mainLayer.addPointAtIndexPos(arguments[0],arguments[1],arguments[2],arguments[3]);else if(3===arguments.length&&arguments[1]instanceof GPoint)this.getLayer(arguments[2]).addPointAtIndexPos(arguments[0],arguments[1]);else if(3===arguments.length)this.mainLayer.addPointAtIndexPos(arguments[0],arguments[1],arguments[2]);else{if(2!==arguments.length)throw new Error("GPlot.addPointAtIndexPos(): signature not supported");this.mainLayer.addPointAtIndexPos(arguments[0],arguments[1])}this.updateLimits()},GPlot.prototype.setPointColors=function(a){this.mainLayer.setPointColors(a)},GPlot.prototype.setPointColor=function(a){this.mainLayer.setPointColor(a)},GPlot.prototype.setPointSizes=function(a){this.mainLayer.setPointSizes(a)},GPlot.prototype.setPointSize=function(a){this.mainLayer.setPointSize(a)},GPlot.prototype.setLineColor=function(a){this.mainLayer.setLineColor(a)},GPlot.prototype.setLineWidth=function(a){this.mainLayer.setLineWidth(a)},GPlot.prototype.setHistBasePoint=function(a){this.mainLayer.setHistBasePoint(a)},GPlot.prototype.setHistType=function(a){this.mainLayer.setHistType(a)},GPlot.prototype.setHistVisible=function(a){this.mainLayer.setHistVisible(a)},GPlot.prototype.setDrawHistLabels=function(a){this.mainLayer.setDrawHistLabels(a)},GPlot.prototype.setLabelBgColor=function(a){this.mainLayer.setLabelBgColor(a)},GPlot.prototype.setLabelSeparation=function(a){this.mainLayer.setLabelSeparation(a)},GPlot.prototype.setTitleText=function(a){this.title.setText(a)},GPlot.prototype.setAxesOffset=function(a){this.xAxis.setOffset(a),this.topAxis.setOffset(a),this.yAxis.setOffset(a),this.rightAxis.setOffset(a)},GPlot.prototype.setTicksLength=function(a){this.xAxis.setTickLength(a),this.topAxis.setTickLength(a),this.yAxis.setTickLength(a),this.rightAxis.setTickLength(a)},GPlot.prototype.setHorizontalAxesNTicks=function(a){this.xAxis.setNTicks(a),this.topAxis.setNTicks(a)},GPlot.prototype.setHorizontalAxesTicksSeparation=function(a){this.xAxis.setTicksSeparation(a),this.topAxis.setTicksSeparation(a)},GPlot.prototype.setHorizontalAxesTicks=function(a){this.xAxis.setTicks(a),this.topAxis.setTicks(a)},GPlot.prototype.setVerticalAxesNTicks=function(a){this.yAxis.setNTicks(a),this.rightAxis.setNTicks(a)},GPlot.prototype.setVerticalAxesTicksSeparation=function(a){this.yAxis.setTicksSeparation(a),this.rightAxis.setTicksSeparation(a)},GPlot.prototype.setVerticalAxesTicks=function(a){this.yAxis.setTicks(a),this.rightAxis.setTicks(a)},GPlot.prototype.setFontName=function(a){this.mainLayer.setFontName(a)},GPlot.prototype.setFontColor=function(a){this.mainLayer.setFontColor(a)},GPlot.prototype.setFontSize=function(a){this.mainLayer.setFontSize(a)},GPlot.prototype.setFontProperties=function(a,b,c){this.mainLayer.setFontProperties(a,b,c)},GPlot.prototype.setAllFontProperties=function(a,b,c){this.xAxis.setAllFontProperties(a,b,c),this.topAxis.setAllFontProperties(a,b,c),this.yAxis.setAllFontProperties(a,b,c),this.rightAxis.setAllFontProperties(a,b,c),this.title.setFontProperties(a,b,c),this.mainLayer.setAllFontProperties(a,b,c);for(var d=0;d0&&(this.zoomFactor=a),b!==this.parent.LEFT&&b!==this.parent.RIGHT&&b!==this.parent.CENTER||(this.increaseZoomButton=b),c!==this.parent.LEFT&&c!==this.parent.RIGHT&&c!==this.parent.CENTER||(this.decreaseZoomButton=c),d!==this.parent.SHIFT&&d!==this.parent.CONTROL&&d!==this.parent.ALT&&d!==GPlot.NONE||(this.increaseZoomKeyModifier=d),e!==this.parent.SHIFT&&e!==this.parent.CONTROL&&e!==this.parent.ALT&&e!==GPlot.NONE||(this.decreaseZoomKeyModifier=e)},GPlot.prototype.deactivateZooming=function(){this.zoomingIsActive=!1},GPlot.prototype.activateCentering=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else if(1===arguments.length)a=arguments[0],b=GPlot.NONE;else{if(0!==arguments.length)throw new Error("GPlot.activateCentering(): signature not supported");a=this.parent.LEFT,b=GPlot.NONE}this.centeringIsActive=!0,a!==this.parent.LEFT&&a!==this.parent.RIGHT&&a!==this.parent.CENTER||(this.centeringButton=a),b!==this.parent.SHIFT&&b!==this.parent.CONTROL&&b!==this.parent.ALT&&b!==GPlot.NONE||(this.centeringKeyModifier=b)},GPlot.prototype.deactivateCentering=function(){this.centeringIsActive=!1},GPlot.prototype.activatePanning=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else if(1===arguments.length)a=arguments[0],b=GPlot.NONE;else{if(0!==arguments.length)throw new Error("GPlot.activatePanning(): signature not supported");a=this.parent.LEFT,b=GPlot.NONE}this.panningIsActive=!0,a!==this.parent.LEFT&&a!==this.parent.RIGHT&&a!==this.parent.CENTER||(this.panningButton=a),b!==this.parent.SHIFT&&b!==this.parent.CONTROL&&b!==this.parent.ALT&&b!==GPlot.NONE||(this.panningKeyModifier=b)},GPlot.prototype.deactivatePanning=function(){this.panningIsActive=!1,this.panningReferencePoint=void 0},GPlot.prototype.activatePointLabels=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else if(1===arguments.length)a=arguments[0],b=GPlot.NONE;else{if(0!==arguments.length)throw new Error("GPlot.activatePointLabels(): signature not supported");a=this.parent.LEFT,b=GPlot.NONE}this.labelingIsActive=!0,a!==this.parent.LEFT&&a!==this.parent.RIGHT&&a!==this.parent.CENTER||(this.labelingButton=a),b!==this.parent.SHIFT&&b!==this.parent.CONTROL&&b!==this.parent.ALT&&b!==GPlot.NONE||(this.labelingKeyModifier=b)},GPlot.prototype.deactivatePointLabels=function(){this.labelingIsActive=!1,this.mousePos=void 0},GPlot.prototype.activateReset=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else if(1===arguments.length)a=arguments[0],b=GPlot.NONE;else{if(0!==arguments.length)throw new Error("GPlot.activateReset(): signature not supported");a=this.parent.RIGHT,b=GPlot.NONE}this.resetIsActive=!0,this.xLimReset=void 0,this.yLimReset=void 0,a!==this.parent.LEFT&&a!==this.parent.RIGHT&&a!==this.parent.CENTER||(this.resetButton=a),b!==this.parent.SHIFT&&b!==this.parent.CONTROL&&b!==this.parent.ALT&&b!==GPlot.NONE||(this.resetKeyModifier=b)},GPlot.prototype.deactivateReset=function(){this.resetIsActive=!1,this.xLimReset=void 0,this.yLimReset=void 0},GPlot.prototype.getButton=function(a){var b;return 0===a.button?b=this.parent.LEFT:1===a.button?b=this.parent.CENTER:2===a.button?b=this.parent.RIGHT:void 0===a.button&&(b=this.parent.LEFT),b},GPlot.prototype.getModifier=function(a){return a.altKey?this.parent.ALT:a.ctrlKey?this.parent.CONTROL:a.shiftKey?this.parent.SHIFT:GPlot.NONE},GPlot.prototype.saveResetLimits=function(){void 0!==this.xLimReset&&void 0!==this.yLimReset||(this.xLimReset=this.xLim.slice(),this.yLimReset=this.yLim.slice())},GPlot.prototype.clickEvent=function(a){var b=a||window.event;if(this.isOverBox()){var c=this.getButton(b),d=this.getModifier(b);this.zoomingIsActive&&(c===this.increaseZoomButton&&d===this.increaseZoomKeyModifier?(this.resetIsActive&&this.saveResetLimits(),this.zoom(this.zoomFactor,this.parent.mouseX,this.parent.mouseY)):c===this.decreaseZoomButton&&d===this.decreaseZoomKeyModifier&&(this.resetIsActive&&this.saveResetLimits(),this.zoom(1/this.zoomFactor,this.parent.mouseX,this.parent.mouseY))), this.centeringIsActive&&c===this.centeringButton&&d===this.centeringKeyModifier&&(this.resetIsActive&&this.saveResetLimits(),this.center(this.parent.mouseX,this.parent.mouseY)),this.resetIsActive&&c===this.resetButton&&d===this.resetKeyModifier&&void 0!==this.xLimReset&&void 0!==this.yLimReset&&(this.setXLim(this.xLimReset),this.setYLim(this.yLimReset),this.xLimReset=void 0,this.yLimReset=void 0)}},GPlot.prototype.wheelEvent=function(a){var b=a||window.event;if(this.isOverBox()){var c=b.deltaY,d=this.parent.CENTER,e=this.getModifier(b);this.zoomingIsActive&&(d===this.increaseZoomButton&&e===this.increaseZoomKeyModifier&&c>0?(b.preventDefault(),this.resetIsActive&&this.saveResetLimits(),this.zoom(this.zoomFactor,this.parent.mouseX,this.parent.mouseY)):d===this.decreaseZoomButton&&e===this.decreaseZoomKeyModifier&&c<0&&(b.preventDefault(),this.resetIsActive&&this.saveResetLimits(),this.zoom(1/this.zoomFactor,this.parent.mouseX,this.parent.mouseY)))}},GPlot.prototype.mouseDownEvent=function(a){var b=a||window.event;if(this.isOverBox()){var c=!1,d=this.getButton(b),e=this.getModifier(b);this.panningIsActive&&d===this.panningButton&&e===this.panningKeyModifier&&(c=!0,this.resetIsActive&&this.saveResetLimits(),this.panningReferencePoint=this.getValueAt(this.parent.mouseX,this.parent.mouseY)),this.labelingIsActive&&d===this.labelingButton&&e===this.labelingKeyModifier&&(c=!0,this.mousePos=[this.parent.mouseX,this.parent.mouseY]),c&&(document.addEventListener("mousemove",this.mouseMoveListener,!1),document.addEventListener("mouseup",this.mouseUpListener,!1))}},GPlot.prototype.mouseMoveEvent=function(a){var b=a||window.event,c=this.getButton(b),d=this.getModifier(b);a.preventDefault(),this.panningIsActive&&c===this.panningButton&&d===this.panningKeyModifier&&this.align(this.panningReferencePoint,this.parent.mouseX,this.parent.mouseY),this.labelingIsActive&&c===this.labelingButton&&d===this.labelingKeyModifier&&(this.mousePos=[this.parent.mouseX,this.parent.mouseY])},GPlot.prototype.mouseUpEvent=function(a){var b=a||window.event,c=this.getButton(b);document.removeEventListener("mousemove",this.mouseMoveListener,!1),document.removeEventListener("mouseup",this.mouseUpListener,!1),this.panningIsActive&&c===this.panningButton&&(this.panningReferencePoint=void 0),this.labelingIsActive&&c===this.labelingButton&&(this.mousePos=void 0)},GPlot.prototype.touchStartEvent=function(a){var b=a||window.event;if(this.parent._ontouchstart(b),this.isOverBox()){var c=!1;if(this.panningIsActive&&(c=!0,this.panningReferencePoint=this.getValueAt(this.parent.mouseX,this.parent.mouseY)),this.labelingIsActive&&(c=!0,this.mousePos=[this.parent.mouseX,this.parent.mouseY]),this.zoomingIsActive&&void 0!==b.touches&&2===b.touches.length){c=!0;var d=b.touches[0].pageX-b.touches[1].pageX,e=b.touches[0].pageY-b.touches[1].pageY;this.zoomStartDistance=Math.sqrt(d*d+e*e),this.zoomStartPosition=[this.parent.mouseX,this.parent.mouseY]}c&&(document.addEventListener("touchmove",this.touchMoveListener,{passive:!1}),document.addEventListener("touchend",this.touchEndListener,!1),document.addEventListener("touchcancel",this.touchEndListener,!1))}},GPlot.prototype.touchMoveEvent=function(a){var b=a||window.event;if(b.preventDefault(),this.panningIsActive&&this.align(this.panningReferencePoint,this.parent.mouseX,this.parent.mouseY),this.labelingIsActive&&(this.mousePos=[this.parent.mouseX,this.parent.mouseY]),this.zoomingIsActive&&void 0!==b.touches&&2===b.touches.length){var c=b.touches[0].pageX-b.touches[1].pageX,d=b.touches[0].pageY-b.touches[1].pageY,e=Math.sqrt(c*c+d*d);this.zoom(e/this.zoomStartDistance,this.zoomStartPosition[0],this.zoomStartPosition[1]),this.zoomStartDistance=e}},GPlot.prototype.touchEndEvent=function(a){document.removeEventListener("touchmove",this.touchMoveListener,!1),document.removeEventListener("touchend",this.touchEndListener,!1),document.removeEventListener("touchcancel",this.touchEndListener,!1),this.panningIsActive&&(this.panningReferencePoint=void 0),this.labelingIsActive&&(this.mousePos=void 0),this.zoomingIsActive&&(this.zoomStartDistance=void 0,this.zoomStartPosition=void 0)},GPlot.prototype.preventDefaultEvent=function(a){var b=a||window.event;this.isOverBox()&&b.preventDefault()},GPlot.prototype.contextMenuEvent=function(a){var b=a||window.event;this.isOverBox()&&(b.preventDefault(),this.clickEvent(b))},GPlot.prototype.preventWheelDefault=function(){this.parentElt.addEventListener("wheel",this.preventDefaultEvent.bind(this),!1)},GPlot.prototype.preventRightClickDefault=function(){this.parentElt.addEventListener("contextmenu",this.contextMenuEvent.bind(this),!1)}; \ No newline at end of file diff --git a/releases/grafica.js b/releases/grafica.js index 364db4e..35f8fdd 100644 --- a/releases/grafica.js +++ b/releases/grafica.js @@ -1131,9 +1131,9 @@ GAxis.prototype.setNTicks = function(nTicks) { if (nTicks >= 0) { this.nTicks = nTicks; this.ticksSeparation = -1; + this.fixedTicks = false; if (!this.log) { - this.fixedTicks = false; this.updateTicks(); this.updatePlotTicks(); this.updateTicksInside(); @@ -1144,9 +1144,9 @@ GAxis.prototype.setNTicks = function(nTicks) { GAxis.prototype.setTicksSeparation = function(ticksSeparation) { this.ticksSeparation = ticksSeparation; + this.fixedTicks = false; if (!this.log) { - this.fixedTicks = false; this.updateTicks(); this.updatePlotTicks(); this.updateTicksInside(); @@ -3254,7 +3254,7 @@ GLayer.prototype.addPointAtIndexPos = function() { if (index <= this.points.length) { this.points.splice(index, 0, new GPoint(x, y, label)); this.plotPoints.splice(index, 0, new GPoint(this.valueToXPlot(x), this.valueToYPlot(y), label)); - this.inside.splice(index, 0, this.isInside(this.plotPoints[0])); + this.inside.splice(index, 0, this.isInside(this.plotPoints[index])); if ( typeof this.hist !== "undefined") { this.hist.setPlotPoints(this.plotPoints); @@ -3944,6 +3944,7 @@ GPlot.prototype.moveHorizontalAxesLim = function(delta) { // Fix the limits this.fixedXLim = true; + this.fixedYLim = true; // Move the horizontal axes this.xAxis.moveLim(this.xLim); @@ -3968,6 +3969,7 @@ GPlot.prototype.moveVerticalAxesLim = function(delta) { } // Fix the limits + this.fixedXLim = true; this.fixedYLim = true; // Move the vertical axes diff --git a/releases/grafica.min.js b/releases/grafica.min.js index 72dbf0c..ae54087 100644 --- a/releases/grafica.min.js +++ b/releases/grafica.min.js @@ -1,4 +1,4 @@ -/*! grafica.js (0.3.1): a library for p5.js. Author: Javier GraciĆ” Carpio, license: LGPL-3.0, 2018-09-26 */ function GPoint(){var a,b,c;if(3===arguments.length)a=arguments[0],b=arguments[1],c=arguments[2];else if(2===arguments.length&&arguments[0]instanceof p5.Vector)a=arguments[0].x,b=arguments[0].y,c=arguments[1];else if(2===arguments.length)a=arguments[0],b=arguments[1],c="";else if(1===arguments.length&&arguments[0]instanceof GPoint)a=arguments[0].getX(),b=arguments[0].getY(),c=arguments[0].getLabel();else if(1===arguments.length&&arguments[0]instanceof p5.Vector)a=arguments[0].x,b=arguments[0].y,c="";else{if(0!==arguments.length)throw new Error("GPoint constructor: signature not supported");a=0,b=0,c=""}this.x=a,this.y=b,this.label=c,this.valid=this.isValidNumber(this.x)&&this.isValidNumber(this.y)}function GTitle(a,b){this.parent=a,this.dim=b.slice(),this.relativePos=.5,this.plotPos=this.relativePos*this.dim[0],this.offset=10,this.text="",this.textAlignment=this.parent.CENTER,this.fontName="Helvetica",this.fontColor=this.parent.color(100),this.fontStyle=this.parent.BOLD,this.fontSize=13}function GAxisLabel(a,b,c){this.parent=a,this.type=b===this.parent.BOTTOM||b===this.parent.TOP||b===this.parent.LEFT||b===this.parent.RIGHT?b:this.parent.BOTTOM,this.dim=c.slice(),this.relativePos=.5,this.plotPos=this.type===this.parent.BOTTOM||this.type===this.parent.TOP?this.relativePos*this.dim[0]:-this.relativePos*this.dim[1],this.offset=35,this.rotate=this.type!==this.parent.BOTTOM&&this.type!==this.parent.TOP,this.text="",this.textAlignment=this.parent.CENTER,this.fontName="Helvetica",this.fontColor=this.parent.color(0),this.fontSize=13}function GAxis(a,b,c,d,e){this.parent=a,this.type=b===this.parent.BOTTOM||b===this.parent.TOP||b===this.parent.LEFT||b===this.parent.RIGHT?b:this.parent.BOTTOM,this.dim=c.slice(),this.lim=d.slice(),this.log=e,this.log&&(this.lim[0]<=0||this.lim[1]<=0)&&(console.log("The limits are negative. This is not allowed in logarithmic scale."),console.log("Will set them to (0.1, 10)"),this.lim[1]>this.lim[0]?(this.lim[0]=.1,this.lim[1]=10):(this.lim[0]=10,this.lim[1]=.1)),this.offset=5,this.lineColor=this.parent.color(0),this.lineWidth=1,this.nTicks=5,this.ticksSeparation=-1,this.ticks=[],this.plotTicks=[],this.ticksInside=[],this.tickLabels=[],this.fixedTicks=!1,this.tickLength=3,this.smallTickLength=2,this.expTickLabels=!1,this.rotateTickLabels=this.type!==this.parent.BOTTOM&&this.type!==this.parent.TOP,this.drawTickLabels=this.type===this.parent.BOTTOM||this.type===this.parent.LEFT,this.tickLabelOffset=7,this.ticksPrecision=void 0,this.lab=new GAxisLabel(this.parent,this.type,this.dim),this.drawAxisLabel=!0,this.fontName="Helvetica",this.fontColor=this.parent.color(0),this.fontSize=11,this.updateTicks(),this.updatePlotTicks(),this.updateTicksInside(),this.updateTickLabels()}function GHistogram(a,b,c,d){this.parent=a,this.type=b===GPlot.VERTICAL||b===GPlot.HORIZONTAL?b:GPlot.VERTICAL,this.dim=c.slice(),this.plotPoints=[];for(var e=0;e0&&b>0&&(this.dim[0]=a,this.dim[1]=b,this.plotPos=this.relativePos*this.dim[0])},GTitle.prototype.setRelativePos=function(a){this.relativePos=a,this.plotPos=this.relativePos*this.dim[0]},GTitle.prototype.setOffset=function(a){this.offset=a},GTitle.prototype.setText=function(a){this.text=a},GTitle.prototype.setTextAlignment=function(a){a!==this.parent.CENTER&&a!==this.parent.LEFT&&a!==this.parent.RIGHT||(this.textAlignment=a)},GTitle.prototype.setFontName=function(a){this.fontName=a},GTitle.prototype.setFontColor=function(a){this.fontColor=a},GTitle.prototype.setFontStyle=function(a){this.fontStyle=a},GTitle.prototype.setFontSize=function(a){a>0&&(this.fontSize=a)},GTitle.prototype.setFontProperties=function(a,b,c){c>0&&(this.fontName=a,this.fontColor=b,this.fontSize=c)},GAxisLabel.prototype.draw=function(){switch(this.type){case this.parent.BOTTOM:this.drawAsXLabel();break;case this.parent.LEFT:this.drawAsYLabel();break;case this.parent.TOP:this.drawAsTopLabel();break;case this.parent.RIGHT:this.drawAsRightLabel()}},GAxisLabel.prototype.drawAsXLabel=function(){this.parent.push(),this.parent.textFont(this.fontName),this.parent.textSize(this.fontSize),this.parent.fill(this.fontColor),this.parent.noStroke(),this.rotate?(this.parent.textAlign(this.parent.RIGHT,this.parent.CENTER),this.parent.translate(this.plotPos,this.offset),this.parent.rotate(-.5*Math.PI),this.parent.text(this.text,0,0)):(this.parent.textAlign(this.textAlignment,this.parent.TOP),this.parent.text(this.text,this.plotPos,this.offset)),this.parent.pop()},GAxisLabel.prototype.drawAsYLabel=function(){this.parent.push(),this.parent.textFont(this.fontName),this.parent.textSize(this.fontSize),this.parent.fill(this.fontColor),this.parent.noStroke(),this.rotate?(this.parent.textAlign(this.textAlignment,this.parent.BOTTOM),this.parent.translate(-this.offset,this.plotPos),this.parent.rotate(-.5*Math.PI),this.parent.text(this.text,0,0)):(this.parent.textAlign(this.parent.RIGHT,this.parent.CENTER),this.parent.text(this.text,-this.offset,this.plotPos)),this.parent.pop()},GAxisLabel.prototype.drawAsTopLabel=function(){this.parent.push(),this.parent.textFont(this.fontName),this.parent.textSize(this.fontSize),this.parent.fill(this.fontColor),this.parent.noStroke(),this.rotate?(this.parent.textAlign(this.parent.LEFT,this.parent.CENTER),this.parent.translate(this.plotPos,-this.offset-this.dim[1]),this.parent.rotate(-.5*Math.PI),this.parent.text(this.text,0,0)):(this.parent.textAlign(this.textAlignment,this.parent.BOTTOM),this.parent.text(this.text,this.plotPos,-this.offset-this.dim[1])),this.parent.pop()},GAxisLabel.prototype.drawAsRightLabel=function(){this.parent.push(),this.parent.textFont(this.fontName),this.parent.textSize(this.fontSize),this.parent.fill(this.fontColor),this.parent.noStroke(),this.rotate?(this.parent.textAlign(this.textAlignment,this.parent.TOP),this.parent.translate(this.offset+this.dim[0],this.plotPos),this.parent.rotate(-.5*Math.PI),this.parent.text(this.text,0,0)):(this.parent.textAlign(this.parent.LEFT,this.parent.CENTER),this.parent.text(this.text,this.offset+this.dim[0],this.plotPos)),this.parent.pop()},GAxisLabel.prototype.setDim=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(1!==arguments.length)throw new Error("GAxisLabel.setDim(): signature not supported");a=arguments[0][0],b=arguments[0][1]}a>0&&b>0&&(this.dim[0]=a,this.dim[1]=b,this.plotPos=this.type===this.parent.BOTTOM||this.type===this.parent.TOP?this.relativePos*this.dim[0]:-this.relativePos*this.dim[1])},GAxisLabel.prototype.setRelativePos=function(a){this.relativePos=a,this.plotPos=this.type===this.parent.BOTTOM||this.type===this.parent.TOP?this.relativePos*this.dim[0]:-this.relativePos*this.dim[1]},GAxisLabel.prototype.setOffset=function(a){this.offset=a},GAxisLabel.prototype.setRotate=function(a){this.rotate=a},GAxisLabel.prototype.setText=function(a){this.text=a},GAxisLabel.prototype.setTextAlignment=function(a){a!==this.parent.CENTER&&a!==this.parent.LEFT&&a!==this.parent.RIGHT||(this.textAlignment=a)},GAxisLabel.prototype.setFontName=function(a){this.fontName=a},GAxisLabel.prototype.setFontColor=function(a){this.fontColor=a},GAxisLabel.prototype.setFontSize=function(a){a>0&&(this.fontSize=a)},GAxisLabel.prototype.setFontProperties=function(a,b,c){c>0&&(this.fontName=a,this.fontColor=b,this.fontSize=c)},GAxis.prototype.obtainSigDigits=function(a){return Math.round(-Math.log(.5*Math.abs(a))/Math.LN10)},GAxis.prototype.roundPlus=function(a,b){return a=Math.round(a*Math.pow(10,b))/Math.pow(10,b),b<=0&&(a=Math.round(a)),a},GAxis.prototype.adaptSize=function(a,b){bthis.lim[0]?(a=Math.floor(Math.log(this.lim[0])/Math.LN10),b=Math.ceil(Math.log(this.lim[1])/Math.LN10)):(a=Math.floor(Math.log(this.lim[1])/Math.LN10),b=Math.ceil(Math.log(this.lim[0])/Math.LN10));var c=9*(b-a)+1;this.adaptSize(this.ticks,c);for(var d=a;d0){for(a=this.lim[1]>this.lim[0]?this.ticksSeparation:-this.ticksSeparation,c=this.obtainSigDigits(a);this.roundPlus(a,c)-a!=0;)c++;b=Math.floor((this.lim[1]-this.lim[0])/a)}else this.nTicks>0&&(a=(this.lim[1]-this.lim[0])/this.nTicks,c=this.obtainSigDigits(a),a=this.roundPlus(a,c),(0===a||Math.abs(a)>Math.abs(this.lim[1]-this.lim[0]))&&(c++,a=this.roundPlus((this.lim[1]-this.lim[0])/this.nTicks,c)),b=Math.floor((this.lim[1]-this.lim[0])/a));if(b>0){var d=this.lim[0]+(this.lim[1]-this.lim[0]-b*a)/2;for(d=this.roundPlus(d-2*a,c);(this.lim[1]-d)*(this.lim[0]-d)>0;)d=this.roundPlus(d+a,c);var e=Math.floor(Math.abs((this.lim[1]-d)/a))+1;this.adaptSize(this.ticks,e),this.ticks[0]=d;for(var f=1;f=0&&this.plotTicks[a]<=this.dim[0];else for(a=0;a=0&&-this.plotTicks[a]<=this.dim[1]},GAxis.prototype.updateTickLabels=function(){var a,b,c,d,e=this.ticks.length;if(this.adaptSize(this.tickLabels,e),this.log)for(d=0;d0?(b=Math.log(a)/Math.LN10,c=Math.abs(b-Math.round(b))<1e-4,c?(b=Math.round(b),this.expTickLabels?this.tickLabels[d]="1e"+b:this.tickLabels[d]=b>-3.1&&b<3.1?b>=0?""+Math.round(a):""+a:"1e"+b):this.tickLabels[d]=""):this.tickLabels[d]="";else for(d=0;d=0?this.tickLabels[d]=""+parseFloat(a).toFixed(this.ticksPrecision):this.tickLabels[d]=""+a},GAxis.prototype.moveLim=function(a){if(a[1]!==a[0])if(this.log&&(a[0]<=0||a[1]<=0))console.log("The limits are negative. This is not allowed in logarithmic scale.");else{if(this.lim[0]=a[0],this.lim[1]=a[1],!this.fixedTicks){var b=this.ticks.length;if(this.log)this.obtainLogarithmicTicks();else if(b>0){var c=0,d=0;if(this.ticksSeparation>0)for(c=this.lim[1]>this.lim[0]?this.ticksSeparation:-this.ticksSeparation,d=this.obtainSigDigits(c);this.roundPlus(c,d)-c!=0;)d++;else c=1===b?this.lim[1]-this.lim[0]:this.ticks[1]-this.ticks[0],d=this.obtainSigDigits(c),c=this.roundPlus(c,d),(0===c||Math.abs(c)>Math.abs(this.lim[1]-this.lim[0]))&&(d++,c=1===b?this.lim[1]-this.lim[0]:this.ticks[1]-this.ticks[0],c=this.roundPlus(c,d)),c=this.lim[1]>this.lim[0]?Math.abs(c):-Math.abs(c);var e=this.ticks[0]+c*Math.ceil((this.lim[0]-this.ticks[0])/c);e=this.roundPlus(e,d),(this.lim[1]-e)*(this.lim[0]-e)>0&&(e=this.ticks[0]+c*Math.floor((this.lim[0]-this.ticks[0])/c),e=this.roundPlus(e,d)),b=Math.floor(Math.abs((this.lim[1]-e)/c))+1,this.adaptSize(this.ticks,b),this.ticks[0]=e;for(var f=1;f0&&b>0&&(this.dim[0]=a,this.dim[1]=b,this.updatePlotTicks(),this.lab.setDim(this.dim))},GAxis.prototype.setLim=function(a){a[1]!==a[0]&&(this.log&&(a[0]<=0||a[1]<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.lim[0]=a[0],this.lim[1]=a[1],this.fixedTicks||(this.updateTicks(),this.updateTickLabels()),this.updatePlotTicks(),this.updateTicksInside()))},GAxis.prototype.setLimAndLog=function(a,b){a[1]!==a[0]&&(b&&(a[0]<=0||a[1]<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.lim[0]=a[0],this.lim[1]=a[1],this.log=b,this.fixedTicks||(this.updateTicks(),this.updateTickLabels()),this.updatePlotTicks(),this.updateTicksInside()))},GAxis.prototype.setLog=function(a){a!==this.log&&(this.log=a,this.log&&(this.lim[0]<=0||this.lim[1]<=0)&&(console.log("The limits are negative. This is not allowed in logarithmic scale."),console.log("Will set them to (0.1, 10)"),this.lim[1]>this.lim[0]?(this.lim[0]=.1,this.lim[1]=10):(this.lim[0]=10,this.lim[1]=.1)),this.fixedTicks||(this.updateTicks(),this.updateTickLabels()),this.updatePlotTicks(),this.updateTicksInside())},GAxis.prototype.setOffset=function(a){this.offset=a},GAxis.prototype.setLineColor=function(a){this.lineColor=a},GAxis.prototype.setLineWidth=function(a){a>0&&(this.lineWidth=a)},GAxis.prototype.setNTicks=function(a){a>=0&&(this.nTicks=a,this.ticksSeparation=-1,this.log||(this.fixedTicks=!1,this.updateTicks(),this.updatePlotTicks(),this.updateTicksInside(),this.updateTickLabels()))},GAxis.prototype.setTicksSeparation=function(a){this.ticksSeparation=a,this.log||(this.fixedTicks=!1,this.updateTicks(),this.updatePlotTicks(),this.updateTicksInside(),this.updateTickLabels())},GAxis.prototype.setTicks=function(a){var b=a.length;this.adaptSize(this.ticks,b);for(var c=0;c0&&(this.fontSize=a)},GAxis.prototype.setFontProperties=function(a,b,c){c>0&&(this.fontName=a,this.fontColor=b,this.fontSize=c)},GAxis.prototype.setAllFontProperties=function(a,b,c){this.setFontProperties(a,b,c),this.lab.setFontProperties(a,b,c)},GAxis.prototype.getTicks=function(){if(this.fixedTicks)return this.ticks.slice();for(var a=[],b=0,c=0;cb&&(this.differences.splice(b,Number.MAX_VALUE),this.leftSides.splice(b,Number.MAX_VALUE),this.rightSides.splice(b,Number.MAX_VALUE)),1===b)this.leftSides[0]=this.type===GPlot.VERTICAL?.2*this.dim[0]:.2*this.dim[1],this.rightSides[0]=this.leftSides[0];else if(b>1){for(a=0;a0?(c-d)/2:(c+d)/2}else this.differences[a]=0;for(this.leftSides[0]=this.differences[0],this.rightSides[0]=this.differences[0],a=1;athis.dim[0]&&(d=this.dim[0]),-f<0?f=0:-f>this.dim[1]&&(f=-this.dim[1]),e<0?e=0:e>this.dim[0]&&(e=this.dim[0]),-g<0?g=0:-g>this.dim[1]&&(g=-this.dim[1]),h=this.lineWidths[j%this.lineWidths.length],this.parent.fill(this.bgColors[j%this.bgColors.length]),this.parent.stroke(this.lineColors[j%this.lineColors.length]),this.parent.strokeWeight(h),Math.abs(e-d)>2*h&&Math.abs(g-f)>2*h?this.parent.rect(d,f,e,g):(this.type===GPlot.VERTICAL&&e!==d&&(f!==g||0!==f&&f!==-this.dim[1])||this.type===GPlot.HORIZONTAL&&g!==f&&(d!==e||0!==d&&d!==this.dim[0]))&&(this.parent.rect(d,f,e,g),this.parent.line(d,f,d,g),this.parent.line(e,f,e,g),this.parent.line(d,f,e,f),this.parent.line(d,g,e,g)));this.parent.pop(),this.drawLabels&&this.drawHistLabels()}},GHistogram.prototype.drawHistLabels=function(){var a,b,c=this.plotPoints.length,d=.5*Math.PI;if(this.parent.push(),this.parent.textFont(this.fontName),this.parent.textSize(this.fontSize),this.parent.fill(this.fontColor),this.parent.noStroke(),this.type===GPlot.VERTICAL)if(this.rotateLabels)for(this.parent.textAlign(this.parent.RIGHT,this.parent.CENTER),b=0;b=0&&a.getX()<=this.dim[0]&&(this.parent.push(),this.parent.translate(a.getX(),this.labelsOffset),this.parent.rotate(-d),this.parent.text(a.getLabel(),0,0),this.parent.pop());else for(this.parent.textAlign(this.parent.CENTER,this.parent.TOP),b=0;b=0&&a.getX()<=this.dim[0]&&this.parent.text(a.getLabel(),a.getX(),this.labelsOffset);else if(this.rotateLabels)for(this.parent.textAlign(this.parent.CENTER,this.parent.BOTTOM),b=0;b=0&&-a.getY()<=this.dim[1]&&(this.parent.push(),this.parent.translate(-this.labelsOffset,a.getY()),this.parent.rotate(-d),this.parent.text(a.getLabel(),0,0),this.parent.pop());else for(this.parent.textAlign(this.parent.RIGHT,this.parent.CENTER),b=0;b=0&&-a.getY()<=this.dim[1]&&this.parent.text(a.getLabel(),-this.labelsOffset,a.getY());this.parent.pop()},GHistogram.prototype.setType=function(a){a===this.type||a!==GPlot.VERTICAL&&a!==GPlot.HORIZONTAL||(this.type=a,this.updateArrays())},GHistogram.prototype.setDim=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(1!==arguments.length)throw new Error("GHistogram.setDim(): signature not supported");a=arguments[0][0],b=arguments[0][1]}a>0&&b>0&&(this.dim[0]=a,this.dim[1]=b,this.updateArrays())},GHistogram.prototype.setPlotPoints=function(a){var b,c=a.length;if(this.plotPoints.length===c)for(b=0;bc){for(b=0;b0&&(this.fontSize=a)},GHistogram.prototype.setFontProperties=function(a,b,c){c>0&&(this.fontName=a,this.fontColor=b,this.fontSize=c)},GLayer.prototype.isValidNumber=function(a){return!isNaN(a)&&isFinite(a)},GLayer.prototype.isId=function(a){return this.id===a},GLayer.prototype.valueToXPlot=function(a){return this.xLog?this.dim[0]*Math.log(a/this.xLim[0])/Math.log(this.xLim[1]/this.xLim[0]):this.dim[0]*(a-this.xLim[0])/(this.xLim[1]-this.xLim[0])},GLayer.prototype.valueToYPlot=function(a){return this.yLog?-this.dim[1]*Math.log(a/this.yLim[0])/Math.log(this.yLim[1]/this.yLim[0]):-this.dim[1]*(a-this.yLim[0])/(this.yLim[1]-this.yLim[0])},GLayer.prototype.valueToPlot=function(){if(2===arguments.length)return[this.valueToXPlot(arguments[0]),this.valueToYPlot(arguments[1])];if(1===arguments.length&&arguments[0]instanceof GPoint)return new GPoint(this.valueToXPlot(arguments[0].getX()),this.valueToYPlot(arguments[0].getY()),arguments[0].getLabel());if(1===arguments.length&&arguments[0]instanceof Array&&arguments[0][0]instanceof GPoint){var a,b,c,d,e,f,g=arguments[0].length,h=[];if(this.xLog&&this.yLog)for(a=this.dim[0]/Math.log(this.xLim[1]/this.xLim[0]),b=-this.dim[1]/Math.log(this.yLim[1]/this.yLim[0]),f=0;fg&&this.plotPoints.splice(g,Number.MAX_VALUE);if(this.xLog&&this.yLog)for(a=this.dim[0]/Math.log(this.xLim[1]/this.xLim[0]),b=-this.dim[1]/Math.log(this.yLim[1]/this.yLim[0]),f=0;f=0&&a<=this.dim[0]&&-b>=0&&-b<=this.dim[1])},GLayer.prototype.updateInsideList=function(){for(var a,b=this.plotPoints.length,c=0;c=0&&a.getX()<=this.dim[0]&&-a.getY()>=0&&-a.getY()<=this.dim[1]);this.inside.length>b&&this.inside.splice(b,Number.MAX_VALUE)},GLayer.prototype.getPointIndexAtPlotPos=function(a,b){var c;if(this.isInside(a,b))for(var d,e,f=Number.MAX_VALUE,g=this.plotPoints.length,h=this.pointSizes.length,i=0;ithis.dim[0]&&f>this.dim[0]||-e<0&&-g<0||-e>this.dim[1]&&-g>this.dim[1])){var j=f-d,k=g-e;if(0===j)c=2,this.cuts[0][0]=d,this.cuts[0][1]=0,this.cuts[1][0]=d,this.cuts[1][1]=-this.dim[1];else if(0===k)c=2,this.cuts[0][0]=0,this.cuts[0][1]=e,this.cuts[1][0]=this.dim[0],this.cuts[1][1]=e;else{var l=k/j,m=e-l*d;c=4,this.cuts[0][0]=-m/l,this.cuts[0][1]=0,this.cuts[1][0]=(-this.dim[1]-m)/l,this.cuts[1][1]=-this.dim[1],this.cuts[2][0]=0,this.cuts[2][1]=m,this.cuts[3][0]=this.dim[0],this.cuts[3][1]=m+l*this.dim[0]}if(c=this.getValidCuts(this.cuts,c,a,b),h||i){if(1!==c){var n=h?a:b;c>1&&(c=this.removeDuplicatedCuts(this.cuts,c,0))>1&&(c=this.removePointFromCuts(this.cuts,c,n,0))>1&&(c=this.removeDuplicatedCuts(this.cuts,c,.001))>1&&(c=this.removePointFromCuts(this.cuts,c,n,.001)),0===c&&(c=1,this.cuts[0][0]=n.getX(),this.cuts[0][1]=n.getY())}}else c>2&&(c=this.removeDuplicatedCuts(this.cuts,c,0))>2&&(c=this.removeDuplicatedCuts(this.cuts,c,.001)),2===c&&(Math.pow(this.cuts[0][0]-d,2),Math.pow(this.cuts[0][1]-e),2>Math.pow(this.cuts[1][0]-d,2)+Math.pow(this.cuts[1][1]-e,2)&&(this.cuts[2][0]=this.cuts[0][0],this.cuts[2][1]=this.cuts[0][1],this.cuts[0][0]=this.cuts[1][0],this.cuts[0][1]=this.cuts[1][1],this.cuts[1][0]=this.cuts[2][0],this.cuts[1][1]=this.cuts[2][1])),1===c&&(c=2,this.cuts[1][0]=this.cuts[0][0],this.cuts[1][1]=this.cuts[0][1]);(h||i)&&1!==c?console.log("There should be one cut!!!"):h||i||0===c||2===c||console.log("There should be either 0 or 2 cuts!!! "+c+" were found")}}return c},GLayer.prototype.getValidCuts=function(a,b,c,d){for(var e=c.getX(),f=c.getY(),g=d.getX(),h=d.getY(),i=Math.abs(g-e),j=Math.abs(h-f),k=0,l=0;ld||Math.abs(a[h][1]-f)>d)&&(a[g][0]=a[h][0],a[g][1]=a[h][1],g++);return g},GLayer.prototype.startHistogram=function(a){this.hist=new GHistogram(this.parent,a,this.dim,this.plotPoints)},GLayer.prototype.drawPoints=function(){var a,b;if(0===arguments.length){a=this.plotPoints.length;var c=this.pointColors.length,d=this.pointSizes.length;if(this.parent.push(),this.parent.ellipseMode(this.parent.CENTER),this.parent.noStroke(),1===c&&1===d)for(this.parent.fill(this.pointColors[0]),b=0;b=2&&this.parent.line(this.cuts[0][0],this.cuts[0][1],this.cuts[1][0],this.cuts[1][1])}this.parent.pop()},GLayer.prototype.drawLine=function(){var a,b,c,d,e,f;if(4===arguments.length&&arguments[0]instanceof GPoint)a=arguments[0],b=arguments[1],c=arguments[2],d=arguments[3];else if(4===arguments.length)e=arguments[0],f=arguments[1],c=arguments[2],d=arguments[3];else if(2===arguments.length&&arguments[0]instanceof GPoint)a=arguments[0],b=arguments[1],c=this.lineColor,d=this.lineWidth;else{if(2!==arguments.length)throw new Error("GLayer.drawLine(): signature not supported");e=arguments[0],f=arguments[1],c=this.lineColor,d=this.lineWidth}void 0!==e&&(this.xLog&&this.yLog?(a=new GPoint(this.xLim[0],Math.pow(10,e*Math.log(this.xLim[0])/Math.LN10+f)),b=new GPoint(this.xLim[1],Math.pow(10,e*Math.log(this.xLim[1])/Math.LN10+f))):this.xLog?(a=new GPoint(this.xLim[0],e*Math.log(this.xLim[0])/Math.LN10+f),b=new GPoint(this.xLim[1],e*Math.log(this.xLim[1])/Math.LN10+f)):this.yLog?(a=new GPoint(this.xLim[0],Math.pow(10,e*this.xLim[0]+f)),b=new GPoint(this.xLim[1],Math.pow(10,e*this.xLim[1]+f))):(a=new GPoint(this.xLim[0],e*this.xLim[0]+f),b=new GPoint(this.xLim[1],e*this.xLim[1]+f)));var g=this.valueToPlot(a),h=this.valueToPlot(b);if(g.isValid()&&h.isValid()){var i=this.isInside(g),j=this.isInside(h);if(this.parent.push(),this.parent.noFill(),this.parent.stroke(c),this.parent.strokeWeight(d),this.parent.strokeCap(this.parent.SQUARE),i&&j)this.parent.line(g.getX(),g.getY(),h.getX(),h.getY());else{var k=this.obtainBoxIntersections(g,h);i?this.parent.line(g.getX(),g.getY(),this.cuts[0][0],this.cuts[0][1]):j?this.parent.line(this.cuts[0][0],this.cuts[0][1],h.getX(),h.getY()):k>=2&&this.parent.line(this.cuts[0][0],this.cuts[0][1],this.cuts[1][0],this.cuts[1][1])}this.parent.pop()}},GLayer.prototype.drawHorizontalLine=function(){var a,b,c;if(3===arguments.length)a=arguments[0],b=arguments[1],c=arguments[2];else{if(1!==arguments.length)throw new Error("GLayer.drawHorizontalLine(): signature not supported");a=arguments[0],b=this.lineColor,c=this.lineWidth}var d=this.valueToYPlot(a);this.isValidNumber(d)&&-d>=0&&-d<=this.dim[1]&&(this.parent.push(),this.parent.noFill(),this.parent.stroke(b),this.parent.strokeWeight(c),this.parent.strokeCap(this.parent.SQUARE),this.parent.line(0,d,this.dim[0],d),this.parent.pop())},GLayer.prototype.drawVerticalLine=function(){var a,b,c;if(3===arguments.length)a=arguments[0],b=arguments[1],c=arguments[2];else{if(1!==arguments.length)throw new Error("GLayer.drawVerticalLine(): signature not supported");a=arguments[0],b=this.lineColor,c=this.lineWidth}var d=this.valueToXPlot(a);this.isValidNumber(d)&&d>=0&&d<=this.dim[0]&&(this.parent.push(),this.parent.noFill(),this.parent.stroke(b),this.parent.strokeWeight(c),this.parent.strokeCap(this.parent.SQUARE),this.parent.line(d,0,d,-this.dim[1]),this.parent.pop())},GLayer.prototype.drawFilledContour=function(a,b){var c;if(a===GPlot.HORIZONTAL?c=this.getHorizontalShape(b):a===GPlot.VERTICAL&&(c=this.getVerticalShape(b)),void 0!==c&&c.length>0){this.parent.push(),this.parent.fill(this.lineColor),this.parent.noStroke(),this.parent.beginShape();for(var d=0;d=0&&b.getX()<=this.dim[0]&&(-b.getY()<0?(f.push(new GPoint(b.getX(),0,"projection")),c=!0):(f.push(new GPoint(b.getX(),-this.dim[1],"projection")),c=!0)),d=i+1;d0){var l=new GPoint(f[0]);if(0!==l.getX()&&l.getX()!==this.dim[0])if("cut"===l.getLabel())this.plotPoints[g].getX()<0?(l.setX(0),l.setLabel("extreme")):(l.setX(this.dim[0]),l.setLabel("extreme"));else if(0!==g){for(var m=g-1;m>0&&!this.plotPoints[m].isValid();)m--;this.plotPoints[m].isValid()&&(this.plotPoints[m].getX()<0?(l.setX(0),l.setLabel("extreme")):(l.setX(this.dim[0]),l.setLabel("extreme")))}var n=new GPoint(f[f.length-1]);if(0!==n.getX()&&n.getX()!==this.dim[0]&&h!==e-1){for(d=h+1;dthis.dim[1]?(f.push(new GPoint(n.getX(),-this.dim[1])),f.push(new GPoint(l.getX(),-this.dim[1]))):(f.push(new GPoint(n.getX(),o[1])),f.push(new GPoint(l.getX(),o[1]))),"extreme"===l.getLabel()&&f.push(l)}return f},GLayer.prototype.getVerticalShape=function(a){for(var b,c,d,e=this.plotPoints.length,f=[],g=-1,h=-1,i=0;i=0&&-b.getY()<=this.dim[1]&&(b.getX()<0?(f.push(new GPoint(0,b.getY(),"projection")),c=!0):(f.push(new GPoint(this.dim[0],b.getY(),"projection")),c=!0)),d=i+1;d0){var l=new GPoint(f[0]);if(0!==l.getY()&&l.getY()!==-this.dim[1])if("cut"===l.getLabel())-this.plotPoints[g].getY()<0?(l.setY(0),l.setLabel("extreme")):(l.setY(-this.dim[1]),l.setLabel("extreme"));else if(0!==g){for(var m=g-1;m>0&&!this.plotPoints[m].isValid();)m--;this.plotPoints[m].isValid()&&(-this.plotPoints[m].getY()<0?(l.setY(0),l.setLabel("extreme")):(l.setY(-this.dim[1]),l.setLabel("extreme")))}var n=new GPoint(f[f.length-1]);if(0!==n.getY()&&n.getY()!==-this.dim[1]&&h!==e-1){for(d=h+1;dthis.dim[0]?(f.push(new GPoint(this.dim[0],n.getY())),f.push(new GPoint(this.dim[0],l.getY()))):(f.push(new GPoint(o[0],n.getY())),f.push(new GPoint(o[0],l.getY()))),"extreme"===l.getLabel()&&f.push(l)}return f},GLayer.prototype.drawLabel=function(a){var b=this.valueToXPlot(a.getX()),c=this.valueToYPlot(a.getY());if(this.isValidNumber(b)&&this.isValidNumber(c)){var d=b+this.labelSeparation[0],e=c-this.labelSeparation[1],f=this.fontSize/4;this.parent.push(),this.parent.rectMode(this.parent.CORNER),this.parent.noStroke(),this.parent.textFont(this.fontName),this.parent.textSize(this.fontSize),this.parent.textAlign(this.parent.LEFT,this.parent.BOTTOM),this.parent.fill(this.labelBgColor),this.parent.rect(d-f,e-this.fontSize-f,this.parent.textWidth(a.getLabel())+2*f,this.fontSize+2*f),this.parent.fill(this.fontColor),this.parent.text(a.getLabel(),d,e),this.parent.pop()}},GLayer.prototype.drawLabelAtPlotPos=function(a,b){var c=this.getPointAtPlotPos(a,b);void 0!==c&&this.drawLabel(c)},GLayer.prototype.drawHistogram=function(){void 0!==this.hist&&this.hist.draw(this.valueToPlot(this.histBasePoint))},GLayer.prototype.drawPolygon=function(a,b){var c;if(a.length>2){var d=this.valueToPlot(a),e=0;for(c=0;c1&&(h.push(new GPoint(this.cuts[0][0],this.cuts[0][1],"double cut")),h.push(new GPoint(this.cuts[1][0],this.cuts[1][1],"double cut")))}g=h.length;var k=[];for(c=0;c0&&t>0&&s!==this.dim[0]&&t!==this.dim[1]){var u=0===o||o===this.dim[0]?o:q,v=0===p||p===-this.dim[1]?p:r;k.push(new GPoint(u,v,"special cut"))}}}if(k.length>2){for(this.parent.push(),this.parent.fill(b),this.parent.noStroke(),this.parent.beginShape(),c=0;c0&&b>0&&(this.dim[0]=a,this.dim[1]=b,this.updatePlotPoints(),void 0!==this.hist&&(this.hist.setDim(this.dim),this.hist.setPlotPoints(this.plotPoints)))},GLayer.prototype.setXLim=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(1!==arguments.length)throw new Error("GLayer.setXLim(): signature not supported");a=arguments[0][0],b=arguments[0][1]}a!==b&&this.isValidNumber(a)&&this.isValidNumber(b)&&(this.xLog&&(a<=0||b<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.xLim[0]=a,this.xLim[1]=b,this.updatePlotPoints(),this.updateInsideList(),void 0!==this.hist&&this.hist.setPlotPoints(this.plotPoints)))},GLayer.prototype.setYLim=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(1!==arguments.length)throw new Error("GLayer.setYLim(): signature not supported");a=arguments[0][0],b=arguments[0][1]}a!==b&&this.isValidNumber(a)&&this.isValidNumber(b)&&(this.yLog&&(a<=0||b<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.yLim[0]=a,this.yLim[1]=b,this.updatePlotPoints(),this.updateInsideList(),void 0!==this.hist&&this.hist.setPlotPoints(this.plotPoints)))},GLayer.prototype.setXYLim=function(){var a,b,c,d;if(4===arguments.length)a=arguments[0],b=arguments[1],c=arguments[2],d=arguments[3];else{if(2!==arguments.length)throw new Error("GLayer.setXYLim(): signature not supported");a=arguments[0][0],b=arguments[0][1],c=arguments[1][0],d=arguments[1][1]}a!==b&&c!==d&&this.isValidNumber(a)&&this.isValidNumber(b)&&this.isValidNumber(c)&&this.isValidNumber(d)&&(this.xLog&&(a<=0||b<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.xLim[0]=a,this.xLim[1]=b),this.yLog&&(c<=0||d<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.yLim[0]=c,this.yLim[1]=d),this.updatePlotPoints(),this.updateInsideList(),void 0!==this.hist&&this.hist.setPlotPoints(this.plotPoints))},GLayer.prototype.setLimAndLog=function(){var a,b,c,d,e,f;if(6===arguments.length)a=arguments[0],b=arguments[1],c=arguments[2],d=arguments[3],e=arguments[4],f=arguments[5];else{if(4!==arguments.length)throw new Error("GLayer.setLimAndLog(): signature not supported");a=arguments[0][0],b=arguments[0][1],c=arguments[1][0],d=arguments[1][1],e=arguments[2],f=arguments[3]}a!==b&&c!==d&&this.isValidNumber(a)&&this.isValidNumber(b)&&this.isValidNumber(c)&&this.isValidNumber(d)&&(e&&(a<=0||b<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.xLim[0]=a,this.yLim[1]=b,this.xLog=e),f&&(c<=0||d<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.yLim[0]=c,this.yLim[1]=d,this.yLog=f),this.updatePlotPoints(),this.updateInsideList(),void 0!==this.hist&&this.hist.setPlotPoints(this.plotPoints))},GLayer.prototype.setXLog=function(a){a!==this.xLog&&(a&&(this.xLim[0]<=0||this.xLim[1]<=0)&&(console.log("One of the limits is negative. This is not allowed in logarithmic scale."),console.log("Will set horizontal limits to (0.1, 10)"),this.xLim[0]=.1,this.xLim[1]=10),this.xLog=a,this.updatePlotPoints(),this.updateInsideList(),void 0!==this.hist&&this.hist.setPlotPoints(this.plotPoints))},GLayer.prototype.setYLog=function(a){a!==this.yLog&&(a&&(this.yLim[0]<=0||this.yLim[1]<=0)&&(console.log("One of the limits is negative. This is not allowed in logarithmic scale."),console.log("Will set horizontal limits to (0.1, 10)"),this.yLim[0]=.1,this.yLim[1]=10),this.yLog=a,this.updatePlotPoints(),this.updateInsideList(),void 0!==this.hist&&this.hist.setPlotPoints(this.plotPoints))},GLayer.prototype.setPoints=function(a){var b,c=a.length;if(this.points.length>c)this.points.splice(c,Number.MAX_VALUE);else for(b=this.points.length;b0&&(this.pointColors=a.slice())},GLayer.prototype.setPointColor=function(a){this.pointColors=[a]},GLayer.prototype.setPointSizes=function(a){a.length>0&&(this.pointSizes=a.slice())},GLayer.prototype.setPointSize=function(a){this.pointSizes=[a]},GLayer.prototype.setLineColor=function(a){this.lineColor=a},GLayer.prototype.setLineWidth=function(a){a>0&&(this.lineWidth=a)},GLayer.prototype.setHistBasePoint=function(a){this.histBasePoint.set(a)},GLayer.prototype.setHistType=function(a){void 0!==this.hist&&this.hist.setType(a)},GLayer.prototype.setHistVisible=function(a){void 0!==this.hist&&this.hist.setVisible(a)},GLayer.prototype.setDrawHistLabels=function(a){void 0!==this.hist&&this.hist.setDrawLabels(a)},GLayer.prototype.setLabelBgColor=function(a){this.labelBgColor=a},GLayer.prototype.setLabelSeparation=function(a){this.labelSeparation[0]=a[0],this.labelSeparation[1]=a[1]},GLayer.prototype.setFontName=function(a){this.fontName=a},GLayer.prototype.setFontColor=function(a){this.fontColor=a},GLayer.prototype.setFontSize=function(a){a>0&&(this.fontSize=a)},GLayer.prototype.setFontProperties=function(a,b,c){c>0&&(this.fontName=a,this.fontColor=b,this.fontSize=c)},GLayer.prototype.setAllFontProperties=function(a,b,c){this.setFontProperties(a,b,c),void 0!==this.hist&&this.hist.setFontProperties(a,b,c)},GLayer.prototype.getId=function(){return this.id},GLayer.prototype.getDim=function(){return this.dim.slice()},GLayer.prototype.getXLim=function(){return this.xLim.slice()},GLayer.prototype.getYLim=function(){return this.yLim.slice()},GLayer.prototype.getXLog=function(){return this.xLog},GLayer.prototype.getYLog=function(){return this.yLog},GLayer.prototype.getPoints=function(){for(var a=[],b=0;b=this.pos[0]&&a<=this.pos[0]+this.outerDim[0]&&b>=this.pos[1]&&b<=this.pos[1]+this.outerDim[1]},GPlot.prototype.isOverBox=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(0!==arguments.length)throw new Error("GPlot.isOverBox(): signature not supported");a=this.parent.mouseX,b=this.parent.mouseY}return a>=this.pos[0]+this.mar[1]&&a<=this.pos[0]+this.outerDim[0]-this.mar[3]&&b>=this.pos[1]+this.mar[2]&&b<=this.pos[1]+this.outerDim[1]-this.mar[0]},GPlot.prototype.updateLimits=function(){this.fixedXLim||(this.xLim=this.calculatePlotXLim(),this.xAxis.setLim(this.xLim),this.topAxis.setLim(this.xLim)),this.fixedYLim||(this.yLim=this.calculatePlotYLim(),this.yAxis.setLim(this.yLim),this.rightAxis.setLim(this.yLim)),this.mainLayer.setXYLim(this.xLim,this.yLim);for(var a=0;a=this.yLim[0]&&e>=this.yLim[0]&&e<=this.yLim[1]||this.yLim[1]=this.yLim[1]),!f||this.xLog&&d<=0||(db[1]&&(b[1]=d))}return b[1]=this.xLim[0]&&d>=this.xLim[0]&&d<=this.xLim[1]||this.xLim[1]=this.xLim[1]),!f||this.yLog&&e<=0||(eb[1]&&(b[1]=e))}return b[1]=0&&c[b]<=this.dim[0]&&this.parent.line(c[b],0,c[b],-this.dim[1])}if(a===GPlot.BOTH||a===GPlot.HORIZONTAL){var d=this.yAxis.getPlotTicksRef();for(b=0;b=0&&-d[b]<=this.dim[1]&&this.parent.line(0,d[b],this.dim[0],d[b])}this.parent.pop()},GPlot.prototype.drawHistograms=function(){this.mainLayer.drawHistogram();for(var a=0;a0&&b>0){var c=a-this.mar[1]-this.mar[3],d=b-this.mar[0]-this.mar[2];if(c>0&&d>0){this.outerDim[0]=a,this.outerDim[1]=b,this.dim[0]=c,this.dim[1]=d,this.xAxis.setDim(this.dim),this.topAxis.setDim(this.dim),this.yAxis.setDim(this.dim),this.rightAxis.setDim(this.dim),this.title.setDim(this.dim),this.mainLayer.setDim(this.dim);for(var e=0;e0&&f>0&&(this.mar[0]=a,this.mar[1]=b,this.mar[2]=c,this.mar[3]=d,this.outerDim[0]=e,this.outerDim[1]=f)},GPlot.prototype.setDim=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(1!==arguments.length)throw new Error("GPlot.setDim(): signature not supported");a=arguments[0][0],b=arguments[0][1]}if(a>0&&b>0){var c=a+this.mar[1]+this.mar[3],d=b+this.mar[0]+this.mar[2];if(c>0&&d>0){this.outerDim[0]=c,this.outerDim[1]=d,this.dim[0]=a,this.dim[1]=b,this.xAxis.setDim(this.dim),this.topAxis.setDim(this.dim),this.yAxis.setDim(this.dim),this.rightAxis.setDim(this.dim),this.title.setDim(this.dim),this.mainLayer.setDim(this.dim);for(var e=0;ethis.xLim[1],this.fixedXLim=!0,this.xAxis.setLim(this.xLim),this.topAxis.setLim(this.xLim),this.updateLimits()))},GPlot.prototype.setYLim=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(1!==arguments.length)throw new Error("GPlot.setYLim(): signature not supported");a=arguments[0][0],b=arguments[0][1]}a!==b&&(this.yLog&&(a<=0||b<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.yLim[0]=a,this.yLim[1]=b,this.invertedYScale=this.yLim[0]>this.yLim[1],this.fixedYLim=!0,this.yAxis.setLim(this.yLim),this.rightAxis.setLim(this.yLim),this.updateLimits()))},GPlot.prototype.setFixedXLim=function(a){this.fixedXLim=a,this.updateLimits()},GPlot.prototype.setFixedYLim=function(a){this.fixedYLim=a,this.updateLimits()},GPlot.prototype.setLogScale=function(a){var b=this.xLog,c=this.yLog;if("xy"===a||"yx"===a?(b=!0,c=!0):"x"===a?(b=!0,c=!1):"y"===a?(b=!1,c=!0):""===a&&(b=!1,c=!1),b!==this.xLog||c!==this.yLog){this.xLog=b,this.yLog=c,this.xLog&&this.fixedXLim&&(this.xLim[0]<=0||this.xLim[1]<=0)&&(this.fixedXLim=!1),this.yLog&&this.fixedYLim&&(this.yLim[0]<=0||this.yLim[1]<=0)&&(this.fixedYLim=!1),this.fixedXLim||(this.xLim=this.calculatePlotXLim()),this.fixedYLim||(this.yLim=this.calculatePlotYLim()),this.xAxis.setLimAndLog(this.xLim,this.xLog),this.topAxis.setLimAndLog(this.xLim,this.xLog),this.yAxis.setLimAndLog(this.yLim,this.yLog),this.rightAxis.setLimAndLog(this.yLim,this.yLog),this.mainLayer.setLimAndLog(this.xLim,this.yLim,this.xLog,this.yLog);for(var d=0;d=0&&a!==this.expandLimFactor&&(this.expandLimFactor=a,this.updateLimits())},GPlot.prototype.setBgColor=function(a){this.bgColor=a},GPlot.prototype.setBoxBgColor=function(a){this.boxBgColor=a},GPlot.prototype.setBoxLineColor=function(a){this.boxLineColor=a},GPlot.prototype.setBoxLineWidth=function(a){a>0&&(this.boxLineWidth=a)},GPlot.prototype.setGridLineColor=function(a){this.gridLineColor=a},GPlot.prototype.setGridLineWidth=function(a){a>0&&(this.gridLineWidth=a)},GPlot.prototype.setPoints=function(){if(2===arguments.length)this.getLayer(arguments[1]).setPoints(arguments[0]);else{if(1!==arguments.length)throw new Error("GPlot.setPoints(): signature not supported");this.mainLayer.setPoints(arguments[0])}this.updateLimits()},GPlot.prototype.setPoint=function(){if(5===arguments.length)this.getLayer(arguments[4]).setPoint(arguments[0],arguments[1],arguments[2],arguments[3]);else if(4===arguments.length)this.mainLayer.setPoint(arguments[0],arguments[1],arguments[2],arguments[3]);else if(3===arguments.length&&arguments[1]instanceof GPoint)this.getLayer(arguments[2]).setPoint(arguments[0],arguments[1]);else if(3===arguments.length)this.mainLayer.setPoint(arguments[0],arguments[1],arguments[2]);else{if(2!==arguments.length)throw new Error("GPlot.setPoint(): signature not supported");this.mainLayer.setPoint(arguments[0],arguments[1])}this.updateLimits()},GPlot.prototype.addPoint=function(){if(4===arguments.length)this.getLayer(arguments[3]).addPoint(arguments[0],arguments[1],arguments[2]);else if(3===arguments.length)this.mainLayer.addPoint(arguments[0],arguments[1],arguments[2]);else if(2===arguments.length&&arguments[0]instanceof GPoint)this.getLayer(arguments[1]).addPoint(arguments[0]);else if(2===arguments.length)this.mainLayer.addPoint(arguments[0],arguments[1]);else{if(1!==arguments.length)throw new Error("GPlot.addPoint(): signature not supported");this.mainLayer.addPoint(arguments[0])}this.updateLimits()},GPlot.prototype.addPoints=function(){if(2===arguments.length)this.getLayer(arguments[1]).addPoints(arguments[0]);else{if(1!==arguments.length)throw new Error("GPlot.addPoints(): signature not supported");this.mainLayer.addPoints(arguments[0])}this.updateLimits()},GPlot.prototype.removePoint=function(){if(2===arguments.length)this.getLayer(arguments[1]).removePoint(arguments[0]);else{if(1!==arguments.length)throw new Error("GPlot.removePoint(): signature not supported");this.mainLayer.removePoint(arguments[0])}this.updateLimits()},GPlot.prototype.addPointAtIndexPos=function(){if(5===arguments.length)this.getLayer(arguments[4]).addPointAtIndexPos(arguments[0],arguments[1],arguments[2],arguments[3]);else if(4===arguments.length)this.mainLayer.addPointAtIndexPos(arguments[0],arguments[1],arguments[2],arguments[3]);else if(3===arguments.length&&arguments[1]instanceof GPoint)this.getLayer(arguments[2]).addPointAtIndexPos(arguments[0],arguments[1]);else if(3===arguments.length)this.mainLayer.addPointAtIndexPos(arguments[0],arguments[1],arguments[2]);else{if(2!==arguments.length)throw new Error("GPlot.addPointAtIndexPos(): signature not supported");this.mainLayer.addPointAtIndexPos(arguments[0],arguments[1])}this.updateLimits()},GPlot.prototype.setPointColors=function(a){this.mainLayer.setPointColors(a)},GPlot.prototype.setPointColor=function(a){this.mainLayer.setPointColor(a)},GPlot.prototype.setPointSizes=function(a){this.mainLayer.setPointSizes(a)},GPlot.prototype.setPointSize=function(a){this.mainLayer.setPointSize(a)},GPlot.prototype.setLineColor=function(a){this.mainLayer.setLineColor(a)},GPlot.prototype.setLineWidth=function(a){this.mainLayer.setLineWidth(a)},GPlot.prototype.setHistBasePoint=function(a){this.mainLayer.setHistBasePoint(a)},GPlot.prototype.setHistType=function(a){this.mainLayer.setHistType(a)},GPlot.prototype.setHistVisible=function(a){this.mainLayer.setHistVisible(a)},GPlot.prototype.setDrawHistLabels=function(a){this.mainLayer.setDrawHistLabels(a)},GPlot.prototype.setLabelBgColor=function(a){this.mainLayer.setLabelBgColor(a)},GPlot.prototype.setLabelSeparation=function(a){this.mainLayer.setLabelSeparation(a)},GPlot.prototype.setTitleText=function(a){this.title.setText(a)},GPlot.prototype.setAxesOffset=function(a){this.xAxis.setOffset(a),this.topAxis.setOffset(a),this.yAxis.setOffset(a),this.rightAxis.setOffset(a)},GPlot.prototype.setTicksLength=function(a){this.xAxis.setTickLength(a),this.topAxis.setTickLength(a),this.yAxis.setTickLength(a),this.rightAxis.setTickLength(a)},GPlot.prototype.setHorizontalAxesNTicks=function(a){this.xAxis.setNTicks(a),this.topAxis.setNTicks(a)},GPlot.prototype.setHorizontalAxesTicksSeparation=function(a){this.xAxis.setTicksSeparation(a),this.topAxis.setTicksSeparation(a)},GPlot.prototype.setHorizontalAxesTicks=function(a){this.xAxis.setTicks(a),this.topAxis.setTicks(a)},GPlot.prototype.setVerticalAxesNTicks=function(a){this.yAxis.setNTicks(a),this.rightAxis.setNTicks(a)},GPlot.prototype.setVerticalAxesTicksSeparation=function(a){this.yAxis.setTicksSeparation(a),this.rightAxis.setTicksSeparation(a)},GPlot.prototype.setVerticalAxesTicks=function(a){this.yAxis.setTicks(a),this.rightAxis.setTicks(a)},GPlot.prototype.setFontName=function(a){this.mainLayer.setFontName(a)},GPlot.prototype.setFontColor=function(a){this.mainLayer.setFontColor(a)},GPlot.prototype.setFontSize=function(a){this.mainLayer.setFontSize(a)},GPlot.prototype.setFontProperties=function(a,b,c){this.mainLayer.setFontProperties(a,b,c)},GPlot.prototype.setAllFontProperties=function(a,b,c){this.xAxis.setAllFontProperties(a,b,c),this.topAxis.setAllFontProperties(a,b,c),this.yAxis.setAllFontProperties(a,b,c),this.rightAxis.setAllFontProperties(a,b,c),this.title.setFontProperties(a,b,c),this.mainLayer.setAllFontProperties(a,b,c);for(var d=0;d0&&(this.zoomFactor=a),b!==this.parent.LEFT&&b!==this.parent.RIGHT&&b!==this.parent.CENTER||(this.increaseZoomButton=b),c!==this.parent.LEFT&&c!==this.parent.RIGHT&&c!==this.parent.CENTER||(this.decreaseZoomButton=c),d!==this.parent.SHIFT&&d!==this.parent.CONTROL&&d!==this.parent.ALT&&d!==GPlot.NONE||(this.increaseZoomKeyModifier=d),e!==this.parent.SHIFT&&e!==this.parent.CONTROL&&e!==this.parent.ALT&&e!==GPlot.NONE||(this.decreaseZoomKeyModifier=e)},GPlot.prototype.deactivateZooming=function(){this.zoomingIsActive=!1},GPlot.prototype.activateCentering=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else if(1===arguments.length)a=arguments[0],b=GPlot.NONE;else{if(0!==arguments.length)throw new Error("GPlot.activateCentering(): signature not supported");a=this.parent.LEFT,b=GPlot.NONE}this.centeringIsActive=!0,a!==this.parent.LEFT&&a!==this.parent.RIGHT&&a!==this.parent.CENTER||(this.centeringButton=a),b!==this.parent.SHIFT&&b!==this.parent.CONTROL&&b!==this.parent.ALT&&b!==GPlot.NONE||(this.centeringKeyModifier=b)},GPlot.prototype.deactivateCentering=function(){this.centeringIsActive=!1},GPlot.prototype.activatePanning=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else if(1===arguments.length)a=arguments[0],b=GPlot.NONE;else{if(0!==arguments.length)throw new Error("GPlot.activatePanning(): signature not supported");a=this.parent.LEFT,b=GPlot.NONE}this.panningIsActive=!0,a!==this.parent.LEFT&&a!==this.parent.RIGHT&&a!==this.parent.CENTER||(this.panningButton=a),b!==this.parent.SHIFT&&b!==this.parent.CONTROL&&b!==this.parent.ALT&&b!==GPlot.NONE||(this.panningKeyModifier=b)},GPlot.prototype.deactivatePanning=function(){this.panningIsActive=!1,this.panningReferencePoint=void 0},GPlot.prototype.activatePointLabels=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else if(1===arguments.length)a=arguments[0],b=GPlot.NONE;else{if(0!==arguments.length)throw new Error("GPlot.activatePointLabels(): signature not supported");a=this.parent.LEFT,b=GPlot.NONE}this.labelingIsActive=!0,a!==this.parent.LEFT&&a!==this.parent.RIGHT&&a!==this.parent.CENTER||(this.labelingButton=a),b!==this.parent.SHIFT&&b!==this.parent.CONTROL&&b!==this.parent.ALT&&b!==GPlot.NONE||(this.labelingKeyModifier=b)},GPlot.prototype.deactivatePointLabels=function(){this.labelingIsActive=!1,this.mousePos=void 0},GPlot.prototype.activateReset=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else if(1===arguments.length)a=arguments[0],b=GPlot.NONE;else{if(0!==arguments.length)throw new Error("GPlot.activateReset(): signature not supported");a=this.parent.RIGHT,b=GPlot.NONE}this.resetIsActive=!0,this.xLimReset=void 0,this.yLimReset=void 0,a!==this.parent.LEFT&&a!==this.parent.RIGHT&&a!==this.parent.CENTER||(this.resetButton=a),b!==this.parent.SHIFT&&b!==this.parent.CONTROL&&b!==this.parent.ALT&&b!==GPlot.NONE||(this.resetKeyModifier=b)},GPlot.prototype.deactivateReset=function(){this.resetIsActive=!1,this.xLimReset=void 0,this.yLimReset=void 0},GPlot.prototype.getButton=function(a){var b;return 0===a.button?b=this.parent.LEFT:1===a.button?b=this.parent.CENTER:2===a.button?b=this.parent.RIGHT:void 0===a.button&&(b=this.parent.LEFT),b},GPlot.prototype.getModifier=function(a){return a.altKey?this.parent.ALT:a.ctrlKey?this.parent.CONTROL:a.shiftKey?this.parent.SHIFT:GPlot.NONE},GPlot.prototype.saveResetLimits=function(){void 0!==this.xLimReset&&void 0!==this.yLimReset||(this.xLimReset=this.xLim.slice(),this.yLimReset=this.yLim.slice())},GPlot.prototype.clickEvent=function(a){var b=a||window.event;if(this.isOverBox()){var c=this.getButton(b),d=this.getModifier(b);this.zoomingIsActive&&(c===this.increaseZoomButton&&d===this.increaseZoomKeyModifier?(this.resetIsActive&&this.saveResetLimits(),this.zoom(this.zoomFactor,this.parent.mouseX,this.parent.mouseY)):c===this.decreaseZoomButton&&d===this.decreaseZoomKeyModifier&&(this.resetIsActive&&this.saveResetLimits(),this.zoom(1/this.zoomFactor,this.parent.mouseX,this.parent.mouseY))), +/*! grafica.js (0.3.1): a library for p5.js. Author: Javier GraciĆ” Carpio, license: LGPL-3.0, 2018-09-27 */ function GPoint(){var a,b,c;if(3===arguments.length)a=arguments[0],b=arguments[1],c=arguments[2];else if(2===arguments.length&&arguments[0]instanceof p5.Vector)a=arguments[0].x,b=arguments[0].y,c=arguments[1];else if(2===arguments.length)a=arguments[0],b=arguments[1],c="";else if(1===arguments.length&&arguments[0]instanceof GPoint)a=arguments[0].getX(),b=arguments[0].getY(),c=arguments[0].getLabel();else if(1===arguments.length&&arguments[0]instanceof p5.Vector)a=arguments[0].x,b=arguments[0].y,c="";else{if(0!==arguments.length)throw new Error("GPoint constructor: signature not supported");a=0,b=0,c=""}this.x=a,this.y=b,this.label=c,this.valid=this.isValidNumber(this.x)&&this.isValidNumber(this.y)}function GTitle(a,b){this.parent=a,this.dim=b.slice(),this.relativePos=.5,this.plotPos=this.relativePos*this.dim[0],this.offset=10,this.text="",this.textAlignment=this.parent.CENTER,this.fontName="Helvetica",this.fontColor=this.parent.color(100),this.fontStyle=this.parent.BOLD,this.fontSize=13}function GAxisLabel(a,b,c){this.parent=a,this.type=b===this.parent.BOTTOM||b===this.parent.TOP||b===this.parent.LEFT||b===this.parent.RIGHT?b:this.parent.BOTTOM,this.dim=c.slice(),this.relativePos=.5,this.plotPos=this.type===this.parent.BOTTOM||this.type===this.parent.TOP?this.relativePos*this.dim[0]:-this.relativePos*this.dim[1],this.offset=35,this.rotate=this.type!==this.parent.BOTTOM&&this.type!==this.parent.TOP,this.text="",this.textAlignment=this.parent.CENTER,this.fontName="Helvetica",this.fontColor=this.parent.color(0),this.fontSize=13}function GAxis(a,b,c,d,e){this.parent=a,this.type=b===this.parent.BOTTOM||b===this.parent.TOP||b===this.parent.LEFT||b===this.parent.RIGHT?b:this.parent.BOTTOM,this.dim=c.slice(),this.lim=d.slice(),this.log=e,this.log&&(this.lim[0]<=0||this.lim[1]<=0)&&(console.log("The limits are negative. This is not allowed in logarithmic scale."),console.log("Will set them to (0.1, 10)"),this.lim[1]>this.lim[0]?(this.lim[0]=.1,this.lim[1]=10):(this.lim[0]=10,this.lim[1]=.1)),this.offset=5,this.lineColor=this.parent.color(0),this.lineWidth=1,this.nTicks=5,this.ticksSeparation=-1,this.ticks=[],this.plotTicks=[],this.ticksInside=[],this.tickLabels=[],this.fixedTicks=!1,this.tickLength=3,this.smallTickLength=2,this.expTickLabels=!1,this.rotateTickLabels=this.type!==this.parent.BOTTOM&&this.type!==this.parent.TOP,this.drawTickLabels=this.type===this.parent.BOTTOM||this.type===this.parent.LEFT,this.tickLabelOffset=7,this.ticksPrecision=void 0,this.lab=new GAxisLabel(this.parent,this.type,this.dim),this.drawAxisLabel=!0,this.fontName="Helvetica",this.fontColor=this.parent.color(0),this.fontSize=11,this.updateTicks(),this.updatePlotTicks(),this.updateTicksInside(),this.updateTickLabels()}function GHistogram(a,b,c,d){this.parent=a,this.type=b===GPlot.VERTICAL||b===GPlot.HORIZONTAL?b:GPlot.VERTICAL,this.dim=c.slice(),this.plotPoints=[];for(var e=0;e0&&b>0&&(this.dim[0]=a,this.dim[1]=b,this.plotPos=this.relativePos*this.dim[0])},GTitle.prototype.setRelativePos=function(a){this.relativePos=a,this.plotPos=this.relativePos*this.dim[0]},GTitle.prototype.setOffset=function(a){this.offset=a},GTitle.prototype.setText=function(a){this.text=a},GTitle.prototype.setTextAlignment=function(a){a!==this.parent.CENTER&&a!==this.parent.LEFT&&a!==this.parent.RIGHT||(this.textAlignment=a)},GTitle.prototype.setFontName=function(a){this.fontName=a},GTitle.prototype.setFontColor=function(a){this.fontColor=a},GTitle.prototype.setFontStyle=function(a){this.fontStyle=a},GTitle.prototype.setFontSize=function(a){a>0&&(this.fontSize=a)},GTitle.prototype.setFontProperties=function(a,b,c){c>0&&(this.fontName=a,this.fontColor=b,this.fontSize=c)},GAxisLabel.prototype.draw=function(){switch(this.type){case this.parent.BOTTOM:this.drawAsXLabel();break;case this.parent.LEFT:this.drawAsYLabel();break;case this.parent.TOP:this.drawAsTopLabel();break;case this.parent.RIGHT:this.drawAsRightLabel()}},GAxisLabel.prototype.drawAsXLabel=function(){this.parent.push(),this.parent.textFont(this.fontName),this.parent.textSize(this.fontSize),this.parent.fill(this.fontColor),this.parent.noStroke(),this.rotate?(this.parent.textAlign(this.parent.RIGHT,this.parent.CENTER),this.parent.translate(this.plotPos,this.offset),this.parent.rotate(-.5*Math.PI),this.parent.text(this.text,0,0)):(this.parent.textAlign(this.textAlignment,this.parent.TOP),this.parent.text(this.text,this.plotPos,this.offset)),this.parent.pop()},GAxisLabel.prototype.drawAsYLabel=function(){this.parent.push(),this.parent.textFont(this.fontName),this.parent.textSize(this.fontSize),this.parent.fill(this.fontColor),this.parent.noStroke(),this.rotate?(this.parent.textAlign(this.textAlignment,this.parent.BOTTOM),this.parent.translate(-this.offset,this.plotPos),this.parent.rotate(-.5*Math.PI),this.parent.text(this.text,0,0)):(this.parent.textAlign(this.parent.RIGHT,this.parent.CENTER),this.parent.text(this.text,-this.offset,this.plotPos)),this.parent.pop()},GAxisLabel.prototype.drawAsTopLabel=function(){this.parent.push(),this.parent.textFont(this.fontName),this.parent.textSize(this.fontSize),this.parent.fill(this.fontColor),this.parent.noStroke(),this.rotate?(this.parent.textAlign(this.parent.LEFT,this.parent.CENTER),this.parent.translate(this.plotPos,-this.offset-this.dim[1]),this.parent.rotate(-.5*Math.PI),this.parent.text(this.text,0,0)):(this.parent.textAlign(this.textAlignment,this.parent.BOTTOM),this.parent.text(this.text,this.plotPos,-this.offset-this.dim[1])),this.parent.pop()},GAxisLabel.prototype.drawAsRightLabel=function(){this.parent.push(),this.parent.textFont(this.fontName),this.parent.textSize(this.fontSize),this.parent.fill(this.fontColor),this.parent.noStroke(),this.rotate?(this.parent.textAlign(this.textAlignment,this.parent.TOP),this.parent.translate(this.offset+this.dim[0],this.plotPos),this.parent.rotate(-.5*Math.PI),this.parent.text(this.text,0,0)):(this.parent.textAlign(this.parent.LEFT,this.parent.CENTER),this.parent.text(this.text,this.offset+this.dim[0],this.plotPos)),this.parent.pop()},GAxisLabel.prototype.setDim=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(1!==arguments.length)throw new Error("GAxisLabel.setDim(): signature not supported");a=arguments[0][0],b=arguments[0][1]}a>0&&b>0&&(this.dim[0]=a,this.dim[1]=b,this.plotPos=this.type===this.parent.BOTTOM||this.type===this.parent.TOP?this.relativePos*this.dim[0]:-this.relativePos*this.dim[1])},GAxisLabel.prototype.setRelativePos=function(a){this.relativePos=a,this.plotPos=this.type===this.parent.BOTTOM||this.type===this.parent.TOP?this.relativePos*this.dim[0]:-this.relativePos*this.dim[1]},GAxisLabel.prototype.setOffset=function(a){this.offset=a},GAxisLabel.prototype.setRotate=function(a){this.rotate=a},GAxisLabel.prototype.setText=function(a){this.text=a},GAxisLabel.prototype.setTextAlignment=function(a){a!==this.parent.CENTER&&a!==this.parent.LEFT&&a!==this.parent.RIGHT||(this.textAlignment=a)},GAxisLabel.prototype.setFontName=function(a){this.fontName=a},GAxisLabel.prototype.setFontColor=function(a){this.fontColor=a},GAxisLabel.prototype.setFontSize=function(a){a>0&&(this.fontSize=a)},GAxisLabel.prototype.setFontProperties=function(a,b,c){c>0&&(this.fontName=a,this.fontColor=b,this.fontSize=c)},GAxis.prototype.obtainSigDigits=function(a){return Math.round(-Math.log(.5*Math.abs(a))/Math.LN10)},GAxis.prototype.roundPlus=function(a,b){return a=Math.round(a*Math.pow(10,b))/Math.pow(10,b),b<=0&&(a=Math.round(a)),a},GAxis.prototype.adaptSize=function(a,b){bthis.lim[0]?(a=Math.floor(Math.log(this.lim[0])/Math.LN10),b=Math.ceil(Math.log(this.lim[1])/Math.LN10)):(a=Math.floor(Math.log(this.lim[1])/Math.LN10),b=Math.ceil(Math.log(this.lim[0])/Math.LN10));var c=9*(b-a)+1;this.adaptSize(this.ticks,c);for(var d=a;d0){for(a=this.lim[1]>this.lim[0]?this.ticksSeparation:-this.ticksSeparation,c=this.obtainSigDigits(a);this.roundPlus(a,c)-a!=0;)c++;b=Math.floor((this.lim[1]-this.lim[0])/a)}else this.nTicks>0&&(a=(this.lim[1]-this.lim[0])/this.nTicks,c=this.obtainSigDigits(a),a=this.roundPlus(a,c),(0===a||Math.abs(a)>Math.abs(this.lim[1]-this.lim[0]))&&(c++,a=this.roundPlus((this.lim[1]-this.lim[0])/this.nTicks,c)),b=Math.floor((this.lim[1]-this.lim[0])/a));if(b>0){var d=this.lim[0]+(this.lim[1]-this.lim[0]-b*a)/2;for(d=this.roundPlus(d-2*a,c);(this.lim[1]-d)*(this.lim[0]-d)>0;)d=this.roundPlus(d+a,c);var e=Math.floor(Math.abs((this.lim[1]-d)/a))+1;this.adaptSize(this.ticks,e),this.ticks[0]=d;for(var f=1;f=0&&this.plotTicks[a]<=this.dim[0];else for(a=0;a=0&&-this.plotTicks[a]<=this.dim[1]},GAxis.prototype.updateTickLabels=function(){var a,b,c,d,e=this.ticks.length;if(this.adaptSize(this.tickLabels,e),this.log)for(d=0;d0?(b=Math.log(a)/Math.LN10,c=Math.abs(b-Math.round(b))<1e-4,c?(b=Math.round(b),this.expTickLabels?this.tickLabels[d]="1e"+b:this.tickLabels[d]=b>-3.1&&b<3.1?b>=0?""+Math.round(a):""+a:"1e"+b):this.tickLabels[d]=""):this.tickLabels[d]="";else for(d=0;d=0?this.tickLabels[d]=""+parseFloat(a).toFixed(this.ticksPrecision):this.tickLabels[d]=""+a},GAxis.prototype.moveLim=function(a){if(a[1]!==a[0])if(this.log&&(a[0]<=0||a[1]<=0))console.log("The limits are negative. This is not allowed in logarithmic scale.");else{if(this.lim[0]=a[0],this.lim[1]=a[1],!this.fixedTicks){var b=this.ticks.length;if(this.log)this.obtainLogarithmicTicks();else if(b>0){var c=0,d=0;if(this.ticksSeparation>0)for(c=this.lim[1]>this.lim[0]?this.ticksSeparation:-this.ticksSeparation,d=this.obtainSigDigits(c);this.roundPlus(c,d)-c!=0;)d++;else c=1===b?this.lim[1]-this.lim[0]:this.ticks[1]-this.ticks[0],d=this.obtainSigDigits(c),c=this.roundPlus(c,d),(0===c||Math.abs(c)>Math.abs(this.lim[1]-this.lim[0]))&&(d++,c=1===b?this.lim[1]-this.lim[0]:this.ticks[1]-this.ticks[0],c=this.roundPlus(c,d)),c=this.lim[1]>this.lim[0]?Math.abs(c):-Math.abs(c);var e=this.ticks[0]+c*Math.ceil((this.lim[0]-this.ticks[0])/c);e=this.roundPlus(e,d),(this.lim[1]-e)*(this.lim[0]-e)>0&&(e=this.ticks[0]+c*Math.floor((this.lim[0]-this.ticks[0])/c),e=this.roundPlus(e,d)),b=Math.floor(Math.abs((this.lim[1]-e)/c))+1,this.adaptSize(this.ticks,b),this.ticks[0]=e;for(var f=1;f0&&b>0&&(this.dim[0]=a,this.dim[1]=b,this.updatePlotTicks(),this.lab.setDim(this.dim))},GAxis.prototype.setLim=function(a){a[1]!==a[0]&&(this.log&&(a[0]<=0||a[1]<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.lim[0]=a[0],this.lim[1]=a[1],this.fixedTicks||(this.updateTicks(),this.updateTickLabels()),this.updatePlotTicks(),this.updateTicksInside()))},GAxis.prototype.setLimAndLog=function(a,b){a[1]!==a[0]&&(b&&(a[0]<=0||a[1]<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.lim[0]=a[0],this.lim[1]=a[1],this.log=b,this.fixedTicks||(this.updateTicks(),this.updateTickLabels()),this.updatePlotTicks(),this.updateTicksInside()))},GAxis.prototype.setLog=function(a){a!==this.log&&(this.log=a,this.log&&(this.lim[0]<=0||this.lim[1]<=0)&&(console.log("The limits are negative. This is not allowed in logarithmic scale."),console.log("Will set them to (0.1, 10)"),this.lim[1]>this.lim[0]?(this.lim[0]=.1,this.lim[1]=10):(this.lim[0]=10,this.lim[1]=.1)),this.fixedTicks||(this.updateTicks(),this.updateTickLabels()),this.updatePlotTicks(),this.updateTicksInside())},GAxis.prototype.setOffset=function(a){this.offset=a},GAxis.prototype.setLineColor=function(a){this.lineColor=a},GAxis.prototype.setLineWidth=function(a){a>0&&(this.lineWidth=a)},GAxis.prototype.setNTicks=function(a){a>=0&&(this.nTicks=a,this.ticksSeparation=-1,this.fixedTicks=!1,this.log||(this.updateTicks(),this.updatePlotTicks(),this.updateTicksInside(),this.updateTickLabels()))},GAxis.prototype.setTicksSeparation=function(a){this.ticksSeparation=a,this.fixedTicks=!1,this.log||(this.updateTicks(),this.updatePlotTicks(),this.updateTicksInside(),this.updateTickLabels())},GAxis.prototype.setTicks=function(a){var b=a.length;this.adaptSize(this.ticks,b);for(var c=0;c0&&(this.fontSize=a)},GAxis.prototype.setFontProperties=function(a,b,c){c>0&&(this.fontName=a,this.fontColor=b,this.fontSize=c)},GAxis.prototype.setAllFontProperties=function(a,b,c){this.setFontProperties(a,b,c),this.lab.setFontProperties(a,b,c)},GAxis.prototype.getTicks=function(){if(this.fixedTicks)return this.ticks.slice();for(var a=[],b=0,c=0;cb&&(this.differences.splice(b,Number.MAX_VALUE),this.leftSides.splice(b,Number.MAX_VALUE),this.rightSides.splice(b,Number.MAX_VALUE)),1===b)this.leftSides[0]=this.type===GPlot.VERTICAL?.2*this.dim[0]:.2*this.dim[1],this.rightSides[0]=this.leftSides[0];else if(b>1){for(a=0;a0?(c-d)/2:(c+d)/2}else this.differences[a]=0;for(this.leftSides[0]=this.differences[0],this.rightSides[0]=this.differences[0],a=1;athis.dim[0]&&(d=this.dim[0]),-f<0?f=0:-f>this.dim[1]&&(f=-this.dim[1]),e<0?e=0:e>this.dim[0]&&(e=this.dim[0]),-g<0?g=0:-g>this.dim[1]&&(g=-this.dim[1]),h=this.lineWidths[j%this.lineWidths.length],this.parent.fill(this.bgColors[j%this.bgColors.length]),this.parent.stroke(this.lineColors[j%this.lineColors.length]),this.parent.strokeWeight(h),Math.abs(e-d)>2*h&&Math.abs(g-f)>2*h?this.parent.rect(d,f,e,g):(this.type===GPlot.VERTICAL&&e!==d&&(f!==g||0!==f&&f!==-this.dim[1])||this.type===GPlot.HORIZONTAL&&g!==f&&(d!==e||0!==d&&d!==this.dim[0]))&&(this.parent.rect(d,f,e,g),this.parent.line(d,f,d,g),this.parent.line(e,f,e,g),this.parent.line(d,f,e,f),this.parent.line(d,g,e,g)));this.parent.pop(),this.drawLabels&&this.drawHistLabels()}},GHistogram.prototype.drawHistLabels=function(){var a,b,c=this.plotPoints.length,d=.5*Math.PI;if(this.parent.push(),this.parent.textFont(this.fontName),this.parent.textSize(this.fontSize),this.parent.fill(this.fontColor),this.parent.noStroke(),this.type===GPlot.VERTICAL)if(this.rotateLabels)for(this.parent.textAlign(this.parent.RIGHT,this.parent.CENTER),b=0;b=0&&a.getX()<=this.dim[0]&&(this.parent.push(),this.parent.translate(a.getX(),this.labelsOffset),this.parent.rotate(-d),this.parent.text(a.getLabel(),0,0),this.parent.pop());else for(this.parent.textAlign(this.parent.CENTER,this.parent.TOP),b=0;b=0&&a.getX()<=this.dim[0]&&this.parent.text(a.getLabel(),a.getX(),this.labelsOffset);else if(this.rotateLabels)for(this.parent.textAlign(this.parent.CENTER,this.parent.BOTTOM),b=0;b=0&&-a.getY()<=this.dim[1]&&(this.parent.push(),this.parent.translate(-this.labelsOffset,a.getY()),this.parent.rotate(-d),this.parent.text(a.getLabel(),0,0),this.parent.pop());else for(this.parent.textAlign(this.parent.RIGHT,this.parent.CENTER),b=0;b=0&&-a.getY()<=this.dim[1]&&this.parent.text(a.getLabel(),-this.labelsOffset,a.getY());this.parent.pop()},GHistogram.prototype.setType=function(a){a===this.type||a!==GPlot.VERTICAL&&a!==GPlot.HORIZONTAL||(this.type=a,this.updateArrays())},GHistogram.prototype.setDim=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(1!==arguments.length)throw new Error("GHistogram.setDim(): signature not supported");a=arguments[0][0],b=arguments[0][1]}a>0&&b>0&&(this.dim[0]=a,this.dim[1]=b,this.updateArrays())},GHistogram.prototype.setPlotPoints=function(a){var b,c=a.length;if(this.plotPoints.length===c)for(b=0;bc){for(b=0;b0&&(this.fontSize=a)},GHistogram.prototype.setFontProperties=function(a,b,c){c>0&&(this.fontName=a,this.fontColor=b,this.fontSize=c)},GLayer.prototype.isValidNumber=function(a){return!isNaN(a)&&isFinite(a)},GLayer.prototype.isId=function(a){return this.id===a},GLayer.prototype.valueToXPlot=function(a){return this.xLog?this.dim[0]*Math.log(a/this.xLim[0])/Math.log(this.xLim[1]/this.xLim[0]):this.dim[0]*(a-this.xLim[0])/(this.xLim[1]-this.xLim[0])},GLayer.prototype.valueToYPlot=function(a){return this.yLog?-this.dim[1]*Math.log(a/this.yLim[0])/Math.log(this.yLim[1]/this.yLim[0]):-this.dim[1]*(a-this.yLim[0])/(this.yLim[1]-this.yLim[0])},GLayer.prototype.valueToPlot=function(){if(2===arguments.length)return[this.valueToXPlot(arguments[0]),this.valueToYPlot(arguments[1])];if(1===arguments.length&&arguments[0]instanceof GPoint)return new GPoint(this.valueToXPlot(arguments[0].getX()),this.valueToYPlot(arguments[0].getY()),arguments[0].getLabel());if(1===arguments.length&&arguments[0]instanceof Array&&arguments[0][0]instanceof GPoint){var a,b,c,d,e,f,g=arguments[0].length,h=[];if(this.xLog&&this.yLog)for(a=this.dim[0]/Math.log(this.xLim[1]/this.xLim[0]),b=-this.dim[1]/Math.log(this.yLim[1]/this.yLim[0]),f=0;fg&&this.plotPoints.splice(g,Number.MAX_VALUE);if(this.xLog&&this.yLog)for(a=this.dim[0]/Math.log(this.xLim[1]/this.xLim[0]),b=-this.dim[1]/Math.log(this.yLim[1]/this.yLim[0]),f=0;f=0&&a<=this.dim[0]&&-b>=0&&-b<=this.dim[1])},GLayer.prototype.updateInsideList=function(){for(var a,b=this.plotPoints.length,c=0;c=0&&a.getX()<=this.dim[0]&&-a.getY()>=0&&-a.getY()<=this.dim[1]);this.inside.length>b&&this.inside.splice(b,Number.MAX_VALUE)},GLayer.prototype.getPointIndexAtPlotPos=function(a,b){var c;if(this.isInside(a,b))for(var d,e,f=Number.MAX_VALUE,g=this.plotPoints.length,h=this.pointSizes.length,i=0;ithis.dim[0]&&f>this.dim[0]||-e<0&&-g<0||-e>this.dim[1]&&-g>this.dim[1])){var j=f-d,k=g-e;if(0===j)c=2,this.cuts[0][0]=d,this.cuts[0][1]=0,this.cuts[1][0]=d,this.cuts[1][1]=-this.dim[1];else if(0===k)c=2,this.cuts[0][0]=0,this.cuts[0][1]=e,this.cuts[1][0]=this.dim[0],this.cuts[1][1]=e;else{var l=k/j,m=e-l*d;c=4,this.cuts[0][0]=-m/l,this.cuts[0][1]=0,this.cuts[1][0]=(-this.dim[1]-m)/l,this.cuts[1][1]=-this.dim[1],this.cuts[2][0]=0,this.cuts[2][1]=m,this.cuts[3][0]=this.dim[0],this.cuts[3][1]=m+l*this.dim[0]}if(c=this.getValidCuts(this.cuts,c,a,b),h||i){if(1!==c){var n=h?a:b;c>1&&(c=this.removeDuplicatedCuts(this.cuts,c,0))>1&&(c=this.removePointFromCuts(this.cuts,c,n,0))>1&&(c=this.removeDuplicatedCuts(this.cuts,c,.001))>1&&(c=this.removePointFromCuts(this.cuts,c,n,.001)),0===c&&(c=1,this.cuts[0][0]=n.getX(),this.cuts[0][1]=n.getY())}}else c>2&&(c=this.removeDuplicatedCuts(this.cuts,c,0))>2&&(c=this.removeDuplicatedCuts(this.cuts,c,.001)),2===c&&(Math.pow(this.cuts[0][0]-d,2),Math.pow(this.cuts[0][1]-e),2>Math.pow(this.cuts[1][0]-d,2)+Math.pow(this.cuts[1][1]-e,2)&&(this.cuts[2][0]=this.cuts[0][0],this.cuts[2][1]=this.cuts[0][1],this.cuts[0][0]=this.cuts[1][0],this.cuts[0][1]=this.cuts[1][1],this.cuts[1][0]=this.cuts[2][0],this.cuts[1][1]=this.cuts[2][1])),1===c&&(c=2,this.cuts[1][0]=this.cuts[0][0],this.cuts[1][1]=this.cuts[0][1]);(h||i)&&1!==c?console.log("There should be one cut!!!"):h||i||0===c||2===c||console.log("There should be either 0 or 2 cuts!!! "+c+" were found")}}return c},GLayer.prototype.getValidCuts=function(a,b,c,d){for(var e=c.getX(),f=c.getY(),g=d.getX(),h=d.getY(),i=Math.abs(g-e),j=Math.abs(h-f),k=0,l=0;ld||Math.abs(a[h][1]-f)>d)&&(a[g][0]=a[h][0],a[g][1]=a[h][1],g++);return g},GLayer.prototype.startHistogram=function(a){this.hist=new GHistogram(this.parent,a,this.dim,this.plotPoints)},GLayer.prototype.drawPoints=function(){var a,b;if(0===arguments.length){a=this.plotPoints.length;var c=this.pointColors.length,d=this.pointSizes.length;if(this.parent.push(),this.parent.ellipseMode(this.parent.CENTER),this.parent.noStroke(),1===c&&1===d)for(this.parent.fill(this.pointColors[0]),b=0;b=2&&this.parent.line(this.cuts[0][0],this.cuts[0][1],this.cuts[1][0],this.cuts[1][1])}this.parent.pop()},GLayer.prototype.drawLine=function(){var a,b,c,d,e,f;if(4===arguments.length&&arguments[0]instanceof GPoint)a=arguments[0],b=arguments[1],c=arguments[2],d=arguments[3];else if(4===arguments.length)e=arguments[0],f=arguments[1],c=arguments[2],d=arguments[3];else if(2===arguments.length&&arguments[0]instanceof GPoint)a=arguments[0],b=arguments[1],c=this.lineColor,d=this.lineWidth;else{if(2!==arguments.length)throw new Error("GLayer.drawLine(): signature not supported");e=arguments[0],f=arguments[1],c=this.lineColor,d=this.lineWidth}void 0!==e&&(this.xLog&&this.yLog?(a=new GPoint(this.xLim[0],Math.pow(10,e*Math.log(this.xLim[0])/Math.LN10+f)),b=new GPoint(this.xLim[1],Math.pow(10,e*Math.log(this.xLim[1])/Math.LN10+f))):this.xLog?(a=new GPoint(this.xLim[0],e*Math.log(this.xLim[0])/Math.LN10+f),b=new GPoint(this.xLim[1],e*Math.log(this.xLim[1])/Math.LN10+f)):this.yLog?(a=new GPoint(this.xLim[0],Math.pow(10,e*this.xLim[0]+f)),b=new GPoint(this.xLim[1],Math.pow(10,e*this.xLim[1]+f))):(a=new GPoint(this.xLim[0],e*this.xLim[0]+f),b=new GPoint(this.xLim[1],e*this.xLim[1]+f)));var g=this.valueToPlot(a),h=this.valueToPlot(b);if(g.isValid()&&h.isValid()){var i=this.isInside(g),j=this.isInside(h);if(this.parent.push(),this.parent.noFill(),this.parent.stroke(c),this.parent.strokeWeight(d),this.parent.strokeCap(this.parent.SQUARE),i&&j)this.parent.line(g.getX(),g.getY(),h.getX(),h.getY());else{var k=this.obtainBoxIntersections(g,h);i?this.parent.line(g.getX(),g.getY(),this.cuts[0][0],this.cuts[0][1]):j?this.parent.line(this.cuts[0][0],this.cuts[0][1],h.getX(),h.getY()):k>=2&&this.parent.line(this.cuts[0][0],this.cuts[0][1],this.cuts[1][0],this.cuts[1][1])}this.parent.pop()}},GLayer.prototype.drawHorizontalLine=function(){var a,b,c;if(3===arguments.length)a=arguments[0],b=arguments[1],c=arguments[2];else{if(1!==arguments.length)throw new Error("GLayer.drawHorizontalLine(): signature not supported");a=arguments[0],b=this.lineColor,c=this.lineWidth}var d=this.valueToYPlot(a);this.isValidNumber(d)&&-d>=0&&-d<=this.dim[1]&&(this.parent.push(),this.parent.noFill(),this.parent.stroke(b),this.parent.strokeWeight(c),this.parent.strokeCap(this.parent.SQUARE),this.parent.line(0,d,this.dim[0],d),this.parent.pop())},GLayer.prototype.drawVerticalLine=function(){var a,b,c;if(3===arguments.length)a=arguments[0],b=arguments[1],c=arguments[2];else{if(1!==arguments.length)throw new Error("GLayer.drawVerticalLine(): signature not supported");a=arguments[0],b=this.lineColor,c=this.lineWidth}var d=this.valueToXPlot(a);this.isValidNumber(d)&&d>=0&&d<=this.dim[0]&&(this.parent.push(),this.parent.noFill(),this.parent.stroke(b),this.parent.strokeWeight(c),this.parent.strokeCap(this.parent.SQUARE),this.parent.line(d,0,d,-this.dim[1]),this.parent.pop())},GLayer.prototype.drawFilledContour=function(a,b){var c;if(a===GPlot.HORIZONTAL?c=this.getHorizontalShape(b):a===GPlot.VERTICAL&&(c=this.getVerticalShape(b)),void 0!==c&&c.length>0){this.parent.push(),this.parent.fill(this.lineColor),this.parent.noStroke(),this.parent.beginShape();for(var d=0;d=0&&b.getX()<=this.dim[0]&&(-b.getY()<0?(f.push(new GPoint(b.getX(),0,"projection")),c=!0):(f.push(new GPoint(b.getX(),-this.dim[1],"projection")),c=!0)),d=i+1;d0){var l=new GPoint(f[0]);if(0!==l.getX()&&l.getX()!==this.dim[0])if("cut"===l.getLabel())this.plotPoints[g].getX()<0?(l.setX(0),l.setLabel("extreme")):(l.setX(this.dim[0]),l.setLabel("extreme"));else if(0!==g){for(var m=g-1;m>0&&!this.plotPoints[m].isValid();)m--;this.plotPoints[m].isValid()&&(this.plotPoints[m].getX()<0?(l.setX(0),l.setLabel("extreme")):(l.setX(this.dim[0]),l.setLabel("extreme")))}var n=new GPoint(f[f.length-1]);if(0!==n.getX()&&n.getX()!==this.dim[0]&&h!==e-1){for(d=h+1;dthis.dim[1]?(f.push(new GPoint(n.getX(),-this.dim[1])),f.push(new GPoint(l.getX(),-this.dim[1]))):(f.push(new GPoint(n.getX(),o[1])),f.push(new GPoint(l.getX(),o[1]))),"extreme"===l.getLabel()&&f.push(l)}return f},GLayer.prototype.getVerticalShape=function(a){for(var b,c,d,e=this.plotPoints.length,f=[],g=-1,h=-1,i=0;i=0&&-b.getY()<=this.dim[1]&&(b.getX()<0?(f.push(new GPoint(0,b.getY(),"projection")),c=!0):(f.push(new GPoint(this.dim[0],b.getY(),"projection")),c=!0)),d=i+1;d0){var l=new GPoint(f[0]);if(0!==l.getY()&&l.getY()!==-this.dim[1])if("cut"===l.getLabel())-this.plotPoints[g].getY()<0?(l.setY(0),l.setLabel("extreme")):(l.setY(-this.dim[1]),l.setLabel("extreme"));else if(0!==g){for(var m=g-1;m>0&&!this.plotPoints[m].isValid();)m--;this.plotPoints[m].isValid()&&(-this.plotPoints[m].getY()<0?(l.setY(0),l.setLabel("extreme")):(l.setY(-this.dim[1]),l.setLabel("extreme")))}var n=new GPoint(f[f.length-1]);if(0!==n.getY()&&n.getY()!==-this.dim[1]&&h!==e-1){for(d=h+1;dthis.dim[0]?(f.push(new GPoint(this.dim[0],n.getY())),f.push(new GPoint(this.dim[0],l.getY()))):(f.push(new GPoint(o[0],n.getY())),f.push(new GPoint(o[0],l.getY()))),"extreme"===l.getLabel()&&f.push(l)}return f},GLayer.prototype.drawLabel=function(a){var b=this.valueToXPlot(a.getX()),c=this.valueToYPlot(a.getY());if(this.isValidNumber(b)&&this.isValidNumber(c)){var d=b+this.labelSeparation[0],e=c-this.labelSeparation[1],f=this.fontSize/4;this.parent.push(),this.parent.rectMode(this.parent.CORNER),this.parent.noStroke(),this.parent.textFont(this.fontName),this.parent.textSize(this.fontSize),this.parent.textAlign(this.parent.LEFT,this.parent.BOTTOM),this.parent.fill(this.labelBgColor),this.parent.rect(d-f,e-this.fontSize-f,this.parent.textWidth(a.getLabel())+2*f,this.fontSize+2*f),this.parent.fill(this.fontColor),this.parent.text(a.getLabel(),d,e),this.parent.pop()}},GLayer.prototype.drawLabelAtPlotPos=function(a,b){var c=this.getPointAtPlotPos(a,b);void 0!==c&&this.drawLabel(c)},GLayer.prototype.drawHistogram=function(){void 0!==this.hist&&this.hist.draw(this.valueToPlot(this.histBasePoint))},GLayer.prototype.drawPolygon=function(a,b){var c;if(a.length>2){var d=this.valueToPlot(a),e=0;for(c=0;c1&&(h.push(new GPoint(this.cuts[0][0],this.cuts[0][1],"double cut")),h.push(new GPoint(this.cuts[1][0],this.cuts[1][1],"double cut")))}g=h.length;var k=[];for(c=0;c0&&t>0&&s!==this.dim[0]&&t!==this.dim[1]){var u=0===o||o===this.dim[0]?o:q,v=0===p||p===-this.dim[1]?p:r;k.push(new GPoint(u,v,"special cut"))}}}if(k.length>2){for(this.parent.push(),this.parent.fill(b),this.parent.noStroke(),this.parent.beginShape(),c=0;c0&&b>0&&(this.dim[0]=a,this.dim[1]=b,this.updatePlotPoints(),void 0!==this.hist&&(this.hist.setDim(this.dim),this.hist.setPlotPoints(this.plotPoints)))},GLayer.prototype.setXLim=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(1!==arguments.length)throw new Error("GLayer.setXLim(): signature not supported");a=arguments[0][0],b=arguments[0][1]}a!==b&&this.isValidNumber(a)&&this.isValidNumber(b)&&(this.xLog&&(a<=0||b<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.xLim[0]=a,this.xLim[1]=b,this.updatePlotPoints(),this.updateInsideList(),void 0!==this.hist&&this.hist.setPlotPoints(this.plotPoints)))},GLayer.prototype.setYLim=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(1!==arguments.length)throw new Error("GLayer.setYLim(): signature not supported");a=arguments[0][0],b=arguments[0][1]}a!==b&&this.isValidNumber(a)&&this.isValidNumber(b)&&(this.yLog&&(a<=0||b<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.yLim[0]=a,this.yLim[1]=b,this.updatePlotPoints(),this.updateInsideList(),void 0!==this.hist&&this.hist.setPlotPoints(this.plotPoints)))},GLayer.prototype.setXYLim=function(){var a,b,c,d;if(4===arguments.length)a=arguments[0],b=arguments[1],c=arguments[2],d=arguments[3];else{if(2!==arguments.length)throw new Error("GLayer.setXYLim(): signature not supported");a=arguments[0][0],b=arguments[0][1],c=arguments[1][0],d=arguments[1][1]}a!==b&&c!==d&&this.isValidNumber(a)&&this.isValidNumber(b)&&this.isValidNumber(c)&&this.isValidNumber(d)&&(this.xLog&&(a<=0||b<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.xLim[0]=a,this.xLim[1]=b),this.yLog&&(c<=0||d<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.yLim[0]=c,this.yLim[1]=d),this.updatePlotPoints(),this.updateInsideList(),void 0!==this.hist&&this.hist.setPlotPoints(this.plotPoints))},GLayer.prototype.setLimAndLog=function(){var a,b,c,d,e,f;if(6===arguments.length)a=arguments[0],b=arguments[1],c=arguments[2],d=arguments[3],e=arguments[4],f=arguments[5];else{if(4!==arguments.length)throw new Error("GLayer.setLimAndLog(): signature not supported");a=arguments[0][0],b=arguments[0][1],c=arguments[1][0],d=arguments[1][1],e=arguments[2],f=arguments[3]}a!==b&&c!==d&&this.isValidNumber(a)&&this.isValidNumber(b)&&this.isValidNumber(c)&&this.isValidNumber(d)&&(e&&(a<=0||b<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.xLim[0]=a,this.yLim[1]=b,this.xLog=e),f&&(c<=0||d<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.yLim[0]=c,this.yLim[1]=d,this.yLog=f),this.updatePlotPoints(),this.updateInsideList(),void 0!==this.hist&&this.hist.setPlotPoints(this.plotPoints))},GLayer.prototype.setXLog=function(a){a!==this.xLog&&(a&&(this.xLim[0]<=0||this.xLim[1]<=0)&&(console.log("One of the limits is negative. This is not allowed in logarithmic scale."),console.log("Will set horizontal limits to (0.1, 10)"),this.xLim[0]=.1,this.xLim[1]=10),this.xLog=a,this.updatePlotPoints(),this.updateInsideList(),void 0!==this.hist&&this.hist.setPlotPoints(this.plotPoints))},GLayer.prototype.setYLog=function(a){a!==this.yLog&&(a&&(this.yLim[0]<=0||this.yLim[1]<=0)&&(console.log("One of the limits is negative. This is not allowed in logarithmic scale."),console.log("Will set horizontal limits to (0.1, 10)"),this.yLim[0]=.1,this.yLim[1]=10),this.yLog=a,this.updatePlotPoints(),this.updateInsideList(),void 0!==this.hist&&this.hist.setPlotPoints(this.plotPoints))},GLayer.prototype.setPoints=function(a){var b,c=a.length;if(this.points.length>c)this.points.splice(c,Number.MAX_VALUE);else for(b=this.points.length;b0&&(this.pointColors=a.slice())},GLayer.prototype.setPointColor=function(a){this.pointColors=[a]},GLayer.prototype.setPointSizes=function(a){a.length>0&&(this.pointSizes=a.slice())},GLayer.prototype.setPointSize=function(a){this.pointSizes=[a]},GLayer.prototype.setLineColor=function(a){this.lineColor=a},GLayer.prototype.setLineWidth=function(a){a>0&&(this.lineWidth=a)},GLayer.prototype.setHistBasePoint=function(a){this.histBasePoint.set(a)},GLayer.prototype.setHistType=function(a){void 0!==this.hist&&this.hist.setType(a)},GLayer.prototype.setHistVisible=function(a){void 0!==this.hist&&this.hist.setVisible(a)},GLayer.prototype.setDrawHistLabels=function(a){void 0!==this.hist&&this.hist.setDrawLabels(a)},GLayer.prototype.setLabelBgColor=function(a){this.labelBgColor=a},GLayer.prototype.setLabelSeparation=function(a){this.labelSeparation[0]=a[0],this.labelSeparation[1]=a[1]},GLayer.prototype.setFontName=function(a){this.fontName=a},GLayer.prototype.setFontColor=function(a){this.fontColor=a},GLayer.prototype.setFontSize=function(a){a>0&&(this.fontSize=a)},GLayer.prototype.setFontProperties=function(a,b,c){c>0&&(this.fontName=a,this.fontColor=b,this.fontSize=c)},GLayer.prototype.setAllFontProperties=function(a,b,c){this.setFontProperties(a,b,c),void 0!==this.hist&&this.hist.setFontProperties(a,b,c)},GLayer.prototype.getId=function(){return this.id},GLayer.prototype.getDim=function(){return this.dim.slice()},GLayer.prototype.getXLim=function(){return this.xLim.slice()},GLayer.prototype.getYLim=function(){return this.yLim.slice()},GLayer.prototype.getXLog=function(){return this.xLog},GLayer.prototype.getYLog=function(){return this.yLog},GLayer.prototype.getPoints=function(){for(var a=[],b=0;b=this.pos[0]&&a<=this.pos[0]+this.outerDim[0]&&b>=this.pos[1]&&b<=this.pos[1]+this.outerDim[1]},GPlot.prototype.isOverBox=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(0!==arguments.length)throw new Error("GPlot.isOverBox(): signature not supported");a=this.parent.mouseX,b=this.parent.mouseY}return a>=this.pos[0]+this.mar[1]&&a<=this.pos[0]+this.outerDim[0]-this.mar[3]&&b>=this.pos[1]+this.mar[2]&&b<=this.pos[1]+this.outerDim[1]-this.mar[0]},GPlot.prototype.updateLimits=function(){this.fixedXLim||(this.xLim=this.calculatePlotXLim(),this.xAxis.setLim(this.xLim),this.topAxis.setLim(this.xLim)),this.fixedYLim||(this.yLim=this.calculatePlotYLim(),this.yAxis.setLim(this.yLim),this.rightAxis.setLim(this.yLim)),this.mainLayer.setXYLim(this.xLim,this.yLim);for(var a=0;a=this.yLim[0]&&e>=this.yLim[0]&&e<=this.yLim[1]||this.yLim[1]=this.yLim[1]),!f||this.xLog&&d<=0||(db[1]&&(b[1]=d))}return b[1]=this.xLim[0]&&d>=this.xLim[0]&&d<=this.xLim[1]||this.xLim[1]=this.xLim[1]),!f||this.yLog&&e<=0||(eb[1]&&(b[1]=e))}return b[1]=0&&c[b]<=this.dim[0]&&this.parent.line(c[b],0,c[b],-this.dim[1])}if(a===GPlot.BOTH||a===GPlot.HORIZONTAL){var d=this.yAxis.getPlotTicksRef();for(b=0;b=0&&-d[b]<=this.dim[1]&&this.parent.line(0,d[b],this.dim[0],d[b])}this.parent.pop()},GPlot.prototype.drawHistograms=function(){this.mainLayer.drawHistogram();for(var a=0;a0&&b>0){var c=a-this.mar[1]-this.mar[3],d=b-this.mar[0]-this.mar[2];if(c>0&&d>0){this.outerDim[0]=a,this.outerDim[1]=b,this.dim[0]=c,this.dim[1]=d,this.xAxis.setDim(this.dim),this.topAxis.setDim(this.dim),this.yAxis.setDim(this.dim),this.rightAxis.setDim(this.dim),this.title.setDim(this.dim),this.mainLayer.setDim(this.dim);for(var e=0;e0&&f>0&&(this.mar[0]=a,this.mar[1]=b,this.mar[2]=c,this.mar[3]=d,this.outerDim[0]=e,this.outerDim[1]=f)},GPlot.prototype.setDim=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(1!==arguments.length)throw new Error("GPlot.setDim(): signature not supported");a=arguments[0][0],b=arguments[0][1]}if(a>0&&b>0){var c=a+this.mar[1]+this.mar[3],d=b+this.mar[0]+this.mar[2];if(c>0&&d>0){this.outerDim[0]=c,this.outerDim[1]=d,this.dim[0]=a,this.dim[1]=b,this.xAxis.setDim(this.dim),this.topAxis.setDim(this.dim),this.yAxis.setDim(this.dim),this.rightAxis.setDim(this.dim),this.title.setDim(this.dim),this.mainLayer.setDim(this.dim);for(var e=0;ethis.xLim[1],this.fixedXLim=!0,this.xAxis.setLim(this.xLim),this.topAxis.setLim(this.xLim),this.updateLimits()))},GPlot.prototype.setYLim=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else{if(1!==arguments.length)throw new Error("GPlot.setYLim(): signature not supported");a=arguments[0][0],b=arguments[0][1]}a!==b&&(this.yLog&&(a<=0||b<=0)?console.log("One of the limits is negative. This is not allowed in logarithmic scale."):(this.yLim[0]=a,this.yLim[1]=b,this.invertedYScale=this.yLim[0]>this.yLim[1],this.fixedYLim=!0,this.yAxis.setLim(this.yLim),this.rightAxis.setLim(this.yLim),this.updateLimits()))},GPlot.prototype.setFixedXLim=function(a){this.fixedXLim=a,this.updateLimits()},GPlot.prototype.setFixedYLim=function(a){this.fixedYLim=a,this.updateLimits()},GPlot.prototype.setLogScale=function(a){var b=this.xLog,c=this.yLog;if("xy"===a||"yx"===a?(b=!0,c=!0):"x"===a?(b=!0,c=!1):"y"===a?(b=!1,c=!0):""===a&&(b=!1,c=!1),b!==this.xLog||c!==this.yLog){this.xLog=b,this.yLog=c,this.xLog&&this.fixedXLim&&(this.xLim[0]<=0||this.xLim[1]<=0)&&(this.fixedXLim=!1),this.yLog&&this.fixedYLim&&(this.yLim[0]<=0||this.yLim[1]<=0)&&(this.fixedYLim=!1),this.fixedXLim||(this.xLim=this.calculatePlotXLim()),this.fixedYLim||(this.yLim=this.calculatePlotYLim()),this.xAxis.setLimAndLog(this.xLim,this.xLog),this.topAxis.setLimAndLog(this.xLim,this.xLog),this.yAxis.setLimAndLog(this.yLim,this.yLog),this.rightAxis.setLimAndLog(this.yLim,this.yLog),this.mainLayer.setLimAndLog(this.xLim,this.yLim,this.xLog,this.yLog);for(var d=0;d=0&&a!==this.expandLimFactor&&(this.expandLimFactor=a,this.updateLimits())},GPlot.prototype.setBgColor=function(a){this.bgColor=a},GPlot.prototype.setBoxBgColor=function(a){this.boxBgColor=a},GPlot.prototype.setBoxLineColor=function(a){this.boxLineColor=a},GPlot.prototype.setBoxLineWidth=function(a){a>0&&(this.boxLineWidth=a)},GPlot.prototype.setGridLineColor=function(a){this.gridLineColor=a},GPlot.prototype.setGridLineWidth=function(a){a>0&&(this.gridLineWidth=a)},GPlot.prototype.setPoints=function(){if(2===arguments.length)this.getLayer(arguments[1]).setPoints(arguments[0]);else{if(1!==arguments.length)throw new Error("GPlot.setPoints(): signature not supported");this.mainLayer.setPoints(arguments[0])}this.updateLimits()},GPlot.prototype.setPoint=function(){if(5===arguments.length)this.getLayer(arguments[4]).setPoint(arguments[0],arguments[1],arguments[2],arguments[3]);else if(4===arguments.length)this.mainLayer.setPoint(arguments[0],arguments[1],arguments[2],arguments[3]);else if(3===arguments.length&&arguments[1]instanceof GPoint)this.getLayer(arguments[2]).setPoint(arguments[0],arguments[1]);else if(3===arguments.length)this.mainLayer.setPoint(arguments[0],arguments[1],arguments[2]);else{if(2!==arguments.length)throw new Error("GPlot.setPoint(): signature not supported");this.mainLayer.setPoint(arguments[0],arguments[1])}this.updateLimits()},GPlot.prototype.addPoint=function(){if(4===arguments.length)this.getLayer(arguments[3]).addPoint(arguments[0],arguments[1],arguments[2]);else if(3===arguments.length)this.mainLayer.addPoint(arguments[0],arguments[1],arguments[2]);else if(2===arguments.length&&arguments[0]instanceof GPoint)this.getLayer(arguments[1]).addPoint(arguments[0]);else if(2===arguments.length)this.mainLayer.addPoint(arguments[0],arguments[1]);else{if(1!==arguments.length)throw new Error("GPlot.addPoint(): signature not supported");this.mainLayer.addPoint(arguments[0])}this.updateLimits()},GPlot.prototype.addPoints=function(){if(2===arguments.length)this.getLayer(arguments[1]).addPoints(arguments[0]);else{if(1!==arguments.length)throw new Error("GPlot.addPoints(): signature not supported");this.mainLayer.addPoints(arguments[0])}this.updateLimits()},GPlot.prototype.removePoint=function(){if(2===arguments.length)this.getLayer(arguments[1]).removePoint(arguments[0]);else{if(1!==arguments.length)throw new Error("GPlot.removePoint(): signature not supported");this.mainLayer.removePoint(arguments[0])}this.updateLimits()},GPlot.prototype.addPointAtIndexPos=function(){if(5===arguments.length)this.getLayer(arguments[4]).addPointAtIndexPos(arguments[0],arguments[1],arguments[2],arguments[3]);else if(4===arguments.length)this.mainLayer.addPointAtIndexPos(arguments[0],arguments[1],arguments[2],arguments[3]);else if(3===arguments.length&&arguments[1]instanceof GPoint)this.getLayer(arguments[2]).addPointAtIndexPos(arguments[0],arguments[1]);else if(3===arguments.length)this.mainLayer.addPointAtIndexPos(arguments[0],arguments[1],arguments[2]);else{if(2!==arguments.length)throw new Error("GPlot.addPointAtIndexPos(): signature not supported");this.mainLayer.addPointAtIndexPos(arguments[0],arguments[1])}this.updateLimits()},GPlot.prototype.setPointColors=function(a){this.mainLayer.setPointColors(a)},GPlot.prototype.setPointColor=function(a){this.mainLayer.setPointColor(a)},GPlot.prototype.setPointSizes=function(a){this.mainLayer.setPointSizes(a)},GPlot.prototype.setPointSize=function(a){this.mainLayer.setPointSize(a)},GPlot.prototype.setLineColor=function(a){this.mainLayer.setLineColor(a)},GPlot.prototype.setLineWidth=function(a){this.mainLayer.setLineWidth(a)},GPlot.prototype.setHistBasePoint=function(a){this.mainLayer.setHistBasePoint(a)},GPlot.prototype.setHistType=function(a){this.mainLayer.setHistType(a)},GPlot.prototype.setHistVisible=function(a){this.mainLayer.setHistVisible(a)},GPlot.prototype.setDrawHistLabels=function(a){this.mainLayer.setDrawHistLabels(a)},GPlot.prototype.setLabelBgColor=function(a){this.mainLayer.setLabelBgColor(a)},GPlot.prototype.setLabelSeparation=function(a){this.mainLayer.setLabelSeparation(a)},GPlot.prototype.setTitleText=function(a){this.title.setText(a)},GPlot.prototype.setAxesOffset=function(a){this.xAxis.setOffset(a),this.topAxis.setOffset(a),this.yAxis.setOffset(a),this.rightAxis.setOffset(a)},GPlot.prototype.setTicksLength=function(a){this.xAxis.setTickLength(a),this.topAxis.setTickLength(a),this.yAxis.setTickLength(a),this.rightAxis.setTickLength(a)},GPlot.prototype.setHorizontalAxesNTicks=function(a){this.xAxis.setNTicks(a),this.topAxis.setNTicks(a)},GPlot.prototype.setHorizontalAxesTicksSeparation=function(a){this.xAxis.setTicksSeparation(a),this.topAxis.setTicksSeparation(a)},GPlot.prototype.setHorizontalAxesTicks=function(a){this.xAxis.setTicks(a),this.topAxis.setTicks(a)},GPlot.prototype.setVerticalAxesNTicks=function(a){this.yAxis.setNTicks(a),this.rightAxis.setNTicks(a)},GPlot.prototype.setVerticalAxesTicksSeparation=function(a){this.yAxis.setTicksSeparation(a),this.rightAxis.setTicksSeparation(a)},GPlot.prototype.setVerticalAxesTicks=function(a){this.yAxis.setTicks(a),this.rightAxis.setTicks(a)},GPlot.prototype.setFontName=function(a){this.mainLayer.setFontName(a)},GPlot.prototype.setFontColor=function(a){this.mainLayer.setFontColor(a)},GPlot.prototype.setFontSize=function(a){this.mainLayer.setFontSize(a)},GPlot.prototype.setFontProperties=function(a,b,c){this.mainLayer.setFontProperties(a,b,c)},GPlot.prototype.setAllFontProperties=function(a,b,c){this.xAxis.setAllFontProperties(a,b,c),this.topAxis.setAllFontProperties(a,b,c),this.yAxis.setAllFontProperties(a,b,c),this.rightAxis.setAllFontProperties(a,b,c),this.title.setFontProperties(a,b,c),this.mainLayer.setAllFontProperties(a,b,c);for(var d=0;d0&&(this.zoomFactor=a),b!==this.parent.LEFT&&b!==this.parent.RIGHT&&b!==this.parent.CENTER||(this.increaseZoomButton=b),c!==this.parent.LEFT&&c!==this.parent.RIGHT&&c!==this.parent.CENTER||(this.decreaseZoomButton=c),d!==this.parent.SHIFT&&d!==this.parent.CONTROL&&d!==this.parent.ALT&&d!==GPlot.NONE||(this.increaseZoomKeyModifier=d),e!==this.parent.SHIFT&&e!==this.parent.CONTROL&&e!==this.parent.ALT&&e!==GPlot.NONE||(this.decreaseZoomKeyModifier=e)},GPlot.prototype.deactivateZooming=function(){this.zoomingIsActive=!1},GPlot.prototype.activateCentering=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else if(1===arguments.length)a=arguments[0],b=GPlot.NONE;else{if(0!==arguments.length)throw new Error("GPlot.activateCentering(): signature not supported");a=this.parent.LEFT,b=GPlot.NONE}this.centeringIsActive=!0,a!==this.parent.LEFT&&a!==this.parent.RIGHT&&a!==this.parent.CENTER||(this.centeringButton=a),b!==this.parent.SHIFT&&b!==this.parent.CONTROL&&b!==this.parent.ALT&&b!==GPlot.NONE||(this.centeringKeyModifier=b)},GPlot.prototype.deactivateCentering=function(){this.centeringIsActive=!1},GPlot.prototype.activatePanning=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else if(1===arguments.length)a=arguments[0],b=GPlot.NONE;else{if(0!==arguments.length)throw new Error("GPlot.activatePanning(): signature not supported");a=this.parent.LEFT,b=GPlot.NONE}this.panningIsActive=!0,a!==this.parent.LEFT&&a!==this.parent.RIGHT&&a!==this.parent.CENTER||(this.panningButton=a),b!==this.parent.SHIFT&&b!==this.parent.CONTROL&&b!==this.parent.ALT&&b!==GPlot.NONE||(this.panningKeyModifier=b)},GPlot.prototype.deactivatePanning=function(){this.panningIsActive=!1,this.panningReferencePoint=void 0},GPlot.prototype.activatePointLabels=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else if(1===arguments.length)a=arguments[0],b=GPlot.NONE;else{if(0!==arguments.length)throw new Error("GPlot.activatePointLabels(): signature not supported");a=this.parent.LEFT,b=GPlot.NONE}this.labelingIsActive=!0,a!==this.parent.LEFT&&a!==this.parent.RIGHT&&a!==this.parent.CENTER||(this.labelingButton=a),b!==this.parent.SHIFT&&b!==this.parent.CONTROL&&b!==this.parent.ALT&&b!==GPlot.NONE||(this.labelingKeyModifier=b)},GPlot.prototype.deactivatePointLabels=function(){this.labelingIsActive=!1,this.mousePos=void 0},GPlot.prototype.activateReset=function(){var a,b;if(2===arguments.length)a=arguments[0],b=arguments[1];else if(1===arguments.length)a=arguments[0],b=GPlot.NONE;else{if(0!==arguments.length)throw new Error("GPlot.activateReset(): signature not supported");a=this.parent.RIGHT,b=GPlot.NONE}this.resetIsActive=!0,this.xLimReset=void 0,this.yLimReset=void 0,a!==this.parent.LEFT&&a!==this.parent.RIGHT&&a!==this.parent.CENTER||(this.resetButton=a),b!==this.parent.SHIFT&&b!==this.parent.CONTROL&&b!==this.parent.ALT&&b!==GPlot.NONE||(this.resetKeyModifier=b)},GPlot.prototype.deactivateReset=function(){this.resetIsActive=!1,this.xLimReset=void 0,this.yLimReset=void 0},GPlot.prototype.getButton=function(a){var b;return 0===a.button?b=this.parent.LEFT:1===a.button?b=this.parent.CENTER:2===a.button?b=this.parent.RIGHT:void 0===a.button&&(b=this.parent.LEFT),b},GPlot.prototype.getModifier=function(a){return a.altKey?this.parent.ALT:a.ctrlKey?this.parent.CONTROL:a.shiftKey?this.parent.SHIFT:GPlot.NONE},GPlot.prototype.saveResetLimits=function(){void 0!==this.xLimReset&&void 0!==this.yLimReset||(this.xLimReset=this.xLim.slice(),this.yLimReset=this.yLim.slice())},GPlot.prototype.clickEvent=function(a){var b=a||window.event;if(this.isOverBox()){var c=this.getButton(b),d=this.getModifier(b);this.zoomingIsActive&&(c===this.increaseZoomButton&&d===this.increaseZoomKeyModifier?(this.resetIsActive&&this.saveResetLimits(),this.zoom(this.zoomFactor,this.parent.mouseX,this.parent.mouseY)):c===this.decreaseZoomButton&&d===this.decreaseZoomKeyModifier&&(this.resetIsActive&&this.saveResetLimits(),this.zoom(1/this.zoomFactor,this.parent.mouseX,this.parent.mouseY))), this.centeringIsActive&&c===this.centeringButton&&d===this.centeringKeyModifier&&(this.resetIsActive&&this.saveResetLimits(),this.center(this.parent.mouseX,this.parent.mouseY)),this.resetIsActive&&c===this.resetButton&&d===this.resetKeyModifier&&void 0!==this.xLimReset&&void 0!==this.yLimReset&&(this.setXLim(this.xLimReset),this.setYLim(this.yLimReset),this.xLimReset=void 0,this.yLimReset=void 0)}},GPlot.prototype.wheelEvent=function(a){var b=a||window.event;if(this.isOverBox()){var c=b.deltaY,d=this.parent.CENTER,e=this.getModifier(b);this.zoomingIsActive&&(d===this.increaseZoomButton&&e===this.increaseZoomKeyModifier&&c>0?(b.preventDefault(),this.resetIsActive&&this.saveResetLimits(),this.zoom(this.zoomFactor,this.parent.mouseX,this.parent.mouseY)):d===this.decreaseZoomButton&&e===this.decreaseZoomKeyModifier&&c<0&&(b.preventDefault(),this.resetIsActive&&this.saveResetLimits(),this.zoom(1/this.zoomFactor,this.parent.mouseX,this.parent.mouseY)))}},GPlot.prototype.mouseDownEvent=function(a){var b=a||window.event;if(this.isOverBox()){var c=!1,d=this.getButton(b),e=this.getModifier(b);this.panningIsActive&&d===this.panningButton&&e===this.panningKeyModifier&&(c=!0,this.resetIsActive&&this.saveResetLimits(),this.panningReferencePoint=this.getValueAt(this.parent.mouseX,this.parent.mouseY)),this.labelingIsActive&&d===this.labelingButton&&e===this.labelingKeyModifier&&(c=!0,this.mousePos=[this.parent.mouseX,this.parent.mouseY]),c&&(document.addEventListener("mousemove",this.mouseMoveListener,!1),document.addEventListener("mouseup",this.mouseUpListener,!1))}},GPlot.prototype.mouseMoveEvent=function(a){var b=a||window.event,c=this.getButton(b),d=this.getModifier(b);a.preventDefault(),this.panningIsActive&&c===this.panningButton&&d===this.panningKeyModifier&&this.align(this.panningReferencePoint,this.parent.mouseX,this.parent.mouseY),this.labelingIsActive&&c===this.labelingButton&&d===this.labelingKeyModifier&&(this.mousePos=[this.parent.mouseX,this.parent.mouseY])},GPlot.prototype.mouseUpEvent=function(a){var b=a||window.event,c=this.getButton(b);document.removeEventListener("mousemove",this.mouseMoveListener,!1),document.removeEventListener("mouseup",this.mouseUpListener,!1),this.panningIsActive&&c===this.panningButton&&(this.panningReferencePoint=void 0),this.labelingIsActive&&c===this.labelingButton&&(this.mousePos=void 0)},GPlot.prototype.touchStartEvent=function(a){var b=a||window.event;if(this.parent._ontouchstart(b),this.isOverBox()){var c=!1;if(this.panningIsActive&&(c=!0,this.panningReferencePoint=this.getValueAt(this.parent.mouseX,this.parent.mouseY)),this.labelingIsActive&&(c=!0,this.mousePos=[this.parent.mouseX,this.parent.mouseY]),this.zoomingIsActive&&void 0!==b.touches&&2===b.touches.length){c=!0;var d=b.touches[0].pageX-b.touches[1].pageX,e=b.touches[0].pageY-b.touches[1].pageY;this.zoomStartDistance=Math.sqrt(d*d+e*e),this.zoomStartPosition=[this.parent.mouseX,this.parent.mouseY]}c&&(document.addEventListener("touchmove",this.touchMoveListener,{passive:!1}),document.addEventListener("touchend",this.touchEndListener,!1),document.addEventListener("touchcancel",this.touchEndListener,!1))}},GPlot.prototype.touchMoveEvent=function(a){var b=a||window.event;if(b.preventDefault(),this.panningIsActive&&this.align(this.panningReferencePoint,this.parent.mouseX,this.parent.mouseY),this.labelingIsActive&&(this.mousePos=[this.parent.mouseX,this.parent.mouseY]),this.zoomingIsActive&&void 0!==b.touches&&2===b.touches.length){var c=b.touches[0].pageX-b.touches[1].pageX,d=b.touches[0].pageY-b.touches[1].pageY,e=Math.sqrt(c*c+d*d);this.zoom(e/this.zoomStartDistance,this.zoomStartPosition[0],this.zoomStartPosition[1]),this.zoomStartDistance=e}},GPlot.prototype.touchEndEvent=function(a){document.removeEventListener("touchmove",this.touchMoveListener,!1),document.removeEventListener("touchend",this.touchEndListener,!1),document.removeEventListener("touchcancel",this.touchEndListener,!1),this.panningIsActive&&(this.panningReferencePoint=void 0),this.labelingIsActive&&(this.mousePos=void 0),this.zoomingIsActive&&(this.zoomStartDistance=void 0,this.zoomStartPosition=void 0)},GPlot.prototype.preventDefaultEvent=function(a){var b=a||window.event;this.isOverBox()&&b.preventDefault()},GPlot.prototype.contextMenuEvent=function(a){var b=a||window.event;this.isOverBox()&&(b.preventDefault(),this.clickEvent(b))},GPlot.prototype.preventWheelDefault=function(){this.parentElt.addEventListener("wheel",this.preventDefaultEvent.bind(this),!1)},GPlot.prototype.preventRightClickDefault=function(){this.parentElt.addEventListener("contextmenu",this.contextMenuEvent.bind(this),!1)}; \ No newline at end of file diff --git a/src/GAxis.js b/src/GAxis.js index 9efb220..25ce729 100644 --- a/src/GAxis.js +++ b/src/GAxis.js @@ -715,9 +715,9 @@ GAxis.prototype.setNTicks = function(nTicks) { if (nTicks >= 0) { this.nTicks = nTicks; this.ticksSeparation = -1; + this.fixedTicks = false; if (!this.log) { - this.fixedTicks = false; this.updateTicks(); this.updatePlotTicks(); this.updateTicksInside(); @@ -728,9 +728,9 @@ GAxis.prototype.setNTicks = function(nTicks) { GAxis.prototype.setTicksSeparation = function(ticksSeparation) { this.ticksSeparation = ticksSeparation; + this.fixedTicks = false; if (!this.log) { - this.fixedTicks = false; this.updateTicks(); this.updatePlotTicks(); this.updateTicksInside(); diff --git a/src/GLayer.js b/src/GLayer.js index a9821fd..d3802d6 100644 --- a/src/GLayer.js +++ b/src/GLayer.js @@ -1561,7 +1561,7 @@ GLayer.prototype.addPointAtIndexPos = function() { if (index <= this.points.length) { this.points.splice(index, 0, new GPoint(x, y, label)); this.plotPoints.splice(index, 0, new GPoint(this.valueToXPlot(x), this.valueToYPlot(y), label)); - this.inside.splice(index, 0, this.isInside(this.plotPoints[0])); + this.inside.splice(index, 0, this.isInside(this.plotPoints[index])); if ( typeof this.hist !== "undefined") { this.hist.setPlotPoints(this.plotPoints); diff --git a/src/GPlot.js b/src/GPlot.js index 872efbf..5f108b6 100644 --- a/src/GPlot.js +++ b/src/GPlot.js @@ -514,6 +514,7 @@ GPlot.prototype.moveHorizontalAxesLim = function(delta) { // Fix the limits this.fixedXLim = true; + this.fixedYLim = true; // Move the horizontal axes this.xAxis.moveLim(this.xLim); @@ -538,6 +539,7 @@ GPlot.prototype.moveVerticalAxesLim = function(delta) { } // Fix the limits + this.fixedXLim = true; this.fixedYLim = true; // Move the vertical axes