@abi-software/flatmapvuer 0.3.11 → 0.3.12

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": "@abi-software/flatmapvuer",
3
- "version": "0.3.11",
3
+ "version": "0.3.12",
4
4
  "main": "./dist/flatmapvuer.common.js",
5
5
  "files": [
6
6
  "dist/*",
@@ -12,7 +12,7 @@
12
12
  <div class="beta-popovers">
13
13
  <div>
14
14
  <el-popover
15
- :content="warningMessage"
15
+ :content="isLegacy ? 'This is a legacy map, you may view the latest map instead.' : warningMessage"
16
16
  placement="right"
17
17
  :appendToBody="false"
18
18
  trigger="manual"
@@ -27,7 +27,13 @@
27
27
  @mouseout="hideToolitip(6)"
28
28
  v-popover:warningPopover
29
29
  >
30
- <span class="warning-text">Beta</span>
30
+ <template v-if="isLegacy">
31
+ <span class="warning-text">Legacy Map</span>
32
+ <div class="latest-map-text" @click="viewLatestMap">Click here for the latest map</div>
33
+ </template>
34
+ <template v-else>
35
+ <span class="warning-text">Beta</span>
36
+ </template>
31
37
  </i>
32
38
  </div>
33
39
  <el-popover
@@ -294,6 +300,19 @@ export default {
294
300
  this.mapImp = undefined;
295
301
  },
296
302
  methods: {
303
+ viewLatestMap: function() {
304
+ let biologicalSex = this.biologicalSex ? this.biologicalSex : undefined;
305
+ //Human requires special handling
306
+ if (this.entry === "NCBITaxon:9606") {
307
+ biologicalSex = "PATO:0000384";
308
+ }
309
+ const state = {
310
+ entry: this.entry,
311
+ biologicalSex,
312
+ viewport: this.mapImp.getState()
313
+ };
314
+ this.$emit("view-latest-map", state);
315
+ },
297
316
  backgroundChangeCallback: function(colour) {
298
317
  this.currentBackground = colour;
299
318
  if (this.mapImp) {
@@ -620,13 +639,18 @@ export default {
620
639
  // be loaded, overriding ``taxon`` and ``biologicalSex``.
621
640
 
622
641
  let identifier = { taxon: this.entry };
623
- if (state && state.entry) {
624
- identifier.taxon = state.entry;
625
- if (state.biologicalSex) {
626
- identifier["biologicalSex"] = state.biologicalSex;
627
- } else if (identifier.taxon === "NCBITaxon:9606") {
628
- //For backward compatibility
629
- identifier["biologicalSex"] ="PATO:0000384";
642
+ //This now handle the uses of uuid when resuming states
643
+ if (state) {
644
+ if (state.uuid) {
645
+ identifier = { uuid: state.uuid };
646
+ } else if (state.entry) {
647
+ identifier.taxon = state.entry;
648
+ if (state.biologicalSex) {
649
+ identifier["biologicalSex"] = state.biologicalSex;
650
+ } else if (identifier.taxon === "NCBITaxon:9606") {
651
+ //For backward compatibility
652
+ identifier["biologicalSex"] ="PATO:0000384";
653
+ }
630
654
  }
631
655
  } else {
632
656
  // Set the bioloicalSex now if map is not resumed from
@@ -669,8 +693,11 @@ export default {
669
693
  this.mapImp.setState(state.viewport);
670
694
  });
671
695
  } else if (state) {
672
- if (this.entry == state.entry)
696
+ if (this.entry == state.entry) {
673
697
  this._viewportToBeSet = state.viewport;
698
+ if (this.mapImp && !this.loading)
699
+ this.mapImp.setState(this._viewportToBeSet);
700
+ }
674
701
  }
675
702
  },
676
703
  showMinimap: function(flag) {
@@ -755,6 +782,10 @@ export default {
755
782
  type: String,
756
783
  default: "Beta feature - This map is based on the connectivity of a rat. New connectivity and species specificity will be added as the SPARC program progress."
757
784
  },
785
+ isLegacy: {
786
+ type: Boolean,
787
+ default: false
788
+ },
758
789
  displayLatestChanges: {
759
790
  type: Boolean,
760
791
  default: false,
@@ -868,6 +899,15 @@ export default {
868
899
  vertical-align: 5px;
869
900
  }
870
901
 
902
+ .latest-map-text {
903
+ color: $app-primary-color;;
904
+ font-family: Asap, sans-serif;
905
+ font-size: 12px;
906
+ margin-top: 5px;
907
+ vertical-align: 10px;
908
+ cursor: pointer;
909
+ }
910
+
871
911
  .latest-changesicon {
872
912
  color: $success;
873
913
 
@@ -949,13 +989,15 @@ export default {
949
989
  .svg-legends-container {
950
990
  width:70%;
951
991
  height:auto;
992
+ position:relative;
993
+ max-height:140px;
952
994
  }
953
995
 
954
996
  .pathway-container {
955
997
  float: left;
956
998
  padding-left: 16px;
957
999
  padding-right: 18px;
958
- max-height: calc(100% - 184px);
1000
+ max-height: calc(100% - 140px);
959
1001
  text-align: left;
960
1002
  overflow: auto;
961
1003
  border: 1px solid rgb(220, 223, 230);
@@ -36,7 +36,9 @@
36
36
  :warningMessage="warningMessage"
37
37
  :displayLatestChanges="item.displayLatestChanges"
38
38
  :latestChangesMessage="item.latestChangesMessage"
39
+ :isLegacy="item.isLegacy"
39
40
  :ref="key"
41
+ @view-latest-map="viewLatestMap"
40
42
  @resource-selected="FlatmapSelected"
41
43
  @ready="FlatmapReady"
42
44
  @pan-zoom-callback="panZoomCallback"
@@ -70,6 +72,13 @@ Vue.use(Option);
70
72
  Vue.use(Select);
71
73
  Vue.use(Popover)
72
74
 
75
+ const TAXON_UUID = {
76
+ "NCBITaxon:10114": "01fedbf9-d783-509c-a10c-827941ab13da",
77
+ "NCBITaxon:9823": "a336ac04-24db-561f-a25f-1c994fe17410",
78
+ "NCBITaxon:9606": "42ed6323-f645-5fbe-bada-9581819cf689",
79
+ "NCBITaxon:10090": "25285fab-48a0-5620-a6a0-f9a0374837d5",
80
+ "NCBITaxon:9685": "73060497-46a6-52bf-b975-cac511c127cb"
81
+ }
73
82
 
74
83
  export default {
75
84
  name: "MultiFlatmapVuer",
@@ -85,39 +94,45 @@ export default {
85
94
  methods: {
86
95
  initialise: function() {
87
96
  return new Promise(resolve => {
88
- fetch(this.flatmapAPI)
89
- .then(response => response.json())
90
- .then(data => {
91
- this.speciesList= {};
92
- Object.keys(this.availableSpecies).forEach(key => {
93
- for (let i = 0; i < data.length; i++) {
94
- if (this.availableSpecies[key].taxo === data[i].taxon) {
95
- if (this.availableSpecies[key].biologicalSex) {
96
- if (data[i].biologicalSex &&
97
- data[i].biologicalSex === this.availableSpecies[key].biologicalSex) {
98
- this.speciesList[key] = this.availableSpecies[key];
99
- break;
100
- }
101
- } else {
102
- this.speciesList[key] = this.availableSpecies[key];
103
- break;
97
+ if (this.requireInitialisation) {
98
+ //It has not been initialised yet
99
+ this.requireInitialisation = false;
100
+ fetch(this.flatmapAPI)
101
+ .then(response => response.json())
102
+ .then(data => {
103
+ //Check each key in the provided availableSpecies against the one
104
+ //on the server, add them to the Select if the key is found
105
+ Object.keys(this.availableSpecies).forEach(key => {
106
+ for (let i = 0; i < data.length; i++) {
107
+ if (this.availableSpecies[key].taxo === data[i].taxon) {
108
+ if (this.availableSpecies[key].biologicalSex) {
109
+ if (data[i].biologicalSex &&
110
+ data[i].biologicalSex === this.availableSpecies[key].biologicalSex) {
111
+ this.$set(this.speciesList, key, this.availableSpecies[key]);
112
+ break;
113
+ }
114
+ } else {
115
+ this.$set(this.speciesList, key, this.availableSpecies[key]);
116
+ break;
117
+ }
104
118
  }
105
119
  }
120
+ });
121
+ if (!this.state) {
122
+ //No state resuming, set the current flatmap to {this.initial}
123
+ if (this.initial && this.speciesList[this.initial] !== undefined) {
124
+ this.activeSpecies = this.initial;
125
+ } else {
126
+ this.activeSpecies = Object.keys(this.speciesList)[0];
127
+ }
128
+ Vue.nextTick(() => {
129
+ if (this.$refs[this.activeSpecies])
130
+ this.$refs[this.activeSpecies][0].createFlatmap();
131
+ });
106
132
  }
107
133
  });
108
- if (!this.state) {
109
- if (this.initial && this.speciesList[this.initial] !== undefined) {
110
- this.activeSpecies = this.initial;
111
- } else {
112
- this.activeSpecies = Object.keys(this.speciesList)[0];
113
- }
114
- Vue.nextTick(() => {
115
- if (this.$refs[this.activeSpecies])
116
- this.$refs[this.activeSpecies][0].createFlatmap();
117
- });
118
- }
119
- resolve();
120
- });
134
+ }
135
+ resolve();
121
136
  })
122
137
  },
123
138
  FlatmapSelected: function(resource) {
@@ -147,13 +162,104 @@ export default {
147
162
  let map = this.getCurrentFlatmap();
148
163
  map.showMarkerPopup(featureId, node, options);
149
164
  },
150
- flatmapChanged: function(species){
165
+ flatmapChanged: function(species, viewport){
151
166
  if (this.activeSpecies != species)
152
167
  this.activeSpecies = species;
153
- this.$refs[this.activeSpecies][0].createFlatmap();
168
+ this.$refs[this.activeSpecies][0].createFlatmap(viewport);
154
169
  this.$emit('flatmapChanged', this.activeSpecies);
155
170
  },
156
- /**
171
+ /**
172
+ * Function to switch to the latest existing map from
173
+ * a legacy map of the same species.
174
+ *
175
+ * @private
176
+ */
177
+ viewLatestMap: function(state) {
178
+ const keys = Object.keys(this.speciesList);
179
+ for (let i = 0; i < keys.length; i++) {
180
+ const species = this.speciesList[keys[i]];
181
+ if (!species.isLegacy &&
182
+ (species.taxo === state.entry) &&
183
+ (species.biologicalSex === state.biologicalSex)) {
184
+ this.flatmapChanged(keys[i], state);
185
+ return;
186
+ }
187
+ }
188
+ },
189
+ /**
190
+ * Create a legacy entry with the provided information
191
+ *
192
+ * @private
193
+ */
194
+ createLegacyEntry: function(state, taxo, uuid) {
195
+ if (uuid && taxo) {
196
+ let name = "Legacy";
197
+ if (state.species) {
198
+ if (state.species.slice(0, 6) === "Legacy")
199
+ name = state.species;
200
+ else
201
+ name = name + ` ${state.species}`;
202
+ }
203
+ this.$set(
204
+ this.speciesList,
205
+ name,
206
+ {
207
+ taxo: taxo,
208
+ isLegacy: true,
209
+ displayWarning: true
210
+ }
211
+ );
212
+ return {
213
+ species: name,
214
+ state: {
215
+ entry: taxo,
216
+ uuid: uuid,
217
+ viewport: state.state.viewport,
218
+ },
219
+ }
220
+ }
221
+ },
222
+ /**
223
+ * Function used to translate the legacy map state to one that can be used in current
224
+ * flatmap if required. If it is a legacy, an Select entry will be added
225
+ *
226
+ * @private
227
+ */
228
+ updateState: function(state) {
229
+ return new Promise((resolve) => {
230
+ if (state && state.state) {
231
+ const mapState = state.state;
232
+ //uuid is not in the state, this is a legacy map
233
+ if (!mapState.uuid) {
234
+ if (mapState.entry) {
235
+ const uuid = mapState.entry in TAXON_UUID ? TAXON_UUID[mapState.entry] : undefined;
236
+ const newState = this.createLegacyEntry(state, mapState.entry, uuid);
237
+ resolve(newState ? newState : state);
238
+ }
239
+ } else if (mapState.entry) {
240
+ //uuid is in the state but should be checked if it is the latest map
241
+ //for that taxon
242
+ return new Promise(() => {
243
+ const mapManager = new (require("@abi-software/flatmap-viewer")).MapManager(this.flatmapAPI);
244
+ //mapManager.findMap_ is an async function so we need to wrap this with a promise
245
+ mapManager.findMap_({taxon: mapState.entry}).then(map => {
246
+ if (map.uuid !== mapState.uuid) {
247
+ return this.createLegacyEntry(state, mapState.entry, mapState.uuid);
248
+ }
249
+ }).then(newState => {
250
+ resolve(newState ? newState : state);
251
+ })
252
+ .catch(() => {
253
+ resolve(state);
254
+ });
255
+ });
256
+ }
257
+ //Create a new state and add the legacy map to the select
258
+ }
259
+ resolve(state);
260
+ });
261
+ },
262
+ /**
157
263
  * Function used for getting the current states of the scene. This exported states
158
264
  * can be imported using the importStates method.
159
265
  *
@@ -177,19 +283,24 @@ export default {
177
283
  setState: function(state) {
178
284
  if (state) {
179
285
  this.initialise().then(() => {
180
- if (state.species && state.species !== this.activeSpecies) {
181
- this.activeSpecies = state.species;
182
- if (state.state) {
183
- //Wait for next tick when the refs are ready for rendering
184
- this.$nextTick(() => {
185
- this.$refs[this.activeSpecies][0].createFlatmap(state.state);
186
- this.$emit('flatmapChanged', this.activeSpecies);
187
- })
286
+ //Update state if required
287
+ this.updateState(state).then(currentState => {
288
+ if (currentState.species && (currentState.species !== this.activeSpecies)) {
289
+ this.activeSpecies = currentState.species;
290
+ if (currentState.state) {
291
+ //Wait for next tick when the refs are ready for rendering
292
+ this.$nextTick(() => {
293
+ if (this.activeSpecies in this.$refs) {
294
+ this.$refs[this.activeSpecies][0].createFlatmap(currentState.state);
295
+ this.$emit('flatmapChanged', this.activeSpecies);
296
+ }
297
+ })
298
+ }
299
+ } else if (currentState.state) {
300
+ let map = this.getCurrentFlatmap();
301
+ map.setState(currentState.state);
188
302
  }
189
- } else if (state.state) {
190
- let map = this.getCurrentFlatmap();
191
- map.setState(state.state);
192
- }
303
+ });
193
304
  })
194
305
  }
195
306
  },
@@ -242,7 +353,19 @@ export default {
242
353
  type: String,
243
354
  default: "Beta feature - This map is based on the connectivity of a rat. New connectivity and species specificity will be added as the SPARC program progress."
244
355
  },
245
- availableSpecies: {},
356
+ availableSpecies: {
357
+ type: Object,
358
+ default: function() {
359
+ return {
360
+ "Human Female":{taxo: "NCBITaxon:9606", biologicalSex: "PATO:0000383", iconClass:"mapicon-icon_human", displayWarning:true},
361
+ "Human Male":{taxo: "NCBITaxon:9606", biologicalSex: "PATO:0000384", iconClass:"mapicon-icon_human", displayWarning:true},
362
+ "Rat":{taxo: "NCBITaxon:10114", iconClass:"mapicon-icon_rat", displayLatestChanges: true},
363
+ "Mouse":{taxo: "NCBITaxon:10090", iconClass:"mapicon-icon_mouse", displayWarning: true},
364
+ "Pig":{taxo: "NCBITaxon:9823", iconClass:"mapicon-icon_pig", displayWarning: true},
365
+ "Cat":{taxo: "NCBITaxon:9685", iconClass:"mapicon-icon_cat", displayWarning: true},
366
+ }
367
+ }
368
+ },
246
369
  /**
247
370
  * State containing state of the flatmap.
248
371
  */
@@ -266,7 +389,8 @@ export default {
266
389
  return {
267
390
  activeSpecies: undefined,
268
391
  appendToBody: false,
269
- speciesList: {}
392
+ speciesList: {},
393
+ requireInitialisation: true,
270
394
  };
271
395
  },
272
396
  watch: {
@@ -29,7 +29,7 @@ export default {
29
29
  <style scoped lang="scss">
30
30
  .legends-container {
31
31
  pointer-events: none;
32
- transform: translate(0px, -20px);
32
+ transform: translate(0px, -35px);
33
33
  }
34
34
 
35
35
  .st0-translate {