-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.html
More file actions
317 lines (290 loc) · 9.02 KB
/
debug.html
File metadata and controls
317 lines (290 loc) · 9.02 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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>AST Debugger</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/7.8.5/d3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3-graphviz/5.0.2/d3-graphviz.min.js"></script>
<style>
body {
font-family:
-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
margin: 10px;
background: #fafafa;
font-size: 14px;
}
#graph {
border: 1px solid #ddd;
background: white;
border-radius: 4px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
min-height: 800px;
}
.toolbar {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
padding: 8px;
background: white;
border: 1px solid #ddd;
border-radius: 4px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.file-input input[type="file"] {
display: none;
}
.file-input label {
background: #007acc;
color: white;
border: none;
padding: 6px 12px;
border-radius: 3px;
cursor: pointer;
font-size: 13px;
}
.file-input label:hover {
background: #005a9e;
}
button {
background: #f5f5f5;
color: #333;
border: 1px solid #ccc;
padding: 6px 12px;
border-radius: 3px;
cursor: pointer;
font-size: 13px;
}
button:hover:not(:disabled) {
background: #e8e8e8;
}
button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.step-controls {
display: flex;
align-items: center;
gap: 8px;
}
#stepInput,
#stepByInput {
width: 60px;
padding: 4px 6px;
border: 1px solid #ccc;
border-radius: 3px;
font-size: 13px;
}
.step-info {
color: #666;
font-size: 13px;
margin-left: auto;
}
.playing {
background: #dc3545 !important;
color: white !important;
}
.playing:hover {
background: #c82333 !important;
}
</style>
</head>
<body>
<div class="toolbar">
<div class="file-input">
<input type="file" id="fileInput" multiple accept=".dot" />
<label for="fileInput">Load .dot files</label>
</div>
<div class="step-controls">
<button id="prevBtn" disabled>◀</button>
<button id="nextBtn" disabled>▶</button>
<span>Step:</span>
<input type="number" id="stepInput" min="1" disabled />
<span>Jump by:</span>
<input type="number" id="stepByInput" min="1" value="1" />
<button id="playBtn" disabled>Play</button>
</div>
<div class="step-info">
<span id="fileCount">No files loaded</span>
</div>
</div>
<div id="graph"></div>
<script>
let dotStrings = [];
let currentIndex = 0;
let autoInterval = null;
// Initialize the graphviz renderer
const graphviz = d3
.select("#graph")
.graphviz()
.transition(function () {
return d3.transition("main").ease(d3.easeLinear).duration(500);
});
// Update step counter and input
function updateStepCounter() {
const stepInput = document.getElementById("stepInput");
if (dotStrings.length > 0) {
stepInput.value = currentIndex + 1;
stepInput.max = dotStrings.length;
} else {
stepInput.value = "";
stepInput.max = 0;
}
}
// Update file count display
function updateFileCount(count) {
const fileCount = document.getElementById("fileCount");
if (count === 0) {
fileCount.textContent = "No files loaded";
} else {
fileCount.textContent = `${count} step${count > 1 ? "s" : ""} loaded`;
}
}
// Get current step by value
function getStepBy() {
const stepBy = parseInt(document.getElementById("stepByInput").value);
return isNaN(stepBy) || stepBy < 1 ? 1 : stepBy;
}
// Jump to specific step
function jumpToStep(step) {
if (step >= 1 && step <= dotStrings.length) {
currentIndex = step - 1;
renderCurrentGraph();
}
}
// Render current graph
function renderCurrentGraph() {
if (dotStrings.length === 0) return;
graphviz.renderDot(dotStrings[currentIndex]);
updateStepCounter();
updateButtons();
}
// Update button states
function updateButtons() {
const hasFiles = dotStrings.length > 0;
document.getElementById("prevBtn").disabled =
!hasFiles || currentIndex === 0;
document.getElementById("nextBtn").disabled =
!hasFiles || currentIndex === dotStrings.length - 1;
document.getElementById("playBtn").disabled =
!hasFiles || dotStrings.length < 2;
document.getElementById("stepInput").disabled = !hasFiles;
}
// Toggle play/stop
function togglePlayback() {
const playBtn = document.getElementById("playBtn");
if (autoInterval) {
// Stop playing
clearInterval(autoInterval);
autoInterval = null;
playBtn.textContent = "Play";
playBtn.classList.remove("playing");
} else {
// Start playing
autoInterval = setInterval(function () {
const stepBy = getStepBy();
const nextIndex = currentIndex + stepBy;
if (nextIndex < dotStrings.length) {
currentIndex = nextIndex;
renderCurrentGraph();
} else if (currentIndex < dotStrings.length - 1) {
// Jump to the last step if we would overshoot
currentIndex = dotStrings.length - 1;
renderCurrentGraph();
togglePlayback(); // Stop at the end
} else {
// Stop at the end, don't loop
togglePlayback();
}
}, 600);
playBtn.textContent = "Stop";
playBtn.classList.add("playing");
}
}
// File input handler
document
.getElementById("fileInput")
.addEventListener("change", async function (e) {
const files = Array.from(e.target.files);
if (files.length === 0) return;
try {
// Sort files by name for consistent ordering
files.sort((a, b) => a.name.localeCompare(b.name));
dotStrings = [];
currentIndex = 0;
// Read all files
for (const file of files) {
const content = await readFileContent(file);
if (content.trim()) {
dotStrings.push(content);
}
}
updateFileCount(dotStrings.length);
updateStepCounter();
updateButtons();
// Render first graph if available
if (dotStrings.length > 0) {
renderCurrentGraph();
}
} catch (error) {
alert("Error reading files: " + error.message);
}
});
// Helper function to read file content
function readFileContent(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = (e) => resolve(e.target.result);
reader.onerror = (e) => reject(new Error("Failed to read file"));
reader.readAsText(file);
});
}
// Event handlers
document.getElementById("nextBtn").addEventListener("click", function () {
const stepBy = getStepBy();
const nextIndex = Math.min(
currentIndex + stepBy,
dotStrings.length - 1,
);
if (nextIndex > currentIndex) {
currentIndex = nextIndex;
renderCurrentGraph();
}
});
document.getElementById("prevBtn").addEventListener("click", function () {
const stepBy = getStepBy();
const prevIndex = Math.max(currentIndex - stepBy, 0);
if (prevIndex < currentIndex) {
currentIndex = prevIndex;
renderCurrentGraph();
}
});
document
.getElementById("playBtn")
.addEventListener("click", togglePlayback);
document
.getElementById("stepInput")
.addEventListener("change", function () {
const step = parseInt(this.value);
if (!isNaN(step)) {
jumpToStep(step);
}
});
document
.getElementById("stepInput")
.addEventListener("keypress", function (e) {
if (e.key === "Enter") {
const step = parseInt(this.value);
if (!isNaN(step)) {
jumpToStep(step);
}
}
});
// Initialize
updateStepCounter();
updateFileCount(0);
updateButtons();
</script>
</body>
</html>