diff --git a/src/CytoscapeExport.ts b/src/CytoscapeExport.ts deleted file mode 100644 index d6d67bd..0000000 --- a/src/CytoscapeExport.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { Tree, TreeNode } from './Model' - -export class CytoscapeExport { - public static renderNodeInformation(node: TreeNode): any { - return { - data: { - id: node.sourceEdge.hash(), - label: this.renderLabel(node.value) - } - } - } - public static toDot(tree: Tree): string { - let i = 1 - let leaveEdges = Object.values(tree.edges) - .map(e => e.node) - .map(node => node.leafes()) - .reduce((a, b) => a.concat(b), []) - .map(leave => leave.branch()) - - const allEdges: Array = [] - const nodeInformation: {[s: string]: any} = {} - leaveEdges.map(edges => edges.reduce( (prev, current) => { - let currentHash = current.sourceEdge.hash() - nodeInformation[currentHash] = this.renderNodeInformation(current) - if (current && prev) { - allEdges.push({ - data: { - id: prev.sourceEdge.hash()+currentHash, - source: prev.sourceEdge.hash(), - target: currentHash, - label: this.renderLabel(current.sourceEdge.name) - } - }) - } - return current - })) - - return JSON.stringify( - [this.renderNodeInformation(tree)] - .concat(Object.values(nodeInformation)) - .concat(allEdges), undefined, ' ' - ) - } - - private static renderLabel(value: any): string { - let str; - if(!isNaN(value)) { - str = value - } else { - str = JSON.stringify(value) - if(str && str.length > 0) { - str = str.slice(1, -1) - } - } - - if (!str) { - return "" - } - - if(str.length > 20) { - str = str.slice(0, 20)+'…' - } - - return str - } -} diff --git a/src/VisExport.ts b/src/VisExport.ts deleted file mode 100644 index a2b3fc2..0000000 --- a/src/VisExport.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { Tree, TreeNode } from './Model' - -export class VisExport { - public static renderNodeInformation(node: TreeNode): any { - return { - id: node.sourceEdge.hash(), - label: this.renderLabel(node.value) - } - } - public static toDot(tree: Tree): string { - let i = 1 - let leaveEdges = Object.values(tree.edges) - .map(e => e.node) - .map(node => node.leafes()) - .reduce((a, b) => a.concat(b), []) - .map(leave => leave.branch()) - - const allEdges: {[s: string]: any} = {} - const nodeInformation: {[s: string]: any} = {} - leaveEdges.map(edges => edges.reduce( (prev, current) => { - let currentHash = current.sourceEdge.hash() - nodeInformation[currentHash] = this.renderNodeInformation(current) - if (current && prev) { - let edgeId = prev.sourceEdge.hash()+currentHash - allEdges[prev.sourceEdge.hash()+currentHash] = { - id: prev.sourceEdge.hash()+currentHash, - from: prev.sourceEdge.hash(), - to: currentHash, - label: this.renderLabel(current.sourceEdge.name) - } - } - return current - })) - - return JSON.stringify({ - nodes: [this.renderNodeInformation(tree)].concat(Object.values(nodeInformation)), - edges: Object.values(allEdges) - }, undefined, ' ') - } - - private static renderLabel(value: any): string { - let str; - if(!isNaN(value)) { - str = value - } else { - str = JSON.stringify(value) - if(str && str.length > 0) { - str = str.slice(1, -1) - } - } - - if (!str) { - return "" - } - - if(str.length > 20) { - str = str.slice(0, 20)+'…' - } - - return str - } -}