@abi-software/flatmapvuer 1.6.0-beta.0 → 1.6.0-beta.2

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.
@@ -1,6 +1,6 @@
1
1
  <template>
2
2
  <div class="multi-container" ref="multiContainer">
3
- <div style="position: absolute; z-index: 10" v-if="!disableUI">
3
+ <div style="position: absolute; z-index: 100" v-if="!disableUI">
4
4
  <div class="species-display-text">Species</div>
5
5
  <el-popover
6
6
  content="Select a species"
@@ -68,6 +68,7 @@
68
68
  :connectivityInfoSidebar="connectivityInfoSidebar"
69
69
  @connectivity-info-open="onConnectivityInfoOpen"
70
70
  @connectivity-info-close="onConnectivityInfoClose"
71
+ @connectivity-graph-error="onConnectivityGraphError"
71
72
  @open-map="$emit('open-map', $event)"
72
73
  @pathway-selection-changed="onSelectionsDataChanged"
73
74
  :minZoom="minZoom"
@@ -273,6 +274,9 @@ export default {
273
274
  onConnectivityInfoOpen: function (entryData) {
274
275
  this.$emit('connectivity-info-open', entryData);
275
276
  },
277
+ onConnectivityGraphError: function (errorInfo) {
278
+ this.$emit('connectivity-graph-error', errorInfo);
279
+ },
276
280
  onSelectionsDataChanged: function (data) {
277
281
  this.$emit('pathway-selection-changed', data);
278
282
  },
@@ -538,7 +542,7 @@ export default {
538
542
  */
539
543
  minZoom: {
540
544
  type: Number,
541
- default: 4,
545
+ default: 1,
542
546
  },
543
547
  /**
544
548
  * The option to create map on component mounted.
@@ -768,9 +772,6 @@ export default {
768
772
  }
769
773
 
770
774
  .select-box {
771
- width: 120px;
772
- border-radius: 4px;
773
- border: 1px solid rgb(144, 147, 153);
774
775
  background-color: var(--white);
775
776
  font-weight: 500;
776
777
  color: rgb(48, 49, 51);
@@ -782,6 +783,27 @@ export default {
782
783
  padding-top: 0.25em;
783
784
  }
784
785
  :deep() {
786
+ .el-select__wrapper {
787
+ position: relative;
788
+ width: fit-content;
789
+ box-shadow: none;
790
+ border-radius: 4px;
791
+ border: 1px solid var(--el-border-color);
792
+ &.is-focused {
793
+ border-color: $app-primary-color;
794
+ }
795
+ }
796
+ .el-select__selection {
797
+ width: fit-content;
798
+ position: relative;
799
+ }
800
+ .el-select__placeholder {
801
+ position: relative;
802
+ top: auto;
803
+ transform: none;
804
+ min-width: 80px;
805
+ width: fit-content;
806
+ }
785
807
  .el-input {
786
808
  .el-input__wrapper{
787
809
  &is-focus,
@@ -42,7 +42,7 @@
42
42
  :key="item[identifierKey]"
43
43
  :label="item[identifierKey]"
44
44
  >
45
- <div class="checkbox-container"
45
+ <div class="checkbox-container"
46
46
  @mouseenter="checkboxMouseEnterEmit(item[identifierKey], true)"
47
47
  @mouseleave="checkboxMouseEnterEmit(item[identifierKey], false)"
48
48
  >
@@ -162,7 +162,6 @@ export default {
162
162
  // Update the stated to send to the emit
163
163
  this.$emit('checkboxMouseEnter', { key: key, value: value, selections: this.selections, checked: this.checkedItems})
164
164
  },
165
-
166
165
  handleCheckedItemsChange: function (value) {
167
166
  let checkedCount = value.length
168
167
  this.checkAll = checkedCount === this.selections.length
@@ -171,7 +170,7 @@ export default {
171
170
  this.checkedItems = val
172
171
  ? this.selections.map((a) => a[this.identifierKey])
173
172
  : []
174
-
173
+
175
174
  this.$emit('checkAll', {
176
175
  keys: this.selections.map((a) => a[this.identifierKey]),
177
176
  value: val,
@@ -188,6 +187,33 @@ export default {
188
187
  }
189
188
  return {}
190
189
  },
190
+ getState: function() {
191
+ let checkedCount = this.checkedItems.length
192
+ const checkAll = checkedCount === this.selections.length
193
+ return {
194
+ checkAll,
195
+ checked: !checkAll ? this.checkedItems : []
196
+ }
197
+ },
198
+ setState: function(state) {
199
+ this.checkAll = state.checkAll
200
+ this.checkedItems.length = 0
201
+ if (state.checked?.length) {
202
+ this.checkedItems.push(...state.checked)
203
+ this.selections.forEach((item) => {
204
+ const key = item[this.identifierKey]
205
+ this.$emit('changed', {key, value: this.checkedItems.includes(key)})
206
+ })
207
+ } else {
208
+ const keys = this.selections.map((a) => a[this.identifierKey])
209
+ let value = false
210
+ if (this.checkAll) {
211
+ value = true
212
+ this.checkedItems.push(...keys)
213
+ }
214
+ this.$emit('checkAll', { keys, value })
215
+ }
216
+ },
191
217
  hasLineStyles: function(item) {
192
218
  return 'colour' in item && this.colourStyle === 'line'
193
219
  },
@@ -312,7 +338,7 @@ export default {
312
338
 
313
339
  :deep(.el-checkbox__label) {
314
340
  padding-left: 5px;
315
- color: $app-primary-color;
341
+ color: inherit !important;
316
342
  font-size: 12px;
317
343
  font-weight: 500;
318
344
  letter-spacing: 0px;
@@ -335,10 +361,6 @@ export default {
335
361
  margin-bottom: 0;
336
362
  }
337
363
 
338
- :deep(.el-checkbox__label) {
339
- color: $app-primary-color !important;
340
- }
341
-
342
364
  .checkbox-row {
343
365
  width: 100%;
344
366
  top: 2px;
@@ -0,0 +1,9 @@
1
+ const capitalise = term => {
2
+ if (term)
3
+ return term.charAt(0).toUpperCase() + term.slice(1);
4
+ return term;
5
+ };
6
+
7
+ export {
8
+ capitalise,
9
+ };
@@ -8,6 +8,7 @@ const removeDuplicates = function (arrayOfAnything) {
8
8
  }
9
9
 
10
10
  const cachedLabels = {}
11
+ const cachedTaxonLabels = [];
11
12
 
12
13
  const findTaxonomyLabel = async function (flatmapAPI, taxonomy) {
13
14
  if (cachedLabels && cachedLabels.hasOwnProperty(taxonomy)) {
@@ -35,6 +36,38 @@ const findTaxonomyLabel = async function (flatmapAPI, taxonomy) {
35
36
  })
36
37
  }
37
38
 
39
+ const findTaxonomyLabels = async function (mapImp, taxonomies) {
40
+ const intersectionTaxonomies = taxonomies.filter((taxonomy) =>
41
+ cachedTaxonLabels.some((obj) => obj.taxon === taxonomy)
42
+ );
43
+
44
+ const foundCachedTaxonLabels = cachedTaxonLabels.filter((obj) =>
45
+ intersectionTaxonomies.includes(obj.taxon)
46
+ );
47
+
48
+ const leftoverTaxonomies = taxonomies.filter((taxonomy) =>
49
+ !intersectionTaxonomies.includes(taxonomy)
50
+ );
51
+
52
+ if (!leftoverTaxonomies.length) {
53
+ return foundCachedTaxonLabels;
54
+ } else {
55
+ const entityLabels = await mapImp.queryLabels(leftoverTaxonomies);
56
+ if (entityLabels.length) {
57
+ entityLabels.forEach((entityLabel) => {
58
+ let { entity: taxon, label } = entityLabel;
59
+ if (label === 'Mammalia') {
60
+ label = 'Mammalia not otherwise specified'
61
+ }
62
+ const item = { taxon, label };
63
+ foundCachedTaxonLabels.push(item);
64
+ cachedTaxonLabels.push(item);
65
+ });
66
+ return foundCachedTaxonLabels;
67
+ }
68
+ }
69
+ }
70
+
38
71
  const inArray = function (ar1, ar2) {
39
72
  if (!ar1 || !ar2) return false
40
73
  let as1 = JSON.stringify(ar1)
@@ -54,7 +87,7 @@ let FlatmapQueries = function () {
54
87
  this.lookUp = []
55
88
  }
56
89
 
57
- this.createTooltipData = async function (eventData) {
90
+ this.createTooltipData = async function (mapImp, eventData) {
58
91
  let hyperlinks = []
59
92
  if (
60
93
  eventData.feature.hyperlinks &&
@@ -67,13 +100,12 @@ let FlatmapQueries = function () {
67
100
  let taxonomyLabel = undefined
68
101
  if (eventData.provenanceTaxonomy) {
69
102
  taxonomyLabel = []
70
- for (let i = 0; eventData.provenanceTaxonomy.length > i; i++) {
71
- taxonomyLabel.push(
72
- await findTaxonomyLabel(
73
- this.flatmapAPI,
74
- eventData.provenanceTaxonomy[i]
75
- )
76
- )
103
+ const entityLabels = await findTaxonomyLabels(mapImp, eventData.provenanceTaxonomy);
104
+ if (entityLabels.length) {
105
+ entityLabels.forEach((entityLabel) => {
106
+ const { label } = entityLabel;
107
+ taxonomyLabel.push(label);
108
+ });
77
109
  }
78
110
  }
79
111
 
@@ -104,33 +136,22 @@ let FlatmapQueries = function () {
104
136
  return labelList
105
137
  }
106
138
 
107
- this.createLabelLookup = function (uberons) {
108
- return new Promise((resolve) => {
139
+ this.createLabelLookup = function (mapImp, uberons) {
140
+ return new Promise(async (resolve) => {
109
141
  let uberonMap = {}
110
142
  this.uberons = []
111
- const data = { sql: this.buildLabelSqlStatement(uberons) }
112
- fetch(`${this.flatmapApi}knowledge/query/`, {
113
- method: 'POST',
114
- headers: {
115
- 'Content-Type': 'application/json',
116
- },
117
- body: JSON.stringify(data),
118
- })
119
- .then((response) => response.json())
120
- .then((payload) => {
121
- const entity = payload.keys.indexOf('entity')
122
- const label = payload.keys.indexOf('label')
123
- if (entity > -1 && label > -1) {
124
- payload.values.forEach((pair) => {
125
- uberonMap[pair[entity]] = pair[label]
126
- this.uberons.push({
127
- id: pair[entity],
128
- name: pair[label],
129
- })
130
- })
131
- }
132
- resolve(uberonMap)
133
- })
143
+ const entityLabels = await findTaxonomyLabels(mapImp, uberons);
144
+ if (entityLabels.length) {
145
+ entityLabels.forEach((entityLabel) => {
146
+ const { taxon: entity, label } = entityLabel;
147
+ uberonMap[entity] = label;
148
+ this.uberons.push({
149
+ id: entity,
150
+ name: label,
151
+ })
152
+ });
153
+ resolve(uberonMap)
154
+ }
134
155
  })
135
156
  }
136
157
 
@@ -209,7 +230,7 @@ let FlatmapQueries = function () {
209
230
  return found
210
231
  }
211
232
 
212
- this.retrieveFlatmapKnowledgeForEvent = async function (eventData) {
233
+ this.retrieveFlatmapKnowledgeForEvent = async function (mapImp, eventData) {
213
234
  // check if there is an existing query
214
235
  if (this.controller) this.controller.abort()
215
236
 
@@ -221,15 +242,58 @@ let FlatmapQueries = function () {
221
242
  this.destinations = []
222
243
  this.origins = []
223
244
  this.components = []
224
- if (!keastIds || keastIds.length == 0) return
245
+ this.urls = []
246
+ if (!keastIds || keastIds.length == 0 || !keastIds[0]) return
225
247
 
226
- let prom1 = this.queryForConnectivity(keastIds, signal) // This on returns a promise so dont need 'await'
227
- let prom2 = await this.pubmedQueryOnIds(eventData)
228
- let results = await Promise.all([prom1, prom2])
248
+ let prom1 = this.queryForConnectivityNew(mapImp, keastIds, signal) // This on returns a promise so dont need 'await'
249
+ // let prom2 = await this.pubmedQueryOnIds(eventData)
250
+ let results = await Promise.all([prom1])
229
251
  return results
230
252
  }
231
253
 
232
- this.queryForConnectivity = function (keastIds, signal, processConnectivity=true) {
254
+ this.queryForConnectivityNew = function (mapImp, keastIds, signal, processConnectivity=true) {
255
+ return new Promise((resolve) => {
256
+ mapImp.queryKnowledge(keastIds[0])
257
+ .then((response) => {
258
+ if (this.checkConnectivityExists(response)) {
259
+ let connectivity = response;
260
+ if (processConnectivity) {
261
+ this.processConnectivity(mapImp, connectivity).then((processedConnectivity) => {
262
+ // response.references is publication urls
263
+ if (response.references) {
264
+ // with publications
265
+ this.getURLsForPubMed(response.references).then((urls) => {
266
+ // TODO: if empty urls array is returned,
267
+ // the urls are not on PubMed.
268
+ // Those urls, response.references, will be shown in another way.
269
+ this.urls = urls;
270
+ resolve(processedConnectivity)
271
+ })
272
+ } else {
273
+ // without publications
274
+ resolve(processedConnectivity)
275
+ }
276
+ })
277
+ }
278
+ else resolve(connectivity)
279
+ } else {
280
+ resolve(false)
281
+ }
282
+ })
283
+ .catch((error) => {
284
+ if (error.name === 'AbortError') {
285
+ // This error is from AbortController's abort method.
286
+ } else {
287
+ // console.error('Error:', error)
288
+ // TODO: to update after queryKnowledge method update
289
+ console.warn(`Unable to get the knowledge for the entity ${keastIds[0]}.`)
290
+ }
291
+ resolve(false)
292
+ })
293
+ })
294
+ }
295
+
296
+ this.queryForConnectivity = function (mapImp, keastIds, signal, processConnectivity=true) {
233
297
  const data = { sql: this.buildConnectivitySqlStatement(keastIds) }
234
298
  const headers = {
235
299
  method: 'POST',
@@ -246,7 +310,7 @@ let FlatmapQueries = function () {
246
310
  if (this.connectivityExists(data)) {
247
311
  let connectivity = JSON.parse(data.values[0][0])
248
312
  if (processConnectivity) {
249
- this.processConnectivity(connectivity).then((processedConnectivity) => {
313
+ this.processConnectivity(mapImp, connectivity).then((processedConnectivity) => {
250
314
  resolve(processedConnectivity)
251
315
  })
252
316
  }
@@ -266,6 +330,10 @@ let FlatmapQueries = function () {
266
330
  })
267
331
  }
268
332
 
333
+ this.checkConnectivityExists = function (data) {
334
+ return data && data.connectivity?.length;
335
+ };
336
+
269
337
  this.connectivityExists = function (data) {
270
338
  if (
271
339
  data.values &&
@@ -336,7 +404,7 @@ let FlatmapQueries = function () {
336
404
  )
337
405
  }
338
406
 
339
- this.processConnectivity = function (connectivity) {
407
+ this.processConnectivity = function (mapImp, connectivity) {
340
408
  return new Promise((resolve) => {
341
409
  // Filter the origin and destinations from components
342
410
  let components = this.findComponents(connectivity)
@@ -349,7 +417,7 @@ let FlatmapQueries = function () {
349
417
  let conIds = this.findAllIdsFromConnectivity(connectivity)
350
418
 
351
419
  // Create readable labels from the nodes. Setting this to 'this.origins' updates the display
352
- this.createLabelLookup(conIds).then((lookUp) => {
420
+ this.createLabelLookup(mapImp, conIds).then((lookUp) => {
353
421
  this.destinations = axons.map((a) =>
354
422
  this.createLabelFromNeuralNode(a, lookUp)
355
423
  )
@@ -500,7 +568,11 @@ let FlatmapQueries = function () {
500
568
 
501
569
  this.getURLsForPubMed = function (data) {
502
570
  return new Promise((resolve) => {
503
- const ids = data.values.map((id) => this.extractPublicationIdFromURLString(id[0]))
571
+ const ids = data.map((id) =>
572
+ (typeof id === 'object') ?
573
+ this.extractPublicationIdFromURLString(id[0]) :
574
+ this.extractPublicationIdFromURLString(id)
575
+ )
504
576
  this.convertPublicationIds(ids).then((pmids) => {
505
577
  if (pmids.length > 0) {
506
578
  const transformedIDs = pmids.join()
@@ -552,7 +624,7 @@ let FlatmapQueries = function () {
552
624
  this.flatmapQuery(sql).then((data) => {
553
625
  // Create pubmed url on paths if we have them
554
626
  if (data.values.length > 0) {
555
- this.getURLsForPubMed(data).then((urls) => {
627
+ this.getURLsForPubMed(data.values).then((urls) => {
556
628
  this.urls = urls
557
629
  if (urls.length) {
558
630
  resolve(true)
@@ -579,7 +651,7 @@ let FlatmapQueries = function () {
579
651
  this.buildPubmedSqlStatementForModels(source)
580
652
  ).then((data) => {
581
653
  if (Array.isArray(data.values) && data.values.length > 0) {
582
- this.getURLsForPubMed(data).then((urls) => {
654
+ this.getURLsForPubMed(data.values).then((urls) => {
583
655
  this.urls = urls
584
656
  return true
585
657
  })
@@ -602,4 +674,4 @@ let FlatmapQueries = function () {
602
674
  }
603
675
  }
604
676
 
605
- export { FlatmapQueries, findTaxonomyLabel }
677
+ export { FlatmapQueries, findTaxonomyLabel, findTaxonomyLabels }