2019-09-07 13:05:47 -04:00
|
|
|
export class Sum
|
|
|
|
{
|
|
|
|
ColumnIndex: number;
|
2019-09-10 20:31:41 -04:00
|
|
|
|
2019-09-07 13:05:47 -04:00
|
|
|
Original: number;
|
2019-09-10 20:31:41 -04:00
|
|
|
Adjustment: number;
|
2019-09-07 13:05:47 -04:00
|
|
|
FromParents: number;
|
|
|
|
FromChildren: number;
|
|
|
|
FromOutside: number;
|
|
|
|
|
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
this.ColumnIndex = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-07 12:07:48 -04:00
|
|
|
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;
|
2019-09-07 13:05:47 -04:00
|
|
|
this.Rows.forEach((inRow: Array<string>)=>
|
2019-09-07 12:07:48 -04:00
|
|
|
{
|
|
|
|
cell = inRow[inColumn];
|
2019-09-07 13:05:47 -04:00
|
|
|
child = this.Children.find( (inChild: Table) => inChild.Name == cell );
|
2019-09-07 12:07:48 -04:00
|
|
|
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());
|
2019-09-07 13:05:47 -04:00
|
|
|
this.Children.forEach( (inChild: Table) =>
|
2019-09-07 12:07:48 -04:00
|
|
|
{
|
|
|
|
inChild.PivotTree(columns);
|
|
|
|
});
|
|
|
|
}
|
2019-09-07 13:05:47 -04:00
|
|
|
|
|
|
|
ItrParents(inFunction: Function)
|
|
|
|
{
|
|
|
|
if(this.Parent)
|
|
|
|
{
|
|
|
|
inFunction(this.Parent);
|
|
|
|
this.Parent.ItrParents(inFunction);
|
|
|
|
}
|
|
|
|
}
|
2019-09-10 20:31:41 -04:00
|
|
|
ItrChildren(inFunction: Function)
|
|
|
|
{
|
|
|
|
this.Children.forEach( (inChild: Table) =>
|
|
|
|
{
|
|
|
|
inFunction(inChild);
|
|
|
|
inChild.ItrChildren(inFunction);
|
|
|
|
});
|
|
|
|
}
|
2019-09-07 13:05:47 -04:00
|
|
|
ItrLeaves(inFunction:Function)
|
|
|
|
{
|
|
|
|
if(this.Children.length == 0)
|
|
|
|
{
|
|
|
|
inFunction(this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.Children.forEach( (inChild: Table) => inChild.ItrLeaves(inFunction) );
|
|
|
|
}
|
|
|
|
}
|
2019-09-07 12:07:48 -04:00
|
|
|
}
|