-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath.html
108 lines (100 loc) · 3.03 KB
/
path.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Shortest Path - Minnebar graph algorithms</title>
<script src="src/Graph.js"></script>
<script src="src/Node.js"></script>
<script src="src/Edge.js"></script>
<script src="src/GraphBuilder.js"></script>
<script src="src/Dijkstra.js"></script>
<script src="src/GraphRenderer.js"></script>
<style>
.node {
fill:lightskyblue;
stroke-width:2;
stroke:darkblue;
}
.line {
stroke: darkblue;
}
.u {
fill: forestgreen;
}
.v {
fill: orange;
}
.nodeDist {
fill: darkmagenta;
}
.distConsider {
font-weight: bold;
}
.visited {
fill: dimgray;
}
.sideConsole {
float: right;
width: 300px;
font-family: monospace;
font-size: large;
}
</style>
</head>
<body>
<div class="sideConsole">
<div id="consoleOutput">
</div>
<div id="key" class="sideKey">
Key
<svg height="300" width="300"><g>
<circle r="20" class="node u" cx="25" cy="30" />
<text x="55" y="32">u: under consideration</text>
<circle r="20" class="node v" cx="25" cy="80" />
<text x="55" y="82">v: neighbor</text>
<circle r="20" class="node visited" cx="25" cy="130" />
<text x="55" y="132">visited</text>
</g></svg>
</div>
</div>
<div id="graphViz">
<svg height="500" width="1000" id="graphSvg"><g id="graphSvgG"></g></svg>
</div>
<button id="nextStep">Next step</button>
<script>
const graph = (new GraphBuilder()).buildPathGraph();
const dijkstra = new Dijkstra(graph);
const minneapolis = graph.getNodes().get('Minneapolis');
/*
dijkstra.run(minneapolis);
console.log(dijkstra.summarizeResults());
*/
const graphRenderer = new GraphRenderer(graph);
const width = window.innerWidth - 350;
const height = window.innerHeight - 100;
const svg = document.getElementById('graphSvg');
svg.setAttribute('width', String(width));
svg.setAttribute('height', String(height));
graphRenderer.render(graph, {
'Minneapolis': [0.3 * width, 0.3 * height],
'Rochester': [0.3 * width, 0.5 * height],
'Madison': [0.6 * width, 0.6 * height],
'Des Moines': [0.3 * width, 0.9 * height],
'Chicago': [0.8 * width, 0.9 * height],
'Milwaukee': [0.8 * width, 0.6 * height],
'St Cloud': [0.2 * width, 0.2 * height],
'Fargo': [0.1 * width, 0.1 * height],
'Sioux Falls': [0.1 * width, 0.5 * height],
//'Space': [0.7 * width, 0.1 * height],
});
document.getElementById('nextStep').onclick = function() {
graphRenderer.runNextStep();
}
async function run() {
await dijkstra.runVisualize(minneapolis, graphRenderer);
console.log(dijkstra.summarizeResults());
}
run();
</script>
</body>
</html>