Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrent committed Mar 9, 2022
2 parents 0cfe6ce + 6e2a71b commit c853a99
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "genoverse",
"version": "4.0.0",
"version": "4.0.1",
"description": "Genoverse is a portable, customizable, back-end independent JavaScript and HTML5 based genome browser which allows the user to explore data in a dynamic and interactive manner.",
"main": "src/js/Genoverse.js",
"directories": {
Expand Down
4 changes: 3 additions & 1 deletion src/js/Track.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,9 @@ const Track = Base.extend({
},

reset: function (...args) {
this.setLengthMap();
if (args[0] !== 'resizing') {
this.setLengthMap();
}

Object.values(this.models).filter(model => model.url !== false).forEach(model => model.init(true));
Object.values(this.views).forEach(view => view.init(true));
Expand Down
33 changes: 17 additions & 16 deletions src/js/Track/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export default Base.extend({
return deferred.resolve();
}

const model = this;
const bins = [];
const length = end - start + 1;

Expand All @@ -123,34 +122,36 @@ export default Base.extend({
...bins.map(
(bin) => {
const request = jQuery.ajax({
url : model.parseURL(chr, bin[0], bin[1]),
data : model.urlParams,
dataType : model.dataType,
context : model,
xhrFields : model.xhrFields,
success : function (data) {
url : this.parseURL(chr, bin[0], bin[1]),
data : this.urlParams,
dataType : this.dataType,
xhrFields : this.xhrFields,
}).then(
(data) => {
this.receiveData(data, chr, bin[0], bin[1]);
},
error: function (xhr, statusText, ...args) {
}
).catch(
(xhr, statusText, ...args) => {
this.track.controller.showError(
this.showServerErrors && (xhr.responseJSON || {}).message
this.showServerErrors && xhr.responseJSON?.message
? xhr.responseJSON.message
: `${statusText} while getting the data, see console for more details`,
[ xhr, statusText, ...args ]
);
},
complete: function (xhr) {
this.dataLoading = this.dataLoading.filter(loading => xhr !== loading);
},
});
}
).always(
() => {
this.dataLoading = this.dataLoading.filter(loading => request !== loading);
}
);

request.coords = [ chr, bin[0], bin[1] ]; // store actual chr, start and end on the request, in case they are needed

if (typeof done === 'function') {
request.done(done);
}

model.dataLoading.push(request);
this.dataLoading.push(request);

return request;
}
Expand Down
71 changes: 71 additions & 0 deletions test/change-width.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const { afterTest } = require('./utils');

describe('Changing width', () => {
afterEach(afterTest);

const genoverse = new Genoverse({
chr : 1,
start : 1,
end : 20,
chromosomeSize : 9e99,
width : 100,
tracks : [ Genoverse.Track.extend({ 10: false, model: Genoverse.Track.Model.extend({ __test: true }) }) ],
});

const track = genoverse.tracks[0];

it('Initial settings are correct', () => {
expect(track.lengthMap.length).toBe(2);
expect(track.lengthMap.map(l => l[0])).toEqual([ 10, -1 ]);

expect(track.model).toEqual(track.models[10]);
expect(track.model.__test).toBe(undefined);

expect(genoverse.width).toBe(100);
});

it('Settings are correct after width change', (done) => {
genoverse.setWidth(1000);

setTimeout( // setWidth causes tracks to be reset after a 1ms delay, which we need to wait for here
() => {
try {
expect(track.lengthMap.length).toBe(2);
expect(track.lengthMap.map(l => l[0])).toEqual([ 10, -1 ]);

expect(track.model).toEqual(track.models[10]);
expect(track.model.__test).toBe(undefined);

expect(genoverse.width).toBe(1000);

done();
} catch (e) {
done(e);
}
},
100
);
});

it('Model changes correctly after width change + zoom out', (done) => {
genoverse.setWidth(1000);

setTimeout( // setWidth causes tracks to be reset after a 1ms delay, which we need to wait for here
() => {
genoverse.moveTo(1, 1, 5);

try {
expect(genoverse.width).toBe(1000);
expect(genoverse.length).toBe(5);
expect(track.model).toEqual(track.models[-1]);
expect(track.model.__test).toBe(true);

done();
} catch (e) {
done(e);
}
},
100
);
});
});

0 comments on commit c853a99

Please sign in to comment.