forked from bricaud/graphexp
-
Notifications
You must be signed in to change notification settings - Fork 46
/
graphexp.html
436 lines (392 loc) · 17.6 KB
/
graphexp.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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Graphexp, graph explorer</title>
<head>
<link rel="stylesheet" href="css/graphStyle.css">
<link rel="stylesheet" href="css/styles.css">
<link rel="stylesheet" href="css/bootstrap.css">
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="scripts/utils.js"></script>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="scripts/graphConf.js"></script>
<script src="scripts/graphShapes.js"></script>
<script src="scripts/infobox.js"></script>
<script src="scripts/graph_viz.js"></script>
<script src="scripts/graphioGremlin.js"></script>
<script src="scripts/bootstrap.min.js"></script>
<script src="scripts/editGraph.js"></script>
<script type="text/javascript">
function search_query(){
graphioGremlin.search_query();
}
function get_graph_info(){
graphioGremlin.get_graph_info();
infobox.show_element("#graphInfo");
document.getElementById ("showgraphinfo").checked = true;
}
</script>
</head>
<body style="overflow: hidden;">
<div class="pos-f-t">
<div class="collapse" id="navbarToggleExternalContent">
<nav class="navbar navbar-dark bg-dark" style="color:white;">
<div class="form-inline my-2 my-lg-0" style="color:white;">
<div class="nav input_unit_container form-group">
<label for="label_field">Node label :</label>
<input type="text" class="form-control" name="label_field" id="label_field" placeholder="Node label" value="" />
</div>
<div class="nav input_unit_container form-group">
<label for="search_field">Node property:</label>
<input name="search_field" class="form-control" id="search_field" value="" />
</div>
<div class="nav input_unit_container form-group">
<label class="nav input_label" for="search_value">Property value:</label>
<input name="search_value" class="form-control" id="search_value" value="" />
</div>
<div class="nav input_unit_container form-group">
<label for="search_type">Type of search:</label>
<select class="form-control form-control-lg" name="search_type" id="search_type">
<option value="eq">Equals</option>
<option value="contains">Contains</option>
</select>
</div>
<div class="nav input_unit_container form-group">
<label for="limit_field">Results limit:</label>
<input name="limit_field" class="form-control" id="limit_field" value="50" min="1" max="1000" type="number"/>
</div>
<div class="nav input_unit_container form-group">
<label class="nav input_label" for="edge_filter">Traverse by edge:</label>
<input name="edge_filter" class="form-control" id="edge_filter" value="" />
</div>
<div class="nav input_unit_container form-group">
<label class="nav input_label" for="nbLayers">Nb of layers</label>
<input type="number" class="form-control" id="nbLayers" min="1" max="128" onclick="set_nb_layers()">
</div>
</div>
</nav>
</div>
<nav class="navbar navbar-dark bg-dark">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggleExternalContent" aria-controls="navbarToggleExternalContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span><span style="color: white;"> Form Queries</span>
</button>
<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
<li style="margin-left: 10px;">
<button style="float;left; position: relative;" class="btn btn-default" onclick="editGraph()" > Edit Graph </button>
</li>
<li>
<div class="form-inline my-2 my-lg-0" id="editGraph" style="display:none; margin-left:10px;">
<div class="form-inline my-2 my-lg-0">
<button class="btn btn-default" onclick="addVertexForm()"> Add Vertex </button><br>
<button class="btn btn-default" onclick="editVertexForm()"> Edit Vertex </button><br>
<button class="btn btn-default" onclick="addEditEdgeForm()"> Add/Edit Edge </button><br>
</div>
</div>
</li>
</ul>
<div class="form-inline my-2 my-lg-0" style="color:white;">
<div class="form-inline my-2 my-lg-0">
<div class="form-check abc-checkbox" style="margin-right: 15px">
<input class="form-check-input" type="checkbox" name="Freeze" id="freeze-in" />
<label class="form-check-label" for="freeze-in">Freeze exploration</label>
</div>
<div class="form-check abc-checkbox" style="margin-right: 15px">
<input class="form-check-input" type="checkbox" name="showName_box" id="showName" onclick="graphShapes.show_names()"/>
<label class="form-check-label" for="showName">Show labels</label>
</div>
<button style="margin-right: 8px" name="search query" class="btn btn-outline-default my-2 my-sm-0" onclick="search_query();">Search</button>
<button style="margin-right: 8px" name="clear" class="btn btn-outline-danger my-2 my-sm-0"onclick="graph_viz.clear();">Clear</button>
<button type="button" class="btn btn-outline-info my-2 my-sm-0" data-toggle="modal" data-target="#myModal">Server Settings</button>
</div>
</div>
</nav>
</div>
<div class="container-fluid">
<div class="content">
<div class="main" id="main">
<svg></svg>
</div>
<div class="aside left_bar_edit"><div class="nav input_unit_container", id="addVertexForm" style="display:none;">
<h2>Add Vertex :</h2>
<div class="nav input_unit_container form-group">
<label for="vertexLabel">Vertex Label: </label>
<input type="text" name="vertexLabel" id="vertexLabel" class="form-control" placeholder="Enter Vertex Label">
</div>
<div class="nav input_unit_container form-group">
<label for="vertexPropertyName">Vertex Property:</label>
<input type="text" name="vertexPropertyName" class="form-control" id="vertexPropertyName" placeholder="Enter Comma Seperated Property Name (e.g. name,age,gender)" size="45">
</div>
<div class="nav input_unit_container form-group">
<label for="vertexPropertyValue">Property Value:</label>
<input type="text" name="vertexPropertyValue" class="form-control" id="vertexPropertyValue" placeholder="Enter Comma Seperated Property Value (e.g. Sandeep,27,male)">
</div>
<button class="btn btn-default btn-block" onclick="addVertex()"> Add Vertex </button>
</div><div class="nav input_unit_container", id="editVertexForm" style="display:none;">
<h2>Edit Vertex :</h2>
<div class="nav input_unit_container form-group">
<label for="vertexId" > Vertex ID: </label>
<input type="text" name="vertexId" id="vertexId" class="form-control" size="45" placeholder="Enter Vertex ID (e.g. 123)">
</div>
<div class="nav input_unit_container form-group">
<label for="vertexPropertyName" > Vertex Property: </label>
<input type="text" name="vertexPropertyName_1" id="vertexPropertyName_1" class="form-control" placeholder="Enter Comma Seperated Property Name (e.g. name,age)">
</div>
<div class="nav input_unit_container form-group">
<label for="vertexPropertyValue" > Property Value: </label>
<input type="text" name="vertexPropertyValue_1" id="vertexPropertyValue_1" class="form-control" placeholder="Enter Comma Seperated Property Value (e.g. Sandeep,25)">
</div>
<button class="btn btn-default btn-block" onclick="editVertex()"> Edit Vertex </button>
</div><div class="nav input_unit_container", id="addEditEdgeForm" style="display:none;">
<h2>Add / Edit Edge :</h2>
<div class="nav input_unit_container form-group">
<label for="edgeLabel" > Edge Label: </label>
<input type="text" name="edgeLabel" id="edgeLabel" class="form-control" placeholder="Enter Edge Label">
</div>
<div class="nav input_unit_container form-group">
<label for="sourceVertexId"> Source Vertex ID: </label>
<input type="text" name="sourceVertexId" id="sourceVertexId" class="form-control" placeholder="Enter Source Vertex ID">
</div>
<div class="nav input_unit_container form-group">
<label for="targetVertexId"> Target Vertex ID: </label>
<input type="text" name="targetVertexId" id="targetVertexId" class="form-control" placeholder="Enter Target Vertex ID">
</div>
<div class="nav input_unit_container form-group">
<label for="edgePropertyName"> Property Name: </label>
<input type="text" name="edgePropertyName" id="edgePropertyName" class="form-control" placeholder="Enter Comma Seperated Property Name">
</div>
<div class="nav input_unit_container form-group">
<label for="edgePropertyValue"> Property Value: </label>
<input type="text" name="edgePropertyValue" id="edgePropertyValue" class="form-control" placeholder="Enter Comma Seperated Property Value">
</div>
<button class="btn btn-default btn-block" onclick="addEditEdge()"> Add/Edit Edge </button>
</div></div>
<div class="aside left_bar" style="pointer-events:auto;">
<div id="graphInfoBar" style="pointer-events:auto;">
<button name="graphInfo" class="btn btn-default btn-lg" onclick="get_graph_info();">Get graph info</button>
<div class="form-check">
<input type="checkbox" name="showgraphinfo" id="showgraphinfo" onchange="show_hide_element('#graphInfo')"/>
<label class="form-check-label" for="showgraphinfo">
Show/hide graph info
</label>
</div>
</div>
<div id="graphInfo" style="pointer-events:none;">
</div>
</div>
<div class="middle">
<div id="messageArea"></div><div id="outputArea"></div>
</div>
<div class="aside right_bar" id="details" style="pointer-events:auto;">
<div id="nodeInfo" style="pointer-events:none;">
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Server Settings :</h4>
</div>
<div class="modal-body">
<div class="footer">
<div class="container">
<form>
<div class="form-group">
<label for="server_address">Server address:</label>
<input name="server_address" type="text" class="form-control" id="server_address" placeholder="Enter server address" value="localhost">
<small id="emailHelp" class="form-text text-muted">The gremlin server address with which we want to communicate.</small>
</div>
<div class="form-group">
<label for="server_port">Server Port</label>
<input type="text" class="form-control" name="server_port" id="server_port" placeholder="Server port" value="8182">
</div>
<div class="form-group">
<label for="server_protocol">Protocol:</label>
<select class="form-control form-control-lg" name="server_protocol" id="server_protocol">
<option value="websocket">websocket</option>
<option value="REST">REST</option>
</select>
</div>
<div class="form-group">
<label for="communication_method">Gremlin version:</label>
<select class="form-control form-control-lg" name="communication_method" id="communication_method">
<option value="GraphSON3">3.3.*</option>
<option value="GraphSON2">3.2.*</option>
</select>
</div>
</form>
</div>
</div>
</div>
<div class="modal-footer">
<a style="display: block;position: absolute;left: 30px;" href="http://www.github.com/bricaud/graphexp">Graph Explorer V 0.8.0</a>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- INITIALIZATION -->
<script type="text/javascript">
if(host){
$('#server_address').val(host);
}
init_property_bar();
// Create the graph canvas in the chosen div element
graph_viz.init("#main");
// Add the zoom layer to the graph
//var svg_graph =
graph_viz.addzoom();
//graph_viz.layers.set_nb_layers(4);
// Create the info box for node details
infobox.create("#graphInfo","#nodeInfo"); // from module in infobox.js
//console.log(graph_viz.graph_events.ev);
//graph_viz.graph_events.test();
function init_property_bar(){
document.getElementById('nbLayers').value = default_nb_of_layers;
}
function change_nav_bar(node_data,edge_data){
var nav_bar = d3.select("#prop_choice");
nav_bar.select("input").remove();
nav_bar.select("select").remove();
//nav_choices = nav_bar.append("ul");
//nav_choices.append("li").append("button").attr("onclick",search_query).text("Search")
var select = d3.select('#prop_choice')
.append('select').attr('class','select').attr('id','search_field')
var select_node = select.append('optgroup').attr('label','Nodes')
//.on('change',onchange)
var select_edge = select.append('optgroup').attr('label','Edges')
var node_options = select_node
.selectAll('option')
.data(node_data).enter()
.append('option')
.text(function (d) { return d; });
var edge_options = select_edge
.selectAll('option')
.data(edge_data).enter()
.append('option')
.text(function (d) { return d; });
}
function display_properties_bar(prop_list,item,text){
var nav_bar = d3.select("#graphInfoBar");
nav_bar.select("#property_bar_"+item).remove();
var property_bar = nav_bar.append("div").attr("id","property_bar_"+item);
property_bar.append('text').text(text).style("font-weight","bold");
//d3.select('#property_bar').append('text').text('hello')
var property_label = property_bar.selectAll('input').append("ul")
.data(prop_list).enter().append("li");
//.append('label');
property_label.append('input').attr('type','checkbox').attr('id',function (d) { return item+"_"+d; })
.attr('id_nb',function (d) { return prop_list.indexOf(d); })
//.attr('onchange',function(d){display_prop(d);});
.attr('onchange','display_prop(this)');
property_label.append('label').text(function (d) { return d; });
}
function display_color_choice(prop_list,item,text){
prop_list = ['none','label'].concat(prop_list);
var nav_bar = d3.select("#graphInfoBar");
nav_bar.select("#color_choice_"+item).remove();
var color_bar = nav_bar.append("div").attr("id","color_choice_"+item);
color_bar.append("div").append("text").text(text).style("font-weight","bold");
color_bar.append("div").append("select").attr("class","select").attr("id","color_select_"+item)
.attr("onchange","colorize(this)")
.selectAll("option")
.data(prop_list).enter()
.append("option")
.text(function (d) { return d; });
}
function colorize(selection){
var value = selection.value;
console.log('Color by '+value);
graphShapes.colorize(value);
}
function display_prop(prop){
var prop_id = prop.id;
var prop_id_nb = prop.getAttribute('id_nb');
var text_base_offset = 10;
var text_offset = 10;
var prop_name = prop_id.slice(prop_id.indexOf("_")+1);
var item = prop_id.slice(0,prop_id.indexOf("_"));
console.log(prop_id,item)
if(d3.select("#"+prop_id).property("checked")){
if (item=='nodes'){
var elements_text = d3.selectAll('.node');
} else if (item=='edges'){
var elements_text = d3.selectAll('.edgelabel');
}
attach_property(elements_text,prop_name,prop_id_nb,item)
}
else{
if (item=='nodes'){
d3.selectAll('.node').select('.'+prop_id).remove();
}
else if (item=='edges'){
d3.selectAll('.edgelabel').select('.'+prop_id).remove();
}
}
}
function attach_property(graph_objects,prop_name,prop_id_nb,item){
var text_base_offset = 10;
var text_offset = 10;
var prop_id = item+"_"+prop_name;
if (item=='nodes'){
elements_text = graph_objects.append("text").style("pointer-events", "none");
}
else if (item=='edges'){
var elements_text = graph_objects.append("textPath")
.attr('class','edge_text')
.attr('href', function (d, i) {return '#edgepath' + d.id})
.style("text-anchor", "middle")
.style("pointer-events", "none")
.attr("startOffset", "70%");
//.text(function (d) {return d.label});
prop_id_nb = prop_id_nb + 1;
}
else {
console.log('Bad item name.'); return 1;
}
elements_text.classed("prop_details",true).classed(prop_id,true)
//.attr("x", 12)
.attr("dy",function(d){return graphShapes.node_size(d)+text_base_offset+text_offset*parseInt(prop_id_nb);})
//.attr("y", ".31em")
.text(function(d){return get_prop_value(d,prop_name,item);});
}
function get_prop_value(d,prop_name,item){
//let COMMUNICATION_METHOD = $('#communication_method').val();
if (prop_name in d.properties){
if (item=='nodes'){
if ('summary' in d.properties[prop_name]) {
return d.properties[prop_name]['summary'];
} else if (COMMUNICATION_METHOD == 'GraphSON1') {
return d.properties[prop_name][0].value;
}
}
else if (item=='edges'){
//console.log(d.properties[prop_name])
return d.properties[prop_name];
}
}
else {
return "";
}
}
function set_nb_layers(){
var nb_layers = parseInt(document.getElementById('nbLayers').value);
//var nb_layers = parseInt(layer_input.getAttribute("value"));
console.log(nb_layers)
graph_viz.layers.set_nb_layers(nb_layers);
}
function show_hide_element(element_label){
element = d3.select(element_label);
var input = document.getElementById ("showgraphinfo");
var isChecked = input.checked;
if (isChecked) element.style("display", "inline");
else {element.style("display", "none");}
}
</script>
</div>
</body>
</html>