-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.js
222 lines (148 loc) · 4.65 KB
/
display.js
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
//$.ready(() =>
jsPlumb.ready(() => jsPlumb.setContainer($("#computationtree")[0]));
$(window).resize(() => jsPlumb.repaintEverything());
let _newidcounter = 0;
function getNewID()
{
_newidcounter++;
return "c" + _newidcounter;
}
function drawLine(element1, element2)
{
if(element1.attr('id') == undefined)
element1.attr('id', getNewID());
if(element2.attr('id') == undefined)
element2.attr('id', getNewID());
console.log(element1.attr('id'))
console.log(element2.attr('id'))
jsPlumb.connect({
source: element1.attr('id'),
target: element2.attr('id'),
anchors:[ "BottomCenter","TopCenter" ],
cssClass:"transition",
connector : "Straight",
endpoint: [ "Blank", {} ],
overlays:[
["Arrow" , { width:12, length:12, location:0.5 }]
]
//connector: [ "Bezier", 175 ],
// paintStyle:{ lineWidth:5, strokeStyle:'red' }
});
}
function stringTapeToHTML(tape) {
return tape.replace(/ /g, "_");
}
function tapeinHTML(tapestring, cursor) {
if(cursor > tapestring.length) {
return tapestring;
}
else {
var currentletter = tapestring[cursor];
if(currentletter == undefined)
currentletter = " ";
return stringTapeToHTML(tapestring.substr(0, cursor)) + "<span class='cursor'>" + stringTapeToHTML(currentletter) + "</span>" + stringTapeToHTML(tapestring.substr(cursor+1, 1000));
}
}
var clusterstack = new Array();
function indentationHTML()
{
return "<div class='indentation' style='width:" + (clusterstack.length * 8) + "px; float:left;'> </div>";
}
function isEndClusterState(state)
{
return "c" + getClusterNumber(configuration.state) + "end" == configuration.state.substr(0, configuration.state.indexOf("end")+3);
}
function getClusterNumber(state)
{
if(state == "0")
return 0;
else
return parseInt(configuration.state.substr(1));
}
var _elementFromConfiguration = new Map();
function setElementFromConfiguration(configuration, element)
{
return _elementFromConfiguration.set(configuration, element);
}
function getElementFromConfiguration(configuration)
{
return _elementFromConfiguration.get(configuration);
}
function configurations_print(configurations) {
$('#computationtree').append(getElementConfigurations(configurations));
for(let configuration of configurations)
{
let elementConfiguration = getElementFromConfiguration(configuration);
elementConfiguration.hide();
elementConfiguration.fadeIn("slow");
if(configuration.lastconfiguration != undefined)
setTimeout(() => drawLine(getElementFromConfiguration(configuration.lastconfiguration), getElementFromConfiguration(configuration)), 500);
}
}
function getElementConfigurations(configurations) {
let element = $("<div class='timestep'>");
for(let configuration of configurations)
{
let elementConfiguration = getElementConfiguration(configuration);
setElementFromConfiguration(configuration, elementConfiguration);
element.append(elementConfiguration);
}
return element;
}
function getElementConfiguration(configuration) {
if(configuration.message)
{
return $("<span class='configuration'>" + configuration.message + "</span>");
}
let imin = Math.max(configuration.cursor-3, 0);
let imax = configuration.cursor+3;
if(configuration.cursor < 4)
{
imin = 0;
imax = 7;
}
if(imin == 1)
imin = 0;
let element = $("<table class='configuration'>");
let tapeIndexElement = $("<tr>");
element.append(tapeIndexElement);
if(imin > 0)
tapeIndexElement.append($("<td></td>"));
for(let i = imin; i<=imax; i++) {
let cellElement = $("<td class='cellIndex'>" + i + "</td>");
tapeIndexElement.append(cellElement);
}
let tapeElement = $("<tr class='tape'>");
element.append(tapeElement);
if(imin > 0)
tapeElement.append($("<td class='tapedots'>...</td>"));
for(let i = imin; i<=imax; i++) {
let char = configuration.tape[i];
if(char == " ")
char = "_";
if(char == undefined)
char = "_";
let cellElement = $("<td class='cell'>" + char + "</td>");
if(configuration.cursor == i)
cellElement.addClass("currentcell");
if(i % 2 == 0)
cellElement.addClass("celleven");
tapeElement.append(cellElement);
}
tapeElement.append($("<td class='tapedots'>...</td>"));
let trcursorElement = $("<tr>");
element.append(trcursorElement);
if(imin > 0)
trcursorElement.append($("<td></td>"));
for(let i = imin; i<=imax; i++) {
if(configuration.cursor == i)
trcursorElement.append($("<td class='cursor'>" + configuration.state + "</td>"));
else
trcursorElement.append($("<td></td>"));
}
return element;
}
function displayInit()
{
$('#computationtree').empty();
}