-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcycle_graph_example.html
More file actions
310 lines (278 loc) · 13.2 KB
/
cycle_graph_example.html
File metadata and controls
310 lines (278 loc) · 13.2 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interactive 5-Cycle Graph</title>
<script type="text/javascript" src="https://unpkg.com/vis-network/standalone/umd/vis-network.min.js"></script>
<link href="https://unpkg.com/vis-network/styles/vis-network.min.css" rel="stylesheet" type="text/css" />
<style type="text/css">
body, html {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
background-color: #f4f6f8; /* Light background for the page */
display: flex;
flex-direction: column;
overflow: hidden; /* Prevent body scrollbars */
}
.config-panel-wrapper {
width: 100%;
background-color: #ffffff;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
z-index: 10; /* Ensure it's above the graph if any overlap issues */
flex-shrink: 0; /* Prevent panel from shrinking */
}
.config-panel-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 15px;
border-bottom: 1px solid #e0e0e0;
cursor: pointer;
background-color: #f9f9f9;
}
.config-panel-header h3 {
margin: 0;
font-size: 16px;
font-weight: 600;
color: #333;
}
.config-toggle-btn {
background: none;
border: none;
font-size: 18px;
cursor: pointer;
padding: 5px;
color: #555;
}
.config-toggle-btn::after {
content: '\25BC'; /* Down arrow ▼ */
display: inline-block;
transition: transform 0.2s ease-in-out;
}
.collapsed .config-toggle-btn::after {
transform: rotate(-90deg); /* Right arrow for collapsed state */
}
#config-container-content-ee568209 {
max-height: 40vh; /* Default expanded max height */
overflow-y: auto;
padding: 15px;
box-sizing: border-box;
background-color: #ffffff;
transition: max-height 0.3s ease-in-out, padding 0.3s ease-in-out;
}
.collapsed #config-container-content-ee568209 {
max-height: 0;
padding-top: 0;
padding-bottom: 0;
overflow: hidden;
border-bottom: none; /* Hide border when collapsed */
}
#mynetwork-ee568209 {
width: 100%;
flex-grow: 1; /* Graph takes remaining vertical space */
min-height: 0; /* Important for flex children to shrink */
background-color: #ffffff; /* Graph background */
}
.filter-panel {
display: flex;
align-items: center;
gap: 10px;
padding: 8px 15px;
background-color: #e9ecef;
border-bottom: 1px solid #dee2e6;
flex-shrink: 0;
}
.filter-panel label {
font-size: 13px;
font-weight: 500;
color: #495057;
}
.filter-panel input[type=text] {
flex-grow: 1;
padding: 6px 8px;
border: 1px solid #ced4da;
border-radius: 4px;
font-size: 13px;
}
.filter-panel button {
padding: 6px 12px;
font-size: 13px;
border-radius: 4px;
border: 1px solid #6c757d;
background-color: #6c757d;
color: white;
cursor: pointer;
}
.filter-panel button:hover {
background-color: #5a6268;
}
.info-panel {
padding: 8px 15px;
background-color: #f8f9fa;
font-size: 13px;
color: #495057;
text-align: center;
border-bottom: 1px solid #dee2e6;
flex-shrink: 0;
}
/* Basic styling for vis.js config elements to blend better */
div.vis-configuration-wrapper { padding: 0; }
div.vis-configuration-wrapper table { width: 100%; }
div.vis-configuration-wrapper table tr td:first-child { width: 30%; font-size: 13px; }
div.vis-configuration-wrapper input[type=text],
div.vis-configuration-wrapper select { width: 95%; padding: 6px; margin: 2px 0; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; font-size: 13px; }
div.vis-configuration-wrapper input[type=range] { width: 60%; }
div.vis-configuration-wrapper .vis-label { font-size: 13px; color: #333; }
</style>
</head>
<body>
<div class="config-panel-wrapper" id="config-panel-wrapper-ee568209">
<div class="config-panel-header" id="config-panel-header-ee568209" role="button" tabindex="0" aria-expanded="true" aria-controls="config-container-content-ee568209">
<h3>Configuration</h3>
<button class="config-toggle-btn" id="config-toggle-btn-ee568209" aria-label="Toggle configuration panel"></button>
</div>
<div id="config-container-content-ee568209">
<!-- Vis.js configuration UI will be injected here -->
</div>
</div>
<div class="filter-panel">
<label for="search-input-ee568209">Filter nodes (regex):</label>
<input type="text" id="search-input-ee568209" placeholder="e.g., ^IMP_ or ELEC$">
<button id="clear-btn-ee568209">Clear</button>
</div>
<div class="info-panel">
<strong>Tip:</strong> Click a node to isolate it and its neighbors. Click the background to reset the view.
</div>
<div id="mynetwork-ee568209"></div>
<script type="text/javascript">
(function() {
// These arrays are the master dataset
var allNodesArray = [{"id": "0", "label": "N1", "title": "Tooltip for Node N1", "group": 0, "color": "skyblue", "size": 25}, {"id": "1", "label": "N2", "title": "Tooltip for Node N2", "group": 1}, {"id": "2", "label": "N3", "title": "Tooltip for Node N3", "group": 0}, {"id": "3", "label": "N4", "title": "Tooltip for Node N4", "group": 1}, {"id": "4", "label": "N5", "title": "Tooltip for Node N5", "group": 0}];
var allEdgesArray = [{"from": "0", "to": "1", "label": "Link 0-1", "color": "green", "width": 3}, {"from": "0", "to": "4"}, {"from": "1", "to": "2"}, {"from": "2", "to": "3"}, {"from": "3", "to": "4"}];
var optionsObject = {"autoResize": true, "nodes": {"shape": "dot", "size": 16, "font": {"size": 14, "color": "#333"}, "borderWidth": 2}, "edges": {"width": 2, "smooth": {"type": "dynamic", "roundness": 0.5, "enabled": true}, "arrows": {"to": {"enabled": false, "scaleFactor": 1}}}, "physics": {"enabled": true, "barnesHut": {"gravitationalConstant": -8000, "springConstant": 0.04, "springLength": 150, "damping": 0.09, "avoidOverlap": 0.1}, "solver": "barnesHut", "stabilization": {"iterations": 1000, "fit": true}}, "interaction": {"hover": true, "dragNodes": true, "dragView": true, "zoomView": true, "tooltipDelay": 200, "navigationButtons": true, "keyboard": {"enabled": true, "bindToWindow": false}}, "layout": {"randomSeed": 12345, "improvedLayout": true}, "groups": {"0": {"shape": "dot", "color": {"background": "lightcoral", "border": "red"}}, "1": {"shape": "square", "color": {"background": "lightgreen", "border": "green"}}}};
// Get DOM elements
var configWrapper = document.getElementById('config-panel-wrapper-ee568209');
var configHeader = document.getElementById('config-panel-header-ee568209');
var configContent = document.getElementById('config-container-content-ee568209');
var toggleButton = document.getElementById('config-toggle-btn-ee568209');
var searchInput = document.getElementById('search-input-ee568209');
var clearButton = document.getElementById('clear-btn-ee568209');
// Handle config panel toggle
if (optionsObject.configure && optionsObject.configure.enabled) {
if (!optionsObject.configure.container) {
optionsObject.configure.container = configContent;
}
configHeader.addEventListener('click', function() {
configWrapper.classList.toggle('collapsed');
var isExpanded = !configWrapper.classList.contains('collapsed');
configHeader.setAttribute('aria-expanded', isExpanded);
toggleButton.setAttribute('aria-expanded', isExpanded);
});
configHeader.addEventListener('keydown', function(event) {
if (event.key === 'Enter' || event.key === ' ') {
configWrapper.classList.toggle('collapsed');
var isExpanded = !configWrapper.classList.contains('collapsed');
configHeader.setAttribute('aria-expanded', isExpanded);
toggleButton.setAttribute('aria-expanded', isExpanded);
event.preventDefault();
}
});
} else {
if (configWrapper) { configWrapper.style.display = 'none'; }
}
// These DataSets are the "active" data being displayed
var nodes = new vis.DataSet(allNodesArray);
var edges = new vis.DataSet(allEdgesArray);
var graphContainer = document.getElementById('mynetwork-ee568209');
var data = { nodes: nodes, edges: edges };
var network = new vis.Network(graphContainer, data, optionsObject);
// Function to restore the full graph view
function resetView() {
searchInput.value = ""; // Clear search input
nodes.clear();
edges.clear();
nodes.add(allNodesArray);
edges.add(allEdgesArray);
network.fit();
}
// Function to filter graph based on search query
function filterBySearch(query) {
if (!query) {
resetView();
return;
}
var regex;
try {
regex = new RegExp(query, 'i'); // Case-insensitive regex
} catch (e) {
console.error("Invalid Regex:", e);
return; // Don't filter if regex is invalid
}
var matchingNodeIds = new Set();
allNodesArray.forEach(function(node) {
var textToSearch = node.label || node.id;
if (regex.test(textToSearch)) {
matchingNodeIds.add(node.id);
}
});
var filteredNodes = allNodesArray.filter(function(node) {
return matchingNodeIds.has(node.id);
});
var filteredEdges = allEdgesArray.filter(function(edge) {
return matchingNodeIds.has(edge.from) && matchingNodeIds.has(edge.to);
});
nodes.clear();
edges.clear();
nodes.add(filteredNodes);
edges.add(filteredEdges);
network.fit();
}
// Function to isolate a node and its neighbors
function showNeighborhood(nodeId) {
searchInput.value = ""; // Clear search when isolating
var nodesToShow = new Set([nodeId]);
var edgesToShow = [];
allEdgesArray.forEach(function(edge) {
if (edge.from === nodeId) {
nodesToShow.add(edge.to);
edgesToShow.push(edge);
} else if (edge.to === nodeId) {
nodesToShow.add(edge.from);
edgesToShow.push(edge);
}
});
var filteredNodes = allNodesArray.filter(function(node) {
return nodesToShow.has(node.id);
});
nodes.clear();
edges.clear();
nodes.add(filteredNodes);
edges.add(edgesToShow);
network.fit();
}
// --- Event Listeners ---
// Filter as user types in the search box
searchInput.addEventListener('input', function() {
filterBySearch(this.value);
});
// Clear button resets the view
clearButton.addEventListener('click', resetView);
// Handle clicks on the network
network.on("click", function (params) {
if (params.nodes.length > 0) {
// A node was clicked, show its neighborhood
var clickedNodeId = params.nodes[0];
showNeighborhood(clickedNodeId);
} else {
// The background was clicked, reset everything
resetView();
}
});
})();
</script>
</body>
</html>