initialize summation working
This commit is contained in:
parent
3dad9c1013
commit
49d82eaf86
@ -1,7 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<script src="./index.js"></script>
|
||||
<script src="./index.ts"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
17
index.js
17
index.js
@ -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
31
index.ts
Normal 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) );
|
12
table.ts
12
table.ts
@ -11,6 +11,7 @@ export class Sum
|
||||
constructor(inIndex: number)
|
||||
{
|
||||
this.ColumnIndex = inIndex;
|
||||
this.Original = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,7 +68,7 @@ export class Table
|
||||
{
|
||||
if(this.Parent)
|
||||
{
|
||||
inFunction(this.Parent);
|
||||
inFunction(this.Parent, this);
|
||||
this.Parent.ItrParents(inFunction);
|
||||
}
|
||||
}
|
||||
@ -75,7 +76,7 @@ export class Table
|
||||
{
|
||||
this.Children.forEach( (inChild: Table) =>
|
||||
{
|
||||
inFunction(inChild);
|
||||
inFunction(inChild, this);
|
||||
inChild.ItrChildren(inFunction);
|
||||
});
|
||||
}
|
||||
@ -91,10 +92,3 @@ export class Table
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const Iterators = {
|
||||
SumRows: (inTable: Table) =>
|
||||
{
|
||||
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user