-
Notifications
You must be signed in to change notification settings - Fork 1
/
python_graph.html
307 lines (262 loc) · 11.1 KB
/
python_graph.html
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
<!DOCTYPE html>
<html class="w-100 h-100">
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interactive Workshop Flowchart</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.19.0/cytoscape.min.js"></script>
<link rel="stylesheet" href="https://bootswatch.com/4/litera/bootstrap.min.css">
<!-- Fontawesome JS -->
<script defer src="https://use.fontawesome.com/releases/v5.0.10/js/all.js" integrity="sha384-slN8GvtUJGnv6ca26v8EzVaR9DC58QEwsIk9q1QXdCU8Yu8ck/tL/5szYlBbqmS+" crossorigin="anonymous"></script>
<!-- Custom CSS -->
<link rel="stylesheet" href="static/stylesheets/style.css">
<style>
#cy {
width: 100%;
height: 600px;
border: 1px solid #ccc;
}
#prerequisites {
margin-top: 20px;
padding: 10px;
text-align: center;
background-color: #2C3E50;
color: #FFFFFF;
font-family: 'Roboto', sans-serif;
font-size: 15px;
}
h1 {
text-align: center;
margin-bottom: 20px;
font-family: 'Roboto', sans-serif;
}
</style>
</head>
<body class="w-100 h-100">
<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top borderless">
<a
class="navbar-brand"
href="index.html"
>
D-Lab Workshops
</a>
<button class="navbar-toggler borderless" type="button" data-toggle="collapse" data-target="#navbarColor01" aria-controls="navbarColor01" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarColor01">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link active" href="index.html">Home</a>
<li class="nav-item">
<a class="nav-link" href="library.html">Library</a>
</li>
<li class="nav-item">
<a class="nav-link" target="_blank" href="https://dlab.berkeley.edu/">About D-Lab</a>
</li>
</ul>
</div>
</nav>
<!-- End of Navbar -->
<h2 style="text-align: center; padding-top: 70px;">D-Lab Python Workshops</h2>
<div style="display: flex; justify-content: center; align-items: center;">
<div id="cy"></div>
</div>
<div id="prerequisites">Click on a workshop to see its prerequisites.</div>
<div style="text-align: center; padding-top: 20px;">
<a href="python.html"><button type="button" class="btn btn-warning">Return to default view</button></a>
<a href="https://dlab.berkeley.edu/training/upcoming-workshops"><button type="button" class="btn btn-info">Book a workshop!</button></a>
</div>
<script>
const yPositions = {
'Python Fundamentals 1-3': 0,
'Python Data Visualization': 1,
'Python Fundamentals 4-6': 1,
'Python Data Wrangling': 1,
'Python Web APIs': 2,
'Python Web Scraping': 2,
'Python Text Analysis': 3,
'Python Geospatial Fundamentals': 3,
'Python Machine Learning': 3,
'Python Deep Learning': 3
};
// Step 2: Recompute xCounts
let xCounts = {};
for (let workshop in yPositions) {
let y = yPositions[workshop];
if (!(y in xCounts)) {
xCounts[y] = 0;
}
xCounts[y]++;
}
// Step 3: Reset xOffsets
let xOffsets = {};
// Step 4: Recompute xPositions
let xPositions = {};
let spreadMultiplier = 1.5;
for (let workshop in yPositions) {
let y = yPositions[workshop];
if (!(y in xOffsets)) {
xOffsets[y] = -xCounts[y] / 2 * spreadMultiplier;
}
xPositions[workshop] = xOffsets[y];
xOffsets[y] += 1;
}
const elements = [
{ data: { id: 'A', name: 'Python Fundamentals 1-3' }, position: { x: xPositions['Python Fundamentals 1-3'] * 200, y: yPositions['Python Fundamentals 1-3'] * 150 } },
{ data: { id: 'B', name: 'Python Fundamentals 4-6' }, position: { x: xPositions['Python Fundamentals 4-6'] * 200, y: yPositions['Python Fundamentals 4-6'] * 150 } },
{ data: { id: 'C', name: 'Python Data Visualization' }, position: { x: xPositions['Python Data Visualization'] * 200, y: yPositions['Python Data Visualization'] * 150 } },
{ data: { id: 'D', name: 'Python Data Wrangling' }, position: { x: xPositions['Python Data Wrangling'] * 100, y: yPositions['Python Data Wrangling'] * 150 } },
{ data: { id: 'E', name: 'Python Web APIs' }, position: { x: xPositions['Python Web APIs'] * 200, y: yPositions['Python Web APIs'] * 150 } },
{ data: { id: 'F', name: 'Python Web Scraping' }, position: { x: xPositions['Python Web Scraping'] * 200, y: yPositions['Python Web Scraping'] * 150 } },
{ data: { id: 'G', name: 'Python Text Analysis' }, position: { x: xPositions['Python Text Analysis'] * 250, y: yPositions['Python Text Analysis'] * 150 } },
{ data: { id: 'H', name: 'Python Geospatial Fundamentals' }, position: { x: xPositions['Python Geospatial Fundamentals'] * 250, y: yPositions['Python Geospatial Fundamentals'] * 150 } },
{ data: { id: 'I', name: 'Python Machine Learning' }, position: { x: xPositions['Python Machine Learning'] * 230, y: yPositions['Python Machine Learning'] * 150 } },
{ data: { id: 'J', name: 'Python Deep Learning' }, position: { x: xPositions['Python Deep Learning'] * 200, y: yPositions['Python Deep Learning'] * 150 } },
// Edges
{ data: { source: 'A', target: 'B' } },
{ data: { source: 'A', target: 'C' } },
{ data: { source: 'A', target: 'D' } },
{ data: { source: 'B', target: 'E' } },
{ data: { source: 'B', target: 'F' } },
{ data: { source: 'D', target: 'G' } },
{ data: { source: 'D', target: 'H' } },
{ data: { source: 'D', target: 'I' } },
{ data: { source: 'I', target: 'J' } },
// New edges to indicate dependencies on Fundamentals 4-6 for nodes G, H, I, J
{ data: { source: 'B', target: 'G' } },
{ data: { source: 'B', target: 'H' } },
{ data: { source: 'B', target: 'I' } },
{ data: { source: 'B', target: 'J' } }
];
const cy = cytoscape({
container: document.getElementById('cy'),
elements: elements,
style: [
{
selector: 'node',
style: {
'background-color': '#3498DB',
'label': 'data(name)',
'text-valign': 'center',
'text-halign': 'center',
'color': '#fff',
'width': '50px',
'height': '50px',
'font-size': '16px',
'text-outline-width': 2,
'text-outline-color': '#2C3E50',
'transition-property': 'background-color, width, height, font-size',
'transition-duration': '0.2s'
}
},
{
selector: 'node:selected',
style: {
'background-color': '#E74C3C'
}
},
{
selector: 'node.highlighted',
style: {
'font-size': '24px' // Change the font size to make it larger
}
},
{
selector: 'node.hover',
style: {
'width': '80px',
'height': '80px',
}
},
{
selector: 'node.clicked',
style: {
'background-color': '#2ECC71'
}
},
{
selector: '.prerequisite',
style: {
'background-color': '#ffcc66'
}
},
{
selector: 'edge',
style: {
'width': 2,
'line-color': '#ccc',
'target-arrow-color': '#ccc',
'target-arrow-shape': 'triangle',
'curve-style': 'bezier'
}
},
{
selector: 'edge.highlighted',
style: {
'line-color': '#ff6666',
'target-arrow-color': '#ff6666',
'width': 3
}
},
{
selector: 'node.highlighted',
style: {
'background-color': '#ff6666'
}
}
],
layout: {
name: 'preset'
},
userPanningEnabled: false, // Disable panning
userZoomingEnabled: false, // Disable zooming
});
cy.nodes().ungrabify();
// Add hover event listeners
cy.on('mouseover', 'node', function(event) {
event.target.addClass('hover');
});
cy.on('mouseout', 'node', function(event) {
event.target.removeClass('hover');
});
function findAllPrerequisites(node, prerequisites) {
let edges = node.connectedEdges(`[target="${node.id()}"]`);
edges.forEach(edge => {
let sourceNode = edge.source();
prerequisites.push(sourceNode.data('name'));
findAllPrerequisites(sourceNode, prerequisites);
});
}
cy.on('tap', 'node', function(evt){
cy.$('.prerequisite').removeClass('prerequisite');
cy.$('edge.highlighted').removeClass('highlighted');
cy.$('node.highlighted').removeClass('highlighted');
cy.$('node.clicked').removeClass('clicked'); // Remove any existing 'clicked' class
evt.target.addClass('clicked'); // Add the 'clicked' class to the clicked node
let prerequisites = [];
findAllPrerequisites(evt.target, prerequisites);
// Reverse the prerequisites list just once here
prerequisites.reverse();
if(prerequisites.length > 0) {
let prerequisiteNames = prerequisites.map(name => `<span class="prerequisite-name">${name}</span>`);
document.getElementById('prerequisites').innerHTML = `Prerequisites for ${evt.target.data('name')}: ${prerequisiteNames.join(', ')}`;
} else {
document.getElementById('prerequisites').textContent = `${evt.target.data('name')} has no prerequisites.`;
}
let startNode = evt.target;
function dfs(node) {
let incomingEdges = node.connectedEdges(`[target="${node.id()}"]`);
incomingEdges.forEach(edge => {
edge.addClass('highlighted');
let sourceNode = edge.source();
sourceNode.addClass('highlighted');
dfs(sourceNode);
});
}
dfs(startNode);
});
</script>
</body>
</html>