From e39f5ada10723dc1f5c29f32543051f90df03041 Mon Sep 17 00:00:00 2001
From: Terry Truong <terry06890@gmail.com>
Date: Mon, 28 Mar 2022 12:10:27 +1100
Subject: Move TolNode code to tol.ts

---
 src/App.vue | 27 +++------------------------
 1 file changed, 3 insertions(+), 24 deletions(-)

(limited to 'src/App.vue')

diff --git a/src/App.vue b/src/App.vue
index 0eacbe4..8789653 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -6,36 +6,15 @@ import TileInfoModal from './components/TileInfoModal.vue';
 import SearchModal from './components/SearchModal.vue';
 import HelpModal from './components/HelpModal.vue';
 import SettingsPane from './components/SettingsPane.vue';
-import {TolNode, LayoutNode, initLayoutTree, initLayoutMap, tryLayout} from './lib';
+import {TolNode, TolNodeRaw, tolFromRaw, getTolMap} from './tol';
+import {LayoutNode, initLayoutTree, initLayoutMap, tryLayout} from './lib';
 import type {LayoutOptions} from './lib';
 import {arraySum, randWeightedChoice} from './lib';
 // Import paths lack a .ts or .js extension because .ts makes vue-tsc complain, and .js makes vite complain
 
 // Obtain tree-of-life data
 import tolRaw from './tol.json';
-function preprocessTol(node: any): any {
-	function helper(node: any, parent: any){
-		//Add 'children' field if missing
-		if (node.children == null){
-			node.children = [];
-		}
-		//Add 'parent' field
-		node.parent = parent;
-		node.children.forEach((child: any) => helper(child, node));
-	}
-	helper(node, null);
-	return node;
-}
-const tol: TolNode = preprocessTol(tolRaw);
-function getTolMap(tol: TolNode): Map<string,TolNode> {
-	function helper(node: TolNode, map: Map<string,TolNode>){
-		map.set(node.name, node);
-		node.children.forEach(child => helper(child, map));
-	}
-	let map = new Map();
-	helper(tol, map);
-	return map;
-}
+const tol: TolNode = tolFromRaw(tolRaw);
 const tolMap = getTolMap(tol);
 
 // Configurable settings
-- 
cgit v1.2.3

