From 49d82eaf86aeb83246c0f9908317180545c45e97 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 10 Sep 2019 21:50:42 -0400 Subject: [PATCH] initialize summation working --- index.html | 2 +- index.js | 17 ----------------- index.ts | 31 +++++++++++++++++++++++++++++++ table.ts | 12 +++--------- 4 files changed, 35 insertions(+), 27 deletions(-) delete mode 100644 index.js create mode 100644 index.ts diff --git a/index.html b/index.html index 014b3c1..89e029f 100644 --- a/index.html +++ b/index.html @@ -1,7 +1,7 @@ - + diff --git a/index.js b/index.js deleted file mode 100644 index 910ba38..0000000 --- a/index.js +++ /dev/null @@ -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) ); \ No newline at end of file diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..63c105d --- /dev/null +++ b/index.ts @@ -0,0 +1,31 @@ +import {Table, Sum} from './table'; + +var table: Table; +var rows: Array>; + +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) => + { + inColumn.Original += parseFloat(inRow[inColumn.ColumnIndex]); + }); + inTable.ItrParents( (inParent: Table)=> + { + inParent.Columns[inIndex].Original += inColumn.Original; + }); + }); +} ); +table.ItrChildren( inTable => console.log(inTable) ); \ No newline at end of file diff --git a/table.ts b/table.ts index 674af9f..6a27d89 100644 --- a/table.ts +++ b/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) => - { - - } -}; \ No newline at end of file