aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/App.vue28
-rw-r--r--src/components/SearchModal.vue6
-rw-r--r--src/components/Tile.vue4
-rw-r--r--src/layout.ts16
-rw-r--r--src/tol.ts2
5 files changed, 30 insertions, 26 deletions
diff --git a/src/App.vue b/src/App.vue
index f1e6e2a..24ae12b 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -40,7 +40,8 @@ function getReverseAction(action: Action): Action | null {
// Get tree-of-life data
const rootName = "cellular organisms";
-const tolMap: TolMap = {[rootName]: new TolNode()};
+const tolMap: TolMap = new Map();
+tolMap.set(rootName, new TolNode());
// Configurable options
const defaultLytOpts: LayoutOptions = {
@@ -186,12 +187,12 @@ export default defineComponent({
return success;
};
// Check if data for node-to-expand exists, getting from server if needed
- let tolNode = this.tolMap[layoutNode.name];
- if (tolNode.children[0] in this.tolMap == false){
+ let tolNode = this.tolMap.get(layoutNode.name)!;
+ if (!this.tolMap.has(tolNode.children[0])){
return fetch('/tolnode/' + layoutNode.name + '?type=children')
.then(response => response.json())
.then(obj => {
- Object.getOwnPropertyNames(obj).forEach(key => {this.tolMap[key] = obj[key]});
+ Object.getOwnPropertyNames(obj).forEach(key => {this.tolMap.set(key, obj[key])});
doExpansion();
})
.catch(error => {
@@ -211,16 +212,15 @@ export default defineComponent({
layoutNode.failFlag = !layoutNode.failFlag; // Triggers failure animation
} else {
// Clear out excess nodes when a threshold is reached
- let tolNodeNames = Object.getOwnPropertyNames(this.tolMap)
- let extraNodes = tolNodeNames.length - this.layoutMap.size;
+ let numNodes = this.tolMap.size;
+ let extraNodes = numNodes - this.layoutMap.size;
if (extraNodes > this.excessTolNodeThreshold){
- for (let n of tolNodeNames){
+ for (let n of this.tolMap.keys()){
if (!this.layoutMap.has(n)){
- delete this.tolMap[n];
+ this.tolMap.delete(n)
}
}
- let numRemovedNodes = tolNodeNames.length - Object.getOwnPropertyNames(this.tolMap).length;
- console.log(`Cleaned up tolMap (removed ${numRemovedNodes} out of ${tolNodeNames.length})`);
+ console.log(`Cleaned up tolMap (removed ${numNodes - this.tolMap.size} out of ${numNodes})`);
}
}
return success;
@@ -289,7 +289,7 @@ export default defineComponent({
// Get nearest in-layout-tree ancestor
let ancestorName = name;
while (this.layoutMap.get(ancestorName) == null){
- ancestorName = this.tolMap[ancestorName].parent!;
+ ancestorName = this.tolMap.get(ancestorName)!.parent!;
}
let layoutNode = this.layoutMap.get(ancestorName)!;
// If hidden, expand self/ancestor in ancestry-bar
@@ -349,7 +349,7 @@ export default defineComponent({
// Determine available actions
let action: Action | null;
let actionWeights: {[key: string]: number}; // Maps actions to choice weights
- let node = this.lastFocused;
+ let node: LayoutNode = this.lastFocused;
if (node.children.length == 0){
actionWeights = {'move across': 1, 'move up': 2, 'expand': 3};
// Zero weights for disallowed actions
@@ -359,7 +359,7 @@ export default defineComponent({
if (node == this.activeRoot){
actionWeights['move up'] = 0;
}
- if (this.tolMap[node.name].children.length == 0){
+ if (this.tolMap.get(node.name)!.children.length == 0){
actionWeights['expand'] = 0;
}
} else {
@@ -495,7 +495,7 @@ export default defineComponent({
fetch('/tolnode/' + rootName)
.then(response => response.json())
.then(obj => {
- Object.getOwnPropertyNames(obj).forEach(key => {this.tolMap[key] = obj[key]});
+ Object.getOwnPropertyNames(obj).forEach(key => {this.tolMap.set(key, obj[key])});
this.layoutTree = initLayoutTree(this.tolMap, this.layoutTree.name, 0);
this.activeRoot = this.layoutTree;
this.layoutMap = initLayoutMap(this.layoutTree);
diff --git a/src/components/SearchModal.vue b/src/components/SearchModal.vue
index 5accd62..9c30cbc 100644
--- a/src/components/SearchModal.vue
+++ b/src/components/SearchModal.vue
@@ -21,14 +21,14 @@ export default defineComponent({
// Query server
let url = new URL(window.location.href);
url.pathname = '/tolnode/' + input.value;
- fetch(url)
+ fetch(url.toString())
.then(response => {
// Search successful. Get nodes in parent-chain, add to tolMap, then emit event.
url.search = '?type=chain';
- fetch(url)
+ fetch(url.toString())
.then(response => response.json())
.then(obj => {
- Object.getOwnPropertyNames(obj).forEach(key => {this.tolMap[key] = obj[key]});
+ Object.getOwnPropertyNames(obj).forEach(key => {this.tolMap.set(key, obj[key])});
this.$emit('search-node', input.value);
})
.catch(error => {
diff --git a/src/components/Tile.vue b/src/components/Tile.vue
index c5c261d..1087a58 100644
--- a/src/components/Tile.vue
+++ b/src/components/Tile.vue
@@ -28,8 +28,8 @@ export default defineComponent({
};
},
computed: {
- tolNode(): TolNode{
- return this.tolMap[this.layoutNode.name];
+ tolNode(): TolNode {
+ return this.tolMap.get(this.layoutNode.name)!;
},
// Basic abbreviations
isLeaf(): boolean {
diff --git a/src/layout.ts b/src/layout.ts
index 69e84db..6f1fd77 100644
--- a/src/layout.ts
+++ b/src/layout.ts
@@ -54,7 +54,7 @@ export class LayoutNode {
if (chg != null && this == chg.node){
switch (chg.type){
case 'expand':
- let children = chg.tolMap[this.name].children.map((name: string) => new LayoutNode(name, []));
+ let children = chg.tolMap.get(this.name)!.children.map((name: string) => new LayoutNode(name, []));
newNode = new LayoutNode(this.name, children);
newNode.children.forEach(n => {
n.parent = newNode;
@@ -200,11 +200,15 @@ export function initLayoutTree(tolMap: TolMap, rootName: string, depth: number):
node.depth = atDepth;
return node;
} else {
- let children = tolMap[nodeName].children.map(
- (name: string) => initHelper(tolMap, name, depthLeft-1, atDepth+1));
- let node = new LayoutNode(nodeName, children);
- children.forEach(n => n.parent = node);
- return node;
+ let childNames = tolMap.get(nodeName)!.children;
+ if (childNames.length == 0 || !tolMap.has(childNames[0])){
+ return new LayoutNode(nodeName, []);
+ } else {
+ let children = childNames.map((name: string) => initHelper(tolMap, name, depthLeft-1, atDepth+1));
+ let node = new LayoutNode(nodeName, children);
+ children.forEach(n => n.parent = node);
+ return node;
+ }
}
}
return initHelper(tolMap, rootName, depth);
diff --git a/src/tol.ts b/src/tol.ts
index ba6c6c8..daa3339 100644
--- a/src/tol.ts
+++ b/src/tol.ts
@@ -3,7 +3,7 @@
*/
// Maps tree-of-life node names to node objects
-export type TolMap = {[key: string]: TolNode};
+export type TolMap = Map<string, TolNode>;
// Represents a tree-of-life node
export class TolNode {
children: string[];