-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c93cc91
commit e40c109
Showing
14 changed files
with
224 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var Cell = function (firstValue) { | ||
var value = firstValue || "", | ||
backgroundColor = 'white', | ||
borderStyle = 'SOLID'; | ||
|
||
var links = {}; | ||
|
||
this.setValue = function (newValue) { | ||
value = newValue; | ||
}; | ||
this.getValue = function () { | ||
return value; | ||
}; | ||
this.setBackground = function(newBackground) { | ||
backgroundColor = newBackground; | ||
}; | ||
this._configureLinks = function(newLinks) { | ||
links = newLinks; | ||
}; | ||
this._left = function() { | ||
return links.left; | ||
}; | ||
this._bottom = function() { | ||
return links.bottom; | ||
}; | ||
this._right = function() { | ||
return links.right; | ||
}; | ||
this._top = function() { | ||
return links.top; | ||
}; | ||
}; | ||
|
||
exports.Cell = Cell; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
var Range = function (myMatrix) { | ||
var matrix = myMatrix || [ | ||
[] | ||
]; | ||
this.getValues = function () { | ||
var values = []; | ||
for (var i = 0; i < matrix.length; i++) { | ||
values[i] = []; | ||
for (var j = 0; j < matrix[i].length; j++) { | ||
values[i][j] = matrix[i][j].getValue(); | ||
} | ||
} | ||
return values; | ||
}; | ||
|
||
this.setValue = function (value) { | ||
for (var i = 0; i < matrix.length; i++) { | ||
for (var j = 0; j < matrix.length; j++) { | ||
matrix[i][j].setValue(value); | ||
} | ||
} | ||
}; | ||
|
||
this._getCells = function() { | ||
return matrix; | ||
}; | ||
this.copyTo = function (anotherRange) { | ||
var firstCell = anotherRange._getCells()[0][0]; | ||
var actualLineCell = firstCell; | ||
for (var i = 0; i < matrix.length; i++) { | ||
actualCell = actualLineCell; | ||
for (var j = 0; j < matrix[0].length; j++) { | ||
actualCell.setValue(matrix[i][j].getValue()); | ||
actualCell = actualCell._right(); | ||
} | ||
actualLineCell = actualLineCell._bottom(); | ||
} | ||
}; | ||
|
||
this.setBackground = function (background) { | ||
for (var i = 0; i < matrix.length; i++) { | ||
for (var j = 0; j < matrix[0].length; j++) { | ||
matrix[i][j].setBackground(background); | ||
} | ||
} | ||
}; | ||
}; | ||
|
||
exports.Range = Range; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
var Range = require('./Range').Range; | ||
var Cell = require('./Cell').Cell; | ||
var Sheet = function (myMatrix) { | ||
var matrix = myMatrix || [ | ||
[] | ||
]; | ||
|
||
var setupMatrixLinks = function () { | ||
for (var i = 0; i < matrix.length; i++) { | ||
for (var j = 0; j < matrix[i].length; j++) { | ||
matrix[i][j]._configureLinks({ | ||
top: i != 0 ? matrix[i - 1][j] : undefined, | ||
right: j != (matrix[i].length - 1) ? matrix[i][j + 1] : undefined, | ||
bottom: i != (matrix.length - 1) ? matrix[i + 1][j] : undefined, | ||
left: j != 0 ? matrix[i][j - 1] : undefined | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
setupMatrixLinks(); | ||
this.getRange = function (row, col, lines, cols) { | ||
lines = lines || 1; | ||
cols = cols || 1; | ||
if (!row || !col || row <= 0 || col <= 0 || lines > matrix.length || cols > matrix[0].length) { | ||
throw new Error('Invalid params to range.'); | ||
} | ||
var newMatrix = [ | ||
[] | ||
]; | ||
for (var i = 0; i < lines; i++) { | ||
newMatrix[i] = []; | ||
for (var j = 0; j < cols; j++) { | ||
newMatrix[i][j] = matrix[i + row - 1][j + col - 1]; | ||
} | ||
} | ||
return new Range(newMatrix); | ||
}; | ||
|
||
var createRow = function (qty) { | ||
var row = []; | ||
for (var i = 0; i < qty; i++) { | ||
row.push(new Cell('')); | ||
} | ||
return row; | ||
}; | ||
|
||
this.insertRowsBefore = function (row, qty) { | ||
var newMatrix = []; | ||
for (var i = 0; i < row - 1; i++) { | ||
newMatrix.push(matrix[i]); | ||
} | ||
for (var i = 0; i < qty; i++) { | ||
newMatrix.push(createRow(matrix[0].length)); | ||
} | ||
for (var i = row - 1; i < matrix.length; i++) { | ||
newMatrix.push(matrix[i]); | ||
} | ||
|
||
// for (var i =0; i < newMatrix.length;i++) { | ||
// var a = ''; | ||
// for(var j =0;j < newMatrix[i].length;j++) { | ||
// a = a + ' ' + newMatrix[i][j].getValue(); | ||
// } | ||
// console.info(a); | ||
// } | ||
// console.info(newMatrix.length); | ||
// console.info(newMatrix[0].length); | ||
matrix = newMatrix; | ||
setupMatrixLinks(); | ||
}; | ||
|
||
this.getMaxRows = function () { | ||
return matrix.length; | ||
}; | ||
|
||
this.getMaxColumns = function () { | ||
return matrix[0].length; | ||
}; | ||
}; | ||
|
||
exports.Sheet = Sheet; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters