Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trackers, working breakpoints #46

Merged
merged 103 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
d2d77d7
added a process based implementation for the python side for true par…
sakhalifa Mar 23, 2024
0adb346
Merge branch 'trunk' of github.com:PFA-Visualgo/Visualgo into trunk
sakhalifa Mar 24, 2024
8362d86
implement the comm-api on pyscript.
sakhalifa Mar 24, 2024
dbdfaaa
update DebuggerInterface to an AbstractDebugger so you give it the ca…
sakhalifa Mar 26, 2024
2685e27
Add data_draw
Mar 26, 2024
024f594
Remove individual data drawing files
Mar 26, 2024
5b17a06
Remove debug log
Mar 26, 2024
afdd118
Update submodule
Mar 26, 2024
64e09ad
fix: add missing functions to have pyscript loading
ttrenty Mar 27, 2024
bf78141
Merging
Mar 28, 2024
16d29b0
Fusion
Mar 28, 2024
56f6b94
feat: update submodule and add instuction for submodule dev in makefile
ttrenty Mar 28, 2024
c1408d4
Add editor
Mar 28, 2024
49f14e5
Merge branch 'feature/debugger/pyscript-comm-api' into fix/debugger-v…
sakhalifa Mar 28, 2024
90f773e
Merging
Mar 28, 2024
4c5d8fb
Add editor
Mar 28, 2024
f450ef2
made it work
sakhalifa Mar 28, 2024
e84c80b
merged
sakhalifa Mar 28, 2024
2db279c
fix: update submodule
ttrenty Mar 28, 2024
f5ebe9f
fix: fix import of module in pyscript page
ttrenty Mar 28, 2024
dd29474
fix: update submodule
ttrenty Mar 28, 2024
d336a7f
update submodule
sakhalifa Mar 28, 2024
a3f39d4
Merge remote-tracking branch 'origin/fix/debugger-visualisation/debug…
sakhalifa Mar 28, 2024
ac38675
Fix layout issues
Mar 28, 2024
15cff5a
fix: print variables received by controller
ttrenty Mar 28, 2024
3bc7622
update submodule
sakhalifa Mar 28, 2024
0b37a5c
Add translation from Python to JS for types str, int, list, LinkedList
Mar 28, 2024
a2de20a
Remove testing variables
Mar 28, 2024
e70d403
Merging
Mar 28, 2024
f26bab8
Add editor
Mar 28, 2024
9d603cb
Fix layout issues
Mar 28, 2024
a101a2b
Add translation from Python to JS for types str, int, list, LinkedList
Mar 28, 2024
6715cdb
Remove testing variables
Mar 28, 2024
c1038f4
fix: fix python variables convertion and show labels on buttons
ttrenty Mar 29, 2024
1400484
remove __name__ from global variables xd
sakhalifa Mar 29, 2024
35deab3
update submodule
sakhalifa Mar 29, 2024
b6781bb
Fix variables appending
Mar 29, 2024
69f6ee6
fix: fix to show visualgo types
ttrenty Mar 29, 2024
d61bb50
Merge branch 'fix/debugger-visualisation/debugger-bugging' of github.…
ttrenty Mar 29, 2024
82b2b86
Merge
Mar 29, 2024
7f3b8c4
Add current line highlighting
Mar 29, 2024
99ac95a
Merge
Mar 29, 2024
ba9298f
Merge remote-tracking branch 'origin/fix/debugger-visualisation/debug…
ttrenty Mar 29, 2024
5d1c64b
feat: update to match interfaces and update submodule
ttrenty Mar 30, 2024
ec48c96
feat: update submodule and correct implementations
ttrenty Mar 30, 2024
ee57601
PoC for a restartable worker with successful hook injection and all
sakhalifa Mar 29, 2024
7d75f4b
add comm-api implementation to restart the worker on interrupt_worker…
sakhalifa Mar 30, 2024
2d8db40
fix: update submodule
ttrenty Mar 31, 2024
f91bd95
fix not deleting the old script element when interrupting worker
sakhalifa Mar 31, 2024
f532bca
feat: disable buttons when they should not be used, rename js functions
ttrenty Mar 31, 2024
5fe7f63
fix: when code is done, update submodule
ttrenty Mar 31, 2024
8903d63
remove ugly "worker interrupted" error when the worker is interrupted.
sakhalifa Mar 31, 2024
8821a80
fix: use pyscript.ffi instead of pyodide.ffi (#38)
sakhalifa Mar 31, 2024
5f9a116
fix: enable stop bouton when running automatic
ttrenty Mar 31, 2024
fc53803
Merge branch 'feature/visualisation' of github.com:PFA-Visualgo/Visua…
ttrenty Mar 31, 2024
fcd706c
update pyscript version to 3.2
sakhalifa Apr 1, 2024
ed8e457
remove silly debug message
sakhalifa Apr 1, 2024
5303a64
Make the webpage more appealing and responsive, rework editor (#39)
ttrenty Apr 1, 2024
8e27c92
fix: drop down menu shows over code now
ttrenty Apr 1, 2024
bd46ffe
feat: use default cursor on line numbers
ttrenty Apr 1, 2024
97e7ffe
Merge
Apr 2, 2024
bbcb35d
Merge branch 'feature/visualisation' of https://github.com/PFA-Visual…
Apr 2, 2024
4ecc234
fix: fix boutons and disable code input when running
ttrenty Apr 2, 2024
dc9a998
fix: clear visualisation when restarted
ttrenty Apr 2, 2024
8dbd8bd
fix: update submodule
ttrenty Apr 2, 2024
e72278b
fix double empty lines desyncing debugger's view of the code with the…
sakhalifa Apr 3, 2024
7fbf136
Add line highlighting
Apr 3, 2024
34d436f
Merge branch 'feature/visualisation' of https://github.com/PFA-Visual…
Apr 3, 2024
a0f0554
Fix wrong line highlighting
Apr 3, 2024
298bc6d
feat: highlight current and previous line
ttrenty Apr 3, 2024
36e319e
Merge
Apr 7, 2024
5f43fd5
Merge branch 'feature/visualisation' of https://github.com/PFA-Visual…
Apr 7, 2024
46a92cd
Fix import export of .py files
Apr 7, 2024
4ab7ede
Fix tree display
Apr 7, 2024
ddb8f6b
Add resisability of both code and canvas divs
Apr 7, 2024
d64de28
disable breakpoints at uninteresting lines (empty lines, function dec…
sakhalifa Apr 8, 2024
ad31756
remove test_worker lol
sakhalifa Apr 10, 2024
075ba1c
Add base code for trackers, Python calls from JS
ArthurLeFloch Apr 11, 2024
c4f2edf
Fix call to del_breakpoint
ArthurLeFloch Apr 18, 2024
c56b99d
Fix import
Apr 18, 2024
489885c
Fix do not show type class
Apr 18, 2024
a88f4bb
Update submodule
Apr 18, 2024
3ca880f
Update submodule
Apr 18, 2024
eea01a7
Update submodule
Apr 18, 2024
4b1cc15
Update submodule
Apr 19, 2024
e564fbe
Merge branch 'trunk' into fix/visualisation/type
ttrenty Apr 20, 2024
6c69ef6
Merge
Apr 20, 2024
54fec03
Merge branch 'fix/visualisation/type' of https://github.com/PFA-Visua…
Apr 20, 2024
6007644
Fix visualisation trying to show non implemented data
Apr 20, 2024
b736fed
Merging trunk into feature/controller/tracker-checkpoint-breakpoint
ArthurLeFloch Apr 21, 2024
53f00f1
Merge branch 'fix/visualisation/type' into feature/controller/tracker…
ArthurLeFloch Apr 21, 2024
ce69488
Execution now stops when reaching a breakpoint
ArthurLeFloch Apr 21, 2024
ee43423
Rename enableBoutons, proper commit hash for vs-pypi
ArthurLeFloch Apr 21, 2024
9edaa55
Update vs-pypi hash
ArthurLeFloch Apr 22, 2024
93e055e
Add missing parameter in
ArthurLeFloch Apr 22, 2024
4da32f0
Remove thrown alert at end of execution
ArthurLeFloch Apr 22, 2024
375ad94
fix: update submodule
ttrenty Apr 24, 2024
e8565cf
fix: remove old dead code
ttrenty Apr 24, 2024
c020a39
Remove duplicate call
ArthurLeFloch Apr 24, 2024
0a23f0a
Merging
ArthurLeFloch Apr 24, 2024
2974d19
Comment old code
ArthurLeFloch Apr 24, 2024
c2f8487
Merge vs-pypi up-to-date with its trunk
ArthurLeFloch Apr 24, 2024
d939e17
Merge remote-tracking branch 'origin/trunk' into feature/controller/t…
ttrenty Apr 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions src/ui/editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#code,
#highlightedCode {
border-left: 1px solid #f1f1f1;
left: 50px;
left: 75px;
overflow: hidden;
margin: 0;
padding: 0;
Expand Down Expand Up @@ -54,6 +54,7 @@


#breakpointContainer,
#trackerContainer,
#indices {
background-color: #fafafa;
overflow: hidden;
Expand All @@ -67,8 +68,10 @@
/* height: 80vh; */
}

#breakpointContainer {
#breakpointContainer,
#trackerContainer {
width: 15px;
padding-right: 5px;
}

#indices {
Expand Down Expand Up @@ -105,12 +108,13 @@
font-family: monospace;
}

