new test block
This commit is contained in:
parent
b177f95fb7
commit
79cbbeb287
11
Pivot.js
11
Pivot.js
@ -31,12 +31,8 @@ var Pivot =
|
|||||||
},
|
},
|
||||||
Pivot(inRoot, inParent, inPivotIndicies, inSumIndicies, inDepth)
|
Pivot(inRoot, inParent, inPivotIndicies, inSumIndicies, inDepth)
|
||||||
{
|
{
|
||||||
//arguments:
|
|
||||||
// - a Node with leaf Nodes temporarily stored in its Meta.Leaves
|
|
||||||
// - where each leaf Node has a row of table data in it's Meta.Row
|
|
||||||
// - a list of columns to pivot on
|
|
||||||
// - a list of columns to sum
|
|
||||||
// - optional traversal depth, defaults to 0
|
|
||||||
let depth = inDepth||0;
|
let depth = inDepth||0;
|
||||||
let uniques = {};
|
let uniques = {};
|
||||||
let indexPivot = inPivotIndicies[depth];
|
let indexPivot = inPivotIndicies[depth];
|
||||||
@ -44,6 +40,7 @@ var Pivot =
|
|||||||
{
|
{
|
||||||
console.log("problem")
|
console.log("problem")
|
||||||
}
|
}
|
||||||
|
// create a set of new nodes off of the input node
|
||||||
inParent.Meta.Leaves.forEach((inLeaf)=>
|
inParent.Meta.Leaves.forEach((inLeaf)=>
|
||||||
{
|
{
|
||||||
let row = inLeaf.Meta.Row; // shorthand for the raw "CSV" row in the leaf Node's Meta
|
let row = inLeaf.Meta.Row; // shorthand for the raw "CSV" row in the leaf Node's Meta
|
||||||
@ -78,7 +75,6 @@ var Pivot =
|
|||||||
match.Leaves.push(inLeaf);
|
match.Leaves.push(inLeaf);
|
||||||
});
|
});
|
||||||
|
|
||||||
// get the leaves out of the parent, at this point they have been re-distributed to the children
|
|
||||||
delete inParent.Meta.Leaves;
|
delete inParent.Meta.Leaves;
|
||||||
let iterator = () => {};
|
let iterator = () => {};
|
||||||
if(depth >= inPivotIndicies.length-1)
|
if(depth >= inPivotIndicies.length-1)
|
||||||
@ -136,6 +132,7 @@ var Pivot =
|
|||||||
Pivot.Pivot(inRoot, child, inPivotIndicies, inSumIndicies, depth+1);
|
Pivot.Pivot(inRoot, child, inPivotIndicies, inSumIndicies, depth+1);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
N.Walk(iterator, inParent, "Hierarchy");
|
N.Walk(iterator, inParent, "Hierarchy");
|
||||||
|
|
||||||
return inParent;
|
return inParent;
|
||||||
|
39
index.html
39
index.html
@ -398,13 +398,40 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
Pivot.Create([1, 2], [3, 4]);
|
let root = N.Create("root");
|
||||||
let pivot = N.Path([0], Pivot.Root, "Pivot");
|
let recurse = (node, depth) =>
|
||||||
let node = N.Path([0, 1], pivot, "Hierarchy");
|
{
|
||||||
Pivot.Modify(node);
|
// create a set of new nodes off of the input node
|
||||||
Pivot.Create([2, 1], [3, 4]);
|
let c1 = N.Create(node.Meta+"-1");
|
||||||
Render();
|
let c2 = N.Create(node.Meta+"-2");
|
||||||
|
N.Connect(node, c1, "parent");
|
||||||
|
N.Connect(node, c2, "parent");
|
||||||
|
|
||||||
|
var iterator;
|
||||||
|
if(depth < 3)
|
||||||
|
{
|
||||||
|
// loop over the new nodes and keep recursing
|
||||||
|
|
||||||
|
iterator = (child) =>
|
||||||
|
{
|
||||||
|
recurse(child, depth+1);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// walk up
|
||||||
|
iterator = () =>
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
N.Walk(iterator, node, "parent", true);
|
||||||
|
}
|
||||||
|
recurse(root, 0);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user