setup
This commit is contained in:
commit
9e2012192d
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
.cache/*
|
||||
dist/*
|
||||
node_modules/*
|
9
index.html
Normal file
9
index.html
Normal file
@ -0,0 +1,9 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<script src="./index.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
16
index.js
Normal file
16
index.js
Normal file
@ -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);
|
14
package-lock.json
generated
Normal file
14
package-lock.json
generated
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
}
|
14
package.json
Normal file
14
package.json
Normal file
@ -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"
|
||||
}
|
||||
}
|
53
table.ts
Normal file
53
table.ts
Normal file
@ -0,0 +1,53 @@
|
||||
export class Table
|
||||
{
|
||||
Name: string;
|
||||
Rows: Array<Array<string>>;
|
||||
Parent?: Table;
|
||||
Children: Array<Table>;
|
||||
|
||||
constructor(inName: string, inRows: Array<Array<string>>)
|
||||
{
|
||||
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<number>)
|
||||
{
|
||||
var columns: Array<number>;
|
||||
|
||||
if(inColumns.length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
columns = [...inColumns];
|
||||
this.Pivot(columns.shift());
|
||||
this.Children.forEach( (inChild) =>
|
||||
{
|
||||
inChild.PivotTree(columns);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user