From d855e86706a98cff93f0d3363c2187c650908b39 Mon Sep 17 00:00:00 2001 From: TreetopFlyer Date: Sat, 15 May 2021 12:52:13 -0400 Subject: [PATCH 1/2] pivot deletion working --- index.html | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index 6ebb739..541ba45 100755 --- a/index.html +++ b/index.html @@ -172,14 +172,14 @@ var N = var Pivot = { Leaves:{}, - Root:N.Create({}), + Root:N.Create({Label:"All Pivots"}), Init(inRows) { Pivot.Leaves = inRows.map(r => N.Create({Row:r})); Pivot.Init = ()=>{}; }, - Pivot(inParent, inPivotIndicies, inSumIndicies, inDepth) + Pivot(inRoot, inParent, inPivotIndicies, inSumIndicies, inDepth) { //arguments: // - a Node with leaf Nodes temporarily stored in its Meta.Leaves @@ -226,6 +226,7 @@ var Pivot = { iterator = inLastBranch => { + N.Connect(inRoot, inLastBranch, "Terminal"); inLastBranch.Meta.Leaves.forEach( inLeaf => { // collect modifiers effecting leaves @@ -247,7 +248,7 @@ var Pivot = inLastBranch.ID.Walk = N.ID.Walk; modifiers.forEach( inModifier => N.Connect(inModifier, inLastBranch, "ModifyUp") ) - // also walk them up, but with a unique check connection + // also walk them up and connect, but with "check unique" enabled N.Walk( inNode=> { modifiers.forEach( inModifier => N.Connect(inModifier, inNode, "ModifyUp", true) ) @@ -263,7 +264,7 @@ var Pivot = } else { - iterator = child => Pivot.Pivot(child, inPivotIndicies, inSumIndicies, depth+1); + iterator = child => Pivot.Pivot(inRoot, child, inPivotIndicies, inSumIndicies, depth+1); } N.Step(inParent, "Hierarchy").forEach(iterator); return inParent; @@ -274,10 +275,11 @@ var Pivot = let pivotRoot = N.Create({Label:"Pivot Root", Leaves:Pivot.Leaves}); N.Connect(Pivot.Root, pivotRoot, "Pivot"); - return Pivot.Pivot(pivotRoot, inPivotIndicies, inSumIndicies); + return Pivot.Pivot(pivotRoot, pivotRoot, inPivotIndicies, inSumIndicies); }, Delete(inRoot) { + // disconnect modifiers let check = N.Step(inRoot, "Modifier"); if(check) { @@ -286,6 +288,14 @@ var Pivot = Pivot.Unmodify(check[0]); } } + + // disconnect terminal branches + N.Walk(()=>{}, inRoot, "Terminal", inNode=>{ + N.Disconnect(inNode, null, "Hierarchy"); + }); + + // disconnect from app + N.Disconnect(null, inRoot, "Pivot") }, Modify(inNode) { @@ -461,6 +471,7 @@ let ElModifiers = ({node}) => }; let ElRoot = props => { + let pivots = N.Step(Pivot.Root, "Pivot")||[]; return h("div", null, [ h("h3", null, "tree view"), h(ElModifiers, {node:Pivot.Root}), @@ -469,7 +480,7 @@ let ElRoot = props => AddNewPivot(); } }, "add new pivot"), - ...N.Step(Pivot.Root, "Pivot").map(pivot=>h(ElPivot, {pivot})) + pivots.map(pivot=>h(ElPivot, {pivot})) ]) }; let Render = () => render(h(ElRoot), document.querySelector("#app")); -- 2.34.1 From ae22e995f27aaf4cfc107a6a778cb3ffb7c62ced Mon Sep 17 00:00:00 2001 From: TreetopFlyer Date: Mon, 17 May 2021 22:39:38 -0400 Subject: [PATCH 2/2] pivot builder node-based, ElForm needs clean up --- index.html | 100 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 78 insertions(+), 22 deletions(-) diff --git a/index.html b/index.html index 541ba45..b7ecf28 100755 --- a/index.html +++ b/index.html @@ -173,9 +173,14 @@ var Pivot = { Leaves:{}, Root:N.Create({Label:"All Pivots"}), - - Init(inRows) - { + Schema:N.Create({Label:"Column Details"}), + Proto:N.Create({Label:"User Form"}), + Init(inColumnNames, inColumnTypes, inRows) + { + for(let i=0; i N.Create({Row:r})); Pivot.Init = ()=>{}; }, @@ -349,21 +354,76 @@ import { h, render, createContext, Fragment } from 'https://cdn.skypack.dev/prea import { useReducer } from 'https://cdn.skypack.dev/preact/hooks'; import { css, cx } from 'https://cdn.skypack.dev/@emotion/css'; -Pivot.Init([ - ["#1", "a", "long", 1], - ["#2", "b", "long", 2], - ["#3", "b", "short", 2], - ["#4", "a", "long", 3], - ["#5", "b", "short", 1], - ["#6", "a", "short", 0], - ["#7", "b", "short", 7], -]); -Pivot.Create([1, 2], [3]); +Pivot.Init( + ["number", "type-a", "type-b", "count"], + ["label", "label", "label", "sum"], + [ + ["#1", "a", "long", 1, 4], + ["#2", "b", "long", 2, 4], + ["#3", "b", "short", 2, 4], + ["#4", "a", "long", 3, 4], + ["#5", "b", "short", 1, 4], + ["#6", "a", "short", 0, 4], + ["#7", "b", "short", 7, 4] + ] +); -let AddNewPivot = () => +let ElForm = props => { - Pivot.Create([2], [3]); - Render(); + let labelColumns = N.Step(Pivot.Schema, "label")||[]; + + let used = N.Step(Pivot.Proto, "used")||[]; + let unused = N.Step(Pivot.Schema, "label").filter( columnLabel => !N.Step(columnLabel, "used", false) ); + let indicies = used.map(node=>node.Meta.Index); + + var action; + if(indicies.length) + { + action = h("div", null, [ + h("span", null, "Build"), + h("button", {onClick:e=> + { + N.Disconnect(Pivot.Proto, null, "used"); + Pivot.Create(indicies, [3, 4]); + Render(); + } + }, indicies) + ]); + } + else + { + action = h("div", null, "(select columns)") + } + + return h("div", {}, [ + h("div", null, [ + h("span", null, "available"), + ...unused.map( node=> + { + return h("button", {onClick:e=> + { + N.Connect(Pivot.Proto, node, "used"); + Render(); + } + }, node.Meta.Label); + } + ) + ]), + h("div", null, [ + h("span", null, "taken"), + ...used.map( node=> + { + return h("button", {onClick:e=> + { + N.Disconnect(Pivot.Proto, node, "used"); + Render(); + } + }, node.Meta.Label); + } + ) + ]), + action + ]) }; let ElNode = ({node, depth}) => @@ -449,7 +509,7 @@ let ElNode = ({node, depth}) => }; let ElPivot = ({pivot}) => { - return h("div", {style:{display:"inline-block", width:"500px"}}, [ + return h("div", {style:{display:"inline-block", width:"800px"}}, [ h("button", {onClick:e=>{Pivot.Delete(pivot);Render();}}, "delete?"), h(ElModifiers, {node:pivot}), h(ElNode, {node:pivot, depth:0}) @@ -474,12 +534,8 @@ let ElRoot = props => let pivots = N.Step(Pivot.Root, "Pivot")||[]; return h("div", null, [ h("h3", null, "tree view"), + h(ElForm), h(ElModifiers, {node:Pivot.Root}), - h("button", { onClick:e=> - { - AddNewPivot(); - } - }, "add new pivot"), pivots.map(pivot=>h(ElPivot, {pivot})) ]) }; -- 2.34.1