@abi-software/flatmapvuer 0.5.5-beta.1 → 0.5.6

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.
@@ -4,6 +4,34 @@ const removeDuplicates = function(arrayOfAnything){
4
4
  return [...new Set(arrayOfAnything.map(e => JSON.stringify(e)))].map(e => JSON.parse(e))
5
5
  }
6
6
 
7
+ const cachedLabels = {};
8
+
9
+ const findTaxonomyLabel = async function(flatmapAPI, taxonomy){
10
+ if (cachedLabels && cachedLabels.hasOwnProperty(taxonomy)) {
11
+ return cachedLabels[taxonomy];
12
+ }
13
+
14
+ return new Promise(resolve=>{
15
+ fetch(`${flatmapAPI}knowledge/label/${taxonomy}`, {
16
+ method: 'GET',
17
+ })
18
+ .then(response => response.json())
19
+ .then(data => {
20
+ let label = data.label;
21
+ if (label === "Mammalia") {
22
+ label = "Mammalia not otherwise specified";
23
+ }
24
+ cachedLabels[taxonomy] = label;
25
+ resolve(label);
26
+ })
27
+ .catch((error) => {
28
+ console.error('Error:', error);
29
+ cachedLabels[taxonomy] = taxonomy;
30
+ resolve(taxonomy);
31
+ })
32
+ });
33
+ }
34
+
7
35
  const inArray = function(ar1, ar2){
8
36
  let as1 = JSON.stringify(ar1)
9
37
  let as2 = JSON.stringify(ar2)
@@ -24,13 +52,21 @@ let FlatmapQueries = function(){
24
52
  this.lookUp = []
25
53
  }
26
54
 
27
- this.createTooltipData = function (eventData) {
55
+ this.createTooltipData = async function (eventData) {
28
56
  let hyperlinks = []
29
57
  if (eventData.feature.hyperlinks && eventData.feature.hyperlinks.length > 0) {
30
58
  hyperlinks = eventData.feature.hyperlinks
31
59
  } else {
32
60
  hyperlinks = this.urls.map(url=>({url: url, id: "pubmed"}))
33
61
  }
62
+ let taxonomyLabel = undefined;
63
+ if (eventData.provenanceTaxonomy) {
64
+ taxonomyLabel = [];
65
+ for (let i = 0; eventData.provenanceTaxonomy.length > i; i++) {
66
+ taxonomyLabel.push(await findTaxonomyLabel(this.flatmapAPI, eventData.provenanceTaxonomy[i]))
67
+ }
68
+ }
69
+
34
70
  let tooltipData = {
35
71
  destinations: this.destinations,
36
72
  origins: this.origins,
@@ -41,6 +77,8 @@ let FlatmapQueries = function(){
41
77
  title: eventData.label,
42
78
  featureId: eventData.resource,
43
79
  hyperlinks: hyperlinks,
80
+ provenanceTaxonomy: eventData.provenanceTaxonomy,
81
+ provenanceTaxonomyLabel: taxonomyLabel
44
82
  }
45
83
  return tooltipData
46
84
  }
@@ -371,4 +409,4 @@ let FlatmapQueries = function(){
371
409
  }
372
410
  }
373
411
 
374
- export {FlatmapQueries}
412
+ export {FlatmapQueries, findTaxonomyLabel}