aboutsummaryrefslogtreecommitdiff
path: root/src/components/AncestryBar.vue
blob: f7ce232675769d8f8dac89074598058dd87d6230 (plain)
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
<script lang="ts">
import {defineComponent, PropType} from 'vue';
import {LayoutNode} from '../layout';
import type {LayoutOptions} from '../layout';
import Tile from './Tile.vue'

export default defineComponent({
	props: {
		pos: {type: Array as unknown as PropType<[number,number]>, required: true},
		dims: {type: Array as unknown as PropType<[number,number]>, required: true},
		nodes: {type: Array as PropType<LayoutNode[]>, required: true},
		lytOpts: {type: Object as PropType<LayoutOptions>, required: true},
		uiOpts: {type: Object, required: true},
	},
	data(){
		return {
			tileMargin: 5, //px (gap between detached-ancestor tiles)
			scrollBarOffset: 10, //px (gap for scrollbar, used to prevent overlap with tiles)
		};
	},
	computed: {
		wideArea(){
			return this.dims[0] >= this.dims[1];
		},
		tileSz(){
			return (this.wideArea ? this.dims[1] : this.dims[0]) - (this.tileMargin * 2) - this.scrollBarOffset;
		},
		usedNodes(){
			return this.nodes.map(n => {
				let newNode = new LayoutNode(n.tolNode, []);
				newNode.dims = [this.tileSz, this.tileSz];
				return newNode;
			});
		},
		hasOverflow(){
			let len = this.tileMargin + (this.tileSz + this.tileMargin) * this.nodes.length;
			return len > (this.wideArea ? this.dims[0] : this.dims[1]);
		},
		styles(): Record<string,string> {
			return {
				position: 'absolute',
				left: this.pos[0] + 'px',
				top: this.pos[1] + 'px',
				width: (this.dims[0] + (this.wideArea || this.hasOverflow ? 0 : -this.scrollBarOffset)) + 'px',
				height: (this.dims[1] + (!this.wideArea || this.hasOverflow ? 0 : -this.scrollBarOffset)) + 'px',
				overflowX: this.wideArea ? 'auto' : 'hidden',
				overflowY: this.wideArea ? 'hidden' : 'auto',
				// Extra padding for scrollbar inclusion
				paddingRight: (this.hasOverflow && !this.wideArea ? this.scrollBarOffset : 0) + 'px',
				paddingBottom: (this.hasOverflow && this.wideArea ? this.scrollBarOffset : 0) + 'px',
				// For child layout
				display: 'flex',
				flexDirection: this.wideArea ? 'row' : 'column',
				gap: this.tileMargin + 'px',
				padding: this.tileMargin + 'px',
				//
				backgroundColor: '#44403c',
				boxShadow: this.uiOpts.shadowNormal,
			};
		},
	},
	methods: {
		onClick(node: LayoutNode){
			this.$emit('detached-ancestor-clicked', node);
		},
		onInnerInfoIconClicked(data: LayoutNode){
			this.$emit('info-icon-clicked', data);
		}
	},
	components: {
		Tile,
	},
	emits: ['detached-ancestor-clicked', 'info-icon-clicked'],
});
</script>

<template>
<div :style="styles">
	<tile v-for="(node, idx) in usedNodes" :key="node.tolNode.name" :layoutNode="node"
		:nonAbsPos="true" :lytOpts="lytOpts" :uiOpts="uiOpts"
		@leaf-clicked="onClick(nodes[idx])" @info-icon-clicked="onInnerInfoIconClicked"/>
</div>
</template>