Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "spectral-workbench",
"version": "0.0.8",
"main": "dist/spectral-workbench.js",
"dependencies": {
"fontawesome": "~4.5.0",
Expand Down
48 changes: 36 additions & 12 deletions dist/spectral-workbench.js
Original file line number Diff line number Diff line change
Expand Up @@ -796,10 +796,10 @@ SpectralWorkbench.Spectrum = SpectralWorkbench.Datum.extend({
// Tortured:
if (!_spectrum.graph || (!_spectrum.graph.range || (x >= _spectrum.graph.range[0] && x <= _spectrum.graph.range[1]))) {

_spectrum.average.push({ y: parseInt(line[1] / 2.55)/100, x: x })
_spectrum.red.push( { y: parseInt(line[1] / 2.55)/100, x: x })
_spectrum.green.push( { y: parseInt(line[1] / 2.55)/100, x: x })
_spectrum.blue.push( { y: parseInt(line[1] / 2.55)/100, x: x })
_spectrum.average.push({ y: _spectrum.scale8BitToFloat(line[1]), x: x })
_spectrum.red.push( { y: _spectrum.scale8BitToFloat(line[1]), x: x })
_spectrum.green.push( { y: _spectrum.scale8BitToFloat(line[1]), x: x })
_spectrum.blue.push( { y: _spectrum.scale8BitToFloat(line[1]), x: x })

}

Expand Down Expand Up @@ -839,11 +839,11 @@ SpectralWorkbench.Spectrum = SpectralWorkbench.Datum.extend({
// Tortured:
if (!_spectrum.graph || (!_spectrum.graph.range || (x >= _spectrum.graph.range[0] && x <= _spectrum.graph.range[1]))) {

_spectrum.average.push({ y: parseInt(line.average / 2.55)/100, x: x })
_spectrum.average.push({ y: _spectrum.scale8BitToFloat(line.average), x: x })

if (line.r != null) _spectrum.red.push( { y: parseInt(line.r / 2.55)/100, x: x })
if (line.g != null) _spectrum.green.push({ y: parseInt(line.g / 2.55)/100, x: x })
if (line.b != null) _spectrum.blue.push( { y: parseInt(line.b / 2.55)/100, x: x })
if (line.r != null) _spectrum.red.push( { y: _spectrum.scale8BitToFloat(line.r), x: x })
if (line.g != null) _spectrum.green.push({ y: _spectrum.scale8BitToFloat(line.g), x: x })
if (line.b != null) _spectrum.blue.push( { y: _spectrum.scale8BitToFloat(line.b), x: x })

}

Expand All @@ -864,10 +864,10 @@ SpectralWorkbench.Spectrum = SpectralWorkbench.Datum.extend({
_spectrum.average.forEach(function(line, i) {

lines.push({
average: +(_spectrum.average[i].y * 255).toPrecision(_spectrum.sigFigIntensity),
r: +(_spectrum.red[i].y * 255).toPrecision(_spectrum.sigFigIntensity),
g: +(_spectrum.green[i].y * 255).toPrecision(_spectrum.sigFigIntensity),
b: +(_spectrum.blue[i].y * 255).toPrecision(_spectrum.sigFigIntensity)
average: +_spectrum.average[i].y,
r: +_spectrum.red[i].y,
g: +_spectrum.green[i].y,
b: +_spectrum.blue[i].y
});

if (_spectrum.isCalibrated()) lines[lines.length-1].wavelength = _spectrum.average[i].x;
Expand All @@ -880,6 +880,30 @@ SpectralWorkbench.Spectrum = SpectralWorkbench.Datum.extend({
}


/* ======================================
* Scales data from an 8-bit float to a 0-1 float
* at _spectrum.sigFigIntensity precision
* UNTESTED IN JASMINE
*/
_spectrum.scale8BitToFloat = function(value) {

return parseInt(value / 2.55) / 100;

}


/* ======================================
* Scales data from a 0-1 float to an 8-bit float
* at _spectrum.sigFigIntensity precision
* UNTESTED IN JASMINE
*/
_spectrum.scaleIntensityTo8Bit = function(value) {

return (value * 255).toPrecision(_spectrum.sigFigIntensity);

}


/* ======================================
* Returns closest intensity for a given wavelength,
* from available wavelength/intensity pairs
Expand Down
48 changes: 36 additions & 12 deletions src/SpectralWorkbench.Spectrum.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ SpectralWorkbench.Spectrum = SpectralWorkbench.Datum.extend({
// Tortured:
if (!_spectrum.graph || (!_spectrum.graph.range || (x >= _spectrum.graph.range[0] && x <= _spectrum.graph.range[1]))) {

_spectrum.average.push({ y: parseInt(line[1] / 2.55)/100, x: x })
_spectrum.red.push( { y: parseInt(line[1] / 2.55)/100, x: x })
_spectrum.green.push( { y: parseInt(line[1] / 2.55)/100, x: x })
_spectrum.blue.push( { y: parseInt(line[1] / 2.55)/100, x: x })
_spectrum.average.push({ y: _spectrum.scale8BitToFloat(line[1]), x: x })
_spectrum.red.push( { y: _spectrum.scale8BitToFloat(line[1]), x: x })
_spectrum.green.push( { y: _spectrum.scale8BitToFloat(line[1]), x: x })
_spectrum.blue.push( { y: _spectrum.scale8BitToFloat(line[1]), x: x })

}

Expand Down Expand Up @@ -103,11 +103,11 @@ SpectralWorkbench.Spectrum = SpectralWorkbench.Datum.extend({
// Tortured:
if (!_spectrum.graph || (!_spectrum.graph.range || (x >= _spectrum.graph.range[0] && x <= _spectrum.graph.range[1]))) {

_spectrum.average.push({ y: parseInt(line.average / 2.55)/100, x: x })
_spectrum.average.push({ y: _spectrum.scale8BitToFloat(line.average), x: x })

if (line.r != null) _spectrum.red.push( { y: parseInt(line.r / 2.55)/100, x: x })
if (line.g != null) _spectrum.green.push({ y: parseInt(line.g / 2.55)/100, x: x })
if (line.b != null) _spectrum.blue.push( { y: parseInt(line.b / 2.55)/100, x: x })
if (line.r != null) _spectrum.red.push( { y: _spectrum.scale8BitToFloat(line.r), x: x })
if (line.g != null) _spectrum.green.push({ y: _spectrum.scale8BitToFloat(line.g), x: x })
if (line.b != null) _spectrum.blue.push( { y: _spectrum.scale8BitToFloat(line.b), x: x })

}

Expand All @@ -128,10 +128,10 @@ SpectralWorkbench.Spectrum = SpectralWorkbench.Datum.extend({
_spectrum.average.forEach(function(line, i) {

lines.push({
average: +(_spectrum.average[i].y * 255).toPrecision(_spectrum.sigFigIntensity),
r: +(_spectrum.red[i].y * 255).toPrecision(_spectrum.sigFigIntensity),
g: +(_spectrum.green[i].y * 255).toPrecision(_spectrum.sigFigIntensity),
b: +(_spectrum.blue[i].y * 255).toPrecision(_spectrum.sigFigIntensity)
average: +_spectrum.average[i].y,
r: +_spectrum.red[i].y,
g: +_spectrum.green[i].y,
b: +_spectrum.blue[i].y
});

if (_spectrum.isCalibrated()) lines[lines.length-1].wavelength = _spectrum.average[i].x;
Expand All @@ -144,6 +144,30 @@ SpectralWorkbench.Spectrum = SpectralWorkbench.Datum.extend({
}


/* ======================================
* Scales data from an 8-bit float to a 0-1 float
* at _spectrum.sigFigIntensity precision
* UNTESTED IN JASMINE
*/
_spectrum.scale8BitToFloat = function(value) {

return parseInt(value / 2.55) / 100;

}


/* ======================================
* Scales data from a 0-1 float to an 8-bit float
* at _spectrum.sigFigIntensity precision
* UNTESTED IN JASMINE
*/
_spectrum.scaleIntensityTo8Bit = function(value) {

return (value * 255).toPrecision(_spectrum.sigFigIntensity);

}


/* ======================================
* Returns closest intensity for a given wavelength,
* from available wavelength/intensity pairs
Expand Down