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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
|
<script lang="ts">
import {defineComponent, PropType} from 'vue';
import InfoIcon from './icon/InfoIcon.vue';
import {LayoutNode} from '../layout';
import type {LayoutOptions} from '../layout';
import type {TolMap} from '../tol';
import {TolNode} from '../tol';
import {capitalizeWords} from '../util';
// Displays one, or a hierarchy of, tree-of-life nodes, as a 'tile'
export default defineComponent({
props: {
layoutNode: {type: Object as PropType<LayoutNode>, required: true},
tolMap: {type: Object as PropType<TolMap>, required: true},
// Options
lytOpts: {type: Object as PropType<LayoutOptions>, required: true},
uiOpts: {type: Object, required: true},
// For a leaf node, prevents usage of absolute positioning (used by AncestryBar)
nonAbsPos: {type: Boolean, default: false},
},
data(){
return {
highlight: false, // Used to draw a colored outline on mouse hover
inTransition: false, // Used to prevent content overlap and overflow during user-perceivable transitions
wasClicked: false, // Used to increase z-index during transition after this tile (or a child) is clicked
hasExpanded: false, // Set to true after an expansion transition ends, and false upon collapse
// Used to hide overflow on tile expansion, but not hide a sepSweptArea on subsequent transitions
clickHoldTimer: 0, // Used to recognise click-and-hold events
};
},
computed: {
tolNode(): TolNode {
return this.tolMap.get(this.layoutNode.name)!;
},
// Basic abbreviations
isLeaf(): boolean {
return this.layoutNode.children.length == 0;
},
isExpandableLeaf(): boolean {
return this.isLeaf && this.tolNode.children.length > 0;
},
showNonleafHeader(): boolean {
return (this.layoutNode.showHeader && this.layoutNode.sepSweptArea == null) ||
(this.layoutNode.sepSweptArea != null && this.layoutNode.sepSweptArea.sweptLeft);
},
displayName(): string {
return capitalizeWords(this.tolNode.commonName || this.layoutNode.name);
},
// Style related
nonleafBgColor(): string {
let colorArray = this.uiOpts.nonleafBgColors;
return colorArray[this.layoutNode.depth % colorArray.length];
},
boxShadow(): string {
if (this.highlight){
return this.uiOpts.shadowHighlight;
} else if (this.layoutNode.hasFocus && !this.inTransition){
return this.uiOpts.shadowFocused;
} else {
return this.uiOpts.shadowNormal;
}
},
styles(): Record<string,string> {
let layoutStyles = {
position: 'absolute',
left: this.layoutNode.pos[0] + 'px',
top: this.layoutNode.pos[1] + 'px',
width: this.layoutNode.dims[0] + 'px',
height: this.layoutNode.dims[1] + 'px',
visibility: 'visible',
};
if (this.layoutNode.hidden){
layoutStyles.left = layoutStyles.top = layoutStyles.width = layoutStyles.height = '0';
layoutStyles.visibility = 'hidden';
}
if (this.nonAbsPos){
layoutStyles.position = 'static';
}
return {
...layoutStyles,
// Transition related
transitionDuration: this.uiOpts.tileChgDuration + 'ms',
transitionProperty: 'left, top, width, height, visibility',
transitionTimingFunction: 'ease-out',
zIndex: this.inTransition && this.wasClicked ? '1' : '0',
overflow: this.inTransition && !this.isLeaf && !this.hasExpanded ? 'hidden' : 'visible',
// CSS variables
'--nonleafBgColor': this.nonleafBgColor,
'--tileSpacing': this.lytOpts.tileSpacing + 'px',
};
},
leafStyles(): Record<string,string> {
return {
// Image (and scrims)
backgroundImage: this.tolNode.imgName != null ?
'linear-gradient(to bottom, rgba(0,0,0,0.4), #0000 40%, #0000 60%, rgba(0,0,0,0.4) 100%),' +
'url(\'/img/' + this.tolNode.imgName.replaceAll('\'', '\\\'') + '\')' :
'none',
backgroundColor: '#1c1917',
backgroundSize: 'cover',
// Other
borderRadius: this.uiOpts.borderRadius + 'px',
boxShadow: this.boxShadow,
};
},
leafHeaderStyles(): Record<string,string> {
return {
height: (this.uiOpts.leafHeaderFontSz + this.uiOpts.leafTilePadding * 2) + 'px',
padding: this.uiOpts.leafTilePadding + 'px',
lineHeight: this.uiOpts.leafHeaderFontSz + 'px',
fontSize: this.uiOpts.leafHeaderFontSz + 'px',
fontStyle: this.tolNode.pSupport ? 'normal' : 'italic',
color: this.tolNode.children.length == 0 ?
this.uiOpts.headerColor :
this.tolNode.children.length < this.uiOpts.highTipsVal ?
this.uiOpts.headerColor2 :
this.uiOpts.headerColor3,
// For ellipsis
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
};
},
nonleafStyles(): Record<string,string> {
let borderR = this.uiOpts.borderRadius + 'px';
if (this.layoutNode.sepSweptArea != null){
borderR = this.layoutNode.sepSweptArea.sweptLeft ?
`${borderR} ${borderR} ${borderR} 0` :
`${borderR} 0 ${borderR} ${borderR}`;
}
return {
backgroundColor: this.nonleafBgColor,
borderRadius: borderR,
boxShadow: this.boxShadow,
};
},
nonleafHeaderStyles(): Record<string,string> {
let borderR = this.uiOpts.borderRadius + 'px';
borderR = `${borderR} ${borderR} 0 0`;
return {
height: this.lytOpts.headerSz + 'px',
borderRadius: borderR,
backgroundColor: this.uiOpts.nonleafHeaderBgColor,
fontStyle: this.tolNode.pSupport ? 'normal' : 'italic',
};
},
nonleafHeaderTextStyles(): Record<string,string> {
return {
lineHeight: this.lytOpts.headerSz + 'px',
fontSize: this.uiOpts.nonleafHeaderFontSz + 'px',
textAlign: 'center',
color: this.uiOpts.nonleafHeaderColor,
// For ellipsis
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
};
},
infoIconStyles(): Record<string,string> {
let size = this.uiOpts.infoIconSz + 'px';
return {
width: size,
height: size,
minWidth: size,
minHeight: size,
margin: this.uiOpts.infoIconMargin + 'px',
};
},
sepSweptAreaStyles(): Record<string,string> {
let borderR = this.uiOpts.borderRadius + 'px';
let styles = {
position: 'absolute',
backgroundColor: this.nonleafBgColor,
boxShadow: this.boxShadow,
transitionDuration: this.uiOpts.tileChgDuration + 'ms',
transitionProperty: 'left, top, width, height, visibility',
transitionTimingFunction: 'ease-out',
};
let area = this.layoutNode.sepSweptArea;
if (!this.layoutNode.hidden && area != null){
return {
...styles,
visibility: 'visible',
left: area.pos[0] + 'px',
top: area.pos[1] + 'px',
width: area.dims[0] + 'px',
height: area.dims[1] + 'px',
borderRadius: area.sweptLeft ?
`${borderR} 0 0 ${borderR}` :
`${borderR} ${borderR} 0 0`,
};
} else {
return {
...styles,
visibility: 'hidden',
left: '0',
top: this.lytOpts.headerSz + 'px',
width: '0',
height: '0',
borderRadius: borderR,
};
}
},
// For watching layoutNode data
pos(){
return this.layoutNode.pos;
},
dims(){
return this.layoutNode.dims;
},
failFlag(){
return this.layoutNode.failFlag;
},
},
watch: {
// For setting transition state (can be triggered externally, like via search and auto-mode)
pos: {
handler(newVal, oldVal){
let valChanged = newVal[0] != oldVal[0] || newVal[1] != oldVal[1];
if (valChanged && this.uiOpts.tileChgDuration > 100 && !this.inTransition){
this.inTransition = true;
}
},
deep: true,
},
dims: {
handler(newVal, oldVal){
let valChanged = newVal[0] != oldVal[0] || newVal[1] != oldVal[1];
if (valChanged && this.uiOpts.tileChgDuration > 100 && !this.inTransition){
this.inTransition = true;
}
},
deep: true,
},
// For externally triggering fail animations (used by search and auto-mode)
failFlag(){
this.triggerAnimation(this.isLeaf ? 'animate-expand-shrink' : 'animate-shrink-expand');
},
},
methods: {
// Click handling
onMouseDown(){
this.highlight = false;
clearTimeout(this.clickHoldTimer);
this.clickHoldTimer = setTimeout(() => {
this.clickHoldTimer = 0;
this.onClickHold();
}, this.uiOpts.clickHoldDuration);
},
onMouseUp(){
if (this.clickHoldTimer > 0){
clearTimeout(this.clickHoldTimer);
this.clickHoldTimer = 0;
this.onClick();
}
},
onClick(){
if (this.isLeaf && !this.isExpandableLeaf){
console.log('Ignored click on non-expandable node');
return;
}
this.wasClicked = true;
this.$emit(this.isLeaf ? 'leaf-click' : 'nonleaf-click', this.layoutNode);
},
onClickHold(){
if (this.isLeaf && !this.isExpandableLeaf){
console.log('Ignored click-hold on non-expandable node');
return;
}
this.$emit(this.isLeaf ? 'leaf-click-held' : 'nonleaf-click-held', this.layoutNode);
},
onInfoIconClick(evt: Event){
this.$emit('info-icon-click', this.layoutNode);
},
// Mouse hover handling
onMouseEnter(evt: Event){
if ((!this.isLeaf || this.isExpandableLeaf) && !this.inTransition){
this.highlight = true;
}
},
onMouseLeave(evt: Event){
this.highlight = false;
},
// Child event propagation
onInnerLeafClick(node: LayoutNode){
this.wasClicked = true;
this.$emit('leaf-click', node);
},
onInnerNonleafClick(node: LayoutNode){
this.wasClicked = true;
this.$emit('nonleaf-click', node);
},
onInnerLeafClickHeld(node: LayoutNode){
this.$emit('leaf-click-held', node);
},
onInnerNonleafClickHeld(node: LayoutNode){
this.$emit('nonleaf-click-held', node);
},
onInnerInfoIconClick(node: LayoutNode){
this.$emit('info-icon-click', node);
},
// Other
onTransitionEnd(){
this.inTransition = false;
this.wasClicked = false;
this.hasExpanded = this.layoutNode.children.length > 0;
},
triggerAnimation(animation: string){
this.$el.classList.remove(animation);
this.$el.offsetWidth; // Triggers reflow
this.$el.classList.add(animation);
},
},
name: 'tile', // Note: Need this to use self in template
components: {InfoIcon, },
emits: ['leaf-click', 'nonleaf-click', 'leaf-click-held', 'nonleaf-click-held', 'info-icon-click', ],
});
</script>
<template>
<div :style="styles" @transitionend="onTransitionEnd"> <!-- Enclosing div needed for size transitions -->
<div v-if="isLeaf" :style="leafStyles"
class="w-full h-full flex flex-col overflow-hidden" :class="{'hover:cursor-pointer': isExpandableLeaf}"
@mouseenter="onMouseEnter" @mouseleave="onMouseLeave" @mousedown="onMouseDown" @mouseup="onMouseUp">
<h1 :style="leafHeaderStyles">{{displayName}}</h1>
<info-icon :style="[infoIconStyles, {marginTop: 'auto'}]"
class="self-end text-white/10 hover:text-white hover:cursor-pointer"
@click.stop="onInfoIconClick" @mousedown.stop @mouseup.stop/>
</div>
<div v-else :style="nonleafStyles" class="w-full h-full" ref="nonleaf">
<div v-if="showNonleafHeader" :style="nonleafHeaderStyles" class="flex hover:cursor-pointer"
@mouseenter="onMouseEnter" @mouseleave="onMouseLeave" @mousedown="onMouseDown" @mouseup="onMouseUp">
<h1 :style="nonleafHeaderTextStyles" class="grow">{{displayName}}</h1>
<info-icon :style="infoIconStyles" class="text-white/10 hover:text-white hover:cursor-pointer"
@click.stop="onInfoIconClick" @mousedown.stop @mouseup.stop/>
</div>
<div :style="sepSweptAreaStyles" ref="sepSweptArea"
:class="layoutNode?.sepSweptArea?.sweptLeft ? 'hide-right-edge' : 'hide-top-edge'">
<div v-if="layoutNode?.sepSweptArea?.sweptLeft === false"
:style="nonleafHeaderStyles" class="flex hover:cursor-pointer"
@mouseenter="onMouseEnter" @mouseleave="onMouseLeave" @mousedown="onMouseDown" @mouseup="onMouseUp">
<h1 :style="nonleafHeaderTextStyles" class="grow">{{displayName}}</h1>
<info-icon :style="infoIconStyles" class="text-white/10 hover:text-white hover:cursor-pointer"
@click.stop="onInfoIconClick" @mousedown.stop @mouseup.stop/>
</div>
</div>
<tile v-for="child in layoutNode.children" :key="child.name"
:layoutNode="child" :tolMap="tolMap" :lytOpts="lytOpts" :uiOpts="uiOpts"
@leaf-click="onInnerLeafClick" @nonleaf-click="onInnerNonleafClick"
@leaf-click-held="onInnerLeafClickHeld" @nonleaf-click-held="onInnerNonleafClickHeld"
@info-icon-click="onInnerInfoIconClick"/>
</div>
</div>
</template>
<style>
.hide-right-edge::before {
content: '';
position: absolute;
background-color: var(--nonleafBgColor);
right: calc(0px - var(--tileSpacing));
bottom: 0;
width: var(--tileSpacing);
height: calc(100% + var(--tileSpacing));
}
.hide-top-edge::before {
content: '';
position: absolute;
background-color: var(--nonleafBgColor);
bottom: calc(0px - var(--tileSpacing));
right: 0;
width: calc(100% + var(--tileSpacing));
height: var(--tileSpacing);
}
.animate-expand-shrink {
animation-name: expand-shrink;
animation-duration: 300ms;
animation-iteration-count: 1;
animation-timing-function: ease-in-out;
}
@keyframes expand-shrink {
from {
transform: scale(1, 1);
}
50% {
transform: scale(1.1, 1.1);
}
to {
transform: scale(1, 1);
}
}
.animate-shrink-expand {
animation-name: shrink-expand;
animation-duration: 300ms;
animation-iteration-count: 1;
animation-timing-function: ease-in-out;
}
@keyframes shrink-expand {
from {
transform: translate3d(0,0,0) scale(1, 1);
}
50% {
transform: translate3d(0,0,0) scale(0.9, 0.9);
}
to {
transform: translate3d(0,0,0) scale(1, 1);
}
}
</style>
|