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
|
<script>
import tol from '/src/tol.json';
import {defaultLayout, initTree} from '/src/layout.js';
import Tile from './Tile.vue';
export default {
data(){
return {
tree: initTree(this.preprocessTol(tol), 1),
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight,
layoutSys: defaultLayout,
}
},
methods: {
preprocessTol(tree){
if (!tree.children){
tree.children = [];
} else {
tree.children.forEach(this.preprocessTol);
}
return tree;
},
onResize(){
this.width = document.documentElement.clientWidth;
this.height = document.documentElement.clientHeight;
},
onInnerTileClicked(nodeList){
//nodeList holds an array of tree-objects, from the clicked-on-tile's tree-object upward
let numNewTiles = nodeList[0].tolNode.children.length;
if (numNewTiles == 0){
console.log('Tile-to-expand has no children');
return;
}
//add children
nodeList[0].children = nodeList[0].tolNode.children.map(e => ({
tolNode: e,
children: [],
}));
this.layoutSys.updateLayoutInfoOnExpand(nodeList);
},
onInnerHeaderClicked(nodeList){
//nodeList will hold an array of tree-objects, from the clicked-on-tile's tree-object upward
nodeList[0].children = [];
this.layoutSys.updateLayoutInfoOnCollapse(nodeList);
},
},
created(){
window.addEventListener('resize', this.onResize);
},
unmounted(){
window.removeEventListener('resize', this.onResize);
},
components: {
Tile
}
}
</script>
<template>
<div class="h-[100vh]">
<tile :tree="tree" :x="0" :y="0" :width="width" :height="height" hideHeader
@tile-clicked="onInnerTileClicked" @header-clicked="onInnerHeaderClicked"></tile>
</div>
</template>
|