From a68a55205ed189250693368af7028031a70631d9 Mon Sep 17 00:00:00 2001
From: Terry Truong <terry06890@gmail.com>
Date: Tue, 29 Mar 2022 11:39:33 +1100
Subject: Update comments, adjust names, do minor refactors

---
 src/components/AncestryBar.vue | 64 ++++++++++++++++++++++--------------------
 1 file changed, 34 insertions(+), 30 deletions(-)

(limited to 'src/components/AncestryBar.vue')

diff --git a/src/components/AncestryBar.vue b/src/components/AncestryBar.vue
index f7ce232..6d6ae3c 100644
--- a/src/components/AncestryBar.vue
+++ b/src/components/AncestryBar.vue
@@ -1,83 +1,87 @@
 <script lang="ts">
 import {defineComponent, PropType} from 'vue';
+import Tile from './Tile.vue'
 import {LayoutNode} from '../layout';
 import type {LayoutOptions} from '../layout';
-import Tile from './Tile.vue'
 
+// Displays a sequence of nodes, representing ancestors from a tree-of-life root to a currently-active root
 export default defineComponent({
 	props: {
+		// For absolute positioning
 		pos: {type: Array as unknown as PropType<[number,number]>, required: true},
 		dims: {type: Array as unknown as PropType<[number,number]>, required: true},
+		// The ancestors to display
 		nodes: {type: Array as PropType<LayoutNode[]>, required: true},
+		// Options
 		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;
+			return (this.wideArea ? this.dims[1] : this.dims[0]) -
+				(this.uiOpts.ancestryTileMargin * 2) - this.uiOpts.ancestryBarScrollGap;
 		},
-		usedNodes(){
+		usedNodes(){ // Childless versions of 'nodes' used to parameterise <tile>
 			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;
+		overflowing(){
+			let len = this.uiOpts.ancestryTileMargin +
+				(this.tileSz + this.uiOpts.ancestryTileMargin) * this.nodes.length;
 			return len > (this.wideArea ? this.dims[0] : this.dims[1]);
 		},
+		width(){
+			return this.dims[0] + (this.wideArea || this.overflowing ? 0 : -this.uiOpts.ancestryBarScrollGap);
+		},
+		height(){
+			return this.dims[1] + (!this.wideArea || this.overflowing ? 0 : -this.uiOpts.ancestryBarScrollGap);
+		},
 		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',
+				width: this.width + 'px',
+				height: this.height + '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',
+				paddingRight: (this.overflowing && !this.wideArea ? this.uiOpts.ancestryBarScrollGap : 0) + 'px',
+				paddingBottom: (this.overflowing && this.wideArea ? this.uiOpts.ancestryBarScrollGap : 0) + 'px',
 				// For child layout
 				display: 'flex',
 				flexDirection: this.wideArea ? 'row' : 'column',
-				gap: this.tileMargin + 'px',
-				padding: this.tileMargin + 'px',
-				//
-				backgroundColor: '#44403c',
+				gap: this.uiOpts.ancestryTileMargin + 'px',
+				padding: this.uiOpts.ancestryTileMargin + 'px',
+				// Other
+				backgroundColor: this.uiOpts.ancestryBarBgColor,
 				boxShadow: this.uiOpts.shadowNormal,
 			};
 		},
 	},
 	methods: {
-		onClick(node: LayoutNode){
-			this.$emit('detached-ancestor-clicked', node);
+		onTileClick(node: LayoutNode){
+			this.$emit('detached-ancestor-click', node);
 		},
-		onInnerInfoIconClicked(data: LayoutNode){
-			this.$emit('info-icon-clicked', data);
+		onInfoIconClick(data: LayoutNode){
+			this.$emit('info-icon-click', data);
 		}
 	},
-	components: {
-		Tile,
-	},
-	emits: ['detached-ancestor-clicked', 'info-icon-clicked'],
+	components: {Tile, },
+	emits: ['detached-ancestor-click', 'info-icon-click', ],
 });
 </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"/>
+	<tile v-for="(node, idx) in usedNodes" :key="node.tolNode.name" class="shrink-0"
+		:layoutNode="node" :nonAbsPos="true" :lytOpts="lytOpts" :uiOpts="uiOpts"
+		@leaf-click="onTileClick(nodes[idx])" @info-icon-click="onInfoIconClick"/>
 </div>
 </template>
-- 
cgit v1.2.3

