Skip to content

Commit

Permalink
Merge pull request #37 from jywarren/imageless-spectra
Browse files Browse the repository at this point in the history
accommodate imageless spectra, and tested
  • Loading branch information
jywarren authored Jun 21, 2016
2 parents ecebfff + 18e8ea8 commit 81de09e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
5 changes: 4 additions & 1 deletion dist/spectral-workbench.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,16 @@ SpectralWorkbench.Image = Class.extend({

if (image.options.sample_row) image.setLine(image.options.sample_row);

if (image.options.onLoad) image.options.onLoad(); // since image loading is asynchronous
if (image.options.onLoad) image.options.onLoad(image); // since image loading is asynchronous

}

if (image.el) image.obj.src = image.options.url || image.el.attr('src');
else image.obj.src = image.options.url;

// if there's no image, whether grabbed from the element, or supplied, just trigger onLoad callback already:
if (image.el.length === 0 && !image.options.url && image.options.hasOwnProperty('onLoad')) image.options.onLoad(image);

/* ======================================
* Returns a array of pixel brightnesses in [r,g,b,a] format,
* values from 0-255
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spectral-workbench",
"version": "0.1.0",
"version": "0.1.1",
"description": "Framework for spectrometric data management & analysis by Public Lab",
"main": "dist/spectral-workbench.js",
"scripts": {
Expand Down
20 changes: 20 additions & 0 deletions spec/javascripts/graph_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,26 @@ describe("Graph", function() {
});


it("does not create datum.image for an imageless spectrum", function(done) {

$('img.spectrum').src = "";
var graph = new SpectralWorkbench.Graph({
spectrum_id: 9, // presence of spectrum_id denotes spectrum and not set
imageSelector: 'nothing', // pass nonexistent selector
onImageComplete: function onImageComplete(image) {

// graph.datum doesn't work because we've never run graph.load
// expect(graph.datum).not.toBeDefined();
expect(image.obj).toBeDefined();
expect(image.obj.width).toEqual(0); // no image
done();

}
});

});





Expand Down
5 changes: 4 additions & 1 deletion src/SpectralWorkbench.Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,16 @@ SpectralWorkbench.Image = Class.extend({

if (image.options.sample_row) image.setLine(image.options.sample_row);

if (image.options.onLoad) image.options.onLoad(); // since image loading is asynchronous
if (image.options.onLoad) image.options.onLoad(image); // since image loading is asynchronous

}

if (image.el) image.obj.src = image.options.url || image.el.attr('src');
else image.obj.src = image.options.url;

// if there's no image, whether grabbed from the element, or supplied, just trigger onLoad callback already:
if (image.el.length === 0 && !image.options.url && image.options.hasOwnProperty('onLoad')) image.options.onLoad(image);

/* ======================================
* Returns a array of pixel brightnesses in [r,g,b,a] format,
* values from 0-255
Expand Down

0 comments on commit 81de09e

Please sign in to comment.