pivots #1

Merged
SethTrowbridge merged 17 commits from pivots into master 2021-05-15 12:05:52 -04:00
Showing only changes of commit 87903308e9 - Show all commits

View File

@ -8,6 +8,7 @@ var N =
Walk:0, Walk:0,
Instance:0 Instance:0
}, },
Create(inMeta) Create(inMeta)
{ {
return { return {
@ -19,19 +20,10 @@ var N =
Link:{} Link:{}
}; };
}, },
Step(inNode, inType, inForward)
{
let connectionGroup = inNode.Link[inType];
if(!connectionGroup)
{
inNode.Link[inType] = connectionGroup = {Get:[], Set:[]};
}
return (inForward === undefined || inForward === true) ? connectionGroup.Set : connectionGroup.Get
},
Connect(inNodeMajor, inNodeMinor, inKey) Connect(inNodeMajor, inNodeMinor, inKey)
{ {
N.Step(inNodeMajor, inKey, true ).push(inNodeMinor); N.Step(inNodeMajor, inKey, true, true).push(inNodeMinor);
N.Step(inNodeMinor, inKey, false).push(inNodeMajor); N.Step(inNodeMinor, inKey, false, true).push(inNodeMajor);
}, },
Disconnect(inNodeMajor, inNodeMinor, inKey) Disconnect(inNodeMajor, inNodeMinor, inKey)
{ {
@ -99,6 +91,23 @@ var N =
remove(inNodeMinor.Link[inKey].Get, inNodeMajor); remove(inNodeMinor.Link[inKey].Get, inNodeMajor);
} }
},
Step(inNode, inKey, inForward, inForceCreate)
{
let connectionGroup = inNode.Link[inKey];
if(!connectionGroup)
{
if(inForceCreate)
{
inNode.Link[inKey] = connectionGroup = {Get:[], Set:[]};
}
else
{
return false;
}
}
return (inForward === undefined || inForward === true) ? connectionGroup.Set : connectionGroup.Get;
}, },
Walk(inIterator, inNode, inKey, inForward) Walk(inIterator, inNode, inKey, inForward)
{ {
@ -116,9 +125,21 @@ var N =
} }
} }
} }
},
Path(inArray, inNode, inKey, inForward)
{
var current = inNode;
var direction = inForward||true;
for(let i=0; i<inArray.length; i++)
{
current = N.Step(current, inKey, direction)[inArray[i]];
}
return current;
} }
}; };
</script>
<script>
` `
A C A C
\ / \ \ / \
@ -133,11 +154,12 @@ N.Connect(a, b, "parent");
N.Connect(c, b, "parent"); N.Connect(c, b, "parent");
N.Connect(c, d, "parent"); N.Connect(c, d, "parent");
N.Disconnect(a, null, "parent"); N.Disconnect(a, null, "parent");
/*
console.log(a.Link); console.log(a.Link);
console.log(b.Link); console.log(b.Link);
console.log(c.Link); console.log(c.Link);
console.log(d.Link); console.log(d.Link);
*/
</script> </script>
<script> <script>
@ -211,19 +233,23 @@ var Pivot =
{ {
N.ID.Walk++; N.ID.Walk++;
let modifier = N.Create({});
let leaves = []; let leaves = [];
let gatherUp = n => N.Connect(inNode, n, "ModifyUp"); let gatherUp = n => N.Connect(modifier, n, "ModifyUp");
let gatherDown = n => let gatherDown = n =>
{ {
N.Connect(inNode, n, "ModifyDown"); N.Connect(modifier, n, "ModifyDown");
N.Step(n, "Hierarchy").length == 0 ? leaves.push(n) : null; N.Step(n, "Hierarchy").length == 0 ? leaves.push(n) : null;
}; };
let gatherOut = n => N.Connect(inNode, n, "ModifyOut"); let gatherOut = n => N.Connect(modifier, n, "ModifyOut");
N.Walk(gatherUp, inNode, "Hierarchy", false); N.Walk(gatherUp, inNode, "Hierarchy", false);
N.Connect(inNode, inNode, "ModifyDown"); N.Connect(modifier, inNode, "ModifyDown");
N.Walk(gatherDown, inNode, "Hierarchy"); N.Walk(gatherDown, inNode, "Hierarchy");
leaves.forEach(leaf=>N.Walk(gatherOut, leaf, "Hierarchy", false)); leaves.forEach(leaf=>N.Walk(gatherOut, leaf, "Hierarchy", false));
return modifier;
}, },
Unmodify(inNode) Unmodify(inNode)
{ {
@ -253,6 +279,10 @@ let pivotRoot1 = Pivot.Create([1, 2], [3]);
let pivotRoot2 = Pivot.Create([2, 1], [3]); let pivotRoot2 = Pivot.Create([2, 1], [3]);
let pivots = [pivotRoot1, pivotRoot2]; let pivots = [pivotRoot1, pivotRoot2];
let select = N.Path([0, 1], pivotRoot1, "Hierarchy");
let mod = Pivot.Modify(select);
let Store = createContext(null); let Store = createContext(null);
let StoreState = let StoreState =
@ -262,7 +292,7 @@ let StoreState =
let StoreReducer = (inState, inAction) => let StoreReducer = (inState, inAction) =>
{ {
} };
let ElNode = ({node}) => let ElNode = ({node}) =>
{ {
@ -270,12 +300,27 @@ let ElNode = ({node}) =>
var children = []; var children = [];
var table = []; var table = [];
let styles = {
};
if(node.Link["ModifyOut"])
{
styles.backgroundColor = "lightgrey";
}
if(node.Link["ModifyDown"])
{
styles.backgroundColor = "yellow";
}
if(node.Link["ModifyUp"])
{
styles.backgroundColor = "lavender";
}
if(node.Meta.Row) if(node.Meta.Row)
{ {
table = node.Meta.Row.map( cell => h("span", {style:{padding:"10px"}}, cell)); table = node.Meta.Row.map( cell => h("span", {style:{padding:"10px"}}, cell));
} }
children = [ children = [
h("strong", null, node.Meta.Label||"a node"), h("strong", {style:styles}, node.Meta.Label||"a node"),
...table, ...table,
h(Store.Consumer, null, value=> h(Store.Consumer, null, value=>
{ {