Compare commits

..

No commits in common. "3a8fecf55f211fa61371b2572a2f68b19db476f9" and "490019a27ba6722b8c04521e9fcf665637e0d36a" have entirely different histories.

View File

@ -196,11 +196,10 @@ var Pivot =
// - optional traversal depth, defaults to 0 // - optional traversal depth, defaults to 0
let depth = inDepth||0; let depth = inDepth||0;
let uniques = {}; let uniques = {};
let indexPivot = inPivotIndicies[depth]
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
let value = row[indexPivot]; // get the pivot column let value = row[inPivotIndicies[depth]]; // get the pivot column
let match = uniques[value]; // check in the uniques list if this pivot column exists let match = uniques[value]; // check in the uniques list if this pivot column exists
if(!match) if(!match)
{ {
@ -214,8 +213,6 @@ var Pivot =
match = uniques[value] = { match = uniques[value] = {
Label:value, Label:value,
Row:clone, Row:clone,
IndexPivot:indexPivot,
IndexSum:inSumIndicies,
Leaves:[] Leaves:[]
}; };
// grow a child off of the parent using the meta object // grow a child off of the parent using the meta object
@ -373,8 +370,8 @@ import { useReducer } from 'https://cdn.skypack.dev/preact/hooks';
import { css, cx } from 'https://cdn.skypack.dev/@emotion/css'; import { css, cx } from 'https://cdn.skypack.dev/@emotion/css';
Pivot.Init( Pivot.Init(
["number", "type-a", "type-b", "count", "extra"], ["number", "type-a", "type-b", "count"],
["label", "label", "label", "sum", "sum"], ["label", "label", "label", "sum"],
[ [
["#1", "a", "long", 1, 4], ["#1", "a", "long", 1, 4],
["#2", "b", "long", 2, 4], ["#2", "b", "long", 2, 4],
@ -388,24 +385,21 @@ Pivot.Init(
let ElForm = props => let ElForm = props =>
{ {
let pivotColumns = N.Step(Pivot.Schema, "label")||[]; let labelColumns = N.Step(Pivot.Schema, "label")||[];
let pivotColumnsUsed = N.Step(Pivot.Proto, "used-pivot")||[];
let sumColumns = N.Step(Pivot.Schema, "sum")||[]; let used = N.Step(Pivot.Proto, "used")||[];
let sumColumnsUsed = N.Step(Pivot.Proto, "used-sum")||[]; let unused = N.Step(Pivot.Schema, "label").filter( columnLabel => !N.Step(columnLabel, "used", false) );
let indiciesPivot = used.map(node=>node.Meta.Index);
let indiciesPivot = pivotColumnsUsed.map(node=>node.Meta.Index); let indiciesSum = (N.Step(Pivot.Schema, "sum")||[]).map(n=>n.Meta.Index);
let indiciesSum = sumColumnsUsed.map(node=>node.Meta.Index);
var action; var action;
if(indiciesPivot.length) if(indiciesPivot.length)
{ {
action = h("p", null, [ action = h("div", null, [
h("span", null, "Build"), h("span", null, "Build"),
h("button", {onClick:e=> h("button", {onClick:e=>
{ {
N.Disconnect(Pivot.Proto, null, "used-pivot"); N.Disconnect(Pivot.Proto, null, "used");
N.Disconnect(Pivot.Proto, null, "used-sum");
Pivot.Create(indiciesPivot, indiciesSum); Pivot.Create(indiciesPivot, indiciesSum);
Render(); Render();
} }
@ -414,71 +408,35 @@ let ElForm = props =>
} }
else else
{ {
action = h("p", null, "(select columns)") action = h("div", null, "(select columns)")
} }
return h("div", {}, [ return h("div", {}, [
h("p", null, [ h("div", null, [
h("span", null, "available"),
h("span", null, "Pivot Columns"), ...unused.map( node=>
...pivotColumns.map( columnLabel =>
{ {
let attributes = {}; return h("button", {onClick:e=>
if(N.Step(columnLabel, "used-pivot", false))
{ {
attributes.disabled = true; N.Connect(Pivot.Proto, node, "used");
Render();
} }
else }, node.Meta.Label);
{ }
attributes.onClick = e=> )
{
N.Connect(Pivot.Proto, columnLabel, "used-pivot");
Render();
}
}
return h("button", attributes, columnLabel.Meta.Label);
}),
h("span", null, "Summation Columns"),
...sumColumns.map( columnSum =>
{
let attributes = {};
if(N.Step(columnSum, "used-sum", false))
{
attributes.disabled = true;
}
else
{
attributes.onClick = e=>
{
N.Connect(Pivot.Proto, columnSum, "used-sum");
Render();
}
}
return h("button", attributes, columnSum.Meta.Label);
})
]), ]),
h("p", null, [ h("div", null, [
h("span", null, "Current Pivot"), h("span", null, "taken"),
...pivotColumnsUsed.map( columnLabel => ...used.map( node=>
{ {
return h("button", {onClick:e=> return h("button", {onClick:e=>
{ {
N.Disconnect(Pivot.Proto, columnLabel, "used-pivot"); N.Disconnect(Pivot.Proto, node, "used");
Render(); Render();
} }
}, columnLabel.Meta.Label); }, node.Meta.Label);
}), }
h("span", null, "Current Summation"), )
...sumColumnsUsed.map( columnSum =>
{
return h("button", {onClick:e=>
{
N.Disconnect(Pivot.Proto, columnSum, "used-sum");
Render();
}
}, columnSum.Meta.Label);
}),
]), ]),
action action
]) ])