aboutsummaryrefslogtreecommitdiff
path: root/src/tol.ts
diff options
context:
space:
mode:
authorTerry Truong <terry06890@gmail.com>2022-04-25 01:33:08 +1000
committerTerry Truong <terry06890@gmail.com>2022-04-25 01:33:08 +1000
commit2ab48497797441164e7f57fca2660097d93398ca (patch)
treea6f22d3edff60d182de454359bc40beda82fb5d8 /src/tol.ts
parent23436a9ad4c2a710c7f0d49a07a720e0153d8225 (diff)
Adapt to handle open-tree-of-life data
Added data_otol/ with script that converts data from 'Open Tree of Life' release 13.4 into a JSON form. Moved old tree-of-life data and images into data_tol_old/. Added TolMap type to tol.ts, changed TolNode, and adapted other code to handle it. Temporarily disabling tile images until image data is added.
Diffstat (limited to 'src/tol.ts')
-rw-r--r--src/tol.ts49
1 files changed, 10 insertions, 39 deletions
diff --git a/src/tol.ts b/src/tol.ts
index 42605e5..ba6c6c8 100644
--- a/src/tol.ts
+++ b/src/tol.ts
@@ -2,47 +2,18 @@
* Provides classes for representing and working with tree-of-life data.
*/
-// Represents a tree-of-life node/tree
+// Maps tree-of-life node names to node objects
+export type TolMap = {[key: string]: TolNode};
+// Represents a tree-of-life node
export class TolNode {
- name: string;
- children: TolNode[];
- parent: TolNode | null;
- constructor(name: string, children: TolNode[] = [], parent = null){
- this.name = name;
+ children: string[];
+ parent: string | null;
+ tips: number;
+ pSupport: boolean;
+ constructor(children: string[] = [], parent = null, tips = 0, pSupport = false){
this.children = children;
this.parent = parent;
+ this.tips = tips;
+ this.pSupport = pSupport;
}
}
-// Represents a tree-of-life node obtained from tolData.json
-export class TolNodeRaw {
- name: string;
- children?: TolNodeRaw[];
- constructor(name: string, children: TolNodeRaw[] = []){
- this.name = name;
- this.children = children;
- }
-}
-// Converts a TolNodeRaw tree to a TolNode tree
-export function tolFromRaw(node: TolNodeRaw): TolNode {
- function helper(node: TolNodeRaw, parent: TolNode | null){
- let tolNode = new TolNode(node.name);
- if (node.children == null){
- tolNode.children = [];
- } else {
- tolNode.children = node.children.map(child => helper(child, tolNode));
- }
- tolNode.parent = parent;
- return tolNode;
- }
- return helper(node, null);
-}
-// Returns a map from TolNode names to TolNodes in a given tree
-export function getTolMap(tolTree: 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(tolTree, map);
- return map;
-}