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
|
<script lang="ts">
import {defineComponent, PropType} from 'vue';
import {LayoutNode} from '../lib';
//component holds a tree-node structure representing a tile or tile-group to be rendered
export default defineComponent({
name: 'tile', //need this to use self in template
props: {
layoutNode: {type: Object as PropType<LayoutNode>, required: true},
isRoot: {type: Boolean, default: false},
//settings passed in from parent component
transitionDuration: {type: Number, required: true},
headerSz: {type: Number, required: true},
tileSpacing: {type: Number, required: true},
},
data(){
return {
//used during transitions and to emulate/show an apparently-joined div
zIdx: 0,
overflow: this.isRoot ? 'hidden' : 'visible',
}
},
computed: {
showHeader(){
return (this.layoutNode.showHeader && !this.layoutNode.sepSweptArea) ||
(this.layoutNode.sepSweptArea && this.layoutNode.sepSweptArea.sweptLeft);
},
tileStyles(): Record<string,string> {
return {
//place using layoutNode, with centering if root
position: 'absolute',
top: this.isRoot ? '50%' : this.layoutNode.pos[1] + 'px',
left: this.isRoot ? '50%' : this.layoutNode.pos[0] + 'px',
transform: this.isRoot ? 'translate(-50%, -50%)' : 'none',
width: this.layoutNode.dims[0] + 'px',
height: this.layoutNode.dims[1] + 'px',
//other bindings
transitionDuration: this.transitionDuration + 'ms',
zIndex: String(this.zIdx),
overflow: String(this.overflow),
//static
outline: 'black solid 1px',
backgroundColor: 'white',
transitionProperty: 'top, left, width, height',
transitionTimingFunction: 'ease-out',
};
},
leafStyles(): Record<string,string> {
return {
width: '100%',
height: '100%',
backgroundImage: 'url(\'/img/' + this.layoutNode.tolNode.name.replaceAll('\'', '\\\'') + '.jpg\')',
backgroundSize: 'cover',
opacity: (this.layoutNode.tolNode.children.length > 0) ? '1' : '0.7',
};
},
headerStyles(): Record<string,string> {
return {
height: this.headerSz + 'px',
backgroundColor: 'lightgray',
textAlign: 'center',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
};
},
sepSweptAreaStyles(): Record<string,string> {
let commonStyles = {
position: 'absolute',
backgroundColor: 'white',
transitionDuration: this.transitionDuration + 'ms',
transitionProperty: 'top, left, width, height',
transitionTimingFunction: 'ease-out',
};
let area = this.layoutNode.sepSweptArea;
if (area == null){
return {
...commonStyles,
visibility: 'hidden',
top: this.headerSz + 'px',
left: '0',
width: '0',
height: '0',
};
} else {
return {
...commonStyles,
top: area.pos[1] + 'px',
left: area.pos[0] + 'px',
width: (area.dims[0] + (area.sweptLeft ? 1 : 0)) + 'px',
height: (area.dims[1] + (area.sweptLeft ? 0 : 1)) + 'px',
};
}
},
sepSweptAreaOutlineClasses(){
let area = this.layoutNode.sepSweptArea;
return ['outline-top-left', (area && area.sweptLeft) ? 'outline-bottom-left' : 'outline-top-right'];
},
},
methods: {
onLeafClick(){
this.$emit('leaf-clicked', this.layoutNode);
//increase z-index and hide overflow during transition
this.zIdx = 1;
this.overflow = 'hidden';
setTimeout(() => {this.zIdx = 0; this.overflow = 'visible'}, this.transitionDuration);
},
onInnerLeafClicked(node: LayoutNode){
this.$emit('leaf-clicked', node);
},
onHeaderClick(){
this.$emit('header-clicked', this.layoutNode);
//increase z-index and hide overflow during transition
this.zIdx = 1;
this.overflow = 'hidden';
setTimeout(() => {this.zIdx = 0; this.overflow = 'visible'}, this.transitionDuration);
},
onInnerHeaderClicked(node: LayoutNode){
this.$emit('header-clicked', node);
},
},
});
</script>
<template>
<div :style="tileStyles">
<div v-if="layoutNode.children.length == 0"
:style="leafStyles" class="hover:cursor-pointer" @click="onLeafClick"/>
<div v-else>
<div v-if="showHeader" :style="headerStyles" class="hover:cursor-pointer" @click="onHeaderClick">
{{layoutNode.tolNode.name}}
</div>
<div :style="sepSweptAreaStyles" :class="sepSweptAreaOutlineClasses">
<div v-if="layoutNode?.sepSweptArea?.sweptLeft === false"
:style="headerStyles" class="hover:cursor-pointer" @click="onHeaderClick">
{{layoutNode.tolNode.name}}
</div>
</div>
<tile v-for="child in layoutNode.children" :key="child.tolNode.name" :layoutNode="child"
:headerSz="headerSz" :tileSpacing="tileSpacing" :transitionDuration="transitionDuration"
@leaf-clicked="onInnerLeafClicked" @header-clicked="onInnerHeaderClicked"/>
</div>
</div>
</template>
<style>
.outline-top-left::before {
content: '';
position: absolute;
background-color: black;
top: -1px;
left: -1px;
width: 100%;
height: 100%;
z-index: -10;
}
.outline-bottom-left::after {
content: '';
position: absolute;
background-color: black;
bottom: -1px;
left: -1px;
width: 100%;
height: 100%;
z-index: -10;
}
.outline-top-right::after {
content: '';
position: absolute;
background-color: black;
top: -1px;
right: -1px;
width: 100%;
height: 100%;
z-index: -10;
}
</style>
|