Select Git revision
three.module.js
floopscr.js 7.79 KiB
// view force layout,
/* --------------------------- ---------------------------- */
/* ---------------------- FORCE LAYOUT ----------------------- */
/* --------------------------- ---------------------------- */
// ok, my thoughts on this
/*
when you're up with big programs, spend a day / a handful, just making the UI sing
- https://bl.ocks.org/mbostock/3750558
at the moment this is kind of 'fine'
- starting condition is mostly random (and elsewhere) - maybe some graph analysis
- for who-is-generally-downstream-of-whomst
- this is nice code golf for boring times when you have lots of graphs
- still not looking at links for layout force: do that first
- want to connect this notion with the 'design patterns' ides ...
- (links) find (comm/*) connected, arrange in a stack
- (view) finds (link) connected, also stackup ...
- the links / split through views -> this is actually a lot of the work,
- and it's not unimportant
*/
let blocks = new Array()
let flsimrun = false
let flsim = {}
let flnodes = []
let finAlpha = 0.1
let sizemultiple = 0.5
// happens when items added, deleted (changing topology)
let updateForceLoop = () => {
// init and/or update
if (!flsimrun && blocks.length > 3) {
// Case for starting sim
msgbox.write('starting force sim')
flsimrun = true
// start with two nodes
let positions = this.getAllHunkPositions()
let sizes = this.getAllHunkSizes()
for (let i in positions) {
let nd = {
index: i,
x: positions[i].x,
y: positions[i].y,
vx: 0,
vy: 0,
r: sizes[i].width * sizemultiple
}
flnodes.push(nd)
}
flsim = d3.forceSimulation(flnodes)
.force('charge', d3.forceManyBody().strength(250))
.force('center', d3.forceCenter(600, 600))
.force('collide', d3.forceCollide((node, i, nodes) => {
return node.r
}))
.alphaMin(finAlpha)
.on('tick', flTick)
.on('end', flEnd)
} else if (blocks.length <= 3) {
// donot
} else {
// case for adding / rming from sim
msgbox.write('UPD8 Force Sim')
let positions = this.getAllHunkPositions()
let sizes = this.getAllHunkSizes()