|
@@ -1 +1,502 @@
|
1
|
1
|
|
|
2
|
+{
|
|
3
|
+// forceManyBody
|
|
4
|
+// forceCenter
|
|
5
|
+// forceLink
|
|
6
|
+
|
|
7
|
+window.glob_dev_fns.forceLink = function link(links) {
|
|
8
|
+ var id = index$1,
|
|
9
|
+ strength = defaultStrength,
|
|
10
|
+ strengths,
|
|
11
|
+ distance = constant$7(30),
|
|
12
|
+ distances,
|
|
13
|
+ nodes,
|
|
14
|
+ count,
|
|
15
|
+ bias,
|
|
16
|
+ random,
|
|
17
|
+ iterations = 1;
|
|
18
|
+
|
|
19
|
+ if (links == null) links = [];
|
|
20
|
+
|
|
21
|
+ function defaultStrength(link) {
|
|
22
|
+ return 1 / Math.min(count[link.source.index], count[link.target.index]);
|
|
23
|
+ }
|
|
24
|
+
|
|
25
|
+ function force(alpha) {
|
|
26
|
+ for (var k = 0, n = links.length; k < iterations; ++k) {
|
|
27
|
+ for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
|
|
28
|
+ link = links[i], source = link.source, target = link.target;
|
|
29
|
+ x = target.x + target.vx - source.x - source.vx || jiggle(random);
|
|
30
|
+ y = target.y + target.vy - source.y - source.vy || jiggle(random);
|
|
31
|
+ l = Math.sqrt(x * x + y * y);
|
|
32
|
+ l = (l - distances[i]) / l * alpha * strengths[i];
|
|
33
|
+ x *= l, y *= l;
|
|
34
|
+ target.vx -= x * (b = bias[i]);
|
|
35
|
+ target.vy -= y * b;
|
|
36
|
+ source.vx += x * (b = 1 - b);
|
|
37
|
+ source.vy += y * b;
|
|
38
|
+ }
|
|
39
|
+ }
|
|
40
|
+ }
|
|
41
|
+ function reinit(txt){
|
|
42
|
+ var ret = {};ret.eret = eval(txt);return ret
|
|
43
|
+ }
|
|
44
|
+ force.reinit = reinit
|
|
45
|
+
|
|
46
|
+ function initialize() {
|
|
47
|
+ if (!nodes) return;
|
|
48
|
+
|
|
49
|
+ var i,
|
|
50
|
+ n = nodes.length,
|
|
51
|
+ m = links.length,
|
|
52
|
+ nodeById = new Map(nodes.map((d, i) => [id(d, i, nodes), d])),
|
|
53
|
+ link;
|
|
54
|
+
|
|
55
|
+ for (i = 0, count = new Array(n); i < m; ++i) {
|
|
56
|
+ link = links[i], link.index = i;
|
|
57
|
+ if (typeof link.source !== "object") link.source = find$1(nodeById, link.source);
|
|
58
|
+ if (typeof link.target !== "object") link.target = find$1(nodeById, link.target);
|
|
59
|
+ count[link.source.index] = (count[link.source.index] || 0) + 1;
|
|
60
|
+ count[link.target.index] = (count[link.target.index] || 0) + 1;
|
|
61
|
+ }
|
|
62
|
+
|
|
63
|
+ for (i = 0, bias = new Array(m); i < m; ++i) {
|
|
64
|
+ link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
|
|
65
|
+ }
|
|
66
|
+
|
|
67
|
+ strengths = new Array(m), initializeStrength();
|
|
68
|
+ distances = new Array(m), initializeDistance();
|
|
69
|
+ }
|
|
70
|
+
|
|
71
|
+ function initializeStrength() {
|
|
72
|
+ if (!nodes) return;
|
|
73
|
+
|
|
74
|
+ for (var i = 0, n = links.length; i < n; ++i) {
|
|
75
|
+ strengths[i] = +strength(links[i], i, links);
|
|
76
|
+ }
|
|
77
|
+ }
|
|
78
|
+
|
|
79
|
+ function initializeDistance() {
|
|
80
|
+ if (!nodes) return;
|
|
81
|
+
|
|
82
|
+ for (var i = 0, n = links.length; i < n; ++i) {
|
|
83
|
+ distances[i] = +distance(links[i], i, links);
|
|
84
|
+ }
|
|
85
|
+ }
|
|
86
|
+
|
|
87
|
+ force.initialize = function(_nodes, _random) {
|
|
88
|
+ nodes = _nodes;
|
|
89
|
+ random = _random;
|
|
90
|
+ initialize();
|
|
91
|
+ };
|
|
92
|
+
|
|
93
|
+ force.links = function(_) {
|
|
94
|
+ return arguments.length ? (links = _, initialize(), force) : links;
|
|
95
|
+ };
|
|
96
|
+
|
|
97
|
+ force.id = function(_) {
|
|
98
|
+ return arguments.length ? (id = _, force) : id;
|
|
99
|
+ };
|
|
100
|
+
|
|
101
|
+ force.iterations = function(_) {
|
|
102
|
+ return arguments.length ? (iterations = +_, force) : iterations;
|
|
103
|
+ };
|
|
104
|
+
|
|
105
|
+ force.strength = function(_) {
|
|
106
|
+ return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initializeStrength(), force) : strength;
|
|
107
|
+ };
|
|
108
|
+
|
|
109
|
+ force.distance = function(_) {
|
|
110
|
+ return arguments.length ? (distance = typeof _ === "function" ? _ : constant$7(+_), initializeDistance(), force) : distance;
|
|
111
|
+ };
|
|
112
|
+
|
|
113
|
+ return force;
|
|
114
|
+}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+window.glob_dev_fns.forceCenter = function center$1(x, y) {
|
|
124
|
+ var nodes, strength = 1;
|
|
125
|
+
|
|
126
|
+ if (x == null) x = 0;
|
|
127
|
+ if (y == null) y = 0;
|
|
128
|
+
|
|
129
|
+ function force() {
|
|
130
|
+ var i,
|
|
131
|
+ n = nodes.length,
|
|
132
|
+ node,
|
|
133
|
+ sx = 0,
|
|
134
|
+ sy = 0;
|
|
135
|
+
|
|
136
|
+ for (i = 0; i < n; ++i) {
|
|
137
|
+ node = nodes[i], sx += node.x, sy += node.y;
|
|
138
|
+ }
|
|
139
|
+
|
|
140
|
+ for (sx = (sx / n - x) * strength, sy = (sy / n - y) * strength, i = 0; i < n; ++i) {
|
|
141
|
+ node = nodes[i], node.x -= sx, node.y -= sy;
|
|
142
|
+ }
|
|
143
|
+ }
|
|
144
|
+ function reinit(txt){
|
|
145
|
+ var ret = {};ret.eret = eval(txt);return ret
|
|
146
|
+ }
|
|
147
|
+ force.reinit = reinit
|
|
148
|
+
|
|
149
|
+ force.initialize = function(_) {
|
|
150
|
+ nodes = _;
|
|
151
|
+ };
|
|
152
|
+
|
|
153
|
+ force.x = function(_) {
|
|
154
|
+ return arguments.length ? (x = +_, force) : x;
|
|
155
|
+ };
|
|
156
|
+
|
|
157
|
+ force.y = function(_) {
|
|
158
|
+ return arguments.length ? (y = +_, force) : y;
|
|
159
|
+ };
|
|
160
|
+
|
|
161
|
+ force.strength = function(_) {
|
|
162
|
+ return arguments.length ? (strength = +_, force) : strength;
|
|
163
|
+ };
|
|
164
|
+
|
|
165
|
+ return force;
|
|
166
|
+}
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+window.glob_dev_fns.forceManyBody = function manyBody() {
|
|
172
|
+ clog("d3 dc3")
|
|
173
|
+
|
|
174
|
+ var nodes,
|
|
175
|
+ node,
|
|
176
|
+ random,
|
|
177
|
+ alpha,
|
|
178
|
+ strength = constant$7(-30),
|
|
179
|
+ strengths,
|
|
180
|
+ distanceMin2 = 1,
|
|
181
|
+ distanceMax2 = Infinity,
|
|
182
|
+ theta2 = 0.81;
|
|
183
|
+
|
|
184
|
+ function force(_) {
|
|
185
|
+
|
|
186
|
+ function xfn(){
|
|
187
|
+ clog("XFN")
|
|
188
|
+ }
|
|
189
|
+
|
|
190
|
+ if (glob_dbg.rfn_c > 0){
|
|
191
|
+ glob_dbg.rfn_c -= 1
|
|
192
|
+ clog("d3_r",glob_dbg.rfn_c,this)
|
|
193
|
+ // clog("d3_r",glob_dbg.rfn_c,this,fn_gen[this.name])
|
|
194
|
+ }
|
|
195
|
+
|
|
196
|
+ this.xfn_ = xfn
|
|
197
|
+
|
|
198
|
+ var i, n = nodes.length, tree = quadtree(nodes, x$1, y$1).visitAfter(accumulate);
|
|
199
|
+ for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
|
|
200
|
+ }
|
|
201
|
+
|
|
202
|
+ function reinit(txt){
|
|
203
|
+ var ret = {};ret.eret = eval(txt);return ret
|
|
204
|
+ }
|
|
205
|
+ force.reinit = reinit
|
|
206
|
+
|
|
207
|
+ function initialize() {
|
|
208
|
+ if (!nodes) return;
|
|
209
|
+ var i, n = nodes.length, node;
|
|
210
|
+ strengths = new Array(n);
|
|
211
|
+ for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
|
|
212
|
+ }
|
|
213
|
+
|
|
214
|
+ function accumulate(quad) {
|
|
215
|
+ var strength = 0, q, c, weight = 0, x, y, i;
|
|
216
|
+
|
|
217
|
+ // For internal nodes, accumulate forces from child quadrants.
|
|
218
|
+ if (quad.length) {
|
|
219
|
+ for (x = y = i = 0; i < 4; ++i) {
|
|
220
|
+ if ((q = quad[i]) && (c = Math.abs(q.value))) {
|
|
221
|
+ strength += q.value, weight += c, x += c * q.x, y += c * q.y;
|
|
222
|
+ }
|
|
223
|
+ }
|
|
224
|
+ quad.x = x / weight;
|
|
225
|
+ quad.y = y / weight;
|
|
226
|
+ }
|
|
227
|
+
|
|
228
|
+ // For leaf nodes, accumulate forces from coincident quadrants.
|
|
229
|
+ else {
|
|
230
|
+ q = quad;
|
|
231
|
+ q.x = q.data.x;
|
|
232
|
+ q.y = q.data.y;
|
|
233
|
+ do strength += strengths[q.data.index];
|
|
234
|
+ while (q = q.next);
|
|
235
|
+ }
|
|
236
|
+
|
|
237
|
+ quad.value = strength;
|
|
238
|
+ }
|
|
239
|
+
|
|
240
|
+ function apply(quad, x1, _, x2) {
|
|
241
|
+ if (!quad.value) return true;
|
|
242
|
+
|
|
243
|
+ var x = quad.x - node.x,
|
|
244
|
+ y = quad.y - node.y,
|
|
245
|
+ w = x2 - x1,
|
|
246
|
+ l = x * x + y * y;
|
|
247
|
+
|
|
248
|
+ // Apply the Barnes-Hut approximation if possible.
|
|
249
|
+ // Limit forces for very close nodes; randomize direction if coincident.
|
|
250
|
+ if (w * w / theta2 < l) {
|
|
251
|
+ if (l < distanceMax2) {
|
|
252
|
+ if (x === 0) x = jiggle(random), l += x * x;
|
|
253
|
+ if (y === 0) y = jiggle(random), l += y * y;
|
|
254
|
+ if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
|
|
255
|
+ node.vx += x * quad.value * alpha / l;
|
|
256
|
+ node.vy += y * quad.value * alpha / l;
|
|
257
|
+ }
|
|
258
|
+ return true;
|
|
259
|
+ }
|
|
260
|
+
|
|
261
|
+ // Otherwise, process points directly.
|
|
262
|
+ else if (quad.length || l >= distanceMax2) return;
|
|
263
|
+
|
|
264
|
+ // Limit forces for very close nodes; randomize direction if coincident.
|
|
265
|
+ if (quad.data !== node || quad.next) {
|
|
266
|
+ if (x === 0) x = jiggle(random), l += x * x;
|
|
267
|
+ if (y === 0) y = jiggle(random), l += y * y;
|
|
268
|
+ if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
|
|
269
|
+ }
|
|
270
|
+
|
|
271
|
+ do if (quad.data !== node) {
|
|
272
|
+ w = strengths[quad.data.index] * alpha / l;
|
|
273
|
+ node.vx += x * w;
|
|
274
|
+ node.vy += y * w;
|
|
275
|
+ } while (quad = quad.next);
|
|
276
|
+ }
|
|
277
|
+
|
|
278
|
+ force.initialize = function(_nodes, _random) {
|
|
279
|
+ nodes = _nodes;
|
|
280
|
+ random = _random;
|
|
281
|
+ initialize();
|
|
282
|
+ };
|
|
283
|
+
|
|
284
|
+ force.strength = function(_) {
|
|
285
|
+ if (glob_dbg.rfn_c > 0){
|
|
286
|
+ glob_dbg.rfn_c -= 1
|
|
287
|
+ clog("d3_r strength",glob_dbg.rfn_c,this)
|
|
288
|
+ // clog("d3_r",glob_dbg.rfn_c,this,fn_gen[this.name])
|
|
289
|
+ }
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+ return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
|
|
293
|
+ };
|
|
294
|
+
|
|
295
|
+ force.distanceMin = function(_) {
|
|
296
|
+ return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
|
|
297
|
+ };
|
|
298
|
+
|
|
299
|
+ force.distanceMax = function(_) {
|
|
300
|
+ return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
|
|
301
|
+ };
|
|
302
|
+
|
|
303
|
+ force.theta = function(_) {
|
|
304
|
+ return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
|
|
305
|
+ };
|
|
306
|
+
|
|
307
|
+ return force;
|
|
308
|
+}
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+}
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+glob_dev_fns.forceManyBody_ = glob_dev_fns.forceManyBody
|
|
316
|
+glob_dev_fns.forceCenter_ = glob_dev_fns.forceCenter
|
|
317
|
+glob_dev_fns.forceLink_ = glob_dev_fns.forceLink
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+clog("n2")
|
|
323
|
+function trc(){
|
|
324
|
+ console.trace("zq")
|
|
325
|
+}
|
|
326
|
+
|
|
327
|
+function eval_helper(txt){
|
|
328
|
+ return yglob.d3.evl(txt).fn
|
|
329
|
+}
|
|
330
|
+function eval_helper2(txt,fscope){
|
|
331
|
+ return fscope.reinit(txt).fn
|
|
332
|
+}
|
|
333
|
+window.glob_dev_fns["test"] = function test(){
|
|
334
|
+ clog("TEXT")
|
|
335
|
+}
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+if (window.yglob){
|
|
341
|
+
|
|
342
|
+// glob_dev_fns.forceManyBody_
|
|
343
|
+// glob_dev_fns.forceCenter_
|
|
344
|
+// glob_dev_fns.forceLink_
|
|
345
|
+
|
|
346
|
+// dev_dec_gen2(glob_dev_fns.forceManyBody,"forceManyBody_")
|
|
347
|
+dev_dec_gen2(glob_dev_fns.forceManyBody,"forceManyBody_")
|
|
348
|
+dev_dec_gen2(glob_dev_fns.forceCenter,"forceCenter_")
|
|
349
|
+dev_dec_gen2(glob_dev_fns.forceLink,"forceLink_")
|
|
350
|
+
|
|
351
|
+}
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+function ret_fn(){
|
|
364
|
+ // clog("?")
|
|
365
|
+ if (glob_dbg.rfn_c > 0){
|
|
366
|
+ glob_dbg.rfn_c -= 1
|
|
367
|
+ clog("d3_r",glob_dbg.rfn_c,this,fn_gen[this.name])
|
|
368
|
+ }
|
|
369
|
+ // window.yglob
|
|
370
|
+ return fn_gen[this.name].fn
|
|
371
|
+}
|
|
372
|
+
|
|
373
|
+function txt_dec_fn(fn){
|
|
374
|
+ return "ret.fn = "+ fn + ""
|
|
375
|
+}
|
|
376
|
+
|
|
377
|
+function reinit_helper(nforce,oforce,m){
|
|
378
|
+ var rforce = eval_helper2(txt_dec_fn(nforce),oforce)
|
|
379
|
+ clog("d3_re rf",m)
|
|
380
|
+ var i,k,v
|
|
381
|
+ var varr = []
|
|
382
|
+ for ([k,v] of entries(oforce)){
|
|
383
|
+ varr.push(k)
|
|
384
|
+ if (k=="reinit"){
|
|
385
|
+ // continue
|
|
386
|
+ }
|
|
387
|
+ if (v + "" == rforce[k] + ""){
|
|
388
|
+ rforce[k]=v
|
|
389
|
+ continue
|
|
390
|
+
|
|
391
|
+ } else if (!rforce[k]) {
|
|
392
|
+ rforce[k]=v
|
|
393
|
+ continue
|
|
394
|
+
|
|
395
|
+ } else {
|
|
396
|
+ clog("d3_re rfk",m,k)
|
|
397
|
+ rforce[k] = eval_helper2(txt_dec_fn(rforce[k]),oforce)
|
|
398
|
+ }
|
|
399
|
+
|
|
400
|
+ }
|
|
401
|
+ for ([k,v] of entries(rforce)){
|
|
402
|
+ if (varr.includes(k)){
|
|
403
|
+ continue
|
|
404
|
+ }
|
|
405
|
+ clog("d3_re rfk_",m,k)
|
|
406
|
+ rforce[k] = eval_helper2(txt_dec_fn(rforce[k]),oforce)
|
|
407
|
+ }
|
|
408
|
+ return rforce
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+}
|
|
412
|
+
|
|
413
|
+function dev_dec_gen2(fn_txt,name,args,that){
|
|
414
|
+ let txt = txt_dec_fn(fn_txt)
|
|
415
|
+ let fscope = fn_gen[name]
|
|
416
|
+ let evl_fn = eval_helper(txt,fscope.fn)
|
|
417
|
+ var nforce = evl_fn(...fn_gen[name].args)
|
|
418
|
+ // force.reinit
|
|
419
|
+ let evl_fn2 = reinit_helper(nforce,fscope.fn,{name})
|
|
420
|
+ /*
|
|
421
|
+ let evl_fn2 = eval_helper2(txt_dec_fn(nforce),fscope.fn)
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+ // fn_gen.forceManyBody_.fn
|
|
425
|
+ Object.assign(evl_fn2,fn_gen[name].fn)
|
|
426
|
+ // evl_fn2
|
|
427
|
+ evl_fn2.reinit = fn_gen[name].fn.reinit
|
|
428
|
+ // */
|
|
429
|
+ // fn_gen[name].fn = evl_fn(...fn_gen[name].args)
|
|
430
|
+ fn_gen[name].fn = evl_fn2
|
|
431
|
+}
|
|
432
|
+
|
|
433
|
+function dev_dec_gen2_(fn_txt,name,args,that){
|
|
434
|
+ let txt = txt_dec_fn(fn_txt)
|
|
435
|
+ let evl_fn = eval_helper(txt)
|
|
436
|
+ fn_gen[name].fn = evl_fn(...fn_gen[name].args)
|
|
437
|
+}
|
|
438
|
+
|
|
439
|
+function dev_dec_gen(fn_txt,name,args,that){
|
|
440
|
+ let txt = txt_dec_fn(fn_txt)
|
|
441
|
+ let evl_fn = eval_helper(txt)
|
|
442
|
+ if (!fn_gen[name]){
|
|
443
|
+ fn_gen[name] = {args:[]}
|
|
444
|
+ }
|
|
445
|
+ if (args){
|
|
446
|
+ fn_gen[name].args = args
|
|
447
|
+
|
|
448
|
+ }
|
|
449
|
+ fn_gen[name].fn = evl_fn(...fn_gen[name].args)
|
|
450
|
+ // glob_dev_fns[name] = evl_fn(...args)
|
|
451
|
+ glob_dev_fns[name] = new Proxy(fn_gen[name].fn,{name,...fn_gen.fn_prx})
|
|
452
|
+ // glob_dev_fns[name] = ret_fn.bind({name})
|
|
453
|
+ return glob_dev_fns[name]
|
|
454
|
+}
|
|
455
|
+
|
|
456
|
+fn_gen = window.fn_gen || {}
|
|
457
|
+fn_gen.fn_prx = {
|
|
458
|
+ apply:function(target,that,args){
|
|
459
|
+ return fn_gen[this.name].fn(...args)
|
|
460
|
+ },
|
|
461
|
+ // new Proxy(target, handler)
|
|
462
|
+
|
|
463
|
+}
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+glob_dbg.rfn_b = 0
|
|
469
|
+glob_dbg.rfn_c = 3
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+clog("d3_+",window.yglob,glob_dbg,jc(glob_dbg))
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+// yglob.d3.evl(`clog("d3_~");ret= `+glob_dev_fns.forceManyBody)()
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+// glob_dev_fns.forceLink
|
|
483
|
+
|
|
484
|
+/*
|
|
485
|
+var z = "tx_4"
|
|
486
|
+// var Z = "tx_3"
|
|
487
|
+// window.glob_dev_fns["tx_2"] = function(){
|
|
488
|
+window["glob_dev_fns"][`Z_${1}`] = function(){
|
|
489
|
+ clog("z3")
|
|
490
|
+ // console.trace("zq")
|
|
491
|
+ trc()
|
|
492
|
+}
|
|
493
|
+window["glob_dev_fns"][z] = function(){
|
|
494
|
+ clog("z4")
|
|
495
|
+ // console.trace("zq")
|
|
496
|
+ trc()
|
|
497
|
+}
|
|
498
|
+*/
|
|
499
|
+
|
|
500
|
+// glob_dev_fns["tx_2"]()
|
|
501
|
+// glob_dev_fns["tx_3"]()
|
|
502
|
+// glob_dev_fns["tx_4"]()
|