genoverse 4.0.0 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "genoverse",
3
- "version": "4.0.0",
3
+ "version": "4.0.3",
4
4
  "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.",
5
5
  "main": "src/js/Genoverse.js",
6
6
  "directories": {
@@ -146,17 +146,20 @@ const Genoverse = Base.extend({
146
146
  this.loadedPlugins[plugin.name] = true;
147
147
  };
148
148
 
149
- const pluginImports = Object.keys(pluginsByName).map(pluginName => import(`./plugins/${pluginName}`).then(
150
- (imported) => {
151
- initializePlugin({
152
- name : pluginName,
153
- conf : pluginsByName[pluginName].conf,
154
- exports : imported.default,
155
- });
156
- }
157
- ));
149
+ const pluginImports = Object.keys(pluginsByName).reduce(
150
+ (ready, pluginName) => ready.then(
151
+ () => import(`./plugins/${pluginName}`).then(
152
+ imported => initializePlugin({
153
+ name : pluginName,
154
+ conf : pluginsByName[pluginName].conf,
155
+ exports : imported.default,
156
+ })
157
+ )
158
+ ),
159
+ this.jQuery.Deferred().resolve()
160
+ );
158
161
 
159
- return this.jQuery.when(...pluginImports);
162
+ return this.jQuery.when(pluginImports);
160
163
  },
161
164
 
162
165
  init: function () {
@@ -543,7 +546,7 @@ const Genoverse = Base.extend({
543
546
  onTracks: function (func, ...args) {
544
547
  this.tracks.forEach(
545
548
  (track) => {
546
- if (track.disabled) {
549
+ if (track.disabled || !track._interface) { // if track._interface is undefined, the track has not been fully initialized yet
547
550
  return;
548
551
  }
549
552
 
@@ -100,7 +100,6 @@ export default Base.extend({
100
100
  return deferred.resolve();
101
101
  }
102
102
 
103
- const model = this;
104
103
  const bins = [];
105
104
  const length = end - start + 1;
106
105
 
@@ -123,26 +122,30 @@ export default Base.extend({
123
122
  ...bins.map(
124
123
  (bin) => {
125
124
  const request = jQuery.ajax({
126
- url : model.parseURL(chr, bin[0], bin[1]),
127
- data : model.urlParams,
128
- dataType : model.dataType,
129
- context : model,
130
- xhrFields : model.xhrFields,
131
- success : function (data) {
125
+ url : this.parseURL(chr, bin[0], bin[1]),
126
+ data : this.urlParams,
127
+ dataType : this.dataType,
128
+ xhrFields : this.xhrFields,
129
+ }).done(
130
+ (data) => {
132
131
  this.receiveData(data, chr, bin[0], bin[1]);
133
- },
134
- error: function (xhr, statusText, ...args) {
135
- this.track.controller.showError(
136
- this.showServerErrors && (xhr.responseJSON || {}).message
137
- ? xhr.responseJSON.message
138
- : `${statusText} while getting the data, see console for more details`,
139
- [ xhr, statusText, ...args ]
140
- );
141
- },
142
- complete: function (xhr) {
143
- this.dataLoading = this.dataLoading.filter(loading => xhr !== loading);
144
- },
145
- });
132
+ }
133
+ ).fail(
134
+ (xhr, statusText, ...args) => {
135
+ if (this.track?.controller?.showError) {
136
+ this.track.controller.showError(
137
+ this.showServerErrors && xhr.responseJSON?.message
138
+ ? xhr.responseJSON.message
139
+ : `${statusText} while getting the data, see console for more details`,
140
+ [ xhr, statusText, ...args ]
141
+ );
142
+ }
143
+ }
144
+ ).always(
145
+ () => {
146
+ this.dataLoading = this.dataLoading.filter(loading => request !== loading);
147
+ }
148
+ );
146
149
 
147
150
  request.coords = [ chr, bin[0], bin[1] ]; // store actual chr, start and end on the request, in case they are needed
148
151
 
@@ -150,7 +153,7 @@ export default Base.extend({
150
153
  request.done(done);
151
154
  }
152
155
 
153
- model.dataLoading.push(request);
156
+ this.dataLoading.push(request);
154
157
 
155
158
  return request;
156
159
  }
package/src/js/Track.js CHANGED
@@ -615,7 +615,9 @@ const Track = Base.extend({
615
615
  },
616
616
 
617
617
  reset: function (...args) {
618
- this.setLengthMap();
618
+ if (args[0] !== 'resizing') {
619
+ this.setLengthMap();
620
+ }
619
621
 
620
622
  Object.values(this.models).filter(model => model.url !== false).forEach(model => model.init(true));
621
623
  Object.values(this.views).forEach(view => view.init(true));
@@ -1,13 +1,13 @@
1
- import './controlPanel';
1
+ import controlPanel from './controlPanel';
2
2
 
3
3
  const plugin = function () {
4
4
  this.controls.push({
5
- icon : '<i class="fas fa-map-marker-alt"></i>',
6
- 'class' : 'gv-button-large',
7
- name : `Reset focus to ${this.focusRegion && this.focusRegion.name ? this.focusRegion.name : `${this.chr}:${this.start}-${this.end}`}`,
8
- action : (browser) => { browser.moveTo(browser.focusRegion.chr, browser.focusRegion.start, browser.focusRegion.end, true); },
9
- init : (browser) => { browser.focusRegion = browser.focusRegion || { chr: browser.chr, start: browser.start, end: browser.end }; },
5
+ icon : '<i class="fas fa-map-marker-alt"></i>',
6
+ class : 'gv-button-large',
7
+ name : `Reset focus to ${this.focusRegion && this.focusRegion.name ? this.focusRegion.name : `${this.chr}:${this.start}-${this.end}`}`,
8
+ action : (browser) => { browser.moveTo(browser.focusRegion.chr, browser.focusRegion.start, browser.focusRegion.end, true); },
9
+ init : (browser) => { browser.focusRegion = browser.focusRegion || { chr: browser.chr, start: browser.start, end: browser.end }; },
10
10
  });
11
11
  };
12
12
 
13
- export default { focusRegion: plugin };
13
+ export default { focusRegion: plugin, requires: controlPanel };
@@ -0,0 +1,71 @@
1
+ const { afterTest } = require('./utils');
2
+
3
+ describe('Changing width', () => {
4
+ afterEach(afterTest);
5
+
6
+ const genoverse = new Genoverse({
7
+ chr : 1,
8
+ start : 1,
9
+ end : 20,
10
+ chromosomeSize : 9e99,
11
+ width : 100,
12
+ tracks : [ Genoverse.Track.extend({ 10: false, model: Genoverse.Track.Model.extend({ __test: true }) }) ],
13
+ });
14
+
15
+ const track = genoverse.tracks[0];
16
+
17
+ it('Initial settings are correct', () => {
18
+ expect(track.lengthMap.length).toBe(2);
19
+ expect(track.lengthMap.map(l => l[0])).toEqual([ 10, -1 ]);
20
+
21
+ expect(track.model).toEqual(track.models[10]);
22
+ expect(track.model.__test).toBe(undefined);
23
+
24
+ expect(genoverse.width).toBe(100);
25
+ });
26
+
27
+ it('Settings are correct after width change', (done) => {
28
+ genoverse.setWidth(1000);
29
+
30
+ setTimeout( // setWidth causes tracks to be reset after a 1ms delay, which we need to wait for here
31
+ () => {
32
+ try {
33
+ expect(track.lengthMap.length).toBe(2);
34
+ expect(track.lengthMap.map(l => l[0])).toEqual([ 10, -1 ]);
35
+
36
+ expect(track.model).toEqual(track.models[10]);
37
+ expect(track.model.__test).toBe(undefined);
38
+
39
+ expect(genoverse.width).toBe(1000);
40
+
41
+ done();
42
+ } catch (e) {
43
+ done(e);
44
+ }
45
+ },
46
+ 100
47
+ );
48
+ });
49
+
50
+ it('Model changes correctly after width change + zoom out', (done) => {
51
+ genoverse.setWidth(1000);
52
+
53
+ setTimeout( // setWidth causes tracks to be reset after a 1ms delay, which we need to wait for here
54
+ () => {
55
+ genoverse.moveTo(1, 1, 5);
56
+
57
+ try {
58
+ expect(genoverse.width).toBe(1000);
59
+ expect(genoverse.length).toBe(5);
60
+ expect(track.model).toEqual(track.models[-1]);
61
+ expect(track.model.__test).toBe(true);
62
+
63
+ done();
64
+ } catch (e) {
65
+ done(e);
66
+ }
67
+ },
68
+ 100
69
+ );
70
+ });
71
+ });