1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
<template>
<div class="fixed left-0 top-0 w-full h-full bg-black/40" @click="onClose">
<div class="absolute left-1/2 -translate-x-1/2 top-1/2 -translate-y-1/2 w-4/5 max-h-[80%] p-4" :style="styles">
<close-icon @click.stop="onClose" ref="closeIcon"
class="block absolute top-2 right-2 w-6 h-6 hover:cursor-pointer"/>
<h1 class="text-center text-xl font-bold mb-2">
{{getDisplayName(nodeName, tolNode)}}
<div v-if="tolNode != null">
({{tolNode.children.length}} children, {{tolNode.tips}} tips,
<a :href="'https://tree.opentreeoflife.org/opentree/argus/opentree13.4@' + tolNode.otolId"
target="_blank">{{tolNode.otolId}}</a>)
</div>
</h1>
<hr class="mb-4 border-stone-400"/>
<div v-if="nodes.length > 1">This is a compound node</div>
<div v-for="idx in (nodes.length == 1 ? [0] : [0, 1])">
<h1 v-if="nodes.length > 1" class="text-center font-bold">
{{getDisplayName(subNames![idx], nodes[idx])}}
</h1>
<div class="flex gap-1">
<div class="w-1/2">
<div v-if="imgInfos[idx] == null" :style="getImgStyles(nodes[idx])"/>
<a v-else :href="imgInfos[idx]!.url" target="_blank">
<div :style="getImgStyles(nodes[idx])"/>
</a>
<ul v-if="imgInfos[idx]! != null">
<li>Obtained via: {{imgInfos[idx]!.src}}</li>
<li>License:
<a :href="licenseToUrl(imgInfos[idx]!.license)" target="_blank">
<span class="underline">{{imgInfos[idx]!.license}}</span>
<external-link-icon class="inline-block w-3 h-3 ml-1"/>
</a>
</li>
<li>
<a :href="imgInfos[idx]!.url" target="_blank">
<span class="underline">Source URL</span>
<external-link-icon class="inline-block w-3 h-3 ml-1"/>
</a>
</li>
<li>Artist: {{imgInfos[idx]!.artist}}</li>
<li v-if="imgInfos[idx]!.credit != ''" class="overflow-auto">
Credit: {{imgInfos[idx]!.credit}}
</li>
</ul>
</div>
<div v-if="descInfos[idx]! != null">
<div>
Redirected: {{descInfos[idx]!.fromRedirect}} <br/>
Short-description from {{descInfos[idx]!.fromDbp ? 'DBpedia' : 'Wikipedia'}} <br/>
<a :href="'https://en.wikipedia.org/?curid=' + descInfos[idx]!.wikiId" target="_blank">
<span class="underline">Wikipedia Link</span>
<external-link-icon class="inline-block w-3 h-3 ml-1"/>
</a>
</div>
<hr/>
<div>{{descInfos[idx]!.text}}</div>
</div>
<div v-else>
(No description found)
</div>
</div>
</div>
</div>
</div>
</template>
<script lang="ts">
import {defineComponent, PropType} from 'vue';
import CloseIcon from './icon/CloseIcon.vue';
import ExternalLinkIcon from './icon/ExternalLinkIcon.vue';
import {TolNode, TolMap} from '../tol';
import {LayoutNode, LayoutOptions} from '../layout';
import {getServerResponse, getImagePath, DescInfo, ImgInfo, NodeInfo, InfoResponse, UiOptions} from '../lib';
import {capitalizeWords} from '../util';
export default defineComponent({
props: {
// Node data to display
nodeName: {type: String, required: true},
infoResponse: {type: Object as PropType<InfoResponse>, required: true},
// Options
lytOpts: {type: Object as PropType<LayoutOptions>, required: true},
uiOpts: {type: Object as PropType<UiOptions>, required: true},
},
computed: {
tolNode(): TolNode {
return this.infoResponse.nodeInfo.tolNode;
},
nodes(): TolNode[] {
if (this.infoResponse.subNodesInfo.length == 0){
return [this.tolNode];
} else {
return this.infoResponse.subNodesInfo.map(nodeInfo => nodeInfo.tolNode);
}
},
imgInfos(): (ImgInfo | null)[] {
if (this.infoResponse.subNodesInfo.length == 0){
return [this.infoResponse.nodeInfo.imgInfo];
} else {
return this.infoResponse.subNodesInfo.map(nodeInfo => nodeInfo.imgInfo);
}
},
descInfos(): (DescInfo | null)[] {
if (this.infoResponse.subNodesInfo.length == 0){
return [this.infoResponse.nodeInfo.descInfo];
} else {
return this.infoResponse.subNodesInfo.map(nodeInfo => nodeInfo.descInfo);
}
},
subNames(): [string, string] | null {
const regex = /\[(.+) \+ (.+)\]/;
let results = regex.exec(this.nodeName);
return results == null ? null : [results[1], results[2]];
},
styles(): Record<string,string> {
return {
backgroundColor: this.uiOpts.bgColorAlt,
borderRadius: this.uiOpts.borderRadius + 'px',
boxShadow: this.uiOpts.shadowNormal,
overflow: 'visible auto',
};
},
},
methods: {
getDisplayName(name: string, tolNode: TolNode | null): string {
if (tolNode == null || tolNode.commonName == null){
return capitalizeWords(name);
} else {
return `${capitalizeWords(tolNode.commonName)} (aka ${capitalizeWords(name)})`;
}
},
getImgStyles(tolNode: TolNode): Record<string,string> {
let imgName = null;
if (typeof(tolNode.imgName) === 'string'){ // Exclude string-array case
imgName = tolNode.imgName;
}
return {
width: this.lytOpts.maxTileSz + 'px',
height: this.lytOpts.maxTileSz + 'px',
backgroundImage: imgName != null ?
`url('${getImagePath(imgName as string)}')` :
'none',
backgroundColor: this.uiOpts.bgColorDark,
backgroundSize: 'cover',
borderRadius: this.uiOpts.borderRadius + 'px',
boxShadow: this.uiOpts.shadowNormal,
};
},
licenseToUrl(license: string){
license = license.toLowerCase().replaceAll('-', ' ');
if (license == 'cc0'){
return 'https://creativecommons.org/publicdomain/zero/1.0/';
} else if (license == 'cc publicdomain'){
return 'https://creativecommons.org/licenses/publicdomain/';
} else {
const regex = /cc by( nc)?( sa)?( ([0-9.]+)( [a-z]+)?)?/;
let results = regex.exec(license);
if (results != null){
let url = 'https://creativecommons.org/licenses/by';
if (results[1] != null){
url += '-nc';
}
if (results[2] != null){
url += '-sa';
}
if (results[4] != null){
url += '/' + results[4];
} else {
url += '/4.0';
}
if (results[5] != null){
url += '/' + results[5].substring(1);
}
return url;
}
return "[INVALID LICENSE]";
}
},
onClose(evt: Event){
if (evt.target == this.$el || (this.$refs.closeIcon as typeof CloseIcon).$el.contains(evt.target)){
this.$emit('close');
}
},
},
components: {CloseIcon, ExternalLinkIcon, },
emits: ['close', ],
});
</script>
|