Seetha commited on
Commit
9e70742
·
1 Parent(s): c03bccd

Delete index.html

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