sum indicies in pivot creation #5

Merged
SethTrowbridge merged 1 commits from schema-header into master 2021-05-23 00:11:17 -04:00
Showing only changes of commit 2c0ba237f9 - Show all commits

View File

@ -196,10 +196,11 @@ 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[inPivotIndicies[depth]]; // get the pivot column let value = row[indexPivot]; // 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)
{ {
@ -213,6 +214,8 @@ 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
@ -370,8 +373,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"], ["number", "type-a", "type-b", "count", "extra"],
["label", "label", "label", "sum"], ["label", "label", "label", "sum", "sum"],
[ [
["#1", "a", "long", 1, 4], ["#1", "a", "long", 1, 4],
["#2", "b", "long", 2, 4], ["#2", "b", "long", 2, 4],
@ -385,21 +388,24 @@ Pivot.Init(
let ElForm = props => let ElForm = props =>
{ {
let labelColumns = N.Step(Pivot.Schema, "label")||[]; let pivotColumns = N.Step(Pivot.Schema, "label")||[];
let pivotColumnsUsed = N.Step(Pivot.Proto, "used-pivot")||[];
let used = N.Step(Pivot.Proto, "used")||[]; let sumColumns = N.Step(Pivot.Schema, "sum")||[];
let unused = N.Step(Pivot.Schema, "label").filter( columnLabel => !N.Step(columnLabel, "used", false) ); let sumColumnsUsed = N.Step(Pivot.Proto, "used-sum")||[];
let indiciesPivot = used.map(node=>node.Meta.Index);
let indiciesSum = (N.Step(Pivot.Schema, "sum")||[]).map(n=>n.Meta.Index); let indiciesPivot = pivotColumnsUsed.map(node=>node.Meta.Index);
let indiciesSum = sumColumnsUsed.map(node=>node.Meta.Index);
var action; var action;
if(indiciesPivot.length) if(indiciesPivot.length)
{ {
action = h("div", null, [ action = h("p", null, [
h("span", null, "Build"), h("span", null, "Build"),
h("button", {onClick:e=> h("button", {onClick:e=>
{ {
N.Disconnect(Pivot.Proto, null, "used"); N.Disconnect(Pivot.Proto, null, "used-pivot");
N.Disconnect(Pivot.Proto, null, "used-sum");
Pivot.Create(indiciesPivot, indiciesSum); Pivot.Create(indiciesPivot, indiciesSum);
Render(); Render();
} }
@ -408,35 +414,71 @@ let ElForm = props =>
} }
else else
{ {
action = h("div", null, "(select columns)") action = h("p", null, "(select columns)")
} }
return h("div", {}, [ return h("div", {}, [
h("div", null, [ h("p", null, [
h("span", null, "available"),
...unused.map( node=> h("span", null, "Pivot Columns"),
...pivotColumns.map( columnLabel =>
{ {
return h("button", {onClick:e=> let attributes = {};
if(N.Step(columnLabel, "used-pivot", false))
{ {
N.Connect(Pivot.Proto, node, "used"); attributes.disabled = true;
}
else
{
attributes.onClick = e=>
{
N.Connect(Pivot.Proto, columnLabel, "used-pivot");
Render(); Render();
} }
}, node.Meta.Label);
} }
) 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("div", null, [ h("p", null, [
h("span", null, "taken"), h("span", null, "Current Pivot"),
...used.map( node=> ...pivotColumnsUsed.map( columnLabel =>
{ {
return h("button", {onClick:e=> return h("button", {onClick:e=>
{ {
N.Disconnect(Pivot.Proto, node, "used"); N.Disconnect(Pivot.Proto, columnLabel, "used-pivot");
Render(); Render();
} }
}, node.Meta.Label); }, columnLabel.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
]) ])