Spaces:
Running
Running
File size: 17,735 Bytes
0b64aaf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
<html>
<head>
<meta charset="utf-8">
<script>function neighbourhoodHighlight(params) {
// console.log("in nieghbourhoodhighlight");
allNodes = nodes.get({ returnType: "Object" });
// originalNodes = JSON.parse(JSON.stringify(allNodes));
// if something is selected:
if (params.nodes.length > 0) {
highlightActive = true;
var i, j;
var selectedNode = params.nodes[0];
var degrees = 2;
// mark all nodes as hard to read.
for (let nodeId in allNodes) {
// nodeColors[nodeId] = allNodes[nodeId].color;
allNodes[nodeId].color = "rgba(200,200,200,0.5)";
if (allNodes[nodeId].hiddenLabel === undefined) {
allNodes[nodeId].hiddenLabel = allNodes[nodeId].label;
allNodes[nodeId].label = undefined;
}
}
var connectedNodes = network.getConnectedNodes(selectedNode);
var allConnectedNodes = [];
// get the second degree nodes
for (i = 1; i < degrees; i++) {
for (j = 0; j < connectedNodes.length; j++) {
allConnectedNodes = allConnectedNodes.concat(
network.getConnectedNodes(connectedNodes[j])
);
}
}
// all second degree nodes get a different color and their label back
for (i = 0; i < allConnectedNodes.length; i++) {
// allNodes[allConnectedNodes[i]].color = "pink";
allNodes[allConnectedNodes[i]].color = "rgba(150,150,150,0.75)";
if (allNodes[allConnectedNodes[i]].hiddenLabel !== undefined) {
allNodes[allConnectedNodes[i]].label =
allNodes[allConnectedNodes[i]].hiddenLabel;
allNodes[allConnectedNodes[i]].hiddenLabel = undefined;
}
}
// all first degree nodes get their own color and their label back
for (i = 0; i < connectedNodes.length; i++) {
// allNodes[connectedNodes[i]].color = undefined;
allNodes[connectedNodes[i]].color = nodeColors[connectedNodes[i]];
if (allNodes[connectedNodes[i]].hiddenLabel !== undefined) {
allNodes[connectedNodes[i]].label =
allNodes[connectedNodes[i]].hiddenLabel;
allNodes[connectedNodes[i]].hiddenLabel = undefined;
}
}
// the main node gets its own color and its label back.
// allNodes[selectedNode].color = undefined;
allNodes[selectedNode].color = nodeColors[selectedNode];
if (allNodes[selectedNode].hiddenLabel !== undefined) {
allNodes[selectedNode].label = allNodes[selectedNode].hiddenLabel;
allNodes[selectedNode].hiddenLabel = undefined;
}
} else if (highlightActive === true) {
// console.log("highlightActive was true");
// reset all nodes
for (let nodeId in allNodes) {
// allNodes[nodeId].color = "purple";
allNodes[nodeId].color = nodeColors[nodeId];
// delete allNodes[nodeId].color;
if (allNodes[nodeId].hiddenLabel !== undefined) {
allNodes[nodeId].label = allNodes[nodeId].hiddenLabel;
allNodes[nodeId].hiddenLabel = undefined;
}
}
highlightActive = false;
}
// transform the object into an array
var updateArray = [];
if (params.nodes.length > 0) {
for (let nodeId in allNodes) {
if (allNodes.hasOwnProperty(nodeId)) {
// console.log(allNodes[nodeId]);
updateArray.push(allNodes[nodeId]);
}
}
nodes.update(updateArray);
} else {
// console.log("Nothing was selected");
for (let nodeId in allNodes) {
if (allNodes.hasOwnProperty(nodeId)) {
// console.log(allNodes[nodeId]);
// allNodes[nodeId].color = {};
updateArray.push(allNodes[nodeId]);
}
}
nodes.update(updateArray);
}
}
function filterHighlight(params) {
allNodes = nodes.get({ returnType: "Object" });
// if something is selected:
if (params.nodes.length > 0) {
filterActive = true;
let selectedNodes = params.nodes;
// hiding all nodes and saving the label
for (let nodeId in allNodes) {
allNodes[nodeId].hidden = true;
if (allNodes[nodeId].savedLabel === undefined) {
allNodes[nodeId].savedLabel = allNodes[nodeId].label;
allNodes[nodeId].label = undefined;
}
}
for (let i=0; i < selectedNodes.length; i++) {
allNodes[selectedNodes[i]].hidden = false;
if (allNodes[selectedNodes[i]].savedLabel !== undefined) {
allNodes[selectedNodes[i]].label = allNodes[selectedNodes[i]].savedLabel;
allNodes[selectedNodes[i]].savedLabel = undefined;
}
}
} else if (filterActive === true) {
// reset all nodes
for (let nodeId in allNodes) {
allNodes[nodeId].hidden = false;
if (allNodes[nodeId].savedLabel !== undefined) {
allNodes[nodeId].label = allNodes[nodeId].savedLabel;
allNodes[nodeId].savedLabel = undefined;
}
}
filterActive = false;
}
// transform the object into an array
var updateArray = [];
if (params.nodes.length > 0) {
for (let nodeId in allNodes) {
if (allNodes.hasOwnProperty(nodeId)) {
updateArray.push(allNodes[nodeId]);
}
}
nodes.update(updateArray);
} else {
for (let nodeId in allNodes) {
if (allNodes.hasOwnProperty(nodeId)) {
updateArray.push(allNodes[nodeId]);
}
}
nodes.update(updateArray);
}
}
function selectNode(nodes) {
network.selectNodes(nodes);
neighbourhoodHighlight({ nodes: nodes });
return nodes;
}
function selectNodes(nodes) {
network.selectNodes(nodes);
filterHighlight({nodes: nodes});
return nodes;
}
function highlightFilter(filter) {
let selectedNodes = []
let selectedProp = filter['property']
if (filter['item'] === 'node') {
let allNodes = nodes.get({ returnType: "Object" });
for (let nodeId in allNodes) {
if (allNodes[nodeId][selectedProp] && filter['value'].includes((allNodes[nodeId][selectedProp]).toString())) {
selectedNodes.push(nodeId)
}
}
}
else if (filter['item'] === 'edge'){
let allEdges = edges.get({returnType: 'object'});
// check if the selected property exists for selected edge and select the nodes connected to the edge
for (let edge in allEdges) {
if (allEdges[edge][selectedProp] && filter['value'].includes((allEdges[edge][selectedProp]).toString())) {
selectedNodes.push(allEdges[edge]['from'])
selectedNodes.push(allEdges[edge]['to'])
}
}
}
selectNodes(selectedNodes)
}</script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/vis-network/9.1.2/dist/dist/vis-network.min.css" integrity="sha512-WgxfT5LWjfszlPHXRmBWHkV2eceiWTOBvrKCNbdgDYTHrT2AeLCGbF4sZlZw3UMN3WtL0tGUoIAKsu8mllg/XA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/vis-network/9.1.2/dist/vis-network.min.js" integrity="sha512-LnvoEWDFrqGHlHmDD2101OrLcbsfkrzoSpvtSQtxK3RMnRV0eOkhhBN2dXHKRrUU8p2DGRTk35n4O8nWSVe1mQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<center>
<h1></h1>
</center>
<!-- <link rel="stylesheet" href="../node_modules/vis/dist/vis.min.css" type="text/css" />
<script type="text/javascript" src="../node_modules/vis/dist/vis.js"> </script>-->
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6"
crossorigin="anonymous"
/>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf"
crossorigin="anonymous"
></script>
<center>
<h1></h1>
</center>
<style type="text/css">
#mynetwork {
width: 100%;
height: 500px;
background-color: #ffffff;
border: 1px solid lightgray;
position: relative;
float: left;
}
</style>
</head>
<body>
<div class="card" style="width: 100%">
<div id="mynetwork" class="card-body"></div>
</div>
<script type="text/javascript">
// initialize global variables.
var edges;
var nodes;
var allNodes;
var allEdges;
var nodeColors;
var originalNodes;
var network;
var container;
var options, data;
var filter = {
item : '',
property : '',
value : []
};
// This method is responsible for drawing the graph, returns the drawn network
function drawGraph() {
var container = document.getElementById('mynetwork');
// parsing and collecting nodes and edges from the python
nodes = new vis.DataSet([{"color": "#20b2aa", "id": "patient_0", "label": "patient_0", "opacity": 2.7773168683052063, "shape": "dot", "size": 10, "type": "patient"}, {"color": "#fa8072", "id": "visit_0", "label": "visit_0", "opacity": 11.941373348236084, "shape": "dot", "size": 11, "type": "visit"}, {"color": "#98fb98", "id": "Unspecified problem with special functions", "label": "Unspecified problem with special functions", "opacity": 0.2980312518775463, "shape": "dot", "size": 10, "type": "symptom"}, {"color": "#98fb98", "id": "Systemic lupus erythematosus", "label": "Systemic lupus erythematosus", "opacity": 0.32912302762269974, "shape": "dot", "size": 10, "type": "symptom"}, {"color": "#98fb98", "id": "Atresia and stenosis of aorta", "label": "Atresia and stenosis of aorta", "opacity": 0.2311965450644493, "shape": "dot", "size": 10, "type": "symptom"}, {"color": "#98fb98", "id": "Coarctation of aorta (preductal) (postductal)", "label": "Coarctation of aorta (preductal) (postductal)", "opacity": 0.434977151453495, "shape": "dot", "size": 10, "type": "symptom"}, {"color": "#cd853f", "id": "Atrioventricular block, complete", "label": "Atrioventricular block, complete", "opacity": 0.37939630448818207, "shape": "dot", "size": 10, "type": "diagnosis"}, {"color": "#98fb98", "id": "Conduction disorder, unspecified", "label": "Conduction disorder, unspecified", "opacity": 0.29761018231511116, "shape": "dot", "size": 10, "type": "symptom"}, {"color": "#98fb98", "id": "Heart failure, unspecified", "label": "Heart failure, unspecified", "opacity": 0.269064512103796, "shape": "dot", "size": 10, "type": "symptom"}, {"color": "#98fb98", "id": "Anemia, unspecified", "label": "Anemia, unspecified", "opacity": 0.23666711524128914, "shape": "dot", "size": 10, "type": "symptom"}, {"color": "#98fb98", "id": "Generalized pain", "label": "Generalized pain", "opacity": 0.3131905570626259, "shape": "dot", "size": 10, "type": "symptom"}, {"color": "#98fb98", "id": "Aortic valve disorders", "label": "Aortic valve disorders", "opacity": 0.34145116806030273, "shape": "dot", "size": 10, "type": "symptom"}, {"color": "#98fb98", "id": "Portal hypertension", "label": "Portal hypertension", "opacity": 0.23520531132817268, "shape": "dot", "size": 10, "type": "symptom"}, {"color": "#cd853f", "id": "Cardiac complications, not elsewhere classified", "label": "Cardiac complications, not elsewhere classified", "opacity": 0.2846589684486389, "shape": "dot", "size": 10, "type": "diagnosis"}, {"color": "#cd853f", "id": "Diseases of tricuspid valve", "label": "Diseases of tricuspid valve", "opacity": 0.33642858266830444, "shape": "dot", "size": 10, "type": "diagnosis"}, {"color": "#cd853f", "id": "Atrial flutter", "label": "Atrial flutter", "opacity": 0.3480660915374756, "shape": "dot", "size": 10, "type": "diagnosis"}, {"color": "#cd853f", "id": "Rheumatic heart failure (congestive)", "label": "Rheumatic heart failure (congestive)", "opacity": 0.42175475507974625, "shape": "dot", "size": 10, "type": "diagnosis"}, {"color": "#cd853f", "id": "Acute posthemorrhagic anemia", "label": "Acute posthemorrhagic anemia", "opacity": 0.32012488692998886, "shape": "dot", "size": 10, "type": "diagnosis"}, {"color": "#da70d6", "id": "Extracorporeal circulation auxiliary to open heart surgery", "label": "Extracorporeal circulation auxiliary to open heart surgery", "opacity": 0.5365786328911781, "shape": "dot", "size": 10, "type": "procedure"}, {"color": "#da70d6", "id": "Transfusion of other serum", "label": "Transfusion of other serum", "opacity": 0.47056324779987335, "shape": "dot", "size": 10, "type": "procedure"}, {"color": "#da70d6", "id": "Open and other replacement of mitral valve", "label": "Open and other replacement of mitral valve", "opacity": 0.9560432285070419, "shape": "dot", "size": 10, "type": "procedure"}, {"color": "#da70d6", "id": "Annuloplasty", "label": "Annuloplasty", "opacity": 0.3526274859905243, "shape": "dot", "size": 10, "type": "procedure"}, {"color": "#da70d6", "id": "Other endoscopy of small intestine", "label": "Other endoscopy of small intestine", "opacity": 0.51371019333601, "shape": "dot", "size": 10, "type": "procedure"}, {"color": "#da70d6", "id": "Other electric countershock of heart", "label": "Other electric countershock of heart", "opacity": 0.447126105427742, "shape": "dot", "size": 10, "type": "procedure"}, {"color": "#87ceeb", "id": "HMG CoA reductase inhibitors, plain lipid modifying drugs", "label": "HMG CoA reductase inhibitors, plain lipid modifying drugs", "opacity": 4.706129431724548, "shape": "dot", "size": 10, "type": "medication"}]);
edges = new vis.DataSet([{"color": "#20b2aa", "from": "patient_0", "to": "visit_0", "type": ["patient", "visit"], "width": 1}, {"color": "#98fb98", "from": "visit_0", "to": "Unspecified problem with special functions", "type": ["visit", "symptom"], "width": 1}, {"color": "#cd853f", "from": "visit_0", "to": "Systemic lupus erythematosus", "type": ["visit", "diagnosis"], "width": 1}, {"color": "#98fb98", "from": "visit_0", "to": "Atresia and stenosis of aorta", "type": ["visit", "symptom"], "width": 1}, {"color": "#98fb98", "from": "visit_0", "to": "Coarctation of aorta (preductal) (postductal)", "type": ["visit", "symptom"], "width": 1}, {"color": "#cd853f", "from": "visit_0", "to": "Atrioventricular block, complete", "type": ["visit", "diagnosis"], "width": 1}, {"color": "#98fb98", "from": "visit_0", "to": "Conduction disorder, unspecified", "type": ["visit", "symptom"], "width": 1}, {"color": "#98fb98", "from": "visit_0", "to": "Heart failure, unspecified", "type": ["visit", "symptom"], "width": 1}, {"color": "#98fb98", "from": "visit_0", "to": "Anemia, unspecified", "type": ["visit", "symptom"], "width": 1}, {"color": "#98fb98", "from": "visit_0", "to": "Generalized pain", "type": ["visit", "symptom"], "width": 1}, {"color": "#98fb98", "from": "visit_0", "to": "Aortic valve disorders", "type": ["visit", "symptom"], "width": 1}, {"color": "#98fb98", "from": "visit_0", "to": "Portal hypertension", "type": ["visit", "symptom"], "width": 1}, {"color": "#cd853f", "from": "visit_0", "to": "Cardiac complications, not elsewhere classified", "type": ["visit", "diagnosis"], "width": 1}, {"color": "#cd853f", "from": "visit_0", "to": "Diseases of tricuspid valve", "type": ["visit", "diagnosis"], "width": 1}, {"color": "#cd853f", "from": "visit_0", "to": "Atrial flutter", "type": ["visit", "diagnosis"], "width": 1}, {"color": "#cd853f", "from": "visit_0", "to": "Rheumatic heart failure (congestive)", "type": ["visit", "diagnosis"], "width": 1}, {"color": "#cd853f", "from": "visit_0", "to": "Acute posthemorrhagic anemia", "type": ["visit", "diagnosis"], "width": 1}, {"color": "#da70d6", "from": "visit_0", "to": "Extracorporeal circulation auxiliary to open heart surgery", "type": ["visit", "procedure"], "width": 1}, {"color": "#da70d6", "from": "visit_0", "to": "Transfusion of other serum", "type": ["visit", "procedure"], "width": 1}, {"color": "#da70d6", "from": "visit_0", "to": "Open and other replacement of mitral valve", "type": ["visit", "procedure"], "width": 1}, {"color": "#da70d6", "from": "visit_0", "to": "Annuloplasty", "type": ["visit", "procedure"], "width": 1}, {"color": "#da70d6", "from": "visit_0", "to": "Other endoscopy of small intestine", "type": ["visit", "procedure"], "width": 1}, {"color": "#da70d6", "from": "visit_0", "to": "Other electric countershock of heart", "type": ["visit", "procedure"], "width": 1}, {"color": "#87ceeb", "from": "visit_0", "to": "HMG CoA reductase inhibitors, plain lipid modifying drugs", "type": ["visit", "medication"], "width": 1}]);
nodeColors = {};
allNodes = nodes.get({ returnType: "Object" });
for (nodeId in allNodes) {
nodeColors[nodeId] = allNodes[nodeId].color;
}
allEdges = edges.get({ returnType: "Object" });
// adding nodes and edges to the graph
data = {nodes: nodes, edges: edges};
var options = {"layout": {"randomSeed": 5}, "interaction": {"hover": true, "navigationButtons": true}};
network = new vis.Network(container, data, options);
return network;
}
drawGraph();
</script>
</body>
</html> |