dag-editor/table.ts

53 lines
1.2 KiB
TypeScript

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);
});
}
}