Spaces:
Sleeping
Sleeping
Update index.html
Browse files- index.html +967 -470
index.html
CHANGED
|
@@ -1,540 +1,1037 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
-
<
|
| 3 |
<head>
|
| 4 |
-
<link rel = "stylesheet" href = "/
|
| 5 |
-
<link rel = "stylesheet" href = "/
|
| 6 |
-
<link rel = "stylesheet" href = "/
|
|
|
|
| 7 |
<style>
|
| 8 |
|
| 9 |
-
body {background-color:
|
| 10 |
</style>
|
| 11 |
-
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
<!-- load the d3.js library -->
|
| 21 |
-
<div class = "tree">
|
| 22 |
-
<script src="https://d3js.org/d3.v4.min.js"></script>
|
| 23 |
-
<script>
|
| 24 |
-
|
| 25 |
-
var treeData =
|
| 26 |
-
{"name": "Performance or Not", "children": [{"name": "Performance (P)", "children": [{"name": "Investors (INV)", "children": [{"name": "Accounting-based performance (INV1)"}, {"name": "Stock market-based performance (INV2)"}, {"name": "Survey-based performance (INV3)"}, {"name": "Growth-based performance (INV4)"}]}, {"name": "Customers (CUS)", "children": [{"name": "Customer commitment (CUS1)"}, {"name": "Customer satisfaction (CUS2)"}, {"name": "Brand recognition and reputation (CUS3)"}, {"name": "Product & service quality (CUS4)"}]}, {"name": "Employees (EMP)", "children": [{"name": "Employee commitment (EMP1)"}, {"name": "Employee satisfaction (EMP2)"}, {"name": "Employee compensation, protection and benefits (EMP3)"}, {"name": "Employee health (EMP4)"}]}, {"name": "Society (SOC)", "children": [{"name": "Symbolic socially responsible efforts (SOC1)"}, {"name": "Substantive social impact and performance (SOC2)"}, {"name": "Symbolic environmentally responsible efforts (SOC3)"}, {"name": "Substantive environmental impact and performance (SOC4)"}, {"name": "Uncategorized or combined (SOC5)"}]}, {"name": "Unclassified", "children":""}]}, {"name": "Non-performance", }]};
|
| 27 |
-
|
| 28 |
-
// Set the dimensions and margins of the diagram
|
| 29 |
-
var margin = {top: 20, right: 90, bottom: 30, left: 116},
|
| 30 |
-
width = 850- margin.left - margin.right,
|
| 31 |
-
height = 800 - margin.top - margin.bottom;
|
| 32 |
-
|
| 33 |
-
// append the svg object to the body of the page
|
| 34 |
-
// appends a 'group' element to 'svg'
|
| 35 |
-
// moves the 'group' element to the top left margin
|
| 36 |
-
var svg2 = d3.select("body").append("svg")
|
| 37 |
-
.attr("width", width + margin.right + margin.left)
|
| 38 |
-
.attr("height", height + margin.top + margin.bottom)
|
| 39 |
-
.append("g")
|
| 40 |
-
.attr("transform", "translate("
|
| 41 |
-
+ margin.left + "," + margin.top + ")");
|
| 42 |
-
|
| 43 |
-
var i = 0,
|
| 44 |
-
duration = 750,
|
| 45 |
-
root;
|
| 46 |
-
|
| 47 |
-
// declares a tree layout and assigns the size
|
| 48 |
-
var treemap = d3.tree().size([height, width]);
|
| 49 |
-
|
| 50 |
-
// Assigns parent, children, height, depth
|
| 51 |
-
root = d3.hierarchy(treeData, function(d) { return d.children; });
|
| 52 |
-
root.x0 = height / 2;
|
| 53 |
-
root.y0 = 0;
|
| 54 |
-
|
| 55 |
-
// Collapse after the second level
|
| 56 |
-
root.children.forEach(collapse);
|
| 57 |
-
|
| 58 |
-
update(root);
|
| 59 |
-
|
| 60 |
-
// Collapse the node and all it's children
|
| 61 |
-
function collapse(d) {
|
| 62 |
-
if(d.children) {
|
| 63 |
-
d._children = d.children
|
| 64 |
-
d._children.forEach(collapse)
|
| 65 |
-
d.children = null
|
| 66 |
}
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
-
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
// Normalize for fixed-depth.
|
| 79 |
-
nodes.forEach(function(d){ d.y = d.depth * 130});
|
| 80 |
|
| 81 |
-
// ****************** Nodes section ***************************
|
| 82 |
|
| 83 |
-
// Update the nodes...
|
| 84 |
-
var node = svg2.selectAll('g.node')
|
| 85 |
-
.data(nodes, function(d) {return d.id || (d.id = ++i); });
|
| 86 |
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
}
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
-
// Add labels for the nodes
|
| 108 |
-
nodeEnter.append('text')
|
| 109 |
-
.attr("dy", ".40em")
|
| 110 |
-
.attr("x", function(d) {
|
| 111 |
-
return d.children || d._children ? -13 : 13;
|
| 112 |
-
})
|
| 113 |
-
.attr("text-anchor", function(d) {
|
| 114 |
-
return d.children || d._children ? "end" : "start";
|
| 115 |
-
})
|
| 116 |
-
.text(function(d) { return d.data.name; });
|
| 117 |
|
| 118 |
-
// UPDATE
|
| 119 |
-
var nodeUpdate = nodeEnter.merge(node);
|
| 120 |
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
});
|
| 127 |
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
}else{
|
| 135 |
-
return
|
| 136 |
}
|
| 137 |
})
|
| 138 |
-
.attr('cursor', 'pointer');
|
| 139 |
|
|
|
|
|
|
|
| 140 |
|
| 141 |
-
|
| 142 |
-
var nodeExit = node.exit().transition()
|
| 143 |
-
.duration(duration)
|
| 144 |
-
.attr("transform", function(d) {
|
| 145 |
-
return "translate(" + source.y + "," + source.x + ")";
|
| 146 |
-
})
|
| 147 |
-
.remove();
|
| 148 |
|
| 149 |
-
// On exit reduce the node circles size to 0
|
| 150 |
-
nodeExit.select('circle')
|
| 151 |
-
.attr('r', 1e-6);
|
| 152 |
|
| 153 |
-
// On exit reduce the opacity of text labels
|
| 154 |
-
nodeExit.select('text')
|
| 155 |
-
.style('fill-opacity', 1e-6);
|
| 156 |
|
| 157 |
-
// ****************** links section ***************************
|
| 158 |
|
| 159 |
-
// Update the links...
|
| 160 |
-
var link = svg2.selectAll('path.link')
|
| 161 |
-
.data(links, function(d) { return d.id; });
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
.attr('d', function(d){
|
| 167 |
-
var o = {x: source.x0, y: source.y0}
|
| 168 |
-
return diagonal(o, o)
|
| 169 |
-
});
|
| 170 |
|
| 171 |
-
|
| 172 |
-
|
|
|
|
|
|
|
| 173 |
|
| 174 |
-
// Transition back to the parent element position
|
| 175 |
-
linkUpdate.transition()
|
| 176 |
-
.duration(duration)
|
| 177 |
-
.attr('d', function(d){ return diagonal(d, d.parent) });
|
| 178 |
|
| 179 |
-
// Remove any exiting links
|
| 180 |
-
var linkExit = link.exit().transition()
|
| 181 |
-
.duration(duration)
|
| 182 |
-
.attr('d', function(d) {
|
| 183 |
-
var o = {x: source.x, y: source.y}
|
| 184 |
-
return diagonal(o, o)
|
| 185 |
-
})
|
| 186 |
-
.remove();
|
| 187 |
|
| 188 |
-
// Store the old positions for transition.
|
| 189 |
-
nodes.forEach(function(d){
|
| 190 |
-
d.x0 = d.x;
|
| 191 |
-
d.y0 = d.y;
|
| 192 |
-
});
|
| 193 |
|
| 194 |
-
// Creates a curved (diagonal) path from parent to the child nodes
|
| 195 |
-
function diagonal(s, d) {
|
| 196 |
|
| 197 |
-
path = `M ${s.y} ${s.x}
|
| 198 |
-
C ${(s.y + d.y) / 2} ${s.x},
|
| 199 |
-
${(s.y + d.y) / 2} ${d.x},
|
| 200 |
-
${d.y} ${d.x}`
|
| 201 |
|
| 202 |
-
return path
|
| 203 |
-
}
|
| 204 |
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
}
|
| 214 |
-
update(d);
|
| 215 |
-
}
|
| 216 |
-
}
|
| 217 |
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
<script src="http://d3js.org/d3-selection-multi.v1.js"></script>
|
| 224 |
-
<script>
|
| 225 |
-
|
| 226 |
-
var links = [
|
| 227 |
-
{source: "Non Performance", target: "Customers", type: "49"},
|
| 228 |
-
{source: "Non Performance", target: "Investors", type: "54"},
|
| 229 |
-
{source: "Non Performance", target: "Society", type: "49"},
|
| 230 |
-
{source: "Non Performance", target: "Employee", type: "51"},
|
| 231 |
-
{source: "Employee", target: "Investors", type: "5"},
|
| 232 |
-
{source: "Employee", target: "Non Performance", type: "167"},
|
| 233 |
-
{source: "Employee", target: "Society", type: "0"},
|
| 234 |
-
{source: "Employee", target: "Customers", type: "0"},
|
| 235 |
-
// {source: "Employee", target: "Employee", type: "2"},
|
| 236 |
-
{source: "Investors", target: "Employee", type: "3"},
|
| 237 |
-
{source: "Investors", target: "Society", type: "1"},
|
| 238 |
-
{source: "Investors", target: "Customers", type: "1"},
|
| 239 |
-
{source: "Investors", target: "Non Performance", type: "168"},
|
| 240 |
-
{source: "Society", target: "Investors", type: "5"},
|
| 241 |
-
{source: "Society", target: "Employee", type: "2"},
|
| 242 |
-
{source: "Society", target: "Customers", type: "0"},
|
| 243 |
-
{source: "Society", target: "Non Performance", type: "167"},
|
| 244 |
-
{source: "Customers", target: "Investors", type: "0"},
|
| 245 |
-
{source: "Customers", target: "Employee", type: "2"},
|
| 246 |
-
{source: "Customers", target: "Society", type: "0"},
|
| 247 |
-
{source: "Customers", target: "Non Performance", type: "167"},
|
| 248 |
-
//{source: "Investors", target: "Investors", type: "6"},
|
| 249 |
-
// {source: "Customers", target: "Customers", type: "0"},
|
| 250 |
-
//{source: "Society", target: "Society", type: "0"},
|
| 251 |
-
//{source: "Non Performance", target: "Non Performance", type: "216"}
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
];
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
// Compute the distinct nodes from the links.
|
| 258 |
-
links.sort(function(a,b) {
|
| 259 |
-
if (a.source > b.source) {return 1;}
|
| 260 |
-
else if (a.source < b.source) {return -1;}
|
| 261 |
-
else {
|
| 262 |
-
if (a.target > b.target) {return 1;}
|
| 263 |
-
if (a.target < b.target) {return -1;}
|
| 264 |
-
else {return 0;}
|
| 265 |
-
}
|
| 266 |
-
});
|
| 267 |
-
//any links with duplicate source and target get an incremented 'linknum'
|
| 268 |
-
for (var i=0; i<links.length; i++) {
|
| 269 |
-
if (i != 0 &&
|
| 270 |
-
links[i].source == links[i-1].source &&
|
| 271 |
-
links[i].target == links[i-1].target) {
|
| 272 |
-
links[i].linknum = links[i-1].linknum + 1;
|
| 273 |
-
}
|
| 274 |
-
else {links[i].linknum = 1;};
|
| 275 |
-
};
|
| 276 |
-
|
| 277 |
-
var nodes = {};
|
| 278 |
-
|
| 279 |
-
// Compute the distinct nodes from the links.
|
| 280 |
-
links.forEach(function(link) {
|
| 281 |
-
link.source = nodes[link.source] || (nodes[link.source] = {name: link.source});
|
| 282 |
-
link.target = nodes[link.target] || (nodes[link.target] = {name: link.target});
|
| 283 |
-
});
|
| 284 |
-
|
| 285 |
-
var width = 550,
|
| 286 |
-
height = 850;
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
var force = d3.layout.force()
|
| 291 |
-
.nodes(d3.values(nodes))
|
| 292 |
-
.links(links)
|
| 293 |
-
.size([width, height])
|
| 294 |
-
.linkDistance(400)
|
| 295 |
-
.charge(-3000)
|
| 296 |
-
.on("tick", tick)
|
| 297 |
-
.start();
|
| 298 |
-
|
| 299 |
-
var svg = d3.select("body").append("svg")
|
| 300 |
-
.attr("width", width)
|
| 301 |
-
.attr("height", height)
|
| 302 |
-
.call(d3.behavior.zoom().on("zoom", function () {
|
| 303 |
-
svg.attr("transform", "translate(" + d3.event.translate + ")" + " scale(" + d3.event.scale + ")")
|
| 304 |
-
}))
|
| 305 |
-
.append("g");
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
svg.append("svg:defs").selectAll("marker")
|
| 312 |
-
.data(["49", "54", "49","51","5","167", "0", "0", "2","3","1","1","168","5","2","0","167","0","2","0","167","2","6","0","0","216"])
|
| 313 |
-
.enter().append("svg:marker")
|
| 314 |
-
.attr("id", String)
|
| 315 |
-
.attr("viewBox", "0 -5 10 10")
|
| 316 |
-
.attr("refX", 24)
|
| 317 |
-
.attr("refY", -1.8)
|
| 318 |
-
.attr("markerWidth", 6)
|
| 319 |
-
.attr("markerHeight", 6)
|
| 320 |
-
.attr("orient", "auto")
|
| 321 |
-
.append("svg:path")
|
| 322 |
-
.attr("d", "M0,-5L10,0L0,5");
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
// Per-type markers, as they don't inherit styles.
|
| 326 |
-
var path = svg.append("svg:g").selectAll("path")
|
| 327 |
-
.data(force.links())
|
| 328 |
-
.enter().append("svg:path")
|
| 329 |
-
|
| 330 |
-
.attr("class", function(d) { return "link " + d.type; })
|
| 331 |
-
.attr("id",function(d,i) { return "linkId_" + i; })
|
| 332 |
-
.attr("marker-end", function(d) { return "url(#" + d.type + ")"; });
|
| 333 |
-
|
| 334 |
-
// var node = svg.append("g").selectAll("node")
|
| 335 |
-
// .data(force.nodes())
|
| 336 |
-
// .enter().append("circle")
|
| 337 |
-
// .attr("r", 10)
|
| 338 |
-
// .call(force.drag);
|
| 339 |
-
|
| 340 |
-
var selflink = svg.append("svg:g").selectAll(".selflink")
|
| 341 |
-
.data(force.links())
|
| 342 |
-
.enter().append("path")
|
| 343 |
-
.attr("class","link")
|
| 344 |
-
.attr("class", function(d) { return "link " + d.type; })
|
| 345 |
-
.attr("id",function(d,i) { return "linkId_" + i; })
|
| 346 |
-
.attr("marker-end", function(d) { return "url(#" + d.type + ")"; });
|
| 347 |
-
|
| 348 |
-
var node = svg.selectAll(".node")
|
| 349 |
-
.data(force.nodes())
|
| 350 |
-
.enter().append("g")
|
| 351 |
-
.attr("class", "node")
|
| 352 |
-
.on("click", click)
|
| 353 |
-
.on("dblclick", dblclick)
|
| 354 |
-
.on("mouseover", mouseover)
|
| 355 |
-
.on("mouseout", mouseout)
|
| 356 |
-
.on("mouseenter", (evt, d) => {
|
| 357 |
-
path
|
| 358 |
-
.attr("display", "none")
|
| 359 |
-
.filter(l => l.source.type === d.type || l.target.type === d.type)
|
| 360 |
-
.attr("display", "block");
|
| 361 |
-
})
|
| 362 |
-
.on("mouseleave", evt => {
|
| 363 |
-
path.attr("display", "block");
|
| 364 |
-
})
|
| 365 |
-
.call(force.drag);
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
// add the nodes
|
| 369 |
-
node.append("circle")
|
| 370 |
-
.attr("r", 13)
|
| 371 |
-
.style("fill", function(d){
|
| 372 |
-
if(d.name == "Non Performance"){
|
| 373 |
-
return "red";
|
| 374 |
-
}else{
|
| 375 |
-
return "blue";
|
| 376 |
}
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
var text = svg.append("g").selectAll("text")
|
| 383 |
-
.data(force.nodes())
|
| 384 |
-
.enter().append("text")
|
| 385 |
-
.attr("x", 8)
|
| 386 |
-
.attr("y", ".31em")
|
| 387 |
-
.text(function(d) { return d.name; });
|
| 388 |
-
var linktext = svg.append("svg:g").selectAll("g.linklabelholder").data(force.links());
|
| 389 |
-
|
| 390 |
-
linktext.enter().append("g").attr("class", "linklabelholder")
|
| 391 |
-
.append("text")
|
| 392 |
-
.attr("class", "linklabel")
|
| 393 |
-
.style("font-size", "13px")
|
| 394 |
-
.attr("x", "50")
|
| 395 |
-
.attr("y", "-20")
|
| 396 |
-
.attr("text-anchor", "start")
|
| 397 |
-
.style("fill","#000")
|
| 398 |
-
.append("textPath")
|
| 399 |
-
.attr("xlink:href",function(d,i) { return "#linkId_" + i;})
|
| 400 |
-
.text(function(d) {
|
| 401 |
-
return d.type;
|
| 402 |
-
});
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
// Use elliptical arc path segments to doubly-encode directionality.
|
| 406 |
-
function tick() {
|
| 407 |
-
path.attr("d", linkArc);
|
| 408 |
-
// node.attr("transform", transform);
|
| 409 |
-
text.attr("transform", transform);
|
| 410 |
-
node
|
| 411 |
-
.attr("transform", function(d) {
|
| 412 |
-
return "translate(" + d.x + "," + d.y + ")"; })
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
selflink.attr("d", function(d) {
|
| 416 |
-
var x1 = d.source.x,
|
| 417 |
-
y1 = d.source.y,
|
| 418 |
-
x2 = d.target.x,
|
| 419 |
-
y2 = d.target.y,
|
| 420 |
-
dx = x2 - x1,
|
| 421 |
-
dy = y2 - y1,
|
| 422 |
-
dr = Math.sqrt(dx * dx + dy * dy),
|
| 423 |
-
|
| 424 |
-
// Defaults for normal edge.
|
| 425 |
-
drx = dr,
|
| 426 |
-
dry = dr,
|
| 427 |
-
xRotation = 5, // degrees
|
| 428 |
-
largeArc = 0, // 1 or 0
|
| 429 |
-
sweep = 1; // 1 or 0
|
| 430 |
-
|
| 431 |
-
// Self edge.
|
| 432 |
-
if ( x1 === x2 && y1 === y2 ) {
|
| 433 |
-
// Fiddle with this angle to get loop oriented.
|
| 434 |
-
xRotation = -70;
|
| 435 |
-
|
| 436 |
-
// Needs to be 1.
|
| 437 |
-
largeArc = 1;
|
| 438 |
-
|
| 439 |
-
// Change sweep to change orientation of loop.
|
| 440 |
-
//sweep = 0;
|
| 441 |
-
|
| 442 |
-
// Make drx and dry different to get an ellipse
|
| 443 |
-
// instead of a circle.
|
| 444 |
-
drx = 30;
|
| 445 |
-
dry = 15;
|
| 446 |
-
|
| 447 |
-
// For whatever reason the arc collapses to a point if the beginning
|
| 448 |
-
// and ending points of the arc are the same, so kludge it.
|
| 449 |
-
x2 = x2 + 1;
|
| 450 |
-
y2 = y2 + 1;
|
| 451 |
}
|
| 452 |
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 456 |
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
|
|
|
|
|
|
| 463 |
|
| 464 |
-
function transform(d) {
|
| 465 |
-
return "translate(" + d.x + "," + d.y + ")";
|
| 466 |
-
}
|
| 467 |
-
function click() {
|
| 468 |
-
d3.select(this).select("text").transition()
|
| 469 |
-
.duration(750)
|
| 470 |
-
.attr("x", 22)
|
| 471 |
-
.style("fill", "steelblue")
|
| 472 |
-
.style("stroke", "lightsteelblue")
|
| 473 |
-
.style("stroke-width", ".5px")
|
| 474 |
-
.style("font", "20px sans-serif");
|
| 475 |
-
d3.select(this).select("circle").transition()
|
| 476 |
-
.duration(750)
|
| 477 |
-
.attr("r", 16)
|
| 478 |
-
.style("fill", "lightsteelblue");
|
| 479 |
-
}
|
| 480 |
|
| 481 |
-
|
| 482 |
-
function dblclick() {
|
| 483 |
-
d3.select(this).select("circle").transition()
|
| 484 |
-
.duration(750)
|
| 485 |
-
.attr("r", 6)
|
| 486 |
-
.style("fill", "#ccc");
|
| 487 |
-
d3.select(this).select("text").transition()
|
| 488 |
-
.duration(750)
|
| 489 |
-
.attr("x", 12)
|
| 490 |
-
.style("stroke", "none")
|
| 491 |
-
.style("fill", "black")
|
| 492 |
-
.style("stroke", "none")
|
| 493 |
-
.style("font", "10px sans-serif");
|
| 494 |
-
}
|
| 495 |
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
.attr("r", 25)
|
| 500 |
-
.style("stroke-opacity", 1.0);
|
| 501 |
|
| 502 |
-
|
|
|
|
|
|
|
| 503 |
|
| 504 |
-
|
| 505 |
-
d3.select(this).select("circle").transition()
|
| 506 |
-
.duration(750)
|
| 507 |
-
.attr("r", 15);
|
| 508 |
-
}
|
| 509 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 510 |
|
|
|
|
| 511 |
|
| 512 |
-
function dragstarted(d) {
|
| 513 |
-
if (!d3.event.active) simulation.alphaTarget(0.8).restart()
|
| 514 |
-
d.fx = d.x;
|
| 515 |
-
d.fy = d.y;
|
| 516 |
-
}
|
| 517 |
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
}
|
| 522 |
|
| 523 |
|
|
|
|
|
|
|
|
|
|
| 524 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 530 |
|
|
|
|
|
|
|
| 531 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 532 |
|
|
|
|
|
|
|
| 533 |
|
| 534 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 535 |
|
| 536 |
|
| 537 |
-
</script>
|
| 538 |
-
</div>
|
| 539 |
</div>
|
| 540 |
</body>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
<head>
|
| 4 |
+
<link rel = "stylesheet" href = "css1/tree.css">
|
| 5 |
+
<link rel = "stylesheet" href = "css1/div.css">
|
| 6 |
+
<link rel = "stylesheet" href = "css1/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 |
+
|