use js import like a normal person....
This commit is contained in:
parent
235d5fd005
commit
ed6c5ca779
25
index.html
25
index.html
@ -2,15 +2,22 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<script src="./libraries/papaparse.min.js"></script>
|
||||
<script src="./libraries/n.js"></script>
|
||||
<script src="./libraries/pivot.js"></script>
|
||||
<script src="./data/csv.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<!-- initialize table -->
|
||||
<script>
|
||||
<script type="module">
|
||||
|
||||
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);
|
||||
|
||||
import N from "./src/n.js";
|
||||
import Pivot from "./src/pivot.js";
|
||||
|
||||
let columnNames = CSV.shift();
|
||||
let columnTypes = ([...columnNames]).fill("hidden");
|
||||
columnTypes[29] = "sum";
|
||||
@ -28,14 +35,7 @@
|
||||
columnNames,
|
||||
CSV
|
||||
);
|
||||
</script>
|
||||
<!-- rendering -->
|
||||
<script type="module">
|
||||
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 =>
|
||||
{
|
||||
@ -483,6 +483,7 @@
|
||||
pivots.map(pivot=>h(PivotRoot, {key:pivot.Meta.Label, pivot}))
|
||||
])
|
||||
};
|
||||
|
||||
const Render = () => render(h(ElRoot), document.querySelector("#app"));
|
||||
Render();
|
||||
|
||||
|
172
libraries/n.js
172
libraries/n.js
@ -1,172 +0,0 @@
|
||||
var N =
|
||||
{
|
||||
ID:{
|
||||
Walk:0,
|
||||
Instance:0
|
||||
},
|
||||
Create(inMeta)
|
||||
{
|
||||
return {
|
||||
ID:{
|
||||
Walk:0,
|
||||
Instance:N.ID.Instance++
|
||||
},
|
||||
Meta:inMeta||{},
|
||||
Link:{}
|
||||
};
|
||||
},
|
||||
Connect(inNodeMajor, inNodeMinor, inKey, inUnique)
|
||||
{
|
||||
if(inUnique) // bail if the nodes are already connected
|
||||
{
|
||||
let check = N.Step(inNodeMajor, inKey, true);
|
||||
if(check)
|
||||
{
|
||||
if(check.indexOf(inNodeMinor) !== -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
N.Step(inNodeMajor, inKey, true, true).push(inNodeMinor);
|
||||
N.Step(inNodeMinor, inKey, false, true).push(inNodeMajor);
|
||||
},
|
||||
Disconnect(inNodeMajor, inNodeMinor, inKey)
|
||||
{
|
||||
let remove = (inArray, inMatch) => inArray.findIndex( (inMember, inIndex, inArray) => (inMember === inMatch) ? inArray.splice(inIndex, 1) : false );
|
||||
|
||||
// if no specific child was passed
|
||||
if(inNodeMinor === null)
|
||||
{
|
||||
// get all the children
|
||||
let check = N.Step(inNodeMajor, inKey);
|
||||
if(!check){ return; }
|
||||
|
||||
// go down to each child ...
|
||||
check.forEach( inNodeMinor =>
|
||||
{
|
||||
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)
|
||||
{
|
||||
delete inNodeMinor.Link[inKey];
|
||||
}
|
||||
});
|
||||
|
||||
// we just wiped out all outgoing connections to the parent, if incoming connections are empty too we can purge the key there as well
|
||||
if(inNodeMajor.Link[inKey].Get.length == 0)
|
||||
{
|
||||
delete inNodeMajor.Link[inKey];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// if no specific parent was passed
|
||||
if(inNodeMajor === null)
|
||||
{
|
||||
// get all the parents
|
||||
let check = N.Step(inNodeMinor, inKey, false);
|
||||
if(!check){ return; }
|
||||
|
||||
// go up to each parent ...
|
||||
check.forEach( inNodeMajor =>
|
||||
{
|
||||
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 )
|
||||
{
|
||||
delete inNodeMajor.Link[inKey];
|
||||
}
|
||||
});
|
||||
|
||||
// we just wiped out all incoming connections to the child, if outgoing connections are empty too we can purge the key there as well
|
||||
if(inNodeMinor.Link[inKey].Set.length == 0)
|
||||
{
|
||||
delete inNodeMinor.Link[inKey];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// if a specific parent and child were passed
|
||||
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);
|
||||
}
|
||||
|
||||
},
|
||||
Step(inNode, inKey, inForward, inForceCreate)
|
||||
{
|
||||
let connectionGroup = inNode.Link[inKey];
|
||||
if(!connectionGroup)
|
||||
{
|
||||
if(inForceCreate === true)
|
||||
{
|
||||
inNode.Link[inKey] = connectionGroup = {Get:[], Set:[]};
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return (inForward === undefined || inForward === true) ? connectionGroup.Set : connectionGroup.Get;
|
||||
|
||||
},
|
||||
Walk(inIterator, inNode, inKey, inForward, inTerminal)
|
||||
{
|
||||
let array = N.Step(inNode, inKey, inForward);
|
||||
|
||||
if(!array.length && inTerminal)
|
||||
{
|
||||
return inTerminal(inNode);
|
||||
}
|
||||
|
||||
for(let i=0; i<array.length; i++)
|
||||
{
|
||||
let next = array[i];
|
||||
if(next.ID.Walk !== N.ID.Walk)
|
||||
{
|
||||
next.ID.Walk = N.ID.Walk;
|
||||
//console.log("processing", next.Meta)
|
||||
let results = inIterator(next);
|
||||
if(results !== false)
|
||||
{
|
||||
N.Walk(inIterator, next, inKey, inForward, inTerminal);
|
||||
}
|
||||
else
|
||||
{
|
||||
//console.log("routine exited");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//console.log("id collision");
|
||||
}
|
||||
}
|
||||
},
|
||||
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;
|
||||
}
|
||||
};
|
7
libraries/papaparse.min.js
vendored
7
libraries/papaparse.min.js
vendored
File diff suppressed because one or more lines are too long
0
src/app.js
Normal file
0
src/app.js
Normal file
174
src/n.js
Normal file
174
src/n.js
Normal file
@ -0,0 +1,174 @@
|
||||
const N =
|
||||
{
|
||||
ID:{
|
||||
Walk:0,
|
||||
Instance:0
|
||||
},
|
||||
Create(inMeta)
|
||||
{
|
||||
return {
|
||||
ID:{
|
||||
Walk:0,
|
||||
Instance:N.ID.Instance++
|
||||
},
|
||||
Meta:inMeta||{},
|
||||
Link:{}
|
||||
};
|
||||
},
|
||||
Connect(inNodeMajor, inNodeMinor, inKey, inUnique)
|
||||
{
|
||||
if(inUnique) // bail if the nodes are already connected
|
||||
{
|
||||
let check = N.Step(inNodeMajor, inKey, true);
|
||||
if(check)
|
||||
{
|
||||
if(check.indexOf(inNodeMinor) !== -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
N.Step(inNodeMajor, inKey, true, true).push(inNodeMinor);
|
||||
N.Step(inNodeMinor, inKey, false, true).push(inNodeMajor);
|
||||
},
|
||||
Disconnect(inNodeMajor, inNodeMinor, inKey)
|
||||
{
|
||||
let remove = (inArray, inMatch) => inArray.findIndex( (inMember, inIndex, inArray) => (inMember === inMatch) ? inArray.splice(inIndex, 1) : false );
|
||||
|
||||
// if no specific child was passed
|
||||
if(inNodeMinor === null)
|
||||
{
|
||||
// get all the children
|
||||
let check = N.Step(inNodeMajor, inKey);
|
||||
if(!check){ return; }
|
||||
|
||||
// go down to each child ...
|
||||
check.forEach( inNodeMinor =>
|
||||
{
|
||||
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)
|
||||
{
|
||||
delete inNodeMinor.Link[inKey];
|
||||
}
|
||||
});
|
||||
|
||||
// we just wiped out all outgoing connections to the parent, if incoming connections are empty too we can purge the key there as well
|
||||
if(inNodeMajor.Link[inKey].Get.length == 0)
|
||||
{
|
||||
delete inNodeMajor.Link[inKey];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// if no specific parent was passed
|
||||
if(inNodeMajor === null)
|
||||
{
|
||||
// get all the parents
|
||||
let check = N.Step(inNodeMinor, inKey, false);
|
||||
if(!check){ return; }
|
||||
|
||||
// go up to each parent ...
|
||||
check.forEach( inNodeMajor =>
|
||||
{
|
||||
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 )
|
||||
{
|
||||
delete inNodeMajor.Link[inKey];
|
||||
}
|
||||
});
|
||||
|
||||
// we just wiped out all incoming connections to the child, if outgoing connections are empty too we can purge the key there as well
|
||||
if(inNodeMinor.Link[inKey].Set.length == 0)
|
||||
{
|
||||
delete inNodeMinor.Link[inKey];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// if a specific parent and child were passed
|
||||
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);
|
||||
}
|
||||
|
||||
},
|
||||
Step(inNode, inKey, inForward, inForceCreate)
|
||||
{
|
||||
let connectionGroup = inNode.Link[inKey];
|
||||
if(!connectionGroup)
|
||||
{
|
||||
if(inForceCreate === true)
|
||||
{
|
||||
inNode.Link[inKey] = connectionGroup = {Get:[], Set:[]};
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return (inForward === undefined || inForward === true) ? connectionGroup.Set : connectionGroup.Get;
|
||||
|
||||
},
|
||||
Walk(inIterator, inNode, inKey, inForward, inTerminal)
|
||||
{
|
||||
let array = N.Step(inNode, inKey, inForward);
|
||||
|
||||
if(!array.length && inTerminal)
|
||||
{
|
||||
return inTerminal(inNode);
|
||||
}
|
||||
|
||||
for(let i=0; i<array.length; i++)
|
||||
{
|
||||
let next = array[i];
|
||||
if(next.ID.Walk !== N.ID.Walk)
|
||||
{
|
||||
next.ID.Walk = N.ID.Walk;
|
||||
//console.log("processing", next.Meta)
|
||||
let results = inIterator(next);
|
||||
if(results !== false)
|
||||
{
|
||||
N.Walk(inIterator, next, inKey, inForward, inTerminal);
|
||||
}
|
||||
else
|
||||
{
|
||||
//console.log("routine exited");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//console.log("id collision");
|
||||
}
|
||||
}
|
||||
},
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
export default N;
|
@ -1,4 +1,6 @@
|
||||
var Pivot =
|
||||
import N from "./n.js";
|
||||
|
||||
const Pivot =
|
||||
{
|
||||
Leaves:{},
|
||||
Root:N.Create({Label:"All Pivots"}),
|
||||
@ -195,4 +197,6 @@ Unmodify(inModifier)
|
||||
N.Disconnect(inModifier, null, "ModifyAt");
|
||||
N.Disconnect(null, inModifier, "Modifier");
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export default Pivot;
|
Loading…
Reference in New Issue
Block a user