Network-Customelement/dynamic_usage_example.html
2025-08-14 18:47:12 +02:00

45 lines
1.1 KiB
HTML

<!doctype html>
<html>
<head>
<title>JsNetworkx Custom Element</title>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v3.js"></script>
<script src="jsnetworkx.js"></script>
<script src="widget.js"></script>
</head>
<body>
<net-graph id="graph2" weighted="true" style="width:800px; height:600px;">
{
"nodes": [
[ "orange", { "radius": 5, "color": "orange"} ],
[ 2, { "radius": 15, "color": "green"} ],
[ 3, { "radius": 25, "color": "red"} ]
],
"edges": [
["orange", 2]
]
}
</net-graph>
<net-graph id="graph" weighted="true" style="width:800px; height:600px;" />
<script>
let ele = document.getElementById("graph");
let i = 10;
setInterval(()=>{
ele.G.addNode(i, { "radius": Math.floor(Math.random() * 30), "color": "red"} );
ele.G.addEdge(i - 1, i);
if(i > 20) i = -10;
i += 1;
},1000);
</script>
</body>
</html>