2021-05-08 13:51:19 -04:00
|
|
|
|
<div id="app"></div>
|
2021-05-11 06:26:18 -04:00
|
|
|
|
|
2021-05-26 22:54:50 -04:00
|
|
|
|
<!-- N -->
|
2021-05-09 20:26:40 -04:00
|
|
|
|
<script>
|
2021-05-08 13:51:19 -04:00
|
|
|
|
|
2021-05-09 20:26:40 -04:00
|
|
|
|
var N =
|
|
|
|
|
{
|
2021-05-09 14:19:13 -04:00
|
|
|
|
ID:{
|
|
|
|
|
Walk:0,
|
|
|
|
|
Instance:0
|
|
|
|
|
},
|
2021-05-11 23:18:08 -04:00
|
|
|
|
|
2021-05-11 06:26:18 -04:00
|
|
|
|
Create(inMeta)
|
2021-05-05 21:53:04 -04:00
|
|
|
|
{
|
2021-05-11 06:26:18 -04:00
|
|
|
|
return {
|
2021-05-09 14:19:13 -04:00
|
|
|
|
ID:{
|
|
|
|
|
Walk:0,
|
|
|
|
|
Instance:N.ID.Instance++
|
2021-05-11 06:26:18 -04:00
|
|
|
|
},
|
|
|
|
|
Meta:inMeta||{},
|
|
|
|
|
Link:{}
|
2021-05-05 21:53:04 -04:00
|
|
|
|
};
|
|
|
|
|
},
|
2021-05-14 07:11:23 -04:00
|
|
|
|
Connect(inNodeMajor, inNodeMinor, inKey, inUnique)
|
2021-05-05 21:53:04 -04:00
|
|
|
|
{
|
2021-05-14 07:11:23 -04:00
|
|
|
|
if(inUnique) // bail if the nodes are already connected
|
|
|
|
|
{
|
|
|
|
|
let check = N.Step(inNodeMajor, inKey, true);
|
|
|
|
|
if(check)
|
|
|
|
|
{
|
2021-05-20 19:27:29 -04:00
|
|
|
|
if(check.indexOf(inNodeMinor) !== -1)
|
2021-05-14 07:11:23 -04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-11 23:18:08 -04:00
|
|
|
|
N.Step(inNodeMajor, inKey, true, true).push(inNodeMinor);
|
|
|
|
|
N.Step(inNodeMinor, inKey, false, true).push(inNodeMajor);
|
2021-05-08 07:03:41 -04:00
|
|
|
|
},
|
2021-05-09 20:26:40 -04:00
|
|
|
|
Disconnect(inNodeMajor, inNodeMinor, inKey)
|
2021-05-08 07:03:41 -04:00
|
|
|
|
{
|
2021-05-09 20:26:40 -04:00
|
|
|
|
let remove = (inArray, inMatch) => inArray.findIndex( (inMember, inIndex, inArray) => (inMember === inMatch) ? inArray.splice(inIndex, 1) : false );
|
|
|
|
|
|
2021-05-15 10:47:22 -04:00
|
|
|
|
// if no specific child was passed
|
2021-05-09 20:26:40 -04:00
|
|
|
|
if(inNodeMinor === null)
|
|
|
|
|
{
|
2021-05-15 10:47:22 -04:00
|
|
|
|
// get all the children
|
2021-05-14 07:11:23 -04:00
|
|
|
|
let check = N.Step(inNodeMajor, inKey);
|
|
|
|
|
if(!check){ return; }
|
2021-05-15 10:47:22 -04:00
|
|
|
|
|
|
|
|
|
// go down to each child ...
|
|
|
|
|
check.forEach( inNodeMinor =>
|
2021-05-09 14:19:13 -04:00
|
|
|
|
{
|
2021-05-15 10:47:22 -04:00
|
|
|
|
let connections = inNodeMinor.Link[inKey];
|
|
|
|
|
remove( connections.Get, inNodeMajor); // ... and remove any reference to the parent
|
|
|
|
|
|
|
|
|
|
// if after the remove operation, this child has no connections on inKey, scrub the key
|
|
|
|
|
if(!connections.Set.length && !connections.Get.length)
|
2021-05-09 20:26:40 -04:00
|
|
|
|
{
|
2021-05-15 10:47:22 -04:00
|
|
|
|
delete inNodeMinor.Link[inKey];
|
2021-05-09 20:26:40 -04:00
|
|
|
|
}
|
2021-05-09 14:19:13 -04:00
|
|
|
|
});
|
2021-05-15 10:47:22 -04:00
|
|
|
|
|
|
|
|
|
// we just wiped out all outgoing connections to the parent, if incoming connections are empty too we can purge the key there as well
|
2021-05-09 20:26:40 -04:00
|
|
|
|
if(inNodeMajor.Link[inKey].Get.length == 0)
|
|
|
|
|
{
|
|
|
|
|
delete inNodeMajor.Link[inKey];
|
|
|
|
|
}
|
2021-05-09 14:19:13 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-15 10:47:22 -04:00
|
|
|
|
// if no specific parent was passed
|
2021-05-09 20:26:40 -04:00
|
|
|
|
if(inNodeMajor === null)
|
|
|
|
|
{
|
2021-05-15 10:47:22 -04:00
|
|
|
|
// get all the parents
|
|
|
|
|
let check = N.Step(inNodeMinor, inKey, false);
|
|
|
|
|
if(!check){ return; }
|
|
|
|
|
|
|
|
|
|
// go up to each parent ...
|
|
|
|
|
check.forEach( inNodeMajor =>
|
2021-05-09 14:19:13 -04:00
|
|
|
|
{
|
2021-05-15 10:47:22 -04:00
|
|
|
|
let connections = inNodeMajor.Link[inKey];
|
|
|
|
|
remove( connections.Set, inNodeMinor); // ... and remove any reference to the child
|
|
|
|
|
|
|
|
|
|
// if after the remove operation, this parent has no connections on inKey, scrub the key
|
|
|
|
|
if( !connections.Set.length && !connections.Get.length )
|
2021-05-09 20:26:40 -04:00
|
|
|
|
{
|
2021-05-15 10:47:22 -04:00
|
|
|
|
delete inNodeMajor.Link[inKey];
|
2021-05-09 20:26:40 -04:00
|
|
|
|
}
|
2021-05-09 14:19:13 -04:00
|
|
|
|
});
|
2021-05-15 10:47:22 -04:00
|
|
|
|
|
|
|
|
|
// we just wiped out all incoming connections to the child, if outgoing connections are empty too we can purge the key there as well
|
2021-05-09 20:26:40 -04:00
|
|
|
|
if(inNodeMinor.Link[inKey].Set.length == 0)
|
|
|
|
|
{
|
|
|
|
|
delete inNodeMinor.Link[inKey];
|
|
|
|
|
}
|
2021-05-09 14:19:13 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-15 10:47:22 -04:00
|
|
|
|
// if a specific parent and child were passed
|
2021-05-09 20:26:40 -04:00
|
|
|
|
if(inNodeMajor.Link[inKey].Set.length == 1)
|
|
|
|
|
{
|
|
|
|
|
delete inNodeMajor.Link[inKey];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
remove(inNodeMajor.Link[inKey].Set, inNodeMinor);
|
|
|
|
|
}
|
|
|
|
|
if(inNodeMinor.Link[inKey].Get.length == 1)
|
|
|
|
|
{
|
|
|
|
|
delete inNodeMinor.Link[inKey];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
remove(inNodeMinor.Link[inKey].Get, inNodeMajor);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-11 23:18:08 -04:00
|
|
|
|
},
|
|
|
|
|
Step(inNode, inKey, inForward, inForceCreate)
|
|
|
|
|
{
|
|
|
|
|
let connectionGroup = inNode.Link[inKey];
|
|
|
|
|
if(!connectionGroup)
|
|
|
|
|
{
|
2021-05-15 10:47:22 -04:00
|
|
|
|
if(inForceCreate === true)
|
2021-05-11 23:18:08 -04:00
|
|
|
|
{
|
|
|
|
|
inNode.Link[inKey] = connectionGroup = {Get:[], Set:[]};
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return (inForward === undefined || inForward === true) ? connectionGroup.Set : connectionGroup.Get;
|
|
|
|
|
|
2021-05-05 21:53:04 -04:00
|
|
|
|
},
|
2021-05-15 07:30:52 -04:00
|
|
|
|
Walk(inIterator, inNode, inKey, inForward, inTerminal)
|
2021-05-05 21:53:04 -04:00
|
|
|
|
{
|
2021-05-11 06:26:18 -04:00
|
|
|
|
let array = N.Step(inNode, inKey, inForward);
|
2021-05-15 07:30:52 -04:00
|
|
|
|
|
|
|
|
|
if(!array.length && inTerminal)
|
2021-05-05 21:53:04 -04:00
|
|
|
|
{
|
2021-05-15 07:30:52 -04:00
|
|
|
|
return inTerminal(inNode);
|
|
|
|
|
}
|
2021-05-13 19:54:42 -04:00
|
|
|
|
|
2021-05-15 07:30:52 -04:00
|
|
|
|
for(let i=0; i<array.length; i++)
|
|
|
|
|
{
|
2021-05-05 21:53:04 -04:00
|
|
|
|
let next = array[i];
|
2021-05-09 14:19:13 -04:00
|
|
|
|
if(next.ID.Walk !== N.ID.Walk)
|
2021-05-05 21:53:04 -04:00
|
|
|
|
{
|
2021-05-09 14:19:13 -04:00
|
|
|
|
next.ID.Walk = N.ID.Walk;
|
2021-05-05 21:53:04 -04:00
|
|
|
|
let results = inIterator(next);
|
|
|
|
|
if(results !== false)
|
|
|
|
|
{
|
2021-05-15 07:30:52 -04:00
|
|
|
|
N.Walk(inIterator, next, inKey, inForward, inTerminal);
|
2021-05-05 21:53:04 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-11 23:18:08 -04:00
|
|
|
|
},
|
|
|
|
|
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;
|
2021-05-09 20:26:40 -04:00
|
|
|
|
}
|
|
|
|
|
};
|
2021-05-11 23:18:08 -04:00
|
|
|
|
</script>
|
2021-05-09 20:26:40 -04:00
|
|
|
|
|
2021-05-26 22:54:50 -04:00
|
|
|
|
<!-- Pivot -->
|
2021-05-09 20:26:40 -04:00
|
|
|
|
<script>
|
|
|
|
|
var Pivot =
|
|
|
|
|
{
|
|
|
|
|
Leaves:{},
|
2021-05-15 12:52:13 -04:00
|
|
|
|
Root:N.Create({Label:"All Pivots"}),
|
2021-05-17 22:39:38 -04:00
|
|
|
|
Schema:N.Create({Label:"Column Details"}),
|
|
|
|
|
Proto:N.Create({Label:"User Form"}),
|
|
|
|
|
Init(inColumnNames, inColumnTypes, inRows)
|
|
|
|
|
{
|
|
|
|
|
for(let i=0; i<inColumnNames.length; i++)
|
|
|
|
|
{
|
2021-05-22 21:19:55 -04:00
|
|
|
|
let columnNode = N.Create({Label:inColumnNames[i], Index:i});
|
|
|
|
|
N.Connect(Pivot.Schema, columnNode, inColumnTypes[i]);
|
|
|
|
|
N.Connect(Pivot.Schema, columnNode, "all");
|
2021-05-17 22:39:38 -04:00
|
|
|
|
}
|
2021-05-09 20:26:40 -04:00
|
|
|
|
Pivot.Leaves = inRows.map(r => N.Create({Row:r}));
|
|
|
|
|
Pivot.Init = ()=>{};
|
|
|
|
|
},
|
2021-05-15 12:52:13 -04:00
|
|
|
|
Pivot(inRoot, inParent, inPivotIndicies, inSumIndicies, inDepth)
|
2021-05-09 20:26:40 -04:00
|
|
|
|
{
|
|
|
|
|
//arguments:
|
|
|
|
|
// - a Node with leaf Nodes temporarily stored in its Meta.Leaves
|
|
|
|
|
// - where each leaf Node has a row of table data in it's Meta.Row
|
|
|
|
|
// - a list of columns to pivot on
|
|
|
|
|
// - a list of columns to sum
|
|
|
|
|
// - optional traversal depth, defaults to 0
|
|
|
|
|
let depth = inDepth||0;
|
|
|
|
|
let uniques = {};
|
2021-05-23 00:09:06 -04:00
|
|
|
|
let indexPivot = inPivotIndicies[depth]
|
2021-05-09 20:26:40 -04:00
|
|
|
|
inParent.Meta.Leaves.forEach((inLeaf)=>
|
|
|
|
|
{
|
|
|
|
|
let row = inLeaf.Meta.Row; // shorthand for the raw "CSV" row in the leaf Node's Meta
|
2021-05-23 00:09:06 -04:00
|
|
|
|
let value = row[indexPivot]; // get the pivot column
|
2021-05-09 20:26:40 -04:00
|
|
|
|
let match = uniques[value]; // check in the uniques list if this pivot column exists
|
|
|
|
|
if(!match)
|
|
|
|
|
{
|
|
|
|
|
// if not, store a value under that key that will be the meta object for a new child
|
2021-05-12 19:08:52 -04:00
|
|
|
|
|
|
|
|
|
let clone = row.map(r=>null);
|
|
|
|
|
inSumIndicies.forEach((inSumIndex, inIndex, inArray)=>
|
|
|
|
|
{
|
|
|
|
|
clone[inSumIndex] = row[inSumIndex]
|
|
|
|
|
});
|
2021-05-09 20:26:40 -04:00
|
|
|
|
match = uniques[value] = {
|
|
|
|
|
Label:value,
|
2021-05-12 19:08:52 -04:00
|
|
|
|
Row:clone,
|
2021-05-23 00:09:06 -04:00
|
|
|
|
IndexPivot:indexPivot,
|
|
|
|
|
IndexSum:inSumIndicies,
|
2021-05-09 20:26:40 -04:00
|
|
|
|
Leaves:[]
|
|
|
|
|
};
|
|
|
|
|
// grow a child off of the parent using the meta object
|
|
|
|
|
N.Connect(inParent, N.Create(match), "Hierarchy");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// if a match does exist, sum the appropriate columns
|
2021-05-12 19:08:52 -04:00
|
|
|
|
inSumIndicies.forEach((inSumIndex) => match.Row[inSumIndex] += row[inSumIndex]);
|
2021-05-09 20:26:40 -04:00
|
|
|
|
}
|
|
|
|
|
// move the leaves into the child
|
|
|
|
|
match.Leaves.push(inLeaf);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
delete inParent.Meta.Leaves;
|
|
|
|
|
var iterator;
|
2021-05-12 19:08:52 -04:00
|
|
|
|
if(depth >= inPivotIndicies.length-1)
|
2021-05-09 20:26:40 -04:00
|
|
|
|
{
|
2021-05-14 07:11:23 -04:00
|
|
|
|
iterator = inLastBranch =>
|
2021-05-09 20:26:40 -04:00
|
|
|
|
{
|
2021-05-14 07:11:23 -04:00
|
|
|
|
inLastBranch.Meta.Leaves.forEach( inLeaf =>
|
|
|
|
|
{
|
|
|
|
|
// collect modifiers effecting leaves
|
|
|
|
|
let modifiers = [];
|
2021-05-24 14:26:18 -04:00
|
|
|
|
let collectModifier = n => modifiers.push(n);
|
|
|
|
|
let connectModifiers = n => modifiers.forEach(inModifier => N.Connect(inModifier, n, "ModifyOut", true));
|
|
|
|
|
|
|
|
|
|
N.Walk(collectModifier, inLeaf, "ModifyAt", false);
|
|
|
|
|
N.Walk(collectModifier, inLeaf, "ModifyDown", false);
|
2021-05-14 07:11:23 -04:00
|
|
|
|
|
|
|
|
|
if(modifiers.length)
|
|
|
|
|
{
|
|
|
|
|
// apply them to the branch
|
|
|
|
|
inLastBranch.ID.Walk = N.ID.Walk;
|
2021-05-24 14:26:18 -04:00
|
|
|
|
connectModifiers(inLastBranch);
|
2021-05-14 07:11:23 -04:00
|
|
|
|
|
2021-05-15 12:52:13 -04:00
|
|
|
|
// also walk them up and connect, but with "check unique" enabled
|
2021-05-24 14:26:18 -04:00
|
|
|
|
N.Walk(connectModifiers, inLastBranch, "Hierarchy", false);
|
2021-05-14 07:11:23 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// lastly connect the leaf to the branch
|
2021-05-24 11:35:06 -04:00
|
|
|
|
N.Connect(inLastBranch, inLeaf, "Leaf");
|
2021-05-14 07:11:23 -04:00
|
|
|
|
});
|
|
|
|
|
delete inLastBranch.Meta.Leaves;
|
2021-05-09 20:26:40 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-05-15 12:52:13 -04:00
|
|
|
|
iterator = child => Pivot.Pivot(inRoot, child, inPivotIndicies, inSumIndicies, depth+1);
|
2021-05-09 20:26:40 -04:00
|
|
|
|
}
|
2021-05-24 14:26:18 -04:00
|
|
|
|
N.Walk(iterator, inParent, "Hierarchy");
|
2021-05-09 20:26:40 -04:00
|
|
|
|
return inParent;
|
|
|
|
|
},
|
2021-05-12 19:08:52 -04:00
|
|
|
|
Create(inPivotIndicies, inSumIndicies)
|
2021-05-09 20:26:40 -04:00
|
|
|
|
{
|
2021-05-14 07:11:23 -04:00
|
|
|
|
N.ID.Walk++;
|
2021-05-15 07:30:52 -04:00
|
|
|
|
|
2021-05-23 14:05:02 -04:00
|
|
|
|
let columns = N.Step(Pivot.Schema, "all");
|
2021-05-20 19:27:29 -04:00
|
|
|
|
let label = inPivotIndicies.map( inPivotIndex =>
|
|
|
|
|
{
|
2021-05-23 14:05:02 -04:00
|
|
|
|
return columns[inPivotIndex].Meta.Label;
|
2021-05-20 19:27:29 -04:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let pivotRoot = N.Create({Label:label.join("|"), Leaves:Pivot.Leaves});
|
2021-05-15 07:30:52 -04:00
|
|
|
|
N.Connect(Pivot.Root, pivotRoot, "Pivot");
|
2021-05-15 12:52:13 -04:00
|
|
|
|
return Pivot.Pivot(pivotRoot, pivotRoot, inPivotIndicies, inSumIndicies);
|
2021-05-05 21:53:04 -04:00
|
|
|
|
},
|
2021-05-15 07:30:52 -04:00
|
|
|
|
Delete(inRoot)
|
2021-05-08 07:03:41 -04:00
|
|
|
|
{
|
2021-05-15 12:52:13 -04:00
|
|
|
|
// disconnect modifiers
|
2021-05-24 11:35:06 -04:00
|
|
|
|
let check = N.Step(inRoot, "ModifyUp", false);
|
2021-05-15 10:47:22 -04:00
|
|
|
|
if(check)
|
2021-05-13 19:54:42 -04:00
|
|
|
|
{
|
2021-05-15 10:47:22 -04:00
|
|
|
|
while(check.length>0)
|
|
|
|
|
{
|
|
|
|
|
Pivot.Unmodify(check[0]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-15 12:52:13 -04:00
|
|
|
|
|
2021-05-24 11:51:07 -04:00
|
|
|
|
// disconnect leaves from terminal branches
|
|
|
|
|
N.Walk(()=>{}, inRoot, "Hierarchy", true, terminal=>{
|
|
|
|
|
N.Disconnect(terminal, null, "Leaf");
|
2021-05-15 12:52:13 -04:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// disconnect from app
|
2021-05-24 11:51:07 -04:00
|
|
|
|
N.Disconnect(null, inRoot, "Pivot");
|
2021-05-15 07:30:52 -04:00
|
|
|
|
},
|
|
|
|
|
Modify(inNode)
|
|
|
|
|
{
|
2021-05-15 10:47:22 -04:00
|
|
|
|
let modified = N.Create({Label:"Modifier"});
|
2021-05-20 19:27:29 -04:00
|
|
|
|
|
|
|
|
|
// traverse
|
2021-05-24 11:35:06 -04:00
|
|
|
|
let gatherUp = n => N.Connect(modified, n, "ModifyUp");
|
|
|
|
|
let gatherDown = n => N.Connect(modified, n, "ModifyDown");
|
|
|
|
|
let gatherOut = n => N.Connect(modified, n, "ModifyOut");
|
2021-05-13 19:54:42 -04:00
|
|
|
|
|
|
|
|
|
N.ID.Walk++;
|
|
|
|
|
inNode.ID.Walk = N.ID.Walk;
|
2021-05-24 11:35:06 -04:00
|
|
|
|
|
|
|
|
|
// at
|
2021-05-13 19:54:42 -04:00
|
|
|
|
N.Connect(modified, inNode, "ModifyAt");
|
2021-05-24 11:35:06 -04:00
|
|
|
|
|
|
|
|
|
// up
|
2021-05-09 14:19:13 -04:00
|
|
|
|
N.Walk(gatherUp, inNode, "Hierarchy", false);
|
2021-05-24 11:35:06 -04:00
|
|
|
|
|
|
|
|
|
// down 1
|
|
|
|
|
N.Walk(gatherDown, inNode, "Hierarchy", true, terminal=>
|
|
|
|
|
{
|
|
|
|
|
// down 2
|
|
|
|
|
// for each terminal node, step down into its leaves and gather down
|
|
|
|
|
N.Walk(gatherDown, terminal, "Leaf", true, leaf=>
|
|
|
|
|
{
|
|
|
|
|
// out 1
|
|
|
|
|
// walk back up on the leaf connections on other trees
|
|
|
|
|
N.Walk(gatherOut, leaf, "Leaf", false, terminal=>
|
|
|
|
|
{
|
|
|
|
|
// out 2
|
|
|
|
|
// and continueup the hierarchy
|
|
|
|
|
N.Walk(gatherOut, terminal, "Hierarchy", false);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2021-05-11 23:18:08 -04:00
|
|
|
|
|
2021-05-13 19:54:42 -04:00
|
|
|
|
return modified;
|
2021-05-09 20:26:40 -04:00
|
|
|
|
},
|
2021-05-15 10:47:22 -04:00
|
|
|
|
Unmodify(inModifier)
|
2021-05-09 14:19:13 -04:00
|
|
|
|
{
|
2021-05-15 10:47:22 -04:00
|
|
|
|
N.Disconnect(inModifier, null, "ModifyUp");
|
|
|
|
|
N.Disconnect(inModifier, null, "ModifyDown");
|
|
|
|
|
N.Disconnect(inModifier, null, "ModifyOut");
|
|
|
|
|
N.Disconnect(inModifier, null, "ModifyAt");
|
|
|
|
|
N.Disconnect(null, inModifier, "Modifier");
|
2021-05-09 14:19:13 -04:00
|
|
|
|
}
|
|
|
|
|
};
|
2021-05-09 20:26:40 -04:00
|
|
|
|
</script>
|
2021-05-09 14:19:13 -04:00
|
|
|
|
|
2021-05-26 22:54:50 -04:00
|
|
|
|
<!-- rendering -->
|
2021-05-09 20:26:40 -04:00
|
|
|
|
<script type="module">
|
2021-05-09 14:19:13 -04:00
|
|
|
|
|
2021-05-17 22:39:38 -04:00
|
|
|
|
Pivot.Init(
|
2021-05-23 14:05:02 -04:00
|
|
|
|
["id", "type-a", "type-b", "count", "extra"],
|
2021-05-24 17:03:44 -04:00
|
|
|
|
["label", "label", "label", "sum", "sum"],
|
2021-05-17 22:39:38 -04:00
|
|
|
|
[
|
|
|
|
|
["#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]
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
2021-05-26 22:54:50 -04:00
|
|
|
|
import { h, render, createContext, Fragment } from 'https://cdn.skypack.dev/preact';
|
|
|
|
|
import { useReducer, useState } from 'https://cdn.skypack.dev/preact/hooks';
|
|
|
|
|
import { css, cx } from 'https://cdn.skypack.dev/@emotion/css';
|
|
|
|
|
import htm from 'https://unpkg.com/htm?module';
|
|
|
|
|
const html = htm.bind(h);
|
|
|
|
|
|
|
|
|
|
let PivotForm = props =>
|
|
|
|
|
{
|
|
|
|
|
let styles = css`
|
|
|
|
|
position:realtive;
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
padding: 10px;
|
|
|
|
|
color:black;
|
|
|
|
|
font-family:sans-serif;
|
|
|
|
|
|
|
|
|
|
.Title
|
|
|
|
|
{
|
|
|
|
|
font-size:24px;
|
|
|
|
|
font-weight:100;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.Section
|
|
|
|
|
{
|
|
|
|
|
padding:10px 0 10px 0;
|
|
|
|
|
|
|
|
|
|
.Heading
|
|
|
|
|
{
|
|
|
|
|
display:inline-block;
|
|
|
|
|
color:#666;
|
|
|
|
|
font-family:sans-serif;
|
|
|
|
|
font-size:12px;
|
|
|
|
|
font-weight:900;
|
|
|
|
|
text-transform:uppercase;
|
|
|
|
|
}
|
|
|
|
|
.Group
|
|
|
|
|
{
|
|
|
|
|
display:inline-block;
|
|
|
|
|
padding:5px;
|
|
|
|
|
border-radius:5px;
|
|
|
|
|
margin:3px;
|
|
|
|
|
background:rgba(0, 0, 0, 0.3)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let pivotColumns = N.Step(Pivot.Schema, "label")||[];
|
|
|
|
|
let pivotColumnsUsed = N.Step(Pivot.Proto, "used-pivot")||[];
|
|
|
|
|
|
|
|
|
|
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 = sumColumns.map(node=>node.Meta.Index);
|
|
|
|
|
//let indiciesSum = sumColumnsUsed.map(node=>node.Meta.Index);
|
|
|
|
|
|
|
|
|
|
let displayPivotsAll = html`
|
|
|
|
|
<div class="Section">
|
|
|
|
|
<div class="Heading">Available Columns</div>
|
|
|
|
|
<div class="Group">
|
|
|
|
|
${pivotColumns.map( columnPivot =>
|
|
|
|
|
{
|
|
|
|
|
let attributes = {};
|
|
|
|
|
if(N.Step(columnPivot, "used-pivot", false))
|
|
|
|
|
{
|
|
|
|
|
attributes.disabled = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
attributes.onClick = e=>
|
|
|
|
|
{
|
|
|
|
|
N.Connect(Pivot.Proto, columnPivot, "used-pivot");
|
|
|
|
|
Render();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return html`<button ...${attributes}>${columnPivot.Meta.Label}</button>`;
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
let displayPivotsPending = null;
|
|
|
|
|
if(pivotColumnsUsed.length)
|
|
|
|
|
{
|
|
|
|
|
displayPivotsPending = html`
|
|
|
|
|
<div class="Section">
|
|
|
|
|
<div class="Heading">Pending Pivot</div>
|
|
|
|
|
<div class="Group">
|
|
|
|
|
${pivotColumnsUsed.map(columnPivot=>html`
|
|
|
|
|
<button onClick=${e=>{N.Disconnect(Pivot.Proto, columnPivot, "used-pivot");Render();}}>
|
|
|
|
|
${columnPivot.Meta.Label}
|
|
|
|
|
</button>
|
|
|
|
|
`)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<button onClick=${e=>{
|
|
|
|
|
N.Disconnect(Pivot.Proto, null, "used-pivot");
|
|
|
|
|
N.Disconnect(Pivot.Proto, null, "used-sum");
|
|
|
|
|
Pivot.Create(indiciesPivot, indiciesSum);
|
|
|
|
|
Render();
|
|
|
|
|
}}>Create</button>
|
|
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return html`
|
|
|
|
|
<div class=${styles}>
|
|
|
|
|
<div class="Title">Create New Pivot</div>
|
|
|
|
|
${displayPivotsAll}
|
|
|
|
|
${displayPivotsPending}
|
|
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let Section = props =>
|
|
|
|
|
{
|
|
|
|
|
let styles = css`
|
|
|
|
|
.Heading
|
|
|
|
|
{
|
|
|
|
|
padding:6px 0 6px 0;
|
|
|
|
|
color:#666;
|
|
|
|
|
font-weight:900;
|
|
|
|
|
font-size:12px;
|
|
|
|
|
text-transform:uppercase;
|
|
|
|
|
cursor:pointer;
|
|
|
|
|
|
|
|
|
|
span
|
|
|
|
|
{
|
|
|
|
|
display:inline-block;
|
|
|
|
|
width:20px;
|
|
|
|
|
height:20px;
|
|
|
|
|
margin-right:10px;
|
|
|
|
|
border-radius:20px;
|
|
|
|
|
background:black;
|
|
|
|
|
color:white;
|
|
|
|
|
text-align:center;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.Heading:hover
|
|
|
|
|
{
|
|
|
|
|
color:black;
|
|
|
|
|
}
|
|
|
|
|
.Body
|
|
|
|
|
{
|
|
|
|
|
position:relative;
|
|
|
|
|
padding:10px 0 20px 30px;
|
|
|
|
|
&::before
|
|
|
|
|
{
|
|
|
|
|
content: " ";
|
|
|
|
|
display:block;
|
|
|
|
|
position:absolute;
|
|
|
|
|
top:-8px;
|
|
|
|
|
left:8px;
|
|
|
|
|
width:3px;
|
|
|
|
|
height:100%;
|
|
|
|
|
background:black;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
let [openGet, openSet] = useState(false);
|
|
|
|
|
return html`
|
|
|
|
|
<div class=${styles}>
|
|
|
|
|
<div class="Heading" onClick=${e=>openSet(!openGet)}>
|
|
|
|
|
<span>${openGet ? `−` : `+`}</span>
|
|
|
|
|
${props.label}
|
|
|
|
|
</div>
|
|
|
|
|
${ openGet ? html`<div class="Body">${props.children}</div>` : null }
|
|
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let Modifier = props =>
|
|
|
|
|
{
|
2021-05-28 16:14:52 -04:00
|
|
|
|
let refNode = N.Step(props.modifier, "ModifyAt", false)[0];
|
2021-05-26 22:54:50 -04:00
|
|
|
|
|
|
|
|
|
let handleDelete = () =>
|
|
|
|
|
{
|
|
|
|
|
Pivot.Unmodify(props.modifier);
|
|
|
|
|
Render();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let displayFields = [];
|
|
|
|
|
N.Walk(node=>{
|
|
|
|
|
displayFields.push(html`<input type='number'/>`)
|
|
|
|
|
}, Pivot.Schema, "sum");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return html`
|
|
|
|
|
<div>
|
|
|
|
|
<div>${refNode.Meta.Label}</div>
|
|
|
|
|
<button onClick=${handleDelete}>Delete</button>
|
|
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-28 16:14:52 -04:00
|
|
|
|
let ModificationsIcon = ({node}) =>
|
|
|
|
|
{
|
|
|
|
|
let modsUp = /*N.Step(node, "ModifyUp", false)||[]*/[true];
|
|
|
|
|
let modsDown = /*N.Step(node, "ModifyDown", false)||[]*/[true, true];
|
|
|
|
|
let modsAt = /*N.Step(node, "ModifyAt", false)||[]*/[true, true, true];
|
|
|
|
|
let modsOut = /*N.Step(node, "ModifyOut", false)||[]*/[];
|
|
|
|
|
|
|
|
|
|
let styles = css`
|
|
|
|
|
position:relative;
|
|
|
|
|
display:inline-block;
|
|
|
|
|
width:25px;
|
|
|
|
|
height:25px;
|
|
|
|
|
margin-left:100px;
|
|
|
|
|
.Icon
|
|
|
|
|
{
|
|
|
|
|
position:absolute;
|
|
|
|
|
display:inline-block;
|
|
|
|
|
width:25px;
|
|
|
|
|
height:25px;
|
|
|
|
|
text-align:center;
|
|
|
|
|
font-size:9px;
|
|
|
|
|
font-family:sans-serif;
|
|
|
|
|
font-weight:900;
|
|
|
|
|
line-height:25px;
|
|
|
|
|
|
|
|
|
|
&::after
|
|
|
|
|
{
|
|
|
|
|
content:" ";
|
|
|
|
|
display:block;
|
|
|
|
|
position:absolute;
|
|
|
|
|
width:5px;
|
|
|
|
|
height:5px;
|
|
|
|
|
border:10px solid transparent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&.Down
|
|
|
|
|
{
|
|
|
|
|
left:0;
|
|
|
|
|
bottom:100%;
|
|
|
|
|
&::after
|
|
|
|
|
{
|
|
|
|
|
top:100%;
|
|
|
|
|
border-top-color:green;
|
|
|
|
|
border-bottom:0px solid transparent;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
&.At
|
|
|
|
|
{
|
|
|
|
|
top:0;
|
|
|
|
|
left:100%;
|
|
|
|
|
&::after
|
|
|
|
|
{
|
|
|
|
|
top:0;
|
|
|
|
|
right:100%;
|
|
|
|
|
border-right-color:red;
|
|
|
|
|
border-left:0px solid transparent;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
&.Up
|
|
|
|
|
{
|
|
|
|
|
left:0;
|
|
|
|
|
top:100%;
|
|
|
|
|
&::after
|
|
|
|
|
{
|
|
|
|
|
bottom:100%;
|
|
|
|
|
border-bottom-color:orange;
|
|
|
|
|
border-top:0px solid transparent;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&.Out
|
|
|
|
|
{
|
|
|
|
|
top:0;
|
|
|
|
|
right:100%;
|
|
|
|
|
&::after
|
|
|
|
|
{
|
|
|
|
|
top:0;
|
|
|
|
|
left:100%;
|
|
|
|
|
border-left-color:grey;
|
|
|
|
|
border-right:0px solid transparent;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
let otherStyles = css`
|
|
|
|
|
position:relative;
|
|
|
|
|
left:100px;
|
|
|
|
|
width:5px;
|
|
|
|
|
height:5px;
|
|
|
|
|
border:20px solid transparent;
|
|
|
|
|
background:black;
|
|
|
|
|
|
|
|
|
|
&.Down
|
|
|
|
|
{
|
|
|
|
|
border-top-color:orange;
|
|
|
|
|
}
|
|
|
|
|
&.At
|
|
|
|
|
{
|
|
|
|
|
border-right-color:red;
|
|
|
|
|
}
|
|
|
|
|
&.Up
|
|
|
|
|
{
|
|
|
|
|
border-bottom-color:lightblue;
|
|
|
|
|
}
|
|
|
|
|
&.Out
|
|
|
|
|
{
|
|
|
|
|
border-left:grey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.Icon
|
|
|
|
|
{
|
|
|
|
|
position:absolute;
|
|
|
|
|
width:20px;
|
|
|
|
|
height:20px;
|
|
|
|
|
|
|
|
|
|
&.Down
|
|
|
|
|
{
|
|
|
|
|
bottom:35px;
|
|
|
|
|
left:0;
|
|
|
|
|
}
|
|
|
|
|
&.At
|
|
|
|
|
{
|
|
|
|
|
left:35px;
|
|
|
|
|
top:0;
|
|
|
|
|
}
|
|
|
|
|
&.Up
|
|
|
|
|
{
|
|
|
|
|
top:35px;
|
|
|
|
|
left:0;
|
|
|
|
|
}
|
|
|
|
|
&.Out
|
|
|
|
|
{
|
|
|
|
|
right:35px;
|
|
|
|
|
top:0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
return html`
|
|
|
|
|
<div class=${cx(otherStyles, "At")}>
|
|
|
|
|
${modsDown.length ? html`<div class="Icon Down">${modsDown.length}</div>` : null}
|
|
|
|
|
${modsAt.length ? html`<span class="Icon At">${modsAt.length}</span>` : null}
|
|
|
|
|
${modsUp.length ? html`<span class="Icon Up">${modsUp.length}</span>` : null}
|
|
|
|
|
${modsOut.length ? html`<span class="Icon Out">${modsOut.length}</span>` : null}
|
|
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2021-05-26 22:54:50 -04:00
|
|
|
|
let PivotBranch = props =>
|
|
|
|
|
{
|
|
|
|
|
let row = props.node.Meta.Row;
|
|
|
|
|
let displayCells = row.map(column=>h("td", null, column));
|
|
|
|
|
let displayCellsModify = row.map(column=>false);
|
|
|
|
|
props.node.Meta.IndexSum.forEach(i=>
|
|
|
|
|
{
|
|
|
|
|
displayCellsModify[i] = html`<td><input type="number" value=${row[i]}/></td>`;
|
|
|
|
|
});
|
|
|
|
|
displayCellsModify.forEach((cell, i)=>
|
|
|
|
|
{
|
|
|
|
|
if(!cell)
|
|
|
|
|
{
|
|
|
|
|
displayCellsModify[i] = html`<td>${row[i]}</td>`
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return html`
|
|
|
|
|
<tbody>
|
|
|
|
|
<tr>
|
|
|
|
|
<td>
|
|
|
|
|
<strong>${props.node.Meta.Label}</strong>
|
2021-05-28 16:14:52 -04:00
|
|
|
|
<button>Modify</button>
|
2021-05-26 22:54:50 -04:00
|
|
|
|
</td>
|
|
|
|
|
${displayCells}
|
|
|
|
|
</tr>
|
2021-05-28 16:14:52 -04:00
|
|
|
|
|
2021-05-26 22:54:50 -04:00
|
|
|
|
</tbody>
|
|
|
|
|
`;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let PivotRoot = ({pivot}) =>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
let stylesRoot = css`
|
|
|
|
|
display:block;
|
|
|
|
|
box-sizing:border-box;
|
|
|
|
|
padding:15px;
|
|
|
|
|
font-family:sans-serif;
|
|
|
|
|
`;
|
|
|
|
|
let stylesHeading = css`
|
|
|
|
|
margin: 0 0 15px 0;
|
|
|
|
|
font-weight:0;
|
|
|
|
|
font-size:24px;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
let modifiers = N.Step(pivot, "ModifyUp", false) || [];
|
|
|
|
|
let handleDelete = ()=>
|
|
|
|
|
{
|
|
|
|
|
Pivot.Delete(pivot);
|
|
|
|
|
Render();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let rows = [];
|
|
|
|
|
N.ID.Walk++;
|
|
|
|
|
N.Walk(n=>rows.push(h(PivotBranch, {node:n}, null)), pivot, "Hierarchy");
|
|
|
|
|
|
|
|
|
|
return html`
|
|
|
|
|
<div class=${stylesRoot}>
|
|
|
|
|
<div key="heading" class=${stylesHeading}>${pivot.Meta.Label}</div>
|
|
|
|
|
<${Section} key="settings" label=${`Settings`}>
|
|
|
|
|
<button onClick=${handleDelete}>Destroy Pivot</button>
|
|
|
|
|
<//>
|
|
|
|
|
<${Section} key="modifiers" label=${`Modifiers (${modifiers.length})`}>
|
|
|
|
|
${ !modifiers.length ? html`<em>No modifiers</em>` : modifiers.map( m => html`<${Modifier} modifier=${m}/>`)}
|
|
|
|
|
<//>
|
|
|
|
|
<${Section} key="tree" label=${"Tree"}>
|
|
|
|
|
<table>
|
|
|
|
|
${rows}
|
|
|
|
|
</table>
|
|
|
|
|
<//>
|
|
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
};
|
|
|
|
|
|
2021-05-14 06:47:30 -04:00
|
|
|
|
let ElRoot = props =>
|
2021-05-08 13:51:19 -04:00
|
|
|
|
{
|
2021-05-15 12:52:13 -04:00
|
|
|
|
let pivots = N.Step(Pivot.Root, "Pivot")||[];
|
2021-05-13 19:54:42 -04:00
|
|
|
|
return h("div", null, [
|
2021-05-23 14:05:02 -04:00
|
|
|
|
h(PivotForm),
|
2021-05-28 16:14:52 -04:00
|
|
|
|
h(ModificationsIcon, null, null),
|
2021-05-24 22:52:55 -04:00
|
|
|
|
pivots.map(pivot=>h(PivotRoot, {key:pivot.Meta.Label, pivot}))
|
2021-05-13 19:54:42 -04:00
|
|
|
|
])
|
2021-05-08 13:51:19 -04:00
|
|
|
|
};
|
2021-05-26 22:54:50 -04:00
|
|
|
|
const Render = () => render(h(ElRoot), document.querySelector("#app"));
|
2021-05-14 06:47:30 -04:00
|
|
|
|
Render();
|
2021-05-08 13:51:19 -04:00
|
|
|
|
|
2021-05-26 22:54:50 -04:00
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<!-- testing area -->
|
|
|
|
|
<script>
|
|
|
|
|
let ModificationPull = (inDAG) =>
|
|
|
|
|
{
|
|
|
|
|
let collect = inArray => n => { n.Meta.Tweak.forEach((t, i)=>{ inArray[n.Meta.Indicies[i]] += t; }); };
|
|
|
|
|
let totalScale = [0, 0, 0, 0, 0, 0, 0, 0];
|
|
|
|
|
let totalAdd = [0, 0, 0, 0, 0, 0, 0, 0];
|
|
|
|
|
|
|
|
|
|
N.ID.Walk++;
|
|
|
|
|
N.Walk(collect(totalScale), inDAG, "ModifyAt", false);
|
|
|
|
|
N.Walk(collect(totalScale), inDAG, "ModifyDown", false);
|
|
|
|
|
N.Walk(collect(totalAdd), inDAG, "ModifyUp", false);
|
|
|
|
|
N.Walk(collect(totalAdd), inDAG, "ModifyOut", false);
|
|
|
|
|
|
|
|
|
|
return [totalScale, totalAdd];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let dag1 = N.Create({Label:"dag-1"});
|
|
|
|
|
let m0 = N.Create({Label:"m-0", Tweak:[-1, 2, 0.7], Indicies:[0, 1, 2]});
|
|
|
|
|
let m1 = N.Create({Label:"m-1", Tweak:[0.1, 0.1, 0.1], Indicies:[1, 2, 3]});
|
|
|
|
|
|
|
|
|
|
N.Connect(m0, dag1, "ModifyAt");
|
|
|
|
|
N.Connect(m1, dag1, "ModifyDown");
|
|
|
|
|
|
|
|
|
|
let results = ModificationPull(dag1);
|
|
|
|
|
console.log(results);
|
|
|
|
|
|
2021-05-24 22:52:55 -04:00
|
|
|
|
</script>
|