KGBrain commited on
Commit
e6c0aaf
·
1 Parent(s): 9c34edb

Upload 4 files

Browse files
Files changed (4) hide show
  1. index.html +918 -0
  2. level2.css +18 -0
  3. side.css +21 -0
  4. tree.css +15 -0
index.html ADDED
@@ -0,0 +1,918 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <!-- <iframe
4
+ src="https://seetha-ima-pipeline-streamlit.hf.space?embed=true"
5
+ frameborder="0"
6
+ width="850"
7
+ height="450"
8
+ ></iframe> -->
9
+
10
+ <!-- <div id="dv" class="six columns">
11
+ <iframe id="myFrame" name="myFrame" src="https://seetha-ima-pipeline-streamlit.hf.space?embed=true"></iframe>
12
+ </div> -->
13
+
14
+ <head>
15
+ <link rel = "stylesheet" href = "tree.css">
16
+ <link rel = "stylesheet" href = "level2.css">
17
+ <link rel = "stylesheet" href = "side.css">
18
+ <meta name="viewport" content="width=device-width, initial-scale=1">
19
+ <style>
20
+
21
+ body {background-color: floralwhite;}
22
+ </style>
23
+ <style>
24
+
25
+
26
+ #d1 {
27
+ display: block;
28
+
29
+ }
30
+ #d2 {
31
+ display: none;
32
+ }
33
+ table {
34
+ border-collapse: collapse;
35
+ table-layout: fixed;
36
+ width: 100%;
37
+
38
+ }
39
+
40
+ th, td {
41
+ border: 1px solid black;
42
+ padding: 5px;
43
+ text-align: center;
44
+
45
+ }
46
+ tr:hover {
47
+ background-color: lightgoldenrodyellow;
48
+
49
+ }
50
+ th{
51
+ position: sticky;
52
+ top: 0;
53
+ background-color: lightsteelblue;
54
+ }
55
+
56
+
57
+
58
+ </style>
59
+ <center>
60
+ <h1 style="color:black;">Causal Text to Knowledge Graph </h1>
61
+ </center>
62
+ </head>
63
+ <body>
64
+
65
+
66
+ <div id = "container">
67
+ <div id = "tree">
68
+ <script src="https://d3js.org/d3.v3.min.js"></script>
69
+ <script>
70
+
71
+ var treeData = [
72
+ {
73
+ "name": "Performance or Not",
74
+ "children": [
75
+ {
76
+ "name": "Performance (P)",
77
+ "children": [
78
+ {
79
+ "name": "Investors (INV)"
80
+ },
81
+ {
82
+ "name": "Customers (CUS)"
83
+ },
84
+ {
85
+ "name": "Employees (EMP)"
86
+
87
+ },
88
+ {
89
+ "name": "Society (SOC)"
90
+ },
91
+ {
92
+ "name": "Unclassified"
93
+ }
94
+ ]
95
+ },
96
+ {
97
+ "name": "Non-performance (NP)",
98
+ }
99
+ ]
100
+ }
101
+ ];
102
+
103
+ var margin = {top: 20, right: 120, bottom: 20, left: 120},
104
+ width = 800 - margin.right - margin.left,
105
+ height = 620 - margin.top - margin.bottom;
106
+
107
+ var i = 0,
108
+ duration = 750,
109
+ root;
110
+
111
+
112
+ var tree = d3.layout.tree()
113
+ .size([height, width]);
114
+
115
+ var diagonal = d3.svg.diagonal()
116
+ .projection(function(d) { return [d.y, d.x]; });
117
+
118
+
119
+ var svg3 = d3.select("#tree").append("svg")
120
+ .attr("width", width + margin.right + margin.left)
121
+ .attr("height", height + margin.top + margin.bottom)
122
+ .append("g")
123
+ .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
124
+
125
+ root = treeData[0];
126
+ root.x0 = height / 2;
127
+ root.y0 = 0;
128
+
129
+ function collapse(d) {
130
+ if (d.children) {
131
+ d._children = d.children;
132
+ d._children.forEach(collapse);
133
+ d.children = null;
134
+ }
135
+ }
136
+
137
+ root.children.forEach(collapse);
138
+ update(root);
139
+
140
+ function update(source) {
141
+
142
+ // Compute the new tree layout.
143
+ var nodes = tree.nodes(root).reverse(),
144
+ links = tree.links(nodes);
145
+
146
+
147
+
148
+
149
+ // Normalize for fixed-depth.
150
+ nodes.forEach(function(d) { d.y = d.depth * 200; });
151
+
152
+ // Update the nodes…
153
+ var node = svg3.selectAll("g.node")
154
+ .data(nodes, function(d) { return d.id || (d.id = ++i); });
155
+
156
+ // Enter any new nodes at the parent's previous position.
157
+ var nodeEnter = node.enter().append("g")
158
+ .attr("class", "node")
159
+ .attr("transform", function(d) { return "translate(" + source.y0 + "," + source.x0 + ")"; })
160
+ .on("click", click);
161
+
162
+ nodeEnter.append("circle")
163
+ .attr("r", 1e-6)
164
+ .style("fill", function(d) {
165
+ if(d.name == "Performance or Not") {
166
+ return "white";
167
+ }
168
+ else if (d.name != "Non-performance (NP)") {
169
+ return "blue";
170
+ }
171
+ else {
172
+ return "gray";
173
+ }
174
+ });
175
+
176
+ nodeEnter.append("text")
177
+ .attr("x", function(d) { return d.children || d._children ? -10 : 10; })
178
+ .attr("dy", ".35em")
179
+ .attr("text-anchor", function(d) { return d.children || d._children ? "end" : "start"; })
180
+ .text(function(d) { return d.name; })
181
+ .style("fill-opacity", 1e-6);
182
+
183
+
184
+ var nodeUpdate = node.transition()
185
+ .duration(duration)
186
+ .attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; });
187
+
188
+ nodeUpdate.select("circle")
189
+ .attr("r", 8)
190
+ .style("fill", function(d) {
191
+ if(d.name == "Performance or Not") {
192
+ return "white";
193
+ }
194
+ else if (d.name != "Non-performance (NP)") {
195
+ return "blue";
196
+ }
197
+ else {
198
+ return "gray";
199
+ }
200
+ });
201
+
202
+
203
+ nodeUpdate.select("text")
204
+ .style("fill-opacity", 1);
205
+
206
+ // Transition exiting nodes to the parent's new position.
207
+ var nodeExit = node.exit().transition()
208
+ .duration(duration)
209
+ .attr("transform", function(d) { return "translate(" + source.y + "," + source.x + ")"; })
210
+ .remove();
211
+
212
+ nodeExit.select("circle")
213
+ .attr("r", 1e-6);
214
+
215
+ nodeExit.select("text")
216
+ .style("fill-opacity", 1e-6);
217
+
218
+ // Update the links…
219
+ var link = svg3.selectAll("path.link")
220
+ .data(links, function(d) { return d.target.id; });
221
+
222
+
223
+ // Enter any new links at the parent's previous position.
224
+ link.enter().insert("path", "g")
225
+ .attr("class", "link")
226
+ .attr("d", function(d) {
227
+ var o = {x: source.x0, y: source.y0};
228
+ return diagonal({source: o, target: o});
229
+ });
230
+ link.style("stroke","gray");
231
+
232
+ // Transition links to their new position.
233
+ link.transition()
234
+ .duration(duration)
235
+ .attr("d", diagonal);
236
+
237
+ // Transition exiting nodes to the parent's new position.
238
+ link.exit().transition()
239
+ .duration(duration)
240
+ .attr("d", function(d) {
241
+ var o = {x: source.x, y: source.y};
242
+ return diagonal({source: o, target: o});
243
+ })
244
+ .remove();
245
+
246
+ // Stash the old positions for transition.
247
+ nodes.forEach(function(d) {
248
+ d.x0 = d.x;
249
+ d.y0 = d.y;
250
+ });
251
+ console.log(nodes.length);
252
+ if(nodes.length ==3){
253
+
254
+ var x = document.getElementById("d1"); // Get the graph for Level1 nodes
255
+ var y = document.getElementById("d2"); // Get the graph for level 2 nodes
256
+ // x.style.display = "block"; // If number of nodes ==3, then you will hide the level 2 graph and display the level 1 graph
257
+ // y.style.display = "none";
258
+ var container = document.querySelector(".container");
259
+ // container.style.display = "none";
260
+
261
+ } else if(nodes.length >=8){
262
+
263
+ var x = document.getElementById("d1");
264
+ var y = document.getElementById("d2");
265
+ x.style.display = "none";
266
+ y.style.display = "block";
267
+ var container = document.querySelector(".container");
268
+ // container.style.display = "none";
269
+
270
+ }else if(nodes.length ==1){
271
+ var x = document.getElementById("d1");
272
+ var y = document.getElementById("d2");
273
+ x.style.display = "none";
274
+ y.style.display = "none";
275
+ var container = document.querySelector(".container");
276
+ // container.style.display = "none";
277
+ }
278
+
279
+ }
280
+
281
+
282
+
283
+
284
+ // Toggle children on click.
285
+ function click(d) {
286
+
287
+ if (d.children) {
288
+ d._children = d.children;
289
+ d.children = null;
290
+ } else {
291
+ d.children = d._children;
292
+ d._children = null;
293
+ }
294
+
295
+
296
+ update(d);
297
+
298
+
299
+
300
+
301
+ }
302
+ svg3.append("text")
303
+ .attr("x", width/2 + 10)
304
+ .attr("y", height - 150)
305
+ .attr("text-anchor", "middle")
306
+ .text("Taxonomy")
307
+ .style("font-weight", "bold")
308
+ .style("font-family", "Times New Roman")
309
+ .style("font-size", "16px")
310
+ .style("opacity", 0)
311
+ .transition()
312
+ .duration(2000)
313
+ .style("opacity", 1);
314
+
315
+ </script>
316
+ </div>
317
+
318
+ <div id="d1">
319
+ <script src="//d3js.org/d3.v3.min.js"></script>
320
+ <script>
321
+ var width = 620,
322
+ height = 570;
323
+ // SVG for Level1 graph
324
+ var svg = d3.select("#d1").append("svg")
325
+ .attr("width", width)
326
+ .attr("height", height)
327
+ .append("g");
328
+
329
+
330
+ var nodes1 = [
331
+ {x: width / 4, y: height / 2, label: "Non-Performance"},
332
+ {x: 3 * width / 4, y: height / 2, label: "Performance"}
333
+ ];
334
+
335
+ var links1 = [
336
+ {source: nodes1[0], target: nodes1[1]}
337
+ ];
338
+
339
+ var simulation1 = d3.layout.force()
340
+ .nodes(d3.values(nodes1))
341
+ .links(links1)
342
+ .size([width, height])
343
+ .linkDistance(400)
344
+ .charge(-3000)
345
+ .start();
346
+
347
+ var text1 = svg.append("g") // Append the node node names
348
+ .attr("class", "labels")
349
+ .selectAll("text")
350
+ .data(nodes1)
351
+ .enter().append("text")
352
+ .text(function(d) { return d.label; })
353
+ .attr("x", function(d) { return d.x+15; })
354
+ .attr("y", function(d) { return d.y+20; });
355
+
356
+ var link1 = svg.selectAll(".link") // Links between the nodes in the graph
357
+ .data(links1)
358
+ .enter()
359
+ .append("line")
360
+ .attr("class", "link")
361
+ .attr("x1", function(d) { return d.source.x; })
362
+ .attr("y1", function(d) { return d.source.y; })
363
+ .attr("x2", function(d) { return d.target.x; })
364
+ .attr("y2", function(d) { return d.target.y; });
365
+
366
+ link1.style("stroke","gray") // Color of the link and stroke width
367
+ .style("stroke-width",1.5+"px");
368
+
369
+
370
+ var node1 = svg.append("g") // Nodes in the graph
371
+ .attr("class", "nodes")
372
+ .selectAll("circle")
373
+ .data(nodes1)
374
+ .enter().append("circle")
375
+ .attr("r", 20)
376
+ .style("fill", function(d){
377
+ if(d.label == "Non-Performance"){
378
+ return "gray";
379
+ }else {
380
+ return "blue";
381
+ }
382
+ })
383
+
384
+ .attr("cx", function(d) { return d.x; })
385
+ .attr("cy", function(d) { return d.y; })
386
+ .on("mousedown",mousedown);
387
+
388
+ //To get the detailed results
389
+ function mousedown(d) {
390
+ var tableContainer = d3.select('.container');
391
+ tableContainer.remove();
392
+ d3.select("table").remove();
393
+
394
+ const nodeName = d.label;
395
+
396
+
397
+ var container = d3.select('body')
398
+ .append('div')
399
+ .attr('class', 'container')
400
+ .style('height', '250px')
401
+ .style('overflow', 'auto');
402
+
403
+ // Create the table element inside the container
404
+ var table = container.append('table')
405
+ .attr('class', 'table')
406
+ .style('table-layout', 'auto')
407
+
408
+
409
+
410
+ // Add a header row
411
+ const headerRow = table.append("tr");
412
+ headerRow.append("th").text("Id");
413
+ headerRow.append("th").text("Full Sentence");
414
+ headerRow.append("th").text("Component");
415
+ headerRow.append("th").text("cause/effect");
416
+ headerRow.append("th").text("Label level1");
417
+ headerRow.append("th").text("Label level2");
418
+
419
+
420
+ // Add a data row for the hovered node
421
+
422
+ d3.json("https://huggingface.co/datasets/Seetha/visual_files/raw/main/detailedResults.json", function(data) {
423
+ var table = d3.select("table"); // select the existing table
424
+ var tbody = table.append("tbody"); // create a tbody element
425
+ console.log(data)
426
+
427
+ // loop through each item in the data array
428
+ for (var i = 0; i < data.length; i++) {
429
+ console.log(nodeName);
430
+ console.log([data[i].Labellevel1])
431
+ if(nodeName == [data[i].Labellevel1]) {
432
+ console.log("yipee")
433
+
434
+ var tr = tbody.append("tr"); // create a table row for each item
435
+
436
+ // append a table cell with the Id property
437
+ tr.append("td").text(data[i].Id);
438
+ tr.append("td").text([data[i].Fullsentence]);
439
+ tr.append("td").text([data[i].Component]);
440
+ tr.append("td").text([data[i].causeOrEffect]);
441
+ tr.append("td").text([data[i].Labellevel1]);
442
+ tr.append("td").text([data[i].Labellevel2]);
443
+
444
+ }
445
+
446
+
447
+ }
448
+ });
449
+ }
450
+
451
+ svg.append("text")
452
+ .attr("x", width/2 + 10)
453
+ .attr("y", height - 150)
454
+ .attr("text-anchor", "middle")
455
+ .text(" Click on a node to get the detailed results")
456
+ .style("font-weight", "bold")
457
+ .style("font-family", "Times New Roman")
458
+ .style("font-size", "16px")
459
+ .style("opacity", 0)
460
+ .transition()
461
+ .duration(2000)
462
+ .style("opacity", 1);
463
+
464
+
465
+
466
+
467
+
468
+ </script>
469
+ </div>
470
+
471
+ <div id="d2">
472
+ <script src="http://d3js.org/d3.v3.min.js"></script>
473
+ <script>
474
+
475
+ // Load the data https://huggingface.co/datasets/Seetha/visual_files/
476
+ d3.json("https://huggingface.co/datasets/Seetha/visual_files/raw/main/level2.json", function(data) {
477
+ var links = data;
478
+ console.log(links)
479
+
480
+
481
+ // Compute the distinct nodes from the links.
482
+ links.sort(function(a,b) {
483
+ if (a.source > b.source) {return 1;}
484
+ else if (a.source < b.source) {return -1;}
485
+ else {
486
+ if (a.target > b.target) {return 1;}
487
+ if (a.target < b.target) {return -1;}
488
+ else {return 0;}
489
+ }
490
+ });
491
+
492
+ //any links with duplicate source and target get an incremented 'linknum'
493
+ for (var i=0; i<links.length; i++) {
494
+ if (i != 0 &&
495
+ links[i].source == links[i-1].source &&
496
+ links[i].target == links[i-1].target) {
497
+ links[i].linknum = links[i-1].linknum + 1;
498
+ }
499
+ else {links[i].linknum = 1;};
500
+ };
501
+
502
+ var nodes = {};
503
+
504
+ // Compute the distinct nodes from the links.
505
+ links.forEach(function(link) {
506
+ link.source = nodes[link.source] || (nodes[link.source] = {name: link.source});
507
+ link.target = nodes[link.target] || (nodes[link.target] = {name: link.target});
508
+ });
509
+
510
+
511
+ // width and height of svg
512
+ var width = 650,
513
+ height = 620;
514
+
515
+
516
+ var force = d3.layout.force()
517
+ .nodes(d3.values(nodes))
518
+ .links(links)
519
+ .size([width, height])
520
+ .linkDistance(380)
521
+ .charge(-3000)
522
+ .on("tick", tick)
523
+ .start();
524
+
525
+ var svg2 = d3.select("#d2").append("svg")
526
+ .attr("width", width)
527
+ .attr("height", height)
528
+ .append("g");
529
+
530
+ // Append the arrows
531
+ svg2.append("svg:defs").selectAll("marker")
532
+ .data(["arrow"])
533
+ .enter().append("svg:marker")
534
+ .attr("id", String)
535
+ .attr("viewBox", "0 -5 10 10")
536
+ .attr("refX", 22)
537
+ .attr("refY", -1.8)
538
+ .attr("markerWidth", 6)
539
+ .attr("markerHeight", 6)
540
+ .attr("orient", "auto")
541
+ .append("svg:path")
542
+ .attr("d", "M0,-5L10,0L0,5")
543
+
544
+ // Per-type markers, as they don't inherit styles.
545
+ var path = svg2.append("svg:g").selectAll("path")
546
+ .data(force.links())
547
+ .enter().append("svg:path")
548
+ .attr("class", "link")
549
+ .attr("id",function(d,i) { return "linkId_" + i; })
550
+ .attr("marker-end", function(d) {
551
+ if (d.source.name != d.target.name) {
552
+ console.log("arrow"+ "url(#arrow)");
553
+ return "url(#arrow)";
554
+ } else {
555
+ return "";
556
+ }
557
+ })
558
+ .on("click", function(d) {
559
+
560
+ console.log("Source: " + d.source.name);
561
+ console.log("Target: " + d.target.name);
562
+
563
+ path.style("stroke-width", 2+"px");
564
+ d3.select(this)
565
+ .transition()
566
+ .duration(1000) // Animation duration in milliseconds
567
+ .style("stroke-width", "3px");
568
+
569
+
570
+ var nodeTable = document.querySelector(".container");
571
+ nodeTable.style.display = "none";
572
+
573
+ d3.select("table").remove();
574
+ var tableContainer = d3.select('.container');
575
+ tableContainer.remove();
576
+ var tableheader = d3.select('.headerRow');
577
+ tableheader.remove();
578
+
579
+ const nodeName = d.name;
580
+ console.log("Hovering over node:", nodeName);
581
+
582
+
583
+ var container = d3.select('body')
584
+ .append('div')
585
+ .attr('class', 'container')
586
+ .style('height', '250px')
587
+ .style('overflow', 'auto');
588
+
589
+ var table = container.append('table')
590
+ .attr('class', 'table')
591
+ .style('table-layout', 'auto')
592
+
593
+ d3.selectAll('.table td')
594
+ .style('font-size', '12px');
595
+
596
+
597
+ const headerRow = table.append("tr");
598
+ headerRow.append("th").text("Id");
599
+ headerRow.append("th").text("Full Sentence");
600
+ headerRow.append("th").text("Component");
601
+ headerRow.append("th").text("cause/effect");
602
+ headerRow.append("th").text("Label level1");
603
+ headerRow.append("th").text("Label level2");
604
+
605
+ d3.json("https://huggingface.co/datasets/Seetha/visual_files/raw/main/detailedResults.json", function(data) {
606
+ var table = d3.select("table"); // select the existing table
607
+ var tbody = table.append("tbody"); // create a tbody element
608
+
609
+ // loop through each item in the data array
610
+ for (var i = 0; i < data.length; i++) {
611
+ var lableName = data[i].Labellevel2;
612
+ var causeOrEffect = data[i].causeOrEffect;
613
+ var id = data[i].Id;
614
+ if(lableName == d.source.name && (causeOrEffect == "cause")){
615
+
616
+ // for (var j = 0; j < data.length; j++) {
617
+ // if(id == data[j].Id){
618
+ // var lableName = data[j].Labellevel2;
619
+ // var causeOrEffect = data[j].causeOrEffect;
620
+ // if(lableName == d.target.name && (causeOrEffect == "effect")) {
621
+
622
+ // var tr = tbody.append("tr"); // create a table row for each item
623
+
624
+ // tr.append("td").text(data[i].Id);
625
+ // tr.append("td").text([data[i].Fullsentence]);
626
+ // tr.append("td").text([data[i].Component]);
627
+ // tr.append("td").text([data[i].causeOrEffect]);
628
+ // tr.append("td").text([data[i].Labellevel1]);
629
+ // tr.append("td").text([data[i].Labellevel2]);
630
+
631
+ // tr = tbody.append("tr")
632
+ // // append a table cell with the Id property
633
+ // tr.append("td").text(data[j].Id);
634
+ // tr.append("td").text([data[j].Fullsentence]);
635
+ // tr.append("td").text([data[j].Component]);
636
+ // tr.append("td").text([data[j].causeOrEffect]);
637
+ // tr.append("td").text([data[j].Labellevel1]);
638
+ // tr.append("td").text([data[j].Labellevel2]);
639
+ // }
640
+
641
+ // }
642
+ // }
643
+
644
+ for (var j=0; j<data.length; j++){
645
+ if (id == data[j].Id){
646
+ var labelName = data[j].Labellevel2;
647
+ var causeOrEffect = data[j].causeOrEffect;
648
+
649
+ if(labelName == "Non-performance"&& causeOrEffect == "effect"){
650
+ var tr = tbody.append("tr");
651
+ tr.append("td").text(data[j].Id);
652
+ tr.append("td").text([data[j].Fullsentence]);
653
+ tr.append("td").text([data[j].Component]);
654
+ tr.append("td").text([data[j].causeOrEffect]);
655
+ tr.append("td").text([data[j].Labellevel1]);
656
+ tr.append("td").text([data[j].Labellevel2]); }
657
+ }
658
+ }
659
+
660
+
661
+ }
662
+ }
663
+
664
+
665
+ });
666
+
667
+
668
+ });
669
+
670
+
671
+ path.style("stroke-width",function() { // width of the link
672
+ return 2 + "px";
673
+
674
+ })
675
+
676
+ var node = svg2.selectAll(".node") //nodes in the graph
677
+ .data(force.nodes())
678
+ .enter().append("g")
679
+ .attr("class", "node")
680
+ .on("mousedown", mousedown)
681
+ .call(force.drag);
682
+
683
+
684
+ var colorScale = d3.scale.linear()
685
+ .domain([0, 60]) // Set the domain of the scale to the minimum and maximum possible values of d.value
686
+ .range(["#C0C0C0", "black"]); // Set the range of the scale to the minimum and maximum desired colors
687
+
688
+ path.style("stroke", function(d) {
689
+ console.log(d.value+colorScale(d.value))
690
+ return colorScale(d.value); // Use the scale to map the value of d.value to a color
691
+ });
692
+
693
+
694
+
695
+ // create a map in order to compute the size of the node
696
+ const map1 = new Map();
697
+ for (var nodeName in nodes) {
698
+ var sum = 0;
699
+ console.log("sum"+nodeName)
700
+ links.forEach(function (link) {
701
+ if(nodeName == link.source.name || nodeName == link.target.name) {
702
+ sum = sum + link.value
703
+ }
704
+ map1.set(nodeName, sum);
705
+ });
706
+
707
+ }
708
+
709
+ const min = Math.min(...map1.values());
710
+ console.log(min); // 👉️ 3
711
+
712
+ const max = Math.max(...map1.values());
713
+ console.log(max);
714
+
715
+ var myScale = d3.scale.linear()
716
+ .domain([min, max])
717
+ .range([10, 20]);
718
+
719
+ node.append("circle")
720
+ .attr("r", function(d) {
721
+ console.log("radius"+myScale(map1.get(d.name)))
722
+ return myScale(map1.get(d.name));
723
+ })
724
+ .style("fill", function(d){
725
+ if(d.name == "Non-performance"){
726
+ return "gray";
727
+ }else{
728
+ return "blue";
729
+ }
730
+ })
731
+ .style("stroke", "black")
732
+
733
+
734
+
735
+ var text = svg2.append("g").selectAll("text") // Lable of the node
736
+ .data(force.nodes())
737
+ .enter().append("text")
738
+ .attr("x", 8)
739
+ .attr("y", ".31em")
740
+ .text(function(d) { return d.name; });
741
+ var linktext = svg2.append("svg:g").selectAll("g.linklabelholder").data(force.links());
742
+
743
+ linktext.enter().append("g").attr("class", "linklabelholder")
744
+ .append("text")
745
+ .attr("class", "linklabel")
746
+ .style("font-size", "13px")
747
+ .attr("x", "50")
748
+ .attr("y", "-20")
749
+ .attr("text-anchor", "start")
750
+ .style("fill","#000")
751
+ .append("textPath")
752
+ .attr("xlink:href",function(d,i) { return "#linkId_" + i;})
753
+ .text(function(d) {
754
+ return d.value;
755
+ });
756
+
757
+
758
+ // Use elliptical arc path segments to doubly-encode directionality.
759
+ function tick() {
760
+ path.attr("d", linkArc);
761
+ // node.attr("transform", transform);
762
+ text.attr("transform", transform);
763
+ node
764
+ .attr("transform", function(d) {
765
+ return "translate(" + d.x + "," + d.y + ")"; })
766
+
767
+
768
+ path.attr("d", function(d) {
769
+ // if(d.value !=0 ) {
770
+ var x1 = d.source.x,
771
+ y1 = d.source.y,
772
+ x2 = d.target.x,
773
+ y2 = d.target.y,
774
+
775
+ dx = x2 - x1,
776
+ dy = y2 - y1,
777
+ dr = Math.sqrt(dx * dx + dy * dy),
778
+
779
+ // Defaults for normal edge.
780
+ drx = dr,
781
+ dry = dr,
782
+ xRotation = 5, // degrees
783
+ largeArc = 0, // 1 or 0
784
+ sweep = 1; // 1 or 0
785
+
786
+ // Self edge.
787
+ if (x1 === x2 && y1 === y2) {
788
+ // Fiddle with this angle to get loop oriented.
789
+ xRotation = -70;
790
+
791
+ // Needs to be 1.
792
+ largeArc = 1;
793
+
794
+ // Change sweep to change orientation of loop.
795
+ sweep = 1;
796
+
797
+ // Make drx and dry different to get an ellipse
798
+ // instead of a circle.
799
+ drx = 30;
800
+ dry = 15;
801
+
802
+ // For whatever reason the arc collapses to a point if the beginning
803
+ // and ending points of the arc are the same, so kludge it.
804
+
805
+ x2 = x2 + 1;
806
+ y2 = y2 + 1;
807
+ }
808
+
809
+ return "M" + x1 + "," + y1 + "A" + drx + "," + dry + " " + xRotation + "," + largeArc + "," + sweep + " " + x2 + "," + y2;
810
+ //}
811
+ });
812
+
813
+ }
814
+
815
+ function linkArc(d) {
816
+ var dx = d.target.x - d.source.x,
817
+ dy = d.target.y - d.source.y,
818
+ dr = Math.sqrt(dx * dx + dy * dy);
819
+ return "M" + d.source.x + "," + d.source.y + "A" + dr + "," + dr + " 0 0,1 " + d.target.x + "," + d.target.y;
820
+ }
821
+
822
+ function transform(d) {
823
+ return "translate(" + d.x + "," + d.y + ")";
824
+ }
825
+
826
+ function mousedown(d) {
827
+ path.style("stroke-width", 2+"px");
828
+ d3.event.stopPropagation();
829
+ // Removes the table first cleans all the div container area in order to append the new table
830
+ d3.select("table").remove();
831
+ var tableContainer = d3.select('.container');
832
+ tableContainer.remove();
833
+ var tableheader = d3.select('.headerRow');
834
+ tableheader.remove();
835
+
836
+ const nodeName = d.name;
837
+ console.log("Hovering over node:", nodeName);
838
+
839
+ // Create the container to append the table elements both header and body
840
+ var container = d3.select('body')
841
+ .append('div')
842
+ .attr('class', 'container')
843
+ .style('height', '250px')
844
+ .style('overflow', 'auto');
845
+ // Create the table element inside the container
846
+ var table = container.append('table')
847
+ .attr('class', 'table')
848
+ .style('table-layout', 'auto')
849
+
850
+ d3.selectAll('.table td')
851
+ .style('font-size', '12px');
852
+
853
+ // Add a header row
854
+ const headerRow = table.append("tr");
855
+ headerRow.append("th").text("Id");
856
+ headerRow.append("th").text("Full Sentence");
857
+ headerRow.append("th").text("Component");
858
+ headerRow.append("th").text("cause/effect");
859
+ headerRow.append("th").text("Label level1");
860
+ headerRow.append("th").text("Label level2");
861
+
862
+
863
+ // Add a data row for the hovered node
864
+
865
+ d3.json("https://huggingface.co/datasets/Seetha/visual_files/raw/main/detailedResults.json", function(data) {
866
+ var table = d3.select("table"); // select the existing table
867
+ var tbody = table.append("tbody"); // create a tbody element
868
+
869
+ // loop through each item in the data array
870
+ for (var i = 0; i < data.length; i++) {
871
+ if(nodeName == [data[i].Labellevel2]) { // Check for if the nodename that is cliked matches the name in the csv file
872
+
873
+ var tr = tbody.append("tr"); // create a table row for each item
874
+
875
+ // append a table cell with the Id property
876
+ tr.append("td").text(data[i].Id);
877
+ tr.append("td").text([data[i].Fullsentence]);
878
+ tr.append("td").text([data[i].Component]);
879
+ tr.append("td").text([data[i].causeOrEffect]);
880
+ tr.append("td").text([data[i].Labellevel1]);
881
+ tr.append("td").text([data[i].Labellevel2]);
882
+
883
+ }
884
+
885
+ }
886
+ });
887
+
888
+ }
889
+
890
+
891
+ // The text that appears below the 5 node graph
892
+ svg2.append("text")
893
+ .attr("x", width/2 + 10)
894
+ .attr("y", height - 30)
895
+ .attr("text-anchor", "middle")
896
+ .text(" Click on a node to get the detailed results")
897
+ .style("font-weight", "bold")
898
+ .style("font-family", "Times New Roman")
899
+ .style("font-size", "16px")
900
+ .style("opacity", 0)
901
+ .transition()
902
+ .duration(2000)
903
+ .style("opacity", 1);
904
+
905
+
906
+ });
907
+
908
+
909
+
910
+
911
+ </script>
912
+ </div>
913
+ </div>
914
+ </body>
915
+ </html>
916
+
917
+
918
+
level2.css ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ path.link {
2
+ fill: none;
3
+
4
+ stroke-width: 1.5px;
5
+ }
6
+
7
+
8
+ circle {
9
+ fill: #ccc;
10
+ stroke: #333;
11
+ stroke-width: 1.5px;
12
+ }
13
+
14
+ text {
15
+ font: 10px sans-serif;
16
+ pointer-events: none;
17
+ }
18
+
side.css ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*.tree*/
2
+ /*{*/
3
+ /* position: absolute;*/
4
+ /* top: 50%;*/
5
+ /* left: 50%;*/
6
+ /* transform: translate(-50%, -50%);*/
7
+ /* background-color : #4444aa;*/
8
+ /*}*/
9
+ /*.graph*/
10
+ /*{*/
11
+ /* position: absolute;*/
12
+ /* top: 50%;*/
13
+ /* right: 50%;*/
14
+ /* transform: translate(50%, 50%);*/
15
+ /*}*/
16
+
17
+ #container{
18
+ display: flex;
19
+ flex-direction: row;
20
+ width: 100vw;
21
+ }
tree.css ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .node circle {
2
+ fill: #fff;
3
+ stroke: black;
4
+ stroke-width: 2px;
5
+ }
6
+
7
+ .node text {
8
+ font: 12px sans-serif;
9
+ }
10
+
11
+ .link {
12
+ fill: none;
13
+
14
+ stroke-width: 2px;
15
+ }