-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraph.html
260 lines (238 loc) · 9.42 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rasa Core Visualisation</title>
<script src="https://dagrejs.github.io/project/dagre-d3/latest/dagre-d3.min.js"></script>
<script src="https://dagrejs.github.io/project/dagre/latest/dagre.min.js"></script>
<script src="https://d3js.org/d3.v4.js"></script>
<script src="https://dagrejs.github.io/project/graphlib-dot/v0.6.3/graphlib-dot.js"></script>
</head>
<body>
<div id="errormsg" style="color: #b00"></div>
<svg>
<style id="graph-style">
.node.invisible > rect {
display: none;
}
.node.start > rect {
fill: #7f7;
rx: 30;
ry: 18;
}
.node.end > rect {
fill: #f77;
rx: 30;
ry: 18;
}
.node:not(.active) > rect, .node:not(.active) > .label {
opacity: 0.4;
}
.edgePath:not(.active) path {
opacity: 0.4;
}
.node.ellipsis > rect {
fill: #CCC;
}
.node.intent > rect {
fill: #7ff;
}
.node.dashed > rect {
stroke-dasharray: 5;
}
text {
font-weight: 300;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serf, serif;
font-size: 14px;
color: #1f1d1d;
}
.node rect {
stroke: #444;
fill: #fff;
stroke-width: 1.5px;
}
.edgePath path {
stroke: #333;
stroke-width: 1.5px;
}
svg {
position: fixed;
top: 10px;
left: 0;
height: 100%;
width: 100%
}
</style>
<g></g>
</svg>
<script>
function serveGraph() {
let oldInputGraphValue;
const url = 'visualization.dot';
const refreshInterval = 500;
// trigger a refresh by fetching an updated graph
setInterval(function () {
fetch(url).then(r => r.text()).then(dot => {
document.getElementById('errormsg').innerHTML = '';
if (oldInputGraphValue === dot) return;
oldInputGraphValue = dot;
drawGraph(dot);
}).catch(err => {
document.getElementById('errormsg').innerHTML =
'Failed to update plot. (' + err.message + ')';
});
}, refreshInterval);
}
function drawGraph(graph) {
let g = graphlibDot.read(graph);
// 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(300);
};
// Render the graph into svg g
d3.select("svg g").call(render, g);
}
// Set up zoom support
const svg = d3.select("svg"),
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
const render = dagreD3.render();
let isClient = false;
isClient = true;
if (isClient) {
// Mark all nodes and their edges as active
cssRules = document.getElementById('graph-style').sheet.cssRules;
cssRules[3].style.opacity = 1;
cssRules[4].style.opacity = 1;
let graph;
graph = `digraph {
0 [class="start active", fillcolor=green, fontsize=12, label=START, style=filled];
"-1" [class=end, fillcolor=red, fontsize=12, label=END, style=filled];
1 [class="", fontsize=12, label=utter_greet_back];
2 [class="", fontsize=12, label=action_setup_interview];
5 [class="", fontsize=12, label=action_diagnose];
7 [class="", fontsize=12, label=utter_goodbye];
8 [class="", fontsize=12, label=utter_confirm_restart];
9 [class="", fontsize=12, label=action_restart];
13 [class="", fontsize=12, label=action_diagnose];
20 [class="", fontsize=12, label=action_setup_interview];
21 [class="", fontsize=12, label=action_diagnose];
39 [class="", fontsize=12, label=action_setup_interview];
64 [class="", fontsize=12, label=action_setup_interview];
65 [class="", fontsize=12, label="..."];
66 [class="", fontsize=12, label=utter_symptoms_inquiry_out_of_scope];
68 [class="", fontsize=12, label=utter_fallback_message];
69 [class=intent, fillcolor=lightblue, label="مساء النور", shape=rect, style=filled];
70 [class=intent, fillcolor=lightblue, label="شكرا ووداعا", shape=rect, style=filled];
71 [class=intent, fillcolor=lightblue, label="اعادة البدء", shape=rect, style=filled];
72 [class=intent, fillcolor=lightblue, label="عندي مشكله في الهضم", shape=rect, style=filled];
73 [class=intent, fillcolor=lightblue, label="كنت بعاني من وجع شديد اعلي البطن وخنقه وعدم القدره علي التنفس", shape=rect, style=filled];
74 [class=intent, fillcolor=lightblue, label="تبلغ من العمر 17 عام", shape=rect, style=filled];
75 [class=intent, fillcolor=lightblue, label="عمري 31 عاما ورأسي يؤلمني جدا", shape=rect, style=filled];
76 [class=intent, fillcolor=lightblue, label="عمري 18 عام", shape=rect, style=filled];
77 [class=intent, fillcolor=lightblue, label="انا زلمة", shape=rect, style=filled];
78 [class=intent, fillcolor=lightblue, label="عمتي", shape=rect, style=filled];
79 [class=intent, fillcolor=lightblue, label="أشعر بالم أسفل الصدر في الجهة اليسرى منذ فترة من الاعراض التي تضهر جراء هذا الالم الشعور بالدوار الشعور بالاختناق تنمل الاطراف القلق الشديد التبول بكثرة تنمل الجهة اليسرى خاصة في الرقبة", shape=rect, style=filled];
80 [class=intent, fillcolor=lightblue, label="بالضبط", shape=rect, style=filled];
81 [class=intent, fillcolor=lightblue, label="لا اتفق", shape=rect, style=filled];
82 [class=intent, fillcolor=lightblue, label="انت على حق", shape=rect, style=filled];
83 [class=intent, fillcolor=lightblue, label="ما تقوله خاطئ", shape=rect, style=filled];
84 [class=intent, fillcolor=lightblue, label="ما بدري", shape=rect, style=filled];
85 [class=intent, fillcolor=lightblue, label="رائع. حسنا, مع القاء", shape=rect, style=filled];
86 [class=intent, fillcolor=lightblue, label="ليس بصحيح", shape=rect, style=filled];
87 [class=intent, fillcolor=lightblue, label="اؤكد على ذلك", shape=rect, style=filled];
88 [class=intent, fillcolor=lightblue, label="لا ادري صراحة", shape=rect, style=filled];
89 [class=intent, fillcolor=lightblue, label="لا ادري", shape=rect, style=filled];
90 [class=intent, fillcolor=lightblue, label="وافقت", shape=rect, style=filled];
91 [class=intent, fillcolor=lightblue, label="انا على قبول", shape=rect, style=filled];
92 [class=intent, fillcolor=lightblue, label="عمرها 88 عام", shape=rect, style=filled];
93 [class=intent, fillcolor=lightblue, label="زوجي", shape=rect, style=filled];
94 [class=intent, fillcolor=lightblue, label="عمري 22 سنة", shape=rect, style=filled];
95 [class=intent, fillcolor=lightblue, label="ما هي اعراض مرض السكري؟", shape=rect, style=filled];
96 [class=intent, fillcolor=lightblue, label="/nlu_fallback", shape=rect, style=filled];
0 -> 65 [class="", key=NONE, label=""];
0 -> 69 [class="", key=0];
0 -> 70 [class="", key=0];
0 -> 71 [class="", key=0];
0 -> 72 [class="", key=0];
1 -> "-1" [class="", key=NONE, label=""];
1 -> 73 [class="", key=0];
2 -> 5 [class="", key=NONE, label=""];
2 -> 13 [class="", key=NONE, label=""];
2 -> 74 [class="", key=0];
2 -> 75 [class="", key=0];
2 -> 76 [class="", key=0];
2 -> 77 [class="", key=0];
2 -> 78 [class="", key=0];
2 -> 79 [class="", key=0];
5 -> "-1" [class="", key=NONE, label=""];
7 -> "-1" [class="", key=NONE, label=""];
8 -> 80 [class="", key=0];
8 -> 81 [class="", key=0];
9 -> "-1" [class="", key=NONE, label=""];
13 -> 82 [class="", key=0];
13 -> 83 [class="", key=0];
13 -> 84 [class="", key=0];
13 -> 85 [class="", key=0];
20 -> 21 [class="", key=NONE, label=""];
20 -> 5 [class="", key=NONE, label=""];
21 -> 86 [class="", key=0];
21 -> 87 [class="", key=0];
21 -> 88 [class="", key=0];
21 -> 89 [class="", key=0];
21 -> 90 [class="", key=0];
21 -> 91 [class="", key=0];
39 -> 92 [class="", key=0];
39 -> 93 [class="", key=0];
39 -> 94 [class="", key=0];
64 -> "-1" [class="", key=NONE, label=""];
65 -> 95 [class="", key=0];
65 -> 96 [class="", key=0];
66 -> "-1" [class="", key=NONE, label=""];
68 -> "-1" [class="", key=NONE, label=""];
69 -> 1 [class="", key=0];
70 -> 7 [class="", key=0];
71 -> 8 [class="", key=0];
72 -> 39 [class="", key=0];
73 -> 2 [class="", key=0];
74 -> 2 [class="", key=0];
75 -> 2 [class="", key=0];
76 -> 20 [class="", key=0];
77 -> 20 [class="", key=0];
78 -> 39 [class="", key=0];
79 -> 39 [class="", key=0];
80 -> 9 [class="", key=0];
81 -> "-1" [class="", key=0];
82 -> 13 [class="", key=0];
83 -> 13 [class="", key=0];
84 -> 13 [class="", key=0];
85 -> 7 [class="", key=0];
86 -> 21 [class="", key=0];
87 -> 21 [class="", key=0];
88 -> 21 [class="", key=0];
89 -> 13 [class="", key=0];
90 -> 13 [class="", key=0];
91 -> 5 [class="", key=0];
92 -> 20 [class="", key=0];
93 -> 39 [class="", key=0];
94 -> 64 [class="", key=0];
95 -> 66 [class="", key=0];
96 -> 68 [class="", key=0];
}
`;
drawGraph(graph);
} else {
serveGraph();
}
</script>
</body>
</html>