-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidea_cloud.html
More file actions
244 lines (216 loc) · 7.79 KB
/
idea_cloud.html
File metadata and controls
244 lines (216 loc) · 7.79 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
<!DOCTYPE html>
<html>
<head>
<title>Mindmap</title>
<link rel="icon" type="image/x-icon" href="/Mindmap.png">
<meta charset="utf-8"> <script type="text/javascript" src="https://unpkg.com/vis-network/dist/vis-network.min.js"></script>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
}
#mynetwork {
position: absolute;
top: 0;
left: 0;
width: 70%; /* Initial width for the graph area */
height: 100vh;
transition: width 0.3s, left 0.3s;
z-index: 1;
}
#sidebar {
position: absolute;
top: 0;
left: 70%;
width: 30%;
height: 100vh;
padding: 10px;
box-sizing: border-box;
overflow-y: auto;
border-left: 1px solid #ccc;
background: #f9f9f9;
transition: width 0.3s, left 0.3s, padding-left 0.3s;
z-index: 2;
}
#sidebar.fullscreen {
left: 0;
width: 100%;
padding-left: 30px; /* Push content to the right to make space for the button */
}
#mynetwork.fullscreen {
left: -70%;
width: 70%;
}
#toggle-button {
position: absolute;
top: 0;
left: calc(70% - 20px);
width: 20px;
height: 100vh;
background: #ccc;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
writing-mode: vertical-rl;
text-orientation: upright;
font-size: 12px;
z-index: 3;
border-right: 1px solid #999;
transition: left 0.3s;
}
#toggle-button.fullscreen {
left: 0;
}
/* These styles are no longer directly used for sidebar content but kept for reference
if you decide to revert to direct content injection. */
#sidebar img {
width: 100%;
max-height: 150px;
object-fit: contain;
margin: 10px 0;
}
#sidebar h2 {
font-size: 1rem;
margin-top: 0;
}
#sidebar p {
font-size: 0.9rem;
}
</style>
</head>
<body>
<div id="mynetwork"></div>
<div id="toggle-button" onclick="toggleSidebar()">▶</div>
<div id="sidebar">
<h2>Click a node</h2>
<p>Details will appear here.</p>
</div>
<script type="text/javascript">
// Global variable for vis.js network instance
var network;
var nodeDataLookup = {}; // This will store the sidebar_lookup data
// Function to update sidebar content
function updateSidebar(nodeId) {
var sidebar = document.getElementById("sidebar");
var data = nodeDataLookup[nodeId];
if (data && data.html_file) {
sidebar.innerHTML = '<h2>Loading...</h2><p>Please wait.</p>';
fetch(data.html_file)
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.text();
})
.then(htmlContent => {
sidebar.innerHTML = htmlContent; // Inject the fetched HTML
})
.catch(error => {
console.error('Error loading HTML file:', error);
sidebar.innerHTML = `<h2>Error</h2><p>Could not load details for ${nodeId}.</p><p>${error.message}</p>`;
});
} else {
sidebar.innerHTML = '<h2>No details available</h2><p>Click a node with associated data.</p>';
}
}
// Function to toggle sidebar
function toggleSidebar() {
const sidebar = document.getElementById("sidebar");
const networkDiv = document.getElementById("mynetwork");
const button = document.getElementById("toggle-button");
const isFullscreen = sidebar.classList.toggle("fullscreen");
networkDiv.classList.toggle("fullscreen");
button.classList.toggle("fullscreen");
button.innerText = isFullscreen ? "◀" : "▶";
// Give CSS transition time to complete, then resize network
setTimeout(function() {
if (typeof network !== "undefined") {
network.resize();
if (!isFullscreen) {
network.fit(); // Fit graph to view when exiting fullscreen
}
}
}, 300);
}
// --- NEW JAVASCRIPT FOR DYNAMIC GRAPH CREATION ---
document.addEventListener("DOMContentLoaded", function() {
var container = document.getElementById('mynetwork');
// Fetch the graph data from the JSON file
fetch('node_data/graph_data.json')
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(data => {
// Store sidebar lookup data
nodeDataLookup = data.sidebar_lookup;
// Create nodes and edges DataSets for vis.js
var nodes = new vis.DataSet(data.nodes);
var edges = new vis.DataSet(data.edges);
// Provide the data to the vis.Network
var visData = {
nodes: nodes,
edges: edges
};
// Default options for the network
var options = {
nodes: {
shape: 'dot',
font: {
size: 15
},
shadow:true
},
edges: {
width: 2,
shadow:true
},
physics: {
enabled: true,
barnesHut: {
gravitationalConstant: -2000,
centralGravity: 0.3,
springLength: 95,
springConstant: 0.04,
damping: 0.09,
avoidOverlap: 0
},
solver: 'barnesHut',
stabilization: { iterations: 2500 } // Helps stabilize graph on load
},
interaction: {
hover: true,
navigationButtons: true, // Add zoom in/out, fit buttons
keyboard: true // Enable keyboard navigation
}
};
// Initialize the network
network = new vis.Network(container, visData, options);
// Attach click event listener to the dynamically created network
network.on("click", function(params) {
if (params.nodes.length > 0) {
updateSidebar(params.nodes[0]);
}
});
// Optional: Fit the network to view after it's loaded and stabilized
network.once('stabilizationIterationsDone', function() {
network.fit();
});
})
.catch(error => {
console.error('Error fetching graph data:', error);
document.getElementById('mynetwork').innerHTML = `
<div style="padding: 20px; color: red;">
<h2>Error Loading Graph</h2>
<p>Could not load graph data. Please ensure 'node_data/graph_data.json' exists and the server is running correctly.</p>
<p>Error: ${error.message}</p>
</div>
`;
});
});
</script>
</body>
</html>