-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.html
101 lines (82 loc) · 1.89 KB
/
graph.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
<!DOCTYPE html>
<meta charset="utf-8" />
<title>adventure section graph</title>
<script src="external/d3.v4.js"></script>
<script src="external/graphlib-dot.js"></script>
<script src="external/dagre-d3.js"></script>
<style>
html,
body {
margin: 0;
}
body {
font-family: sans-serif;
}
svg {
overflow: hidden;
}
.node {
white-space: nowrap;
}
.node rect,
.node circle,
.node ellipse {
stroke: #333;
fill: #fff;
stroke-width: 1.5px;
}
.cluster rect {
stroke: #333;
fill: #000;
fill-opacity: 0.1;
stroke-width: 1.5px;
}
.edgePath path.path {
stroke: #333;
stroke-width: 1.5px;
fill: none;
}
</style>
<body>
<svg>
<g />
</svg>
<script>
// Set up zoom support
var svg = d3.select('svg');
svg.attr('width', window.innerWidth);
svg.attr('height', window.innerHeight);
var inner = d3.select('svg g'),
zoom = d3.zoom().on('zoom', function() {
inner.attr('transform', d3.event.transform);
});
svg.call(zoom);
// Create and configure the renderer
var render = dagreD3.render();
var g;
function draw(dotString) {
try {
g = graphlibDot.read(dotString);
} catch (e) {
window.alert(e);
throw e;
}
// Set margins, if not present
if (
!g.graph().hasOwnProperty('marginx') &&
!g.graph().hasOwnProperty('marginy')
) {
g.graph().marginx = 20;
g.graph().marginy = 20;
}
g.graph().transition = function(selection) {
return selection.transition().duration(500);
};
// Render the graph into svg g
d3.select('svg g').call(render, g);
}
fetch('TheSleepingDragon.dot')
.then((resp) => resp.text())
.then(draw);
</script>
</body>