Update templates/index.html
Browse files- templates/index.html +89 -28
templates/index.html
CHANGED
|
@@ -1,35 +1,96 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
| 7 |
</head>
|
| 8 |
<body>
|
| 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 |
</body>
|
| 35 |
</html>
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<title>D3 Python Visualizer</title>
|
| 6 |
+
<link rel="stylesheet" href="/static/style.css">
|
| 7 |
+
<script src="/static/d3.v7.min.js"></script>
|
| 8 |
</head>
|
| 9 |
<body>
|
| 10 |
+
<h2>🐍 Python Visualizer with D3.js</h2>
|
| 11 |
+
|
| 12 |
+
<form method="post" action="/run">
|
| 13 |
+
<textarea name="code" rows="10" cols="70" placeholder="Enter Python code here...">{{ code or '' }}</textarea><br>
|
| 14 |
+
<button type="submit">Run Code</button>
|
| 15 |
+
</form>
|
| 16 |
+
|
| 17 |
+
{% if output %}
|
| 18 |
+
<h3>Output:</h3>
|
| 19 |
+
<pre>{{ output }}</pre>
|
| 20 |
+
{% endif %}
|
| 21 |
+
|
| 22 |
+
<div id="viz"></div>
|
| 23 |
+
|
| 24 |
+
<script>
|
| 25 |
+
const traceData = {{ trace_json | safe if trace_json else '[]' }};
|
| 26 |
+
if (traceData.length > 0) {
|
| 27 |
+
const width = 700, height = 400;
|
| 28 |
+
const svg = d3.select("#viz")
|
| 29 |
+
.append("svg")
|
| 30 |
+
.attr("width", width)
|
| 31 |
+
.attr("height", height)
|
| 32 |
+
.style("background", "#f8f8f8")
|
| 33 |
+
.style("border-radius", "10px");
|
| 34 |
+
|
| 35 |
+
let currentStep = 0;
|
| 36 |
+
|
| 37 |
+
const frameGroup = svg.append("g").attr("transform", "translate(50,80)");
|
| 38 |
+
|
| 39 |
+
function renderStep(step) {
|
| 40 |
+
frameGroup.selectAll("*").remove();
|
| 41 |
+
|
| 42 |
+
const stepData = traceData[step];
|
| 43 |
+
if (stepData.error) {
|
| 44 |
+
frameGroup.append("text")
|
| 45 |
+
.text("Error: " + stepData.error)
|
| 46 |
+
.attr("fill", "red")
|
| 47 |
+
.attr("x", 50)
|
| 48 |
+
.attr("y", 20);
|
| 49 |
+
return;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
frameGroup.append("text")
|
| 53 |
+
.text("Line: " + stepData.line)
|
| 54 |
+
.attr("x", 0)
|
| 55 |
+
.attr("y", -30)
|
| 56 |
+
.attr("font-weight", "bold");
|
| 57 |
+
|
| 58 |
+
const vars = Object.entries(stepData.locals);
|
| 59 |
+
vars.forEach((v, i) => {
|
| 60 |
+
const [name, val] = v;
|
| 61 |
+
const boxY = i * 50;
|
| 62 |
+
frameGroup.append("rect")
|
| 63 |
+
.attr("x", 0)
|
| 64 |
+
.attr("y", boxY)
|
| 65 |
+
.attr("width", 200)
|
| 66 |
+
.attr("height", 40)
|
| 67 |
+
.attr("fill", "#fff")
|
| 68 |
+
.attr("stroke", "#000");
|
| 69 |
+
|
| 70 |
+
frameGroup.append("text")
|
| 71 |
+
.text(name + " = " + val)
|
| 72 |
+
.attr("x", 10)
|
| 73 |
+
.attr("y", boxY + 25)
|
| 74 |
+
.attr("font-family", "monospace");
|
| 75 |
+
});
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
function addButtons() {
|
| 79 |
+
const controls = d3.select("body").append("div").attr("id", "controls");
|
| 80 |
+
controls.append("button").text("◀ Prev").on("click", () => {
|
| 81 |
+
if (currentStep > 0) { currentStep--; renderStep(currentStep); }
|
| 82 |
+
});
|
| 83 |
+
controls.append("button").text("▶ Next").on("click", () => {
|
| 84 |
+
if (currentStep < traceData.length - 1) { currentStep++; renderStep(currentStep); }
|
| 85 |
+
});
|
| 86 |
+
controls.append("span")
|
| 87 |
+
.text(" Step " + (currentStep+1) + " of " + traceData.length)
|
| 88 |
+
.attr("id", "stepInfo");
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
addButtons();
|
| 92 |
+
renderStep(0);
|
| 93 |
+
}
|
| 94 |
+
</script>
|
| 95 |
</body>
|
| 96 |
</html>
|