Skip to content

Commit

Permalink
pre-allocated cell array in MultiplicationTableNode, see #117
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Nov 10, 2015
1 parent 85869f9 commit 2998974
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions js/common/view/table/MultiplicationTableNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@ define( function( require ) {
this.viewForLevel = []; // @private

// three-dimensional array of the cells, indexed by [levelNumber][leftMultiplier][rightMultiplier]
this.cells = []; // @private
this.cells = new Array( levelModels.length ); // @private

// add stroke for all multiplication table views
var backgroundRect = new Rectangle( 0, 0, 0, 0, {
fill: 'white',
stroke: 'white',
cursor: 'pointer' // this is done so that the cursor doesn't change when moving between cells
} );
this.addChild( backgroundRect );
Expand All @@ -72,27 +71,24 @@ define( function( require ) {
levelModels.forEach( function( level, levelIndex ) {
var tableSize = level.tableSize;
var cellOptions = {
lineWidth: 1,
width: TABLE_SIZE.width / (tableSize + 1),
height: TABLE_SIZE.height / (tableSize + 1)
lineWidth: Math.max( Math.ceil( ( TABLE_SIZE.width / ( tableSize + 1 ) ) / 40 ), 2 ),
width: TABLE_SIZE.width / ( tableSize + 1 ),
height: TABLE_SIZE.height / ( tableSize + 1 )
};
var levelRootNode = new Node( { visible: false } ); // root node for a single level
var row;
var column;

// set the background line width to match that of the cells for this level
backgroundRect.lineWidth = cellOptions.lineWidth;

// init store for cells
self.cells[ levelIndex ] = [];
self.cells[ levelIndex ] = new Array( tableSize + 1 );

var cell;
var cellTop = 0;
var cellLeft = 0;

// create the table row by row
for ( row = 0; row <= tableSize; row++ ) {
self.cells[ levelIndex ][ row ] = [];
self.cells[ levelIndex ][ row ] = new Array( tableSize + 1 );

// first row
if ( row === 0 ) {
Expand Down

0 comments on commit 2998974

Please sign in to comment.