@abi-software/flatmapvuer 0.3.11 → 0.3.12-beta-0

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-beta-0",
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,17 @@ 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
+ if (state) {
643
+ if (state.uuid) {
644
+ identifier = { uuid: state.uuid };
645
+ } else if (state.entry) {
646
+ identifier.taxon = state.entry;
647
+ if (state.biologicalSex) {
648
+ identifier["biologicalSex"] = state.biologicalSex;
649
+ } else if (identifier.taxon === "NCBITaxon:9606") {
650
+ //For backward compatibility
651
+ identifier["biologicalSex"] ="PATO:0000384";
652
+ }
630
653
  }
631
654
  } else {
632
655
  // Set the bioloicalSex now if map is not resumed from
@@ -669,8 +692,11 @@ export default {
669
692
  this.mapImp.setState(state.viewport);
670
693
  });
671
694
  } else if (state) {
672
- if (this.entry == state.entry)
695
+ if (this.entry == state.entry) {
673
696
  this._viewportToBeSet = state.viewport;
697
+ if (this.mapImp && !this.loading)
698
+ this.mapImp.setState(this._viewportToBeSet);
699
+ }
674
700
  }
675
701
  },
676
702
  showMinimap: function(flag) {
@@ -755,6 +781,10 @@ export default {
755
781
  type: String,
756
782
  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
783
  },
784
+ isLegacy: {
785
+ type: Boolean,
786
+ default: false
787
+ },
758
788
  displayLatestChanges: {
759
789
  type: Boolean,
760
790
  default: false,
@@ -868,6 +898,15 @@ export default {
868
898
  vertical-align: 5px;
869
899
  }
870
900
 
901
+ .latest-map-text {
902
+ color: $app-primary-color;;
903
+ font-family: Asap, sans-serif;
904
+ font-size: 12px;
905
+ margin-top: 5px;
906
+ vertical-align: 10px;
907
+ cursor: pointer;
908
+ }
909
+
871
910
  .latest-changesicon {
872
911
  color: $success;
873
912
 
@@ -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",
@@ -89,6 +98,8 @@ export default {
89
98
  .then(response => response.json())
90
99
  .then(data => {
91
100
  this.speciesList= {};
101
+ //Check each key in the provided availableSpecies against the one
102
+ // on the server, add them to the Select if the key is found
92
103
  Object.keys(this.availableSpecies).forEach(key => {
93
104
  for (let i = 0; i < data.length; i++) {
94
105
  if (this.availableSpecies[key].taxo === data[i].taxon) {
@@ -106,6 +117,7 @@ export default {
106
117
  }
107
118
  });
108
119
  if (!this.state) {
120
+ //No state resuming, set the current flatmap to {this.initial}
109
121
  if (this.initial && this.speciesList[this.initial] !== undefined) {
110
122
  this.activeSpecies = this.initial;
111
123
  } else {
@@ -147,13 +159,95 @@ export default {
147
159
  let map = this.getCurrentFlatmap();
148
160
  map.showMarkerPopup(featureId, node, options);
149
161
  },
150
- flatmapChanged: function(species){
162
+ flatmapChanged: function(species, viewport){
151
163
  if (this.activeSpecies != species)
152
164
  this.activeSpecies = species;
153
- this.$refs[this.activeSpecies][0].createFlatmap();
165
+ this.$refs[this.activeSpecies][0].createFlatmap(viewport);
154
166
  this.$emit('flatmapChanged', this.activeSpecies);
155
167
  },
156
- /**
168
+ /**
169
+ * Function to switch to the latest existing map from
170
+ * a legacy map of the same species.
171
+ *
172
+ * @private
173
+ */
174
+ viewLatestMap: function(state) {
175
+ const keys = Object.keys(this.speciesList);
176
+ for (let i = 0; i < keys.length; i++) {
177
+ const species = this.speciesList[keys[i]];
178
+ if (!species.isLegacy &&
179
+ (species.taxo === state.entry) &&
180
+ (species.biologicalSex === state.biologicalSex)) {
181
+ this.flatmapChanged(keys[i], state);
182
+ return;
183
+ }
184
+ }
185
+ },
186
+ createLegacyEntry: function(state, taxo, uuid) {
187
+ if (uuid && taxo) {
188
+ let name = "Legacy";
189
+ if (state.species) {
190
+ if (state.species.slice(0, 6) === "Legacy")
191
+ name = state.species;
192
+ else
193
+ name = name + ` ${state.species}`;
194
+ }
195
+ this.speciesList[name] = {
196
+ taxo: taxo,
197
+ isLegacy: true,
198
+ displayWarning: true
199
+ };
200
+ return {
201
+ species: name,
202
+ state: {
203
+ entry: taxo,
204
+ uuid: uuid
205
+ },
206
+ viewport: state.state.viewport,
207
+ }
208
+ }
209
+ },
210
+ /**
211
+ * Function used to translate the legacy map state to one that can be used in current
212
+ * flatmap if required. If it is a legacy, an Select entry will be added
213
+ *
214
+ * @private
215
+ */
216
+ updateState: function(state) {
217
+ return new Promise((resolve) => {
218
+ if (state && state.state) {
219
+ const mapState = state.state;
220
+ //uuid is not in the state, this is a legacy map
221
+ if (!mapState.uuid) {
222
+ if (mapState.entry) {
223
+ const uuid = mapState.entry in TAXON_UUID ? TAXON_UUID[mapState.entry] : undefined;
224
+ const newState = this.createLegacyEntry(state, mapState.entry, uuid);
225
+ resolve(newState ? newState : state);
226
+ }
227
+ } else if (mapState.entry) {
228
+ //uuid is in the state but should be checked if it is the latest map
229
+ //for that taxon
230
+ return new Promise(() => {
231
+ const mapManager = new (require("@abi-software/flatmap-viewer")).MapManager(this.flatmapAPI);
232
+ //mapManager.findMap_ is an async function so we need to wrap this with a promise
233
+ mapManager.findMap_({taxon: mapState.entry}).then(map => {
234
+ if (map.uuid !== mapState.uuid) {
235
+ return this.createLegacyEntry(state, mapState.entry, mapState.uuid);
236
+ }
237
+ }).then(newState => {
238
+ resolve(newState ? newState : state);
239
+ })
240
+ .catch(() => {
241
+ resolve(state);
242
+ });
243
+ });
244
+ }
245
+ //Create a new state and add the legacy map to the select
246
+ }
247
+ resolve(state);
248
+ });
249
+ },
250
+ /**
157
251
  * Function used for getting the current states of the scene. This exported states
158
252
  * can be imported using the importStates method.
159
253
  *
@@ -177,19 +271,24 @@ export default {
177
271
  setState: function(state) {
178
272
  if (state) {
179
273
  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
- })
274
+ //Update state if required
275
+ this.updateState(state).then(currentState => {
276
+ if (currentState.species && (currentState.species !== this.activeSpecies)) {
277
+ this.activeSpecies = currentState.species;
278
+ if (currentState.state) {
279
+ //Wait for next tick when the refs are ready for rendering
280
+ this.$nextTick(() => {
281
+ if (this.activeSpecies in this.$refs) {
282
+ this.$refs[this.activeSpecies][0].createFlatmap(currentState.state);
283
+ this.$emit('flatmapChanged', this.activeSpecies);
284
+ }
285
+ })
286
+ }
287
+ } else if (currentState.state) {
288
+ let map = this.getCurrentFlatmap();
289
+ map.setState(currentState.state);
188
290
  }
189
- } else if (state.state) {
190
- let map = this.getCurrentFlatmap();
191
- map.setState(state.state);
192
- }
291
+ });
193
292
  })
194
293
  }
195
294
  },
@@ -242,7 +341,19 @@ export default {
242
341
  type: String,
243
342
  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
343
  },
245
- availableSpecies: {},
344
+ availableSpecies: {
345
+ type: Object,
346
+ default: function() {
347
+ return {
348
+ "Human Female":{taxo: "NCBITaxon:9606", biologicalSex: "PATO:0000383", iconClass:"mapicon-icon_human", displayWarning:true},
349
+ "Human Male":{taxo: "NCBITaxon:9606", biologicalSex: "PATO:0000384", iconClass:"mapicon-icon_human", displayWarning:true},
350
+ "Rat":{taxo: "NCBITaxon:10114", iconClass:"mapicon-icon_rat", displayLatestChanges: true},
351
+ "Mouse":{taxo: "NCBITaxon:10090", iconClass:"mapicon-icon_mouse", displayWarning: true},
352
+ "Pig":{taxo: "NCBITaxon:9823", iconClass:"mapicon-icon_pig", displayWarning: true},
353
+ "Cat":{taxo: "NCBITaxon:9685", iconClass:"mapicon-icon_cat", displayWarning: true},
354
+ }
355
+ }
356
+ },
246
357
  /**
247
358
  * State containing state of the flatmap.
248
359
  */