diff --git a/js/least-squares-regression/model/Graph.ts b/js/least-squares-regression/model/Graph.ts index 47481c3..7141495 100644 --- a/js/least-squares-regression/model/Graph.ts +++ b/js/least-squares-regression/model/Graph.ts @@ -217,11 +217,10 @@ export default class Graph { public getBoundaryPoints( slope: number, intercept: number ): { point1: Vector2; point2: Vector2 } { const yValueLeft = slope * this.bounds.minX + intercept; const yValueRight = slope * this.bounds.maxX + intercept; - const boundaryPoints = { + return { point1: new Vector2( this.bounds.minX, yValueLeft ), point2: new Vector2( this.bounds.maxX, yValueRight ) }; - return boundaryPoints; } /** @@ -256,7 +255,7 @@ export default class Graph { } /** - * Determine if a best fit line can be defined (at least two points and no vertical alignment). + * Determine if the best fit line can be defined (at least two points and no vertical alignment). */ public isLinearFitDefined(): boolean { @@ -285,11 +284,10 @@ export default class Graph { const slope = slopeNumerator / slopeDenominator; const intercept = this.averageOfSumOfY - slope * this.averageOfSumOfX; - const fitParameters = { + return { slope: slope, intercept: intercept }; - return fitParameters; } /** @@ -304,29 +302,29 @@ export default class Graph { return null; } else { - this.getStatistics(); + this.getStatistics(); let pearsonCoefficientCorrelationNumerator = this.averageOfSumOfSquaresXY - this.averageOfSumOfX * this.averageOfSumOfY; - if ( Math.abs( pearsonCoefficientCorrelationNumerator ) < 1E-10 ) { - pearsonCoefficientCorrelationNumerator = 0; - } + if ( Math.abs( pearsonCoefficientCorrelationNumerator ) < 1E-10 ) { + pearsonCoefficientCorrelationNumerator = 0; + } // for very small values, we can end up with a very small or negative number. In this case, return null so we // don't get a NaN for the coefficient. + const number = ( this.averageOfSumOfSquaresXX - this.averageOfSumOfX * this.averageOfSumOfX ) * ( this.averageOfSumOfSquaresYY - this.averageOfSumOfY * this.averageOfSumOfY ); - if ( number < 1E-15 ) { - return null; - } - const pearsonCoefficientCorrelationDenominator = Math.sqrt( number ); + if ( number < 1E-15 ) { + return null; + } + const pearsonCoefficientCorrelationDenominator = Math.sqrt( number ); // make sure the denominator is not equal to zero, this happens if all the points are aligned vertically - if ( pearsonCoefficientCorrelationDenominator === 0 ) { - return null; - } - else { - const pearsonCoefficientCorrelation = pearsonCoefficientCorrelationNumerator / pearsonCoefficientCorrelationDenominator; - return pearsonCoefficientCorrelation; - } + if ( pearsonCoefficientCorrelationDenominator === 0 ) { + return null; + } + else { + return pearsonCoefficientCorrelationNumerator / pearsonCoefficientCorrelationDenominator; + } } } } diff --git a/js/least-squares-regression/view/EquationNode.ts b/js/least-squares-regression/view/EquationNode.ts index 5b18807..db87932 100644 --- a/js/least-squares-regression/view/EquationNode.ts +++ b/js/least-squares-regression/view/EquationNode.ts @@ -59,7 +59,7 @@ export default class EquationNode extends Node { // options for the text elements of the equation let numericalTextOptions; // font and fill options for numerical strings , i.e. '- 9.54' - let stringTextOptions; // font and fill options for 'pure' strings, eg. 'y' + let stringTextOptions; // font and fill options for 'pure' strings, e.g., 'y' switch( options.mode ) { case 'myLine': @@ -162,12 +162,11 @@ export default class EquationNode extends Node { const signString = isNegative ? MathSymbols.MINUS : MathSymbols.PLUS; const optionalSignString = isNegative ? MathSymbols.MINUS : ' '; const absoluteNumber = this.roundNumber( Math.abs( parseFloat( this.roundNumber( number ) ) ) ); - const numberString = { + return { absoluteNumber: absoluteNumber, optionalSign: optionalSignString, sign: signString }; - return numberString; } /** diff --git a/js/least-squares-regression/view/GraphAxesNode.ts b/js/least-squares-regression/view/GraphAxesNode.ts index 2094a0a..8736daa 100644 --- a/js/least-squares-regression/view/GraphAxesNode.ts +++ b/js/least-squares-regression/view/GraphAxesNode.ts @@ -125,7 +125,7 @@ class MajorTickNode extends Node { // label position if ( isVertical ) { - // center label under line, compensate for minus sign + // center label under the line, compensate for minus sign const signXOffset = ( parseFloat( value ) < 0 ) ? -( MINUS_SIGN_WIDTH / 2 ) : 0; tickLabelNode.left = tickLineNode.centerX - ( tickLabelNode.width / 2 ) + signXOffset; tickLabelNode.top = tickLineNode.bottom + TICK_LABEL_SPACING; @@ -200,7 +200,7 @@ function tickSpacing( range: Range ): { const numberOfTicks = ( tickStopPosition - tickStartPosition ) / minorTickSpacing + 1; // number of ticks const decimalPlaces = Utils.roundSymmetric( majorTickSpacing > 1 ? 0 : -1 * Math.log( majorTickSpacing ) / Math.LN10 + 1 ); // the precision of ticks (for text purposes) - const tickSeparation = { + return { majorTickSpacing: majorTickSpacing, minorTickSpacing: minorTickSpacing, minorTicksPerMajor: minorTicksPerMajor, @@ -209,7 +209,6 @@ function tickSpacing( range: Range ): { numberOfTicks: numberOfTicks, decimalPlaces: decimalPlaces }; - return tickSeparation; } //---------------------------------------------------------------------------------------- @@ -386,7 +385,7 @@ class GridNode extends Node { const maxX = dataSet.xRange.max; for ( let i = 0; i < numberOfHorizontalGridLines; i++ ) { const modelY = tickYSeparation.tickStartPosition + tickYSeparation.minorTickSpacing * i; - if ( modelY !== dataSet.yRange.min ) { // skip origin, x axis will live here + if ( modelY !== dataSet.yRange.min ) { // skip origin, x-axis will live here const yOffset = modelY; const isMajorX = Math.abs( modelY / tickYSeparation.minorTickSpacing ) % ( tickYSeparation.minorTicksPerMajor ) < SMALL_EPSILON; if ( isMajorX ) { @@ -409,7 +408,7 @@ class GridNode extends Node { const maxY = dataSet.yRange.min; for ( let j = 0; j < numberOfVerticalGridLines; j++ ) { const modelX = tickXSeparation.tickStartPosition + tickXSeparation.minorTickSpacing * j; - if ( modelX !== dataSet.xRange.min ) { // skip origin, y axis will live here + if ( modelX !== dataSet.xRange.min ) { // skip origin, y-axis will live here const xOffset = modelX; const isMajorY = Math.abs( modelX / tickXSeparation.minorTickSpacing ) % ( tickXSeparation.minorTicksPerMajor ) < SMALL_EPSILON; if ( isMajorY ) { diff --git a/js/least-squares-regression/view/GraphNode.ts b/js/least-squares-regression/view/GraphNode.ts index 4ccba19..3f7f93d 100644 --- a/js/least-squares-regression/view/GraphNode.ts +++ b/js/least-squares-regression/view/GraphNode.ts @@ -146,7 +146,7 @@ export default class GraphNode extends Node { this.addChild( this.bestFitLine ); } - public step( dt: number ): void { + public step(): void { this.residualCanvasNode.invalidatePaint(); } diff --git a/js/least-squares-regression/view/LeastSquaresRegressionScreenView.ts b/js/least-squares-regression/view/LeastSquaresRegressionScreenView.ts index b9a0df9..9e0d202 100644 --- a/js/least-squares-regression/view/LeastSquaresRegressionScreenView.ts +++ b/js/least-squares-regression/view/LeastSquaresRegressionScreenView.ts @@ -343,14 +343,14 @@ export default class LeastSquaresRegressionScreenView extends ScreenView { public override step( dt: number ): void { super.step( dt ); - this.graphNode.step( dt ); + this.graphNode.step( ); } /** * This is taken from MoleculesAndLightScreenView with modifications. * - * Update the Source and Reference 'Dialog-like' Node visibility. This node has behavior which is identical to the about dialog - * window, and this code is heavily borrowed from AboutDialog.js. + * Update the Source and Reference 'Dialog-like' Node visibility. This node has behavior which is identical to the + * AboutDialog window, and this code is heavily borrowed from AboutDialog.js. * * @param sourceAndReferenceNode - The SourceAndReferenceNode whose visibility should be updated. */ diff --git a/js/least-squares-regression/view/SourceAndReferenceNode.ts b/js/least-squares-regression/view/SourceAndReferenceNode.ts index 72cbf63..0cb42ea 100644 --- a/js/least-squares-regression/view/SourceAndReferenceNode.ts +++ b/js/least-squares-regression/view/SourceAndReferenceNode.ts @@ -27,7 +27,7 @@ export default class SourceAndReferenceNode extends ScreenView { */ // A PhET wide decision was made to not update custom layout bounds even if they do not match the // default layout bounds in ScreenView. Do not change these bounds as changes could break or disturb - // any phet-io instrumention. https://github.com/phetsims/phet-io/issues/1939 + // any phet-io instrumentation. https://github.com/phetsims/phet-io/issues/1939 super( { layoutBounds: new Bounds2( 0, 0, 1024, 618 ) } ); // limit the width of the dialog content for i18n @@ -99,8 +99,7 @@ export default class SourceAndReferenceNode extends ScreenView { // no need to unlink, present for the lifetime of the sim Multilink.multilink( [ LeastSquaresRegressionStrings.sourcePatternStringProperty, selectedDataSetProperty ], ( sourcePatternString, selectedDataSet ) => { referenceText.setStringProperty( selectedDataSet.reference ); - const formattedSourceString = StringUtils.format( sourcePatternString, selectedDataSet.source ); - sourceText.string = formattedSourceString; + sourceText.string = StringUtils.format( sourcePatternString, selectedDataSet.source ); panel.centerX = this.layoutBounds.centerX; panel.centerY = this.layoutBounds.centerY; button.centerX = panel.right; diff --git a/js/least-squares-regression/view/SumOfSquaredResidualsChart.ts b/js/least-squares-regression/view/SumOfSquaredResidualsChart.ts index 102e60c..df6e69e 100644 --- a/js/least-squares-regression/view/SumOfSquaredResidualsChart.ts +++ b/js/least-squares-regression/view/SumOfSquaredResidualsChart.ts @@ -80,9 +80,7 @@ export default class SumOfSquaredResidualsChart extends Node { // The barometer width is adjustable // the square of the residuals vary if the position of the point change, points are added/subtracted to the graph and if the line change position - Multilink.multilink( [ graph.angleProperty, graph.interceptProperty ], ( angle, intercept ) => { - updateWidth(); - } ); + Multilink.multilink( [ graph.angleProperty, graph.interceptProperty ], () => updateWidth() ); // Trigger an update after all the points have been added in bulk to the model dataPointsAddedEmitter.addListener( updateWidth );