Skip to content

Commit

Permalink
#51 maxOrderOfFit moved to constants
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-zelenkov committed Sep 14, 2015
1 parent 40f7c38 commit b4a973e
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 18 deletions.
2 changes: 2 additions & 0 deletions js/curve-fitting/CurveFittingConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ define( function() {
'use strict';

return {
MAX_ORDER_OF_FIT: 3,

// barometer
BAROMETER_HEIGHT: 270,
BAROMETER_TICK_WIDTH: 15,
Expand Down
5 changes: 2 additions & 3 deletions js/curve-fitting/model/Curve.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ define( function( require ) {
/**
* @param {Property.<number>} orderOfFitProperty - Property to control curve type.
* @param {Property.<string>} fitTypeProperty - Property to control fit type.
* @param {number} maxFitOrder - Max order of fit.
* @constructor
*/
function Curve( orderOfFitProperty, fitTypeProperty, maxFitOrder ) {
function Curve( orderOfFitProperty, fitTypeProperty ) {
var self = this;

PropertySet.call( this, {
Expand All @@ -53,7 +52,7 @@ define( function( require ) {
this.points = new ObservableArray();

// special object to getting fit for points
this.fitMaker = new FitMaker( maxFitOrder );
this.fitMaker = new FitMaker();

this._updateFitBound = this.updateFit.bind( this );

Expand Down
5 changes: 1 addition & 4 deletions js/curve-fitting/model/CurveFittingModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ define( function( require ) {
isEquationPanelExpanded: true // property to control equation panel expansion
} );

// max order of fit
this.maxOrderOfFit = 3;

// bucket model
var BUCKET_WIDTH = 90;
var BUCKET_HEIGHT = BUCKET_WIDTH * 0.50;
Expand All @@ -46,7 +43,7 @@ define( function( require ) {
} );

// curve model
this.curve = new Curve( this.orderOfFitProperty, this.fitTypeProperty, this.maxOrderOfFit );
this.curve = new Curve( this.orderOfFitProperty, this.fitTypeProperty );

// graph area size
this.graphArea = {
Expand Down
10 changes: 6 additions & 4 deletions js/curve-fitting/model/FitMaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
*
* @author Andrey Zelenkov (Mlearner)
*/
define( function() {
define( function( require ) {
'use strict';

// modules
var CurveFittingConstants = require( 'CURVE_FITTING/curve-fitting/CurveFittingConstants' );

/**
* @param {number} maxOrderOfFit - Max order of fit.
* @constructor
*/
function FitMaker( maxOrderOfFit ) {
function FitMaker() {
// set max size of matrix
this.maxM = maxOrderOfFit + 1;
this.maxM = CurveFittingConstants.MAX_ORDER_OF_FIT + 1;
this.m = null;

// create solution array
Expand Down
2 changes: 1 addition & 1 deletion js/curve-fitting/view/ControlMenuNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ define( function( require ) {
this.addChild( curveTypePanel );

// create fit type menu
var fitTypeMenu = new FitTypeMenu( curveFittingModel.curve, curveFittingModel.fitTypeProperty, curveFittingModel.orderOfFitProperty, curveFittingModel.maxOrderOfFit );
var fitTypeMenu = new FitTypeMenu( curveFittingModel.curve, curveFittingModel.fitTypeProperty, curveFittingModel.orderOfFitProperty, curveFittingModel );
this.addChild( fitTypeMenu );

// add observers
Expand Down
5 changes: 2 additions & 3 deletions js/curve-fitting/view/EquationFitNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@ define( function( require ) {

/**
* @param {Property.<number>} orderFitProperty parameter to track.
* @param {number} maxOrderFit - Possible range for property.
* @param {Object} [options] for slider node.
* @constructor
*/
function EquationFitNode( orderFitProperty, maxOrderFit, options ) {
function EquationFitNode( orderFitProperty, options ) {
var self = this;
var equationTextArray = [];
var boxNode;

for ( var i = 1; i < maxOrderFit + 1; i++ ) {
for ( var i = 1; i < CurveFittingConstants.MAX_ORDER_OF_FIT + 1; i++ ) {
boxNode = new HBox( { align: 'bottom' } );
var yNode = new Text( 'y = ', TEXT_OPTIONS );
boxNode.addChild( yNode );
Expand Down
5 changes: 2 additions & 3 deletions js/curve-fitting/view/FitTypeMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ define( function( require ) {
* @param {Curve} curve model.
* @param {Property.<string>} fitTypeProperty - Property to control fit type of curve.
* @param {Property.<number>} orderOfFitProperty - Property to control type of curve.
* @param {number} maxOrderOfFit - Max order of fit.
* @param {Object} [options] for graph node.
* @constructor
*/
function FitTypeMenu( curve, fitTypeProperty, orderOfFitProperty, maxOrderOfFit, options ) {
function FitTypeMenu( curve, fitTypeProperty, orderOfFitProperty, options ) {
var content = new VBox();

// create radio buttons
Expand All @@ -53,7 +52,7 @@ define( function( require ) {
content.addChild( fitTypeRadioButtonGroup );

// create equation node
content.addChild( new EquationFitNode( orderOfFitProperty, maxOrderOfFit ) );
content.addChild( new EquationFitNode( orderOfFitProperty ) );

// create slider for parameters
var aSliderBox = new SliderParameterNode( curve.aProperty, { min: -1, max: 1 }, 'a' );
Expand Down

0 comments on commit b4a973e

Please sign in to comment.