.breakpoint {
.breakpoint, .tracker {
border: none;
background-color: transparent;
margin-top: 0.225em;
margin-bottom: 0.45em;
margin-left: 6px;
padding: none;
padding: 0;
width: 9px;
height: 9px;
border-radius: 50%;
Expand Down Expand Up @@ -140,4 +144,23 @@

.breakpoint.red:hover {
background-color: #bb908d;
}

.tracker {
color: #aaa;
}

.tracker.enabled {
color: #55f;
font-weight: bold;
}

#selectTrackers {
position: absolute;
top: 0;
left: 0;
background-color: #f9f9f9;
border: 1px solid #ccc;
z-index: 1;
display: none;
}
147 changes: 134 additions & 13 deletions src/ui/editor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let indices, code, highlightedCode, suggestionsDiv, breakpointContainer, resizer;
let indices, code, highlightedCode, suggestionsDiv, breakpointContainer, trackerContainer, selectTrackers, resizer;

let suggestions = [];

Expand All @@ -7,12 +7,15 @@ let currentWord;

let selectedSuggestionIndex = 0;

const trackers = [];

function initEditor() {
indices = document.getElementById("indices");
code = document.getElementById("code");
highlightedCode = document.getElementById("highlightedCode");
suggestionsDiv = document.getElementById("suggestions");
breakpointContainer = document.getElementById("breakpointContainer");
trackerContainer = document.getElementById("trackerContainer");
resizer = document.getElementById('resizer');

// code.innerHTML = '<div>from visualgo.structures import LinkedList, Array, DoublyLinkedList, Queue, Stack, Set</div><div>\n</div><div>a = LinkedList()</div><div>a.insert_head(1)</div><div>a.insert_head(2)</div><div>a.insert_head(3)</div><div>\n</div><div>b = Array(2)</div><div>b.set(0, 0)</div><div>\n</div><div>c = DoublyLinkedList()</div><div>c.insert_head(1)</div><div>c.insert_head(2)</div><div>c.insert_head(3)</div><div>\n</div><div>d = Queue()</div><div>d.enqueue(1)</div><div>d.enqueue(2)</div><div>d.enqueue(3)</div><div>\n</div><div>e = Set()</div><div>e.add(1)</div><div>e.add(2)</div><div>e.add(3)</div>'
Expand Down Expand Up @@ -58,8 +61,10 @@ function updateIndices(len) {
breakpointStates.push(b.classList[1]);
}
breakpointContainer.innerHTML = "";
trackerContainer.innerHTML = "";
for (let i = 1; i < len + 1; i++) {
createBreakpoints(i);
createTrackerElement(i);
if (i < breakpointStates.length) {
let breakpoint = document.getElementById("breakpoint" + i);
breakpoint.classList.remove("grey");
Expand Down Expand Up @@ -160,6 +165,7 @@ function updateColor() {
*/
function updateScroll() {
breakpointContainer.scrollTop = code.scrollTop;
trackerContainer.scrollTop = code.scrollTop;
indices.scrollTop = code.scrollTop;
highlightedCode.scrollTop = code.scrollTop;
highlightedCode.scrollLeft = code.scrollLeft;
Expand Down Expand Up @@ -352,47 +358,162 @@ function createBreakpoints(index) {
breakpointContainer.appendChild(breakpoint);
}

function createTrackerElement(index) {
const tracker = document.createElement("button");
tracker.className = "tracker";
tracker.id = "tracker" + index;
tracker.innerHTML = "+";
let trackerValue = undefined;

function setTracker(data) {
tracker.innerHTML = data[0];
tracker.className = "tracker enabled";
trackerValue = data;
tracker.title = data;
addTracker(data, index);
}

function askTracker() {
const data = prompt("Enter a name for the tracker", "");
if (data === null)
return;
if (data === "") {
alert("Please enter a valid name");
return;
}
setTracker(data);
}

function removeTracker() {
tracker.innerHTML = "+";
tracker.className = "tracker";
if (trackerValue === undefined) return;
window.del_tracker(trackerValue, index);
trackerValue = undefined;
}

tracker.addEventListener("click", () => {
if (trackers.length === 0) {
askTracker();
return;
}

// Show all available trackers
const rect = tracker.getBoundingClientRect();
let selectTrackers = document.getElementById("selectTrackers");
selectTrackers.style.top = rect.top + "px";
selectTrackers.style.left = (rect.right + 40) + "px";
selectTrackers.innerHTML = "";
selectTrackers.style.display = "block";

const noOption = document.createElement("option");
noOption.value = "no_option";
noOption.innerHTML = "Select a tracker...";
noOption.selected = true;

if (trackerValue !== undefined) {
noOption.innerHTML = trackerValue[0];
noOption.value = trackerValue;
}
selectTrackers.appendChild(noOption);
selectTrackers.selectedIndex = 0;
noOption.hidden = true;

const noTracker = document.createElement("option");
noTracker.value = "no_option";
noTracker.selected = true;
noTracker.innerHTML = "No tracker";
selectTrackers.appendChild(noTracker);

trackers.forEach((tracker, index) => {
if (trackerValue === tracker) return;
const option = document.createElement("option");
option.value = tracker;
option.innerHTML = tracker;
selectTrackers.appendChild(option);
});

// Allow to create a new tracker
const newOption = document.createElement("option");
newOption.value = "new_tracker";
newOption.innerHTML = "(+) Add new tracker";
selectTrackers.appendChild(newOption);

// Clear all selectTrackers event listeners
const newSelectTrackers = selectTrackers.cloneNode(true);
selectTrackers.parentNode.replaceChild(newSelectTrackers, selectTrackers);
selectTrackers = newSelectTrackers;

// Handle tracker selection
const handler = () => {
selectTrackers.removeEventListener('change', handler, false);
selectTrackers.style.display = "none";
if (selectTrackers.value === "new_tracker") {
console.log("new tracker")
askTracker();
return;
} else if (selectTrackers.value === "no_option") {
removeTracker();
return;
}
setTracker(selectTrackers.value);
};
selectTrackers.addEventListener('change', handler, false);
});
trackerContainer.appendChild(tracker);
}

function addTracker(name, index) {
console.log(`Adding tracker ${name} to line ${index}`)
window.new_tracker(name, index);
if (trackers.includes(name))
return;
trackers.push(name);
}

function handleBreakpointClick(breakpointId) {
let breakpoint = document.getElementById(breakpointId)
let state = breakpoint.classList[1];
const index = parseInt(breakpointId.replace("breakpoint", ""));

switch (state) {
case "grey":
breakpoint.classList.remove("grey");
breakpoint.classList.add("green");
state = "green"
function1();
addCheckpoint(index);
break;
case "green":
breakpoint.classList.remove("green");
breakpoint.classList.add("red");
state = "red"
function2();
addBreakpointRemoveCheckpoint(index);
break;
case "red":
breakpoint.classList.remove("red");
breakpoint.classList.add("grey");
state = "grey"
function3();
removeBreakpoint(index);
break;
default:
break;
}
}

function function1() {
console.log("Function 1 called");
// Your function1 implementation here
function addCheckpoint(lineNumber) {
console.log("addCheckpoint");
window.new_checkpoint(lineNumber);
}

function function2() {
console.log("Function 2 called");
// Your function2 implementation here
function addBreakpointRemoveCheckpoint(lineNumber) {
console.log("addBreakpointRemoveCheckpoint");
window.new_breakpoint(lineNumber);
window.del_checkpoint(lineNumber);
}

function function3() {
console.log("Function 3 called");
// Your function3 implementation here
function removeBreakpoint(lineNumber) {
console.log("removeCheckpoint");
window.del_breakpoint(lineNumber);
}


Expand Down
5 changes: 5 additions & 0 deletions src/ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<div id="codeContainer">
<div id="leftDivsContainer">
<div id="breakpointContainer"></div>
<div id="trackerContainer"></div>
<div id="indices"></div>
<!-- Other left divs here -->
</div>
Expand All @@ -89,6 +90,7 @@
<button class="playButton" id="stepForwardButton" data-label="Step Forward"><i
class="fa fa-step-forward"></i></button>
<button class="playButton" id="continueButton" data-label="Continue"><i class="fa fa-fast-forward"></i></button>
<button id="fetchStats">Log stats</button>
</footer>

<script>
Expand Down Expand Up @@ -153,6 +155,9 @@
<script type="py" src="../wasm-scripts/main.py" config="../pyscript/pyscript.json"></script>
</py-env>

<select id="selectTrackers">
</select>


</body>

Expand Down
8 changes: 4 additions & 4 deletions src/ui/ui_public_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function disableButtons() {
stop.disabled = false;
}

function enableBoutons() {
function enableButtons() {
let buttons = document.getElementsByClassName("playButton");
let pause = document.getElementById("pauseButton");
let step_backwards = document.getElementById("stepBackwardButton");
Expand Down Expand Up @@ -83,7 +83,7 @@ function disableCodeInput() {
}

function debuggerReady() {
enableBoutons();
enableButtons();
enableCodeInput();
}

Expand All @@ -94,7 +94,7 @@ function debuggerInterrupted() {
}

function executionPaused() {
enableBoutons();
enableButtons();
}

function setStaticVariablesAndUserFun(static_variables) {
Expand All @@ -115,7 +115,7 @@ function disableInteractions() {

function enableInteractions() {
console.log("Enabling all interactions");
enableBoutons();
enableButtons();
// + enabling code input
let codeInput = document.getElementById("code");
codeInput.contentEditable = true;
Expand Down
Loading