commit 9e2012192d76ab0d1ded74d0f4be739d5dae7574 Author: unknown Date: Sat Sep 7 12:07:48 2019 -0400 setup diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..63358e0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.cache/* +dist/* +node_modules/* \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..014b3c1 --- /dev/null +++ b/index.html @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..3f1cb2b --- /dev/null +++ b/index.js @@ -0,0 +1,16 @@ +import {Table} from './table.ts'; + +var rows = [ + ["a","1"], + ["b","2"], + ["a","3"], + ["b","1"], + ["a","2"], + ["b","3"], +] + +var t; +t = new Table("Root", rows); +t.PivotTree([0, 1]); + +console.log(t); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..0fea92b --- /dev/null +++ b/package-lock.json @@ -0,0 +1,14 @@ +{ + "name": "dag-editor", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "typescript": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.6.2.tgz", + "integrity": "sha512-lmQ4L+J6mnu3xweP8+rOrUwzmN+MRAj7TgtJtDaXE5PMyX2kCrklhg3rvOsOIfNeAWMQWO2F1GPc1kMD2vLAfw==", + "dev": true + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..33d3a5c --- /dev/null +++ b/package.json @@ -0,0 +1,14 @@ +{ + "name": "dag-editor", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "devDependencies": { + "typescript": "^3.6.2" + } +} diff --git a/table.ts b/table.ts new file mode 100644 index 0000000..a0ffd21 --- /dev/null +++ b/table.ts @@ -0,0 +1,53 @@ +export class Table +{ + Name: string; + Rows: Array>; + Parent?: Table; + Children: Array; + + constructor(inName: string, inRows: Array>) + { + this.Name = inName; + this.Rows = inRows; + this.Parent = null; + this.Children = []; + } + + Pivot(inColumn: number) + { + var cell: string; + var child: Table; + var context: Table; + + context = this; + this.Rows.forEach((inRow)=> + { + cell = inRow[inColumn]; + child = this.Children.find( inChild => inChild.Name == cell ); + if(!child) + { + child = new Table(cell, []); + child.Parent = context; + context.Children.push(child); + } + child.Rows.push(inRow); + }); + this.Rows = []; + } + + PivotTree(inColumns: Array) + { + var columns: Array; + + if(inColumns.length == 0) + { + return; + } + columns = [...inColumns]; + this.Pivot(columns.shift()); + this.Children.forEach( (inChild) => + { + inChild.PivotTree(columns); + }); + } +} \ No newline at end of file