-
Notifications
You must be signed in to change notification settings - Fork 1
/
R_graph.html
219 lines (197 loc) · 7.97 KB
/
R_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
<!DOCTYPE html>
<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">
<script defer src="https://use.fontawesome.com/releases/v5.0.10/js/all.js" integrity="sha384-slN8GvtUJGnv6ca26v8EzVaR9DC58QEwsIk9q1QXdCU8Yu8ck/tL/5szYlBbqmS+" crossorigin="anonymous"></script>
<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;
}
h2 {
text-align: center;
margin-bottom: 20px;
font-family: 'Roboto', sans-serif;
}
</style>
</head>
<body class="w-100 h-100">
<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>
<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>
<h2 style="text-align: center; padding-top: 70px;">D-Lab R 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="r.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 elements = [
{ data: { id: 'A', name: 'R Fundamentals' }, position: { x: 400, y: 0 } },
{ data: { id: 'B', name: 'R Data Wrangling and Manipulation' }, position: { x: 400, y: 200 } },
{ data: { id: 'C', name: 'R Machine Learning' }, position: { x: 200, y: 400 } },
{ data: { id: 'D', name: 'R Deep Learning' }, position: { x: 400, y: 400 } },
{ data: { id: 'E', name: 'R Geospatial Fundamentals' }, position: { x: 600, y: 400 } },
{ data: { source: 'A', target: 'B' } },
{ data: { source: 'B', target: 'C' } },
{ data: { source: 'B', target: 'D' } },
{ data: { source: 'B', target: 'E' } }
];
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>