-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.html
More file actions
826 lines (752 loc) · 37 KB
/
index.html
File metadata and controls
826 lines (752 loc) · 37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hypergraph 3D</title>
<meta charset="utf-8">
<meta content='width=device-width, height=device-height, minimum-scale=1, initial-scale=1.0' name='viewport'>
<link rel="icon" type="image/png" href="favicon.png">
<meta name="twitter:title" content="Hypergraph 3D">
<meta name="twitter:description" content="Hypergraph Rewriting System.">
<meta name="twitter:image" content="https://met4citizen.github.io/Hypergraph/screenshot.jpg">
<meta name="twitter:card" content="summary_large_image">
<meta name="google-site-verification" content="TtlGgWaxz0wpDLbTNSYXxis0n1eGc_3Pl3qMUSjugM8" />
<style>
html{ width:100%; height:100%; height: -webkit-fill-available; font-size: 10px; font-family: Verdana, Geneva, sans-serif; letter-spacing: -0.3px; }
body{ width: 100%; height: 100%; min-height: 100vh; min-height: -webkit-fill-available; margin: 0; padding: 0; background-color: white; color: black; line-height:1.5rem; overflow: hidden; cursor: crosshair; text-align: left; }
div.controls { margin: 2px; padding: 2px; position: fixed; z-index: 3; opacity: 0.7; cursor: default; pointer-events: none; }
span { display: inline-block; vertical-align: top; }
a { cursor: pointer; pointer-events: auto; }
hr { display: block; height: 1px; border: 0; border-top: 1px solid #ccc; margin: 4px 0; padding: 0; }
#topleft { top:0; left:0; z-index: 5; }
#topright { top:0; right:0; text-align: left; }
#bottomleft { bottom:0; left:0; margin-left: 42px; }
#bottomright { bottom:0; right:4px; text-align: right; }
#paused { position: fixed; z-index: 2; top:0; left:50%; width: 120px; margin-left: -60px; text-align: center; background-color: transparent; display:none; }
#paused span { background-color: white; padding: 0 10px; }
#logo { margin: 3px; padding: 3px; position: fixed; z-index: 3; opacity: 0.7; bottom: 0; left: 0; width: 32px; height: 32px; }
.button { display: inline-block; margin: 1px 0; padding: 0; background-color: black; color: white; width: 32px; height: 14px; border: 1px solid black; border-radius: 3px; font-size: 8px; font-weight: bold; line-height:14px; text-align: center; vertical-align: middle; cursor: pointer; pointer-events: auto; }
.button:active { opacity: 0.2; }
.button-disabled { opacity: 0.2; pointer-events: none; }
#red { background-color: hotpink; border-color: hotpink; }
#blue { background-color: deepskyblue; border-color: deepskyblue; }
#grad { background-image: linear-gradient(to right, #00b4b4, #00b9a1, #2fbc86, #59bd66, #80bb43, #97af29, #aaa110, #bb9200, #bc7900, #bc5d00, #b93d00, #b40000); border-color: lightgrey; }
#stop, #reheat, #red-result-label, #blue-result-label, #grad-result-label { display: none; }
#cancel { float: right; margin: 0 0 0 10px; padding: 0;}
.text { display: inline-block; margin: 0 0 0 3px; padding: 0 5px; background-color: transparent; color: black; width: auto; line-height: 16px; font-size: 10px; font-weight: bold; text-align:left; text-transform: lowercase; vertical-align: top; }
.text-disabled { opacity: 0.2; }
.text[contenteditable="true"] { min-width: 320px; -webkit-touch-callout: text; -webkit-user-select: text; -khtml-user-select: text; -moz-user-select: text; -ms-user-select: text; user-select: text; opacity: 1; }
div.settings { margin:4px 0 15px 46px; padding:0; display: none; }
div.settings a { display: inline-block; color: inherit; text-decoration: inherit; pointer-events: auto; }
#rule-opt { display: block; margin:0 0 4px 46px; padding:0; pointer-events: none; white-space: nowrap; clear:both; }
#rule-opt span { display: inline-block; margin: 0 1px; padding: 0 2px; height:12px; background-color: transparent; color: grey; border: 1px solid grey; border-radius: 3px; font-size: 7px; font-weight: bold; line-height: 12px; text-align: center; vertical-align: middle; }
#visual { display:block; text-align: left; margin: 2px 0 0 0; width: 110px; padding:0; line-height: 10px; }
input[type=range] { width: 100%; margin: 0; }
#distance-range, #decay-range { cursor: pointer; pointer-events: auto; }
.option { display: inline-block; margin: 0; padding: 0 1px; height:14px; background-color: transparent; color: black; border: 1px solid transparent; border-radius: 3px; font-size: 8px; font-weight: bold; line-height: 14px; text-align: center; vertical-align: middle; cursor: pointer; pointer-events: auto; }
.view { width: 30px }
.selected { border: 1px solid grey; }
.label { display: inline-block; line-height: 16px; font-size: 8px; font-weight: bold; text-align:left; text-transform: uppercase; color: grey; margin: 2px; min-width: 4px; }
.status { min-width: 38px; }
#grad-result { min-width: 80px; }
.up { position: absolute; transform: translateY(-17px); z-index: -1; }
.down { position: absolute; transform: translateY(15px); z-index: -1; }
.up:before, .down:before { content: "|"; }
#progress, #progress2 { position:fixed; width: 300px; height: 76px; z-index: 15; top: 40%; left: 50%; margin: 0 0 0 -150px; padding: 5px 10px; background-color: white; border: 1px solid lightgrey; box-shadow: 6px 6px 4px 1px rgba(128, 128, 128, .2); display: none; }
#progress span.status, #progress2 span.status { min-width: 46px; }
span.status:nth-child(2) { min-width: 36px !important; }
#progress-bar, #progress2-bar { display: inline-block; width: 250px; background-color: #e0e0e0; margin: 0; padding: 0; line-height: 16px; height: 16px; border-radius: 3px; }
#progress-bar-fill, #progress2-bar-fill { display: inline-block; height: 16px; background-color: #659cef; border-radius: 3px; transition: width 100ms ease-in-out; }
.noselect { -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; }
.nodeLabelGraph3d, .linkLabelGraph3d { display: inline-block; background-color: olive; color: white; font-size: 14px; font-weight: bold; line-height: 20px; padding: 0 4px; height: auto; min-width: 14px; border-radius: 4px; text-align: center; vertical-align: middle; }
</style>
<script type="importmap">
{ "imports":
{
"three": "https://cdn.jsdelivr.net/npm/three@0.180.0/build/three.module.js/+esm",
"three/examples/": "https://cdn.jsdelivr.net/npm/three@0.180.0/examples/",
"forcegraph": "https://cdn.jsdelivr.net/npm/3d-force-graph@1.79.0/+esm"
}
}
</script>
<script nomodule>alert("You browser doesn't seem to support modules. Use a modern desktop browser to run Hypergraph 3D.");</script>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha256-4+XzXVhsDmqanXGHaHvgh1gMQKX40OUvDEBTu8JcmNs=" crossorigin="anonymous"></script>
<script type="module">
import { Simulator } from "./modules/Simulator.mjs";
function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.href);
return results === null ? false : decodeURIComponent(results[1].replace(/\+/g, ' '));
}
$(document).ready(function() {
// Hypergraph object and define colors, sizes and widths for different graph styles
// Note: use CSS to define node label style .nodeLabelGraph3d
const canvas = document.getElementById("3d-graph");
const status = document.getElementById("status");
const sim = new Simulator( canvas, status );
window.sim = sim; // TODO: REMOVE THIS AFTER DEBUGGING
// Monitor inactivity
let idleTimer = null;
const idleTimeout = 6000;
// Pause rendering cycle
function pause() {
sim.G.FG.pauseAnimation();
$("#paused").show();
}
// Resume rendering cycle
function resume() {
sim.G.FG.resumeAnimation();
$(".text").prop("contenteditable","false").blur();
$(".settings, #paused").hide();
$("#topleft").css("pointer-events","none");
if ( idleTimer ) { clearTimeout( idleTimer ); idleTimer = null; }
}
// Resume rendering cycle
function resumeTimeout() {
resume();
idleTimer = setTimeout( function() {
if ( !$("#paused").is(":visible") && $("#play").is(":visible") ) {
pause();
}
}, idleTimeout );
}
// Resume when controls active
sim.G.FG.controls().addEventListener( 'start', resume );
sim.G.FG.controls().addEventListener( 'end', resumeTimeout );
// Dynamics
function force() {
let distance = parseInt( $("#distance-range").val(), 10 );
let decay = parseInt( $("#decay-range").val(), 10 );
sim.G.force( distance, decay );
sim.G.refresh();
resumeTimeout();
}
// Window resize event, resume and update graph dimensions
$(window).on('resize', function(){
sim.G.size( $(this).width(), $(this).height() );
resumeTimeout();
});
// Paste as plain text (work-a-round)
document.querySelector('.text').addEventListener('paste', function (event) {
event.preventDefault();
document.execCommand('inserttext', false, event.clipboardData.getData('text/plain'));
});
// Open settings dialogs
[ "#rule", "#red", "#blue", "#grad" ].forEach( x => {
$(x).on("click", function() {
if ( $(x+"-settings").is(":visible") ) {
resumeTimeout();
} else {
pause();
$(x+"-text").prop("contenteditable","true").focus();
$(x+"-settings").show();
$("#topleft").css("pointer-events","auto");
}
});
});
// Check the rule
$("#rule-check").on("click", function() {
try {
var rulestr = $("#rule-text")[0].innerText.split("\n").join(";").replace(/;$/g,"");
var validated = sim.validateRule( rulestr );
$("#rule-text").html( validated );
}
catch (e) {
if (e instanceof RangeError || e instanceof TypeError) {
console.log(e.stack);
alert(e);
} else {
console.log(e.stack);
alert("Unknown error, sorry for this.");
}
}
});
// Run the given rule
$("#rule-run").on("click", function() {
try {
// parameters
let r = $("#rule-text")[0].innerText.split("\n").join(";").replace(/;$/g,"");
let i = $(".interactions.selected").toArray().reduce( (a,x) => a | $(x).data("value"), 0 );
let e = $(".evolution.selected").data("value");
$("#playstop, #playnext, #playprevious, #finalreheat").addClass('button-disabled');
if ( $("#stop").is(":visible") ) {
sim.stop();
$("#playstop").css("background-color","black");
$("#play, #stop").toggle();
}
$("#progress-bar-fill").css("width", "0");
$("#progress").show();
// Run rules
let opt = {
interactions: i,
evolution: e,
noduplicates: Boolean($(".noduplicates.selected").length),
deduplicate: Boolean($(".deduplicate.selected").length),
wolfram: Boolean($(".wolfram.selected").length),
rulendx: Boolean($(".rulendx.selected").length)
};
// Show options
$(".filtertime").removeClass("selected").first().addClass("selected");
$(".filterbranch").removeClass("selected");
if ( e === 1 ) {
$("#brachlike").hide();
} else {
$("#brachlike").show();
}
if ( e === 0 || e === 4 ) {
$(".filterbranch[data-value='4']").show();
$(".filterbranch[data-value='8']").show();
} else {
$(".filterbranch[data-value='4']").hide();
$(".filterbranch[data-value='8']").hide();
}
sim.run( r, opt, function(o) {
$("#progress-bar-fill").css("width", Math.min(100, Math.round( 100 * o.progress) )+"%" );
let status = "";
Object.keys(o).forEach( k => {
if ( k !== 'progress' ) {
status += '<span class="label down">'+k
+'</span><span class="label status">'+o[k]+'</span>';
}
});
$("#progress-status").html( status );
}, function() {
// Rule-opt
let selected = [
...$(".evolution.selected").toArray(),
...$(".interactions.selected").toArray(),
...$(".noduplicates.selected").toArray(),
...$(".deduplicate.selected").toArray(),
...$(".wolfram.selected").toArray(),
...$(".rulendx.selected").toArray()
];
let opt = "";
selected.forEach( x => {
opt += "<span>" + $(x).data("label") + "</span>";
});
$("#rule-opt").html( opt );
$("#progress").hide();
$("#playstop, #finalreheat").removeClass('button-disabled').css("background-color","black");
$(".view.selected").click();
});
}
catch (e) {
$("#progress").hide();
if (e instanceof RangeError || e instanceof TypeError) {
console.log(e.stack);
alert(e);
} else {
console.log(e.stack);
alert("Unknown error, sorry for this.");
}
}
});
// Cancel running the rule
$("#cancel").on("click", function() {
sim.cancel();
});
// Show/hide red/blue subgraph
[ "#red", "#blue" ].forEach( (x,i) => {
$(x+"-show").on("click", function() {
try {
const cmd = $(x+"-text")[0].innerText.split("\n").join(";").replace(/;$/g,"");
const style = i+1;
const element = $(x+"-result")[0];
const surface = $("."+x.substring(1)+"-surface.selected").length;
const background = $(".background.selected").length;
sim.setHighlight( cmd, style, element, surface, background );
$(x+"-result-label").show();
$(x+"-text").removeClass("text-disabled");
resumeTimeout();
}
catch(e) {
if (e instanceof RangeError || e instanceof TypeError) {
console.log(e.stack);
alert(e);
} else {
console.log(e.stack);
alert("Unknown error, sorry for this.");
}
}
});
$(x+"-hide").on("click", function() {
try {
sim.clearHighlight( i+1 );
$(x+"-result-label").hide();
$(x+"-text").addClass("text-disabled");
resumeTimeout();
}
catch(e) {
if (e instanceof RangeError || e instanceof TypeError) {
console.log(e.stack);
alert(e);
} else {
console.log(e.stack);
alert("Unknown error, sorry for this.");
}
}
});
$(x+"-settings a").on("click", function(e) {
e.preventDefault();
$(x+"-text").html( $(this).data("value") );
$(x+"-show").click();
});
});
// Show fields
$("#grad-show").on("click", function() {
try {
const command = $("#grad-text")[0].innerText.split("\n").join(";").replace(/;$/g,"");
const element = $("#grad-result")[0];
const opt = {
smooth: Boolean($(".smooth.selected").length)
};
sim.setField( command, element, opt );
$("#grad-result-label").show();
$("#grad-text").removeClass("text-disabled");
resumeTimeout();
}
catch(e) {
if (e instanceof RangeError || e instanceof TypeError) {
console.log(e.stack);
alert(e);
} else {
console.log(e.stack);
alert("Unknown error, sorry for this.");
}
}
});
$("#grad-settings a").on("click", function(e) {
e.preventDefault();
$("#grad-text").html( $(this).data("value") );
$("#grad-show").click();
});
// Hide fields
$("#grad-hide").on("click", function() {
sim.clearField();
$("#grad-result-label").hide();
$("#grad-text").addClass("text-disabled");
resumeTimeout();
});
// Branches
$(".evolution").on("click", function(e) {
$(".evolution").removeClass("selected");
$(this).addClass("selected");
});
// Single-options
[ "interactions","noduplicates","deduplicate","wolfram","rulendx","red-surface","blue-surface", "smooth" ].forEach( x => {
$("."+x).on("click", function() { $(this).toggleClass("selected"); } );
});
$(".background").on("click", function() { $(".background").toggleClass("selected"); } );
// View specific settings and defaults
let decay = new Map();
let distance = new Map();
let cameraz = new Map();
distance.set("space",20);
decay.set("space",70);
cameraz.set("space", 750 );
distance.set("time",10);
decay.set("time",50);
cameraz.set("time", 750 );
distance.set("phase",30);
decay.set("phase",80);
cameraz.set("phase", 750 );
$("#distance-range").val( distance.get( "space" ) );
$("#decay-range").val( decay.get("space") );
// Mode/reset
$(".view").on("click", function(e) {
// Save current settings
let view = $(".view.selected").data("value");
distance.set(view,parseInt( $("#distance-range").val(), 10 ));
decay.set(view,parseInt( $("#decay-range").val(), 10 ));
cameraz.set(view,parseInt(sim.G.FG.cameraPosition().z,10));
$(".view").removeClass("selected");
$(this).addClass("selected");
// Reset graph
view = $(this).data("value");
let past = Boolean( $(".past.selected").length );
let branches = $(".branches.selected").toArray().reduce( (a,x) => a | $(x).data("value"), 0 );
sim.setRefFrame( {
view: view,
leaves: !past,
branches: branches
});
// Restore previous settings
$("#distance-range").val( distance.get( view ) || 20 );
$("#decay-range").val( decay.get( view ) || 20 );
let z = cameraz.get(view) || 750;
sim.G.FG.cameraPosition( { x: 0, y: 0, z: z }, { x: 0, y: 0, z: 0 } );
$("#playstop").removeClass("button-disabled").css("background-color","black");
if ( view === 'space' ) {
$("#playnext").removeClass('button-disabled');
$("#playprevious").addClass("button-disabled");
} else {
$("#playnext, #playprevious").addClass("button-disabled");
}
$("#play, #final").show();
$("#stop, #reheat").hide();
resumeTimeout();
});
// Filter
$(".past").on("click", function(e) {
$(this).toggleClass("selected");
sim.setRefFrame( {
leaves: !$(this).hasClass("selected")
});
resumeTimeout();
});
$(".branches").on("click", function(e) {
let all = $(this).data("value") === 0;
if ( all ) {
if ( !$(this).hasClass("selected") ) {
$(".branches").removeClass("selected").first().addClass("selected");
}
} else {
$(".branches").first().removeClass("selected");
$(this).toggleClass("selected");
if ( $(".branches.selected").length === 0 ) {
$(".branches").first().addClass("selected");
}
}
let branches = $(".branches.selected").toArray().reduce( (a,x) => a | $(x).data("value"), 0 );
sim.setRefFrame( {
branches: branches
});
resumeTimeout();
});
// Play / stop animation
$("#playstop").on("click", function() {
try {
if ( $("#play").is(":visible") ) {
sim.play( function() { $("#finalreheat").click(); } );
$("#playstop").css("background-color","darkred");
$("#playnext, #playprevious").addClass("button-disabled");
$("#play, #stop").toggle();
force();
resume();
} else {
sim.stop();
$("#playstop").css("background-color","black");
if ( $(".view.selected").data("value") == 'space' ) {
if ( sim.pos >= sim.multiway.EV.length ) {
$("#playnext").addClass("button-disabled");
} else {
$("#playnext").removeClass("button-disabled");
}
if ( sim.pos > 0 ) {
$("#playprevious").removeClass("button-disabled");
} else {
$("#playprevious").addClass("button-disabled");
}
}
$("#play, #stop").toggle();
resumeTimeout();
}
}
catch(e) {
if (e instanceof RangeError || e instanceof TypeError) {
console.log(e.stack);
alert(e);
} else {
console.log(e.stack);
alert("Unknown error, sorry for this.");
}
}
});
// Play next step
$("#playnext").on("click", function() {
try {
if ( !sim.tick() ) {
$("#playnext").addClass("button-disabled");
$("#finalreheat").click();
}
$("#playprevious").removeClass("button-disabled");
sim.stop();
resume();
}
catch(e) {
if (e instanceof RangeError || e instanceof TypeError) {
console.log(e.stack);
alert(e);
} else {
console.log(e.stack);
alert("Unknown error, sorry for this.");
}
}
});
// Play previous step
$("#playprevious").on("click", function() {
try {
if ( !sim.tick(1, true) ) {
$("#playprevious").addClass("button-disabled");
}
$("#playnext").removeClass("button-disabled");
$("#playstop").removeClass("button-disabled").css("background-color","black");
$("#play, #final").show();
$("#stop, #reheat").hide();
sim.stop();
resume();
}
catch(e) {
if (e instanceof RangeError || e instanceof TypeError) {
console.log(e.stack);
alert(e);
} else {
console.log(e.stack);
alert("Unknown error, sorry for this.");
}
}
});
// Final state
$("#finalreheat").on("click", function() {
try {
sim.final();
$("#playstop").addClass("button-disabled").css("background-color","black");
if ( $(".view.selected").data("value") == 'space' ) {
$("#playnext").addClass("button-disabled");
$("#playprevious").removeClass("button-disabled");
}
$("#play, #reheat").show();
$("#stop, #final").hide();
resumeTimeout();
}
catch(e) {
if (e instanceof RangeError || e instanceof TypeError) {
console.log(e.stack);
alert(e);
} else {
console.log(e.stack);
alert("Unknown error, sorry for this.");
}
}
});
// Changed distance/decay
$(document).on('input change keyup', '#distance-range,#decay-range', function() {
force();
});
// Copy URL link for the current rule to clipboard
$("#url").on("click", function() {
let rfn = (a,x) => a | $(x).data("value");
let i = $(".interactions.selected").toArray().reduce( rfn, 0 );
let e = $(".evolution.selected").data("value");
let v = $(".view.selected").data("value");
let b = $(".branches.selected").toArray().reduce( rfn, 0 );
let tfn = (s) => encodeURIComponent($(s)[0].innerText.split("\n").join(";").replace(/;$/g,"")).replace(/%2C/g,",").replace(/%3B/g,";");
let url = window.location.href.split('?')[0]
+ "?rule=" + tfn("#rule-text")
+ ( i !== 1 ? "&i=" + encodeURIComponent(i) : "" )
+ ( e !== 1 ? "&e=" + encodeURIComponent(e) : "" )
+ ( v !== "space" ? "&mode=" + encodeURIComponent(v) : "" )
+ ( Boolean($(".past.selected").length) ? "p=1" : "" )
+ ( b !== 0 ? "&b=" + encodeURIComponent(b) : "" )
+ ( Boolean($(".noduplicates.selected").length) ? "&nd=1" : "" )
+ ( Boolean($(".deduplicate.selected").length) ? "&dd=1" : "" )
+ ( Boolean($(".wolfram.selected").length) ? "&wm=1" : "" )
+ ( Boolean($(".rulendx.selected").length) ? "&ro=1" : "" )
+ ( !$("#red-text").hasClass("text-disabled") ? "&red=" + tfn("#red-text") : "" )
+ ( !$("#blue-text").hasClass("text-disabled") ? "&blue=" + tfn("#blue-text") : "" )
+ ( !$("#grad-text").hasClass("text-disabled") ? "&grad=" + tfn("#grad-text") : "" );
var $temp = $("<input>");
$("body").append($temp);
$temp.val(url).select();
document.execCommand("copy");
$temp.remove();
alert( "The following URL copied to clipboard:\n\n" + url );
});
// Specify the initial rule and settings and run it
function firstrun() {
let tfn = (s,p,d) => {
let v = getUrlParameter(p);
$(s).html($("<p>").html(v||d).text().split(";").join("<br>") );
}
tfn("#rule-text","rule","(1,2)(1,3)->(1,2)(1,4)(2,4)(3,4)");
tfn("#red-text","red","nball(x,2)");
tfn("#blue-text","blue","geodesic(y,100)");
tfn("#grad-text","grad","branch");
let ofn = (p,d,s) => parseInt(getUrlParameter(p)||d) ? $("."+s).addClass("selected") :$("."+s).removeClass("selected");
ofn("nd",0,"noduplicates");
ofn("dd",0,"deduplicate");
ofn("wm",0,"wolfram");
ofn("ro",0,"rulendx");
ofn("p",0,"past");
let i = parseInt( getUrlParameter('i') || "1" );
$(".interactions").each( function() {
let val = $(this).data("value");
if ( i & $(this).data("value") ) {
$(this).addClass("selected");
} else {
$(this).removeClass("selected");
}
});
let e = getUrlParameter('e') || "1";
if ( $(".evolution[data-value='" + e + "']").length ) {
$(".evolution").removeClass("selected");
$(".evolution[data-value='" + e + "']").addClass("selected");
}
let view = getUrlParameter('mode') || "space";
$("#"+view+".view").click();
$("#rule-run").click();
let l = parseInt( getUrlParameter('l') || "0" );
$(".branches").removeClass("selected").each( function() {
let val = $(this).data("value");
if ( (l === val) || ( l>0 && val>0 && (l & val) ) ) {
$(this).addClass("selected");
} else {
$(this).removeClass("selected");
}
});
if ( getUrlParameter("red") ) $("#red-show").click();
if ( getUrlParameter("blue") ) $("#blue-show").click();
if ( getUrlParameter("grad") ) $("#grad-show").click();
}
// Autorun the first time
firstrun();
});
</script>
</head>
<body>
<div id="topleft" class="controls noselect">
<span title="Change rule" id ="rule" class="button">RULE</span>
<span id="rule-text" class="text" spellcheck="false"></span><br/>
<div id="rule-settings" class="settings">
<span title="Run rule" id ="rule-run" class="button">RUN</span>
<span title="Validate rule" id ="rule-check" class="button">SCAN</span>
<span class="label down">Evolution</span>
<span title="Singleway" class="option evolution selected" data-value="1" data-label="SINGLE">1</span>
<span title="2-way" class="option evolution" data-value="2" data-label="2-WAY">2</span>
<span title="4-way" class="option evolution" data-value="4" data-label="4-WAY">4</span>
<span title="Full multiway" class="option evolution" data-value="0" data-label="MULTI">MULTI</span>
<span class="label down">Interactions</span>
<span title="Spacelike" class="option interactions selected" data-value="1" data-label="SPACELIKE">SPACE</span>
<span title="Timelike" class="option interactions" data-value="2" data-label="TIMELIKE">TIME</span>
<span title="Branchlike" class="option interactions" data-value="4" data-label="BRANCHLIKE">BRANCH</span>
<span class="label down">Options</span>
<span title="Wolfram Model" class="option wolfram" data-label="WM">WM</span>
<span title="Rule order Index" class="option rulendx" data-label="RO">RO</span>
<!-- <span title="No duplicates" class="option noduplicates" data-label="ND">ND</span> -->
<span title="De-duplicate" class="option deduplicate" data-label="DD">DD</span>
</div>
<span id="red" class="button">RED</span>
<span id="red-text" class="text text-disabled" spellcheck="false">nball(100,2)</span><br/>
<div id="red-settings" class="settings">
<span title="Show red" id="red-show" class="button">RUN</span>
<span title="Hide red" id="red-hide" class="button">HIDE</span>
<span>
<a href="//curv" data-value="curv(x,y)">curv</a>
<a href="//dim" data-value="dim(x)">dim</a>
<a href="//geodesic" data-value="geodesic(x,y)">geodesic</a>
<a href="//lightcone" data-value="lightcone(x,1)">lightcone</a>
<a href="//phase" data-value="phase(x,y)">phase</a>
<a href="//nball" data-value="nball(x,1)">nball</a><br/>
<a href="//nsphere" data-value="nsphere(x,1)">nsphere</a>
<a href="//random" data-value="random(x,10)">random</a>
<a href="//surface" data-value="surface(x,y)">surface</a>
<a href="//worldline" data-value="worldline(x)">worldline</a>
</span>
<span class="label down">Options</span>
<span title="Show background" class="option background selected">BACK</span>
<span title="Show hypersurfaces" class="option red-surface selected">FACES</span>
</div>
<span id="blue" class="button">BLUE</span>
<span id="blue-text" class="text text-disabled" spellcheck="false"></span><br/>
<div id="blue-settings" class="settings">
<span title="Show blue" id ="blue-show" class="button">RUN</span>
<span title="Hide blue" id ="blue-hide" class="button">HIDE</span>
<span>
<a href="//curv" data-value="curv(x,y)">curv</a>
<a href="//dim" data-value="dim(x)">dim</a>
<a href="//geodesic" data-value="geodesic(x,y)">geodesic</a>
<a href="//lightcone" data-value="lightcone(x,1)">lightcone</a>
<a href="//phase" data-value="phase(x,y)">phase</a>
<a href="//nball" data-value="nball(x,1)">nball</a><br/>
<a href="//nsphere" data-value="nsphere(x,1)">nsphere</a>
<a href="//random" data-value="random(x,10)">random</a>
<a href="//surface" data-value="surface(x,y)">surface</a>
<a href="//worldline" data-value="worldline(x)">worldline</a>
</span>
<span class="label down">Options</span>
<span title="Show background" class="option background selected">BACK</span>
<span title="Show hypersurfaces" class="option blue-surface selected">FACES</span>
</div>
<span id="grad" class="button">GRAD</span>
<span id="grad-text" class="text text-disabled" spellcheck="false">energy</span><br/>
<div id="grad-settings" class="settings">
<span title="Show field" id ="grad-show" class="button">RUN</span>
<span title="Hide field" id ="grad-hide" class="button">HIDE</span>
<span>
<a href="//branch" data-value="branch">branch</a>
<a href="//created" data-value="created">created</a>
<a href="//curvature" data-value="curvature">curvature</a>
<a href="//degree" data-value="degree">degree</a><br>
<a href="//energy" data-value="energy">energy</a>
<a href="//mass" data-value="mass">mass</a>
<a href="//momentum" data-value="momentum">momentum</a><br>
<a href="//pathcnt" data-value="pathcnt">pathcnt</a>
<a href="//phase" data-value="phase(x)">phase</a>
<a href="//probability" data-value="probability(x)">probability</a>
<a href="//step" data-value="step">step</a>
</span>
<span class="label down">Options</span>
<span title="Smooth" class="option smooth">SMOOTH</span>
</div>
</div>
<div id="topright" class="controls noselect">
<span id="space" title="Spatial graph" class="option view selected" data-value="space">SPACE</span>
<span id="time" title="Causal graph" class="option view" data-value="time">TIME</span>
<span id="phase" title="Branchial graph" class="option view" data-value="phase">PHASE</span><br>
<span class="label down">Mode/simulation</span>
<span title="Play/pause" id="playstop" class="button button-disabled" style="width:24px;">
<svg id="play" viewBox="4 0 24 16"><polygon fill="white" points="14,3 14,11 20,7"/></svg>
<svg id="stop" viewBox="4 0 24 14"><polygon fill="white" points="12,3 15,3 15,11 12,11"/><polygon fill="white" points="17,3 20,3 20,11 17,11"/></svg>
</span>
<span title="Previous" id="playprevious" class="button" style="width:24px;">
<svg id="previous" viewBox="4 0 24 16"><polygon fill="white" points="10,7 15,11 15,3"></polygon><polygon fill="white" points="18,3 20,3 20,11 18,11"></polygon></svg>
</span>
<span title="Next" id="playnext" class="button" style="width:26px;">
<svg id="next" viewBox="4 0 24 16"><polygon fill="white" points="17,3 17,11 22,7"></polygon><polygon fill="white" points="12,3 14,3 14,11 12,11"></polygon></svg>
</span>
<span title="End/reheat" id="finalreheat" class="button button-disabled" style="width:24px;">
<svg id="reheat" viewBox="4 0 24 14"><path fill="white" d="M16.1 10.2c-2 0-3-1-3.1-3S14 4 15.7 3.9c1.8-.1 2.1 1.1 2.1 1.1L16.7 6.3h4V2.5l-1.3 1C18.4 2.4 17.5 2 16 2C13 2 11 4 11 7S12.9 11.8 16 12c3.1-.3 4.2-2 4.5-4h-2.1c-.3 1.2-1 2-2.3 2.2z"/></svg>
<svg id="final" viewBox="4 0 24 14"><polygon fill="white" points="12,3 12,11 18,7"/><polygon fill="white" points="18,3 20,3 20,11 18,11" /></svg>
</span>
<br><br><hr>
<span title="All branches" class="option branches selected" data-value="0">ALL</span>
<span title="Branch #1" class="option branches" data-value="1">1</span>
<span title="Branch #2" class="option branches" data-value="2">2</span>
<span title="Branch #3" class="option branches" data-value="4">3</span>
<span title="Branch #4" class="option branches" data-value="8">4</span>
<span style="color: lightgrey">|</span>
<span title="Show past" class="option past">PAST</span>
<div id="visual">
<input id="distance-range" type="range" value="20" min="0" max="100"><br>
<span class="label down">Observer/shape</span>
<input id="decay-range" type="range" value="20" min="0" max="100"><br>
</div>
</div>
<div id="bottomleft" class="controls noselect">
<span class="label up">Docs</span>
<span title="Source/docs" class="label"><a href="https://github.com/met4citizen/Hypergraph" target="_blank">github</a></span>
<span class="label up">Mouse</span>
<span class="label">left-rotate wheel-zoom right-pan</span>
</div>
<div id="bottomright" class="controls noselect">
<span id="rule-opt"></span><br>
<span id="red-result-label" class="label up">Red</span>
<span id="red-result" class="label status"></span>
<span id="blue-result-label" class="label up">Blue</span>
<span id="blue-result" class="label status"></span>
<span id="grad-result-label" class="label up">Grad</span>
<span id="grad-result" class="label status"></span>
<span id="status"></span>
<span class="label up">Share</span>
<span title="Copy URL" id="url" class="button">URL</span>
</div>
<div id="3d-graph" class="noselect"></div>
<div id="paused" class="noselect"><span class="label">Paused</span></div>
<div id="progress" class="noselect">
<span id="progress-label" class="label">|Rewriting</span><br>
<div id="progress-bar"><span id="progress-bar-fill"></span></div>
<span id="cancel" class="button">STOP</span><br>
<span id="progress-status"></span>
</div>
<img id="logo" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAABTQAAAU0Bu8Ff3QAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAjcSURBVHic7Zp7sFZVFcB/6z7gyuVp6b0wloooMmJeX1gMZgw4iqIwRkXW+Bg1SfMyI3/QjMIEkpM3tcamRPNBKaLWmCamQgFZI4RKlpnIQ0BKAoV7uYASj7v6Y63D3RzO+e537vd9fM1w18yec/bea++99jp7PfcRVeVIhopyE1Bu6GJAuQkoN3QxoNwElBu6GFBuAgBE5GYRWSsiow732v8XDADGAAOBLx/uhasO94IpcBuwDmg63AtLlyd4hMMRz4CS6wAROQr4EnAxcK6vKbQzfxXwF2A5sEJVd+eY63zgRqAa+C/wtKrOL4i+UuoAEekBvA2ckOeQvcBbwDJgKbBUVdcG8w0DPgB2Ysz8LTA0xMlMY4kZcAdwe4HTbMGYsQnoA/QF6oAhwJ2qOqug2VW1JMWJ/QDQWNkJtCW0ZynPAQOLQmeJNt8TeN2JXQx8AzgWqPL+KqA/cDbwZsbNbwUqi0Vr0ZWgiAjwS6AB+C7QpDE5U9V92JHeJCKXAxu863fASuyI1wH1wKd8423APuDnqrq/aPSWQgeIyELgGFVtyBP/I2yjQ1R1ZdEJygGl8gMmAgtE5MQ88f/pz+0loicVSsIAVd0KTANGicgzIrJKRNaLyGoReVxExsSGvOPP1lLQkxNKpAQvA/5NbmX2MjDY8WcD+2JzVADnATOBVzHdsAHYDKzHLMHtQM+SWgGgOzAMODoP3FrggQ42HpZm3+R8r3fzeRqAtXnOsQpoyHMfvTvDgGMwU7YbeAYYHx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