initialize summation working

This commit is contained in:
unknown 2019-09-10 21:50:42 -04:00
parent 3dad9c1013
commit 49d82eaf86
4 changed files with 35 additions and 27 deletions

View File

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<script src="./index.js"></script> <script src="./index.ts"></script>
</head> </head>
<body> <body>

View File

@ -1,17 +0,0 @@
import {Table} from './table.ts';
var table;
var leaves;
var rows;
rows = [
["a","1"],
["b","2"],
["a","3"],
["b","1"],
["a","2"],
["b","3"],
];
table = new Table("Root", rows, [1]);
table.PivotTree([0, 1]);
table.ItrLeaves( inLeaf => console.log(inLeaf) );

31
index.ts Normal file
View File

@ -0,0 +1,31 @@
import {Table, Sum} from './table';
var table: Table;
var rows: Array<Array<string>>;
rows = [
["a","1"],
["b","2"],
["a","3"],
["b","1"],
["a","2"],
["b","3"],
];
table = new Table("Root", rows, [1]);
table.PivotTree([0, 1]);
table.ItrLeaves( (inTable: Table) =>
{
inTable.Columns.forEach( (inColumn: Sum, inIndex: number) =>
{
inTable.Rows.forEach( (inRow: Array<string>) =>
{
inColumn.Original += parseFloat(inRow[inColumn.ColumnIndex]);
});
inTable.ItrParents( (inParent: Table)=>
{
inParent.Columns[inIndex].Original += inColumn.Original;
});
});
} );
table.ItrChildren( inTable => console.log(inTable) );

View File

@ -11,6 +11,7 @@ export class Sum
constructor(inIndex: number) constructor(inIndex: number)
{ {
this.ColumnIndex = inIndex; this.ColumnIndex = inIndex;
this.Original = 0;
} }
} }
@ -67,7 +68,7 @@ export class Table
{ {
if(this.Parent) if(this.Parent)
{ {
inFunction(this.Parent); inFunction(this.Parent, this);
this.Parent.ItrParents(inFunction); this.Parent.ItrParents(inFunction);
} }
} }
@ -75,7 +76,7 @@ export class Table
{ {
this.Children.forEach( (inChild: Table) => this.Children.forEach( (inChild: Table) =>
{ {
inFunction(inChild); inFunction(inChild, this);
inChild.ItrChildren(inFunction); inChild.ItrChildren(inFunction);
}); });
} }
@ -91,10 +92,3 @@ export class Table
} }
} }
} }
export const Iterators = {
SumRows: (inTable: Table) =>
{
}
};