summation columns created in pivoting
This commit is contained in:
		
							parent
							
								
									d9c05ba321
								
							
						
					
					
						commit
						3dad9c1013
					
				
							
								
								
									
										4
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								index.js
									
									
									
									
									
								
							@ -12,8 +12,6 @@ rows = [
 | 
			
		||||
    ["b","3"],
 | 
			
		||||
];
 | 
			
		||||
 | 
			
		||||
table = new Table("Root", rows);
 | 
			
		||||
table = new Table("Root", rows, [1]);
 | 
			
		||||
table.PivotTree([0, 1]);
 | 
			
		||||
table.ItrLeaves( inLeaf => console.log(inLeaf) );
 | 
			
		||||
 | 
			
		||||
console.log(table, leaves);
 | 
			
		||||
							
								
								
									
										42
									
								
								table.ts
									
									
									
									
									
								
							
							
						
						
									
										42
									
								
								table.ts
									
									
									
									
									
								
							@ -8,9 +8,9 @@ export class Sum
 | 
			
		||||
    FromChildren: number;
 | 
			
		||||
    FromOutside: number;
 | 
			
		||||
 | 
			
		||||
    constructor()
 | 
			
		||||
    constructor(inIndex: number)
 | 
			
		||||
    {
 | 
			
		||||
        this.ColumnIndex = 0;
 | 
			
		||||
        this.ColumnIndex = inIndex;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -18,52 +18,49 @@ export class Table
 | 
			
		||||
{
 | 
			
		||||
    Name: string;
 | 
			
		||||
    Rows: Array<Array<string>>;
 | 
			
		||||
    Columns: Array<Sum>;
 | 
			
		||||
    Parent?: Table; 
 | 
			
		||||
    Children: Array<Table>;
 | 
			
		||||
 | 
			
		||||
    constructor(inName: string, inRows: Array<Array<string>>)
 | 
			
		||||
    constructor(inName: string, inRows: Array<Array<string>>, inColumns: Array<number>)
 | 
			
		||||
    {
 | 
			
		||||
        this.Name = inName;
 | 
			
		||||
        this.Rows = inRows;
 | 
			
		||||
        this.Parent = null;
 | 
			
		||||
        this.Children = [];
 | 
			
		||||
        this.Columns = inColumns.map( (inIndex: number) => new Sum(inIndex) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Pivot(inColumn: number)
 | 
			
		||||
    Pivot(inColumnPivot: number)
 | 
			
		||||
    {
 | 
			
		||||
        var cell: string;
 | 
			
		||||
        var child: Table;
 | 
			
		||||
        var context: Table;
 | 
			
		||||
 | 
			
		||||
        context = this;
 | 
			
		||||
        this.Rows.forEach((inRow: Array<string>)=>
 | 
			
		||||
        {
 | 
			
		||||
            cell = inRow[inColumn];
 | 
			
		||||
            cell = inRow[inColumnPivot];
 | 
			
		||||
            child = this.Children.find( (inChild: Table) => inChild.Name == cell );
 | 
			
		||||
            if(!child)
 | 
			
		||||
            {
 | 
			
		||||
                child = new Table(cell, []);
 | 
			
		||||
                child.Parent = context;
 | 
			
		||||
                context.Children.push(child);
 | 
			
		||||
                child = new Table(cell, [], this.Columns.map( (inColumn: Sum) => inColumn.ColumnIndex ));
 | 
			
		||||
                child.Parent = this;
 | 
			
		||||
                this.Children.push(child);
 | 
			
		||||
            }
 | 
			
		||||
            child.Rows.push(inRow);
 | 
			
		||||
        });
 | 
			
		||||
        this.Rows = [];
 | 
			
		||||
    }
 | 
			
		||||
    PivotTree(inColumns: Array<number>)
 | 
			
		||||
    PivotTree(inColumnsPivot: Array<number>)
 | 
			
		||||
    {
 | 
			
		||||
        var columns: Array<number>;
 | 
			
		||||
        var pivotsRemaining: Array<number>;
 | 
			
		||||
 | 
			
		||||
        if(inColumns.length == 0)
 | 
			
		||||
        if(inColumnsPivot.length == 0)
 | 
			
		||||
        {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        columns = [...inColumns];
 | 
			
		||||
        this.Pivot(columns.shift());
 | 
			
		||||
        this.Children.forEach( (inChild: Table) =>
 | 
			
		||||
        {
 | 
			
		||||
            inChild.PivotTree(columns);
 | 
			
		||||
        });
 | 
			
		||||
        pivotsRemaining = [...inColumnsPivot];
 | 
			
		||||
        this.Pivot(pivotsRemaining.shift());
 | 
			
		||||
        this.Children.forEach( (inChild: Table) => inChild.PivotTree(pivotsRemaining) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ItrParents(inFunction: Function)
 | 
			
		||||
@ -94,3 +91,10 @@ export class Table
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const Iterators = {
 | 
			
		||||
    SumRows: (inTable: Table) =>
 | 
			
		||||
    {
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user