Sami Marreed
feat: docker-v1 with optimized frontend
0646b18
Raw History Blame Contribute Delete
42.4 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Interactive Graph Visualizer</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); min-height: 100vh; display: flex; flex-direction: column; } .header { background: rgba(255, 255, 255, 0.1); backdrop-filter: blur(10px); padding: 20px; text-align: center; color: white; box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1); } .header h1 { font-size: 2.5em; margin-bottom: 10px; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3); } .controls { background: rgba(255, 255, 255, 0.95); padding: 15px; display: flex; gap: 15px; align-items: center; justify-content: center; flex-wrap: wrap; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); } .control-group { display: flex; align-items: center; gap: 8px; } button { background: linear-gradient(45deg, #667eea, #764ba2); color: white; border: none; padding: 10px 20px; border-radius: 25px; cursor: pointer; font-weight: 600; transition: all 0.3s ease; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2); } button:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); } button:active { transform: translateY(0); } .file-input { display: none; } .file-label { background: linear-gradient(45deg, #28a745, #20c997); color: white; padding: 10px 20px; border-radius: 25px; cursor: pointer; font-weight: 600; transition: all 0.3s ease; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2); } .file-label:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); } .container { flex: 1; display: flex; position: relative; overflow: hidden; } .sidebar { width: 300px; background: rgba(255, 255, 255, 0.95); padding: 20px; overflow-y: auto; box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1); transition: transform 0.3s ease; } .sidebar.hidden { transform: translateX(-100%); } .sidebar h3 { color: #333; margin-bottom: 15px; font-size: 1.2em; border-bottom: 2px solid #667eea; padding-bottom: 5px; } .node-info { background: #f8f9fa; border-radius: 10px; padding: 15px; margin-bottom: 15px; border-left: 4px solid #667eea; } .node-info h4 { color: #495057; margin-bottom: 8px; } .node-info p { color: #6c757d; font-size: 0.9em; line-height: 1.4; } .graph-container { flex: 1; position: relative; background: rgba(255, 255, 255, 0.1); } #graph { width: 100%; height: 100%; cursor: grab; } #graph:active { cursor: grabbing; } .node { cursor: move; transition: all 0.2s ease; } .node:hover { filter: brightness(1.1); } .node.selected { stroke: #ff6b6b; stroke-width: 3; } .node-label { pointer-events: none; text-anchor: middle; dominant-baseline: middle; font-weight: 600; font-size: 12px; fill: white; text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.7); } .edge { stroke: #495057; stroke-width: 2; fill: none; marker-end: url(#arrowhead); } .edge.conditional { stroke-dasharray: 5,5; stroke: #17a2b8; } .edge:hover { stroke-width: 3; stroke: #ff6b6b; } .toggle-sidebar { position: absolute; top: 20px; left: 20px; z-index: 1000; } .legend { position: absolute; bottom: 20px; right: 20px; background: rgba(255, 255, 255, 0.95); padding: 15px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2); } .legend h4 { margin-bottom: 10px; color: #333; } .legend-item { display: flex; align-items: center; margin-bottom: 5px; font-size: 0.9em; } .legend-line { width: 20px; height: 2px; margin-right: 8px; } .solid { background: #495057; } .dashed { background: linear-gradient(to right, #17a2b8 50%, transparent 50%); background-size: 8px 2px; } .loading { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: white; font-size: 1.2em; text-align: center; } .status { background: rgba(40, 167, 69, 0.9); color: white; padding: 10px; text-align: center; margin-top: 10px; border-radius: 5px; display: none; } .status.error { background: rgba(220, 53, 69, 0.9); } @media (max-width: 768px) { .sidebar { width: 250px; } .controls { flex-direction: column; gap: 10px; } .header h1 { font-size: 2em; } } </style> </head> <body> <div class="header"> <h1>🌐 Interactive Graph Visualizer</h1> <p>Drag nodes to rearrange • Click nodes for details • Pan and zoom to explore</p> </div> <div class="controls"> <div class="control-group"> <label for="fileInput" class="file-label">📁 Load Graph JSON</label> <input type="file" id="fileInput" class="file-input" accept=".json"> </div> <button onclick="resetLayout()">🔄 Reset Layout</button> <button onclick="centerGraph()">🎯 Center Graph</button> <button onclick="togglePhysics()">⚡ Toggle Physics</button> <button onclick="exportGraph()">💾 Export SVG</button> </div> <div class="status" id="status"></div> <div class="container"> <div class="sidebar" id="sidebar"> <h3>📊 Graph Information</h3> <div id="graphStats"></div> <h3>🔍 Node Details</h3> <div id="nodeDetails"> <p style="color: #6c757d; text-align: center; padding: 20px;"> Click on a node to see its details </p> </div> </div> <div class="graph-container"> <button class="toggle-sidebar" onclick="toggleSidebar()"> <span id="sidebarToggleText">◀</span> </button> <div class="loading" id="loading"> 🔄 Loading graph data... </div> <svg id="graph"></svg> <div class="legend"> <h4>Legend</h4> <div class="legend-item"> <div class="legend-line solid"></div> <span>Regular Edge</span> </div> <div class="legend-item"> <div class="legend-line dashed"></div> <span>Conditional Edge</span> </div> </div> </div> </div> <script> let graph = null; let svg = null; let simulation = null; let nodes = []; let links = []; let physicsEnabled = true; // Initialize the visualization async function init() { svg = d3.select("#graph"); // Create arrow marker svg.append("defs").append("marker") .attr("id", "arrowhead") .attr("viewBox", "-0 -5 10 10") .attr("refX", 20) .attr("refY", 0) .attr("orient", "auto") .attr("markerWidth", 8) .attr("markerHeight", 8) .append("path") .attr("d", "M 0,-5 L 10 ,0 L 0,5") .attr("fill", "#495057"); // Try to load the default graph.json file try { const response = await fetch('./graph.json'); if (response.ok) { const data = await response.json(); loadGraph(data); showStatus("Graph loaded successfully!", false); } else { document.getElementById('loading').innerHTML = "📁 No graph.json found. Please load a JSON file using the button above."; } } catch (error) { document.getElementById('loading').innerHTML = "📁 No graph.json found. Please load a JSON file using the button above."; } } // File input handler document.getElementById('fileInput').addEventListener('change', function(event) { const file = event.target.files[0]; if (file && file.type === 'application/json') { const reader = new FileReader(); reader.onload = function(e) { try { const data = JSON.parse(e.target.result); loadGraph(data); showStatus("Graph loaded successfully!", false); } catch (error) { showStatus("Error parsing JSON file: " + error.message, true); } }; reader.readAsText(file); } else { showStatus("Please select a valid JSON file", true); } }); function loadGraph(data) { document.getElementById('loading').style.display = 'none'; // Process nodes nodes = data.nodes.map(node => ({ id: node.id, name: node.data?.name || node.id, type: node.type, data: node.data, metadata: node.metadata, x: Math.random() * 800 + 100, y: Math.random() * 600 + 100 })); // Process edges links = data.edges.map(edge => ({ source: edge.source, target: edge.target, conditional: edge.conditional || false })); updateGraphStats(); createVisualization(); } function createVisualization() { const width = window.innerWidth - 320; const height = window.innerHeight - 200; svg.attr("width", width).attr("height", height); // Clear previous content svg.selectAll("*").remove(); // Recreate arrow marker svg.append("defs").append("marker") .attr("id", "arrowhead") .attr("viewBox", "-0 -5 10 10") .attr("refX", 20) .attr("refY", 0) .attr("orient", "auto") .attr("markerWidth", 8) .attr("markerHeight", 8) .append("path") .attr("d", "M 0,-5 L 10 ,0 L 0,5") .attr("fill", "#495057"); // Create main group for zooming and panning const g = svg.append("g"); // Add zoom behavior const zoom = d3.zoom() .scaleExtent([0.1, 3]) .on("zoom", (event) => { g.attr("transform", event.transform); }); svg.call(zoom); // Create simulation simulation = d3.forceSimulation(nodes) .force("link", d3.forceLink(links).id(d => d.id).distance(100)) .force("charge", d3.forceManyBody().strength(-300)) .force("center", d3.forceCenter(width / 2, height / 2)) .force("collision", d3.forceCollide().radius(40)); // Create edges const link = g.append("g") .selectAll("line") .data(links) .enter().append("line") .attr("class", d => `edge ${d.conditional ? 'conditional' : ''}`) .on("mouseover", function(event, d) { d3.select(this).style("stroke-width", "3px"); }) .on("mouseout", function(event, d) { d3.select(this).style("stroke-width", "2px"); }); // Create nodes const node = g.append("g") .selectAll("g") .data(nodes) .enter().append("g") .attr("class", "node") .call(d3.drag() .on("start", dragstarted) .on("drag", dragged) .on("end", dragended)) .on("click", function(event, d) { // Remove previous selection d3.selectAll(".node circle").classed("selected", false); // Add selection to current node d3.select(this).select("circle").classed("selected", true); showNodeDetails(d); }); // Add circles to nodes node.append("circle") .attr("r", d => getNodeSize(d)) .attr("fill", d => getNodeColor(d)) .attr("stroke", "#fff") .attr("stroke-width", 2); // Add labels to nodes node.append("text") .attr("class", "node-label") .attr("dy", 4) .text(d => d.name.length > 15 ? d.name.substring(0, 12) + "..." : d.name); // Update positions on simulation tick simulation.on("tick", () => { link .attr("x1", d => d.source.x) .attr("y1", d => d.source.y) .attr("x2", d => d.target.x) .attr("y2", d => d.target.y); node.attr("transform", d => `translate(${d.x},${d.y})`); }); if (!physicsEnabled) { simulation.stop(); } } function getNodeColor(node) { const colors = { '__start__': '#28a745', '__end__': '#dc3545', 'default': '#667eea' }; if (node.id === '__start__') return colors['__start__']; if (node.id === '__end__') return colors['__end__']; if (node.metadata && node.metadata.__interrupt) return '#fd7e14'; return colors['default']; } function getNodeSize(node) { if (node.id === '__start__' || node.id === '__end__') return 25; return 20; } function showNodeDetails(node) { const details = document.getElementById('nodeDetails'); const interruptInfo = node.metadata && node.metadata.__interrupt ? `<div style="background: #fff3cd; padding: 8px; border-radius: 5px; margin-top: 10px;"> <strong>⚠️ Interrupt:</strong> ${node.metadata.__interrupt} </div>` : ''; details.innerHTML = ` <div class="node-info"> <h4>${node.name}</h4> <p><strong>ID:</strong> ${node.id}</p> <p><strong>Type:</strong> ${node.type}</p> ${node.data && node.data.id ? `<p><strong>Module:</strong> ${node.data.id.join('.')}</p>` : ''} ${interruptInfo} </div> `; } function updateGraphStats() { const stats = document.getElementById('graphStats'); const conditionalEdges = links.filter(l => l.conditional).length; const regularEdges = links.length - conditionalEdges; stats.innerHTML = ` <div class="node-info"> <h4>📈 Graph Statistics</h4> <p><strong>Nodes:</strong> ${nodes.length}</p> <p><strong>Total Edges:</strong> ${links.length}</p> <p><strong>Regular Edges:</strong> ${regularEdges}</p> <p><strong>Conditional Edges:</strong> ${conditionalEdges}</p> </div> `; } // Drag functions function dragstarted(event, d) { if (!event.active && physicsEnabled) simulation.alphaTarget(0.3).restart(); d.fx = d.x; d.fy = d.y; } function dragged(event, d) { d.fx = event.x; d.fy = event.y; } function dragended(event, d) { if (!event.active && physicsEnabled) simulation.alphaTarget(0); d.fx = null; d.fy = null; } // Utility functions function toggleSidebar() { const sidebar = document.getElementById('sidebar'); const toggleText = document.getElementById('sidebarToggleText'); sidebar.classList.toggle('hidden'); toggleText.textContent = sidebar.classList.contains('hidden') ? '▶' : '◀'; } function resetLayout() { if (simulation) { nodes.forEach(node => { node.x = Math.random() * 800 + 100; node.y = Math.random() * 600 + 100; node.fx = null; node.fy = null; }); simulation.alpha(1).restart(); } } function centerGraph() { if (svg) { const width = parseInt(svg.attr("width")); const height = parseInt(svg.attr("height")); svg.transition().duration(750).call( d3.zoom().transform, d3.zoomIdentity.translate(width / 2, height / 2).scale(1) ); } } function togglePhysics() { physicsEnabled = !physicsEnabled; if (simulation) { if (physicsEnabled) { simulation.restart(); } else { simulation.stop(); } } showStatus(`Physics ${physicsEnabled ? 'enabled' : 'disabled'}`, false); } function exportGraph() { const svgElement = document.getElementById('graph'); const serializer = new XMLSerializer(); const svgString = serializer.serializeToString(svgElement); const blob = new Blob([svgString], { type: 'image/svg+xml' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = 'graph-visualization.svg'; a.click(); URL.revokeObjectURL(url); showStatus('Graph exported as SVG!', false); } function showStatus(message, isError) { const status = document.getElementById('status'); status.textContent = message; status.className = isError ? 'status error' : 'status'; status.style.display = 'block'; setTimeout(() => { status.style.display = 'none'; }, 3000); } // Handle window resize window.addEventListener('resize', () => { if (svg && nodes.length > 0) { createVisualization(); } }); // Load D3.js and initialize const script = document.createElement('script'); script.src = 'https://cdnjs.cloudflare.com/ajax/libs/d3/7.8.5/d3.min.js'; script.onload = init; document.head.appendChild(script); </script> </body> </html><!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Interactive Graph Visualizer</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); min-height: 100vh; display: flex; flex-direction: column; } .header { background: rgba(255, 255, 255, 0.1); backdrop-filter: blur(10px); padding: 20px; text-align: center; color: white; box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1); } .header h1 { font-size: 2.5em; margin-bottom: 10px; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3); } .controls { background: rgba(255, 255, 255, 0.95); padding: 15px; display: flex; gap: 15px; align-items: center; justify-content: center; flex-wrap: wrap; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); } .control-group { display: flex; align-items: center; gap: 8px; } button { background: linear-gradient(45deg, #667eea, #764ba2); color: white; border: none; padding: 10px 20px; border-radius: 25px; cursor: pointer; font-weight: 600; transition: all 0.3s ease; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2); } button:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); } button:active { transform: translateY(0); } .file-input { display: none; } .file-label { background: linear-gradient(45deg, #28a745, #20c997); color: white; padding: 10px 20px; border-radius: 25px; cursor: pointer; font-weight: 600; transition: all 0.3s ease; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2); } .file-label:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); } .container { flex: 1; display: flex; position: relative; overflow: hidden; } .sidebar { width: 300px; background: rgba(255, 255, 255, 0.95); padding: 20px; overflow-y: auto; box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1); transition: transform 0.3s ease; } .sidebar.hidden { transform: translateX(-100%); } .sidebar h3 { color: #333; margin-bottom: 15px; font-size: 1.2em; border-bottom: 2px solid #667eea; padding-bottom: 5px; } .node-info { background: #f8f9fa; border-radius: 10px; padding: 15px; margin-bottom: 15px; border-left: 4px solid #667eea; } .node-info h4 { color: #495057; margin-bottom: 8px; } .node-info p { color: #6c757d; font-size: 0.9em; line-height: 1.4; } .graph-container { flex: 1; position: relative; background: rgba(255, 255, 255, 0.1); } #graph { width: 100%; height: 100%; cursor: grab; } #graph:active { cursor: grabbing; } .node { cursor: move; transition: all 0.2s ease; } .node:hover { filter: brightness(1.1); } .node.selected { stroke: #ff6b6b; stroke-width: 3; } .node-label { pointer-events: none; text-anchor: middle; dominant-baseline: middle; font-weight: 600; font-size: 12px; fill: white; text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.7); } .edge { stroke: #495057; stroke-width: 2; fill: none; marker-end: url(#arrowhead); } .edge.conditional { stroke-dasharray: 5,5; stroke: #17a2b8; } .edge:hover { stroke-width: 3; stroke: #ff6b6b; } .toggle-sidebar { position: absolute; top: 20px; left: 20px; z-index: 1000; } .legend { position: absolute; bottom: 20px; right: 20px; background: rgba(255, 255, 255, 0.95); padding: 15px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2); } .legend h4 { margin-bottom: 10px; color: #333; } .legend-item { display: flex; align-items: center; margin-bottom: 5px; font-size: 0.9em; } .legend-line { width: 20px; height: 2px; margin-right: 8px; } .solid { background: #495057; } .dashed { background: linear-gradient(to right, #17a2b8 50%, transparent 50%); background-size: 8px 2px; } .loading { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: white; font-size: 1.2em; text-align: center; } .status { background: rgba(40, 167, 69, 0.9); color: white; padding: 10px; text-align: center; margin-top: 10px; border-radius: 5px; display: none; } .status.error { background: rgba(220, 53, 69, 0.9); } @media (max-width: 768px) { .sidebar { width: 250px; } .controls { flex-direction: column; gap: 10px; } .header h1 { font-size: 2em; } } </style> </head> <body> <div class="header"> <h1>🌐 Interactive Graph Visualizer</h1> <p>Drag nodes to rearrange • Click nodes for details • Pan and zoom to explore</p> </div> <div class="controls"> <div class="control-group"> <label for="fileInput" class="file-label">📁 Load Graph JSON</label> <input type="file" id="fileInput" class="file-input" accept=".json"> </div> <button onclick="resetLayout()">🔄 Reset Layout</button> <button onclick="centerGraph()">🎯 Center Graph</button> <button onclick="togglePhysics()">⚡ Toggle Physics</button> <button onclick="exportGraph()">💾 Export SVG</button> </div> <div class="status" id="status"></div> <div class="container"> <div class="sidebar" id="sidebar"> <h3>📊 Graph Information</h3> <div id="graphStats"></div> <h3>🔍 Node Details</h3> <div id="nodeDetails"> <p style="color: #6c757d; text-align: center; padding: 20px;"> Click on a node to see its details </p> </div> </div> <div class="graph-container"> <button class="toggle-sidebar" onclick="toggleSidebar()"> <span id="sidebarToggleText">◀</span> </button> <div class="loading" id="loading"> 🔄 Loading graph data... </div> <svg id="graph"></svg> <div class="legend"> <h4>Legend</h4> <div class="legend-item"> <div class="legend-line solid"></div> <span>Regular Edge</span> </div> <div class="legend-item"> <div class="legend-line dashed"></div> <span>Conditional Edge</span> </div> </div> </div> </div> <script> let graph = null; let svg = null; let simulation = null; let nodes = []; let links = []; let physicsEnabled = true; // Initialize the visualization async function init() { svg = d3.select("#graph"); // Create arrow marker svg.append("defs").append("marker") .attr("id", "arrowhead") .attr("viewBox", "-0 -5 10 10") .attr("refX", 20) .attr("refY", 0) .attr("orient", "auto") .attr("markerWidth", 8) .attr("markerHeight", 8) .append("path") .attr("d", "M 0,-5 L 10 ,0 L 0,5") .attr("fill", "#495057"); // Try to load the default graph.json file try { const response = await fetch('./graph.json'); if (response.ok) { const data = await response.json(); loadGraph(data); showStatus("Graph loaded successfully!", false); } else { document.getElementById('loading').innerHTML = "📁 No graph.json found. Please load a JSON file using the button above."; } } catch (error) { document.getElementById('loading').innerHTML = "📁 No graph.json found. Please load a JSON file using the button above."; } } // File input handler document.getElementById('fileInput').addEventListener('change', function(event) { const file = event.target.files[0]; if (file && file.type === 'application/json') { const reader = new FileReader(); reader.onload = function(e) { try { const data = JSON.parse(e.target.result); loadGraph(data); showStatus("Graph loaded successfully!", false); } catch (error) { showStatus("Error parsing JSON file: " + error.message, true); } }; reader.readAsText(file); } else { showStatus("Please select a valid JSON file", true); } }); function loadGraph(data) { document.getElementById('loading').style.display = 'none'; // Process nodes nodes = data.nodes.map(node => ({ id: node.id, name: node.data?.name || node.id, type: node.type, data: node.data, metadata: node.metadata, x: Math.random() * 800 + 100, y: Math.random() * 600 + 100 })); // Process edges links = data.edges.map(edge => ({ source: edge.source, target: edge.target, conditional: edge.conditional || false })); updateGraphStats(); createVisualization(); } function createVisualization() { const width = window.innerWidth - 320; const height = window.innerHeight - 200; svg.attr("width", width).attr("height", height); // Clear previous content svg.selectAll("*").remove(); // Recreate arrow marker svg.append("defs").append("marker") .attr("id", "arrowhead") .attr("viewBox", "-0 -5 10 10") .attr("refX", 20) .attr("refY", 0) .attr("orient", "auto") .attr("markerWidth", 8) .attr("markerHeight", 8) .append("path") .attr("d", "M 0,-5 L 10 ,0 L 0,5") .attr("fill", "#495057"); // Create main group for zooming and panning const g = svg.append("g"); // Add zoom behavior const zoom = d3.zoom() .scaleExtent([0.1, 3]) .on("zoom", (event) => { g.attr("transform", event.transform); }); svg.call(zoom); // Create simulation simulation = d3.forceSimulation(nodes) .force("link", d3.forceLink(links).id(d => d.id).distance(100)) .force("charge", d3.forceManyBody().strength(-300)) .force("center", d3.forceCenter(width / 2, height / 2)) .force("collision", d3.forceCollide().radius(40)); // Create edges const link = g.append("g") .selectAll("line") .data(links) .enter().append("line") .attr("class", d => `edge ${d.conditional ? 'conditional' : ''}`) .on("mouseover", function(event, d) { d3.select(this).style("stroke-width", "3px"); }) .on("mouseout", function(event, d) { d3.select(this).style("stroke-width", "2px"); }); // Create nodes const node = g.append("g") .selectAll("g") .data(nodes) .enter().append("g") .attr("class", "node") .call(d3.drag() .on("start", dragstarted) .on("drag", dragged) .on("end", dragended)) .on("click", function(event, d) { // Remove previous selection d3.selectAll(".node circle").classed("selected", false); // Add selection to current node d3.select(this).select("circle").classed("selected", true); showNodeDetails(d); }); // Add circles to nodes node.append("circle") .attr("r", d => getNodeSize(d)) .attr("fill", d => getNodeColor(d)) .attr("stroke", "#fff") .attr("stroke-width", 2); // Add labels to nodes node.append("text") .attr("class", "node-label") .attr("dy", 4) .text(d => d.name.length > 15 ? d.name.substring(0, 12) + "..." : d.name); // Update positions on simulation tick simulation.on("tick", () => { link .attr("x1", d => d.source.x) .attr("y1", d => d.source.y) .attr("x2", d => d.target.x) .attr("y2", d => d.target.y); node.attr("transform", d => `translate(${d.x},${d.y})`); }); if (!physicsEnabled) { simulation.stop(); } } function getNodeColor(node) { const colors = { '__start__': '#28a745', '__end__': '#dc3545', 'default': '#667eea' }; if (node.id === '__start__') return colors['__start__']; if (node.id === '__end__') return colors['__end__']; if (node.metadata && node.metadata.__interrupt) return '#fd7e14'; return colors['default']; } function getNodeSize(node) { if (node.id === '__start__' || node.id === '__end__') return 25; return 20; } function showNodeDetails(node) { const details = document.getElementById('nodeDetails'); const interruptInfo = node.metadata && node.metadata.__interrupt ? `<div style="background: #fff3cd; padding: 8px; border-radius: 5px; margin-top: 10px;"> <strong>⚠️ Interrupt:</strong> ${node.metadata.__interrupt} </div>` : ''; details.innerHTML = ` <div class="node-info"> <h4>${node.name}</h4> <p><strong>ID:</strong> ${node.id}</p> <p><strong>Type:</strong> ${node.type}</p> ${node.data && node.data.id ? `<p><strong>Module:</strong> ${node.data.id.join('.')}</p>` : ''} ${interruptInfo} </div> `; } function updateGraphStats() { const stats = document.getElementById('graphStats'); const conditionalEdges = links.filter(l => l.conditional).length; const regularEdges = links.length - conditionalEdges; stats.innerHTML = ` <div class="node-info"> <h4>📈 Graph Statistics</h4> <p><strong>Nodes:</strong> ${nodes.length}</p> <p><strong>Total Edges:</strong> ${links.length}</p> <p><strong>Regular Edges:</strong> ${regularEdges}</p> <p><strong>Conditional Edges:</strong> ${conditionalEdges}</p> </div> `; } // Drag functions function dragstarted(event, d) { if (!event.active && physicsEnabled) simulation.alphaTarget(0.3).restart(); d.fx = d.x; d.fy = d.y; } function dragged(event, d) { d.fx = event.x; d.fy = event.y; } function dragended(event, d) { if (!event.active && physicsEnabled) simulation.alphaTarget(0); d.fx = null; d.fy = null; } // Utility functions function toggleSidebar() { const sidebar = document.getElementById('sidebar'); const toggleText = document.getElementById('sidebarToggleText'); sidebar.classList.toggle('hidden'); toggleText.textContent = sidebar.classList.contains('hidden') ? '▶' : '◀'; } function resetLayout() { if (simulation) { nodes.forEach(node => { node.x = Math.random() * 800 + 100; node.y = Math.random() * 600 + 100; node.fx = null; node.fy = null; }); simulation.alpha(1).restart(); } } function centerGraph() { if (svg) { const width = parseInt(svg.attr("width")); const height = parseInt(svg.attr("height")); svg.transition().duration(750).call( d3.zoom().transform, d3.zoomIdentity.translate(width / 2, height / 2).scale(1) ); } } function togglePhysics() { physicsEnabled = !physicsEnabled; if (simulation) { if (physicsEnabled) { simulation.restart(); } else { simulation.stop(); } } showStatus(`Physics ${physicsEnabled ? 'enabled' : 'disabled'}`, false); } function exportGraph() { const svgElement = document.getElementById('graph'); const serializer = new XMLSerializer(); const svgString = serializer.serializeToString(svgElement); const blob = new Blob([svgString], { type: 'image/svg+xml' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = 'graph-visualization.svg'; a.click(); URL.revokeObjectURL(url); showStatus('Graph exported as SVG!', false); } function showStatus(message, isError) { const status = document.getElementById('status'); status.textContent = message; status.className = isError ? 'status error' : 'status'; status.style.display = 'block'; setTimeout(() => { status.style.display = 'none'; }, 3000); } // Handle window resize window.addEventListener('resize', () => { if (svg && nodes.length > 0) { createVisualization(); } }); // Load D3.js and initialize const script = document.createElement('script'); script.src = 'https://cdnjs.cloudflare.com/ajax/libs/d3/7.8.5/d3.min.js'; script.onload = init; document.head.appendChild(script); </script> </body> </html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interactive Graph Visualizer</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
flex-direction: column;
}
.header {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
padding: 20px;
text-align: center;
color: white;
box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
}
.header h1 {
font-size: 2.5em;
margin-bottom: 10px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}
.controls {
background: rgba(255, 255, 255, 0.95);
padding: 15px;
display: flex;
gap: 15px;
align-items: center;
justify-content: center;
flex-wrap: wrap;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.control-group {
display: flex;
align-items: center;
gap: 8px;
}
button {
background: linear-gradient(45deg, #667eea, #764ba2);
color: white;
border: none;
padding: 10px 20px;
border-radius: 25px;
cursor: pointer;
font-weight: 600;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}
button:active {
transform: translateY(0);
}
.file-input {
display: none;
}
.file-label {
background: linear-gradient(45deg, #28a745, #20c997);
color: white;
padding: 10px 20px;
border-radius: 25px;
cursor: pointer;
font-weight: 600;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}
.file-label:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}
.container {
flex: 1;
display: flex;
position: relative;
overflow: hidden;
}