From 2c0ba237f903f897a473bdc4d759ca18e8a4317b Mon Sep 17 00:00:00 2001 From: TreetopFlyer Date: Sun, 23 May 2021 00:09:06 -0400 Subject: [PATCH] sum indicies in pivot creation --- index.html | 96 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 69 insertions(+), 27 deletions(-) diff --git a/index.html b/index.html index 8986b61..4f3e5bc 100755 --- a/index.html +++ b/index.html @@ -196,10 +196,11 @@ var Pivot = // - optional traversal depth, defaults to 0 let depth = inDepth||0; let uniques = {}; + let indexPivot = inPivotIndicies[depth] inParent.Meta.Leaves.forEach((inLeaf)=> { 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 if(!match) { @@ -213,6 +214,8 @@ var Pivot = match = uniques[value] = { Label:value, Row:clone, + IndexPivot:indexPivot, + IndexSum:inSumIndicies, Leaves:[] }; // 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'; Pivot.Init( - ["number", "type-a", "type-b", "count"], - ["label", "label", "label", "sum"], + ["number", "type-a", "type-b", "count", "extra"], + ["label", "label", "label", "sum", "sum"], [ ["#1", "a", "long", 1, 4], ["#2", "b", "long", 2, 4], @@ -385,21 +388,24 @@ Pivot.Init( 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 unused = N.Step(Pivot.Schema, "label").filter( columnLabel => !N.Step(columnLabel, "used", false) ); - let indiciesPivot = used.map(node=>node.Meta.Index); - let indiciesSum = (N.Step(Pivot.Schema, "sum")||[]).map(n=>n.Meta.Index); + let sumColumns = N.Step(Pivot.Schema, "sum")||[]; + let sumColumnsUsed = N.Step(Pivot.Proto, "used-sum")||[]; + + let indiciesPivot = pivotColumnsUsed.map(node=>node.Meta.Index); + let indiciesSum = sumColumnsUsed.map(node=>node.Meta.Index); var action; if(indiciesPivot.length) { - action = h("div", null, [ + action = h("p", null, [ h("span", null, "Build"), 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); Render(); } @@ -408,35 +414,71 @@ let ElForm = props => } else { - action = h("div", null, "(select columns)") + action = h("p", null, "(select columns)") } return h("div", {}, [ - h("div", null, [ - h("span", null, "available"), - ...unused.map( node=> + h("p", null, [ + + 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"); - Render(); + attributes.disabled = true; } - }, node.Meta.Label); - } - ) + else + { + 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("div", null, [ - h("span", null, "taken"), - ...used.map( node=> + h("p", null, [ + h("span", null, "Current Pivot"), + ...pivotColumnsUsed.map( columnLabel => { return h("button", {onClick:e=> { - N.Disconnect(Pivot.Proto, node, "used"); + N.Disconnect(Pivot.Proto, columnLabel, "used-pivot"); 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 ])