aboutsummaryrefslogtreecommitdiff
path: root/src/App.vue
diff options
context:
space:
mode:
authorTerry Truong <terry06890@gmail.com>2022-03-28 12:10:27 +1100
committerTerry Truong <terry06890@gmail.com>2022-03-28 12:10:27 +1100
commite39f5ada10723dc1f5c29f32543051f90df03041 (patch)
tree04b7a75789a92da305c3d4493d2e1b4d41a260dd /src/App.vue
parent34e34b9620d88b5d76b87a4bbcd473c2fc6002a9 (diff)
Move TolNode code to tol.ts
Diffstat (limited to 'src/App.vue')
-rw-r--r--src/App.vue27
1 files changed, 3 insertions, 24 deletions
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