Skip to content

Commit

Permalink
add R graph and library
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvannuenen committed Oct 17, 2023
1 parent 3c2c5ab commit 1b902dd
Show file tree
Hide file tree
Showing 7 changed files with 817 additions and 84 deletions.
27 changes: 14 additions & 13 deletions R.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
<h5 class="display-5">
Click below to see which D-Lab workshop is best for you!
</h5>
<p>
<!-- Will be always rendered as plaintext, doesn't use markdown syntax -->

<a href="https://dlab.berkeley.edu/training/upcoming-workshops"><button type="button" class="btn btn-info">Book a workshop!</button></a>



Expand Down Expand Up @@ -114,14 +114,14 @@ <h4 class="card-title">R Fundamentals</h4>
<a
class="btn btn-primary"
tabindex="0"
href="https://dlab.datahub.berkeley.edu/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2Fdlab-berkeley%2FR-Fundamentals-Pilot&urlpath=rstudio%2F&branch=main">
href="https://dlab.datahub.berkeley.edu/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2Fdlab-berkeley%2FR-Fundamentals&urlpath=rstudio%2F&branch=main">
<i class="fas fa-database"></i> Datahub
</a>

<a
class="btn btn-primary"
tabindex="0"
href="https://mybinder.org/v2/gh/dlab-berkeley/R-Fundamentals-Pilot/HEAD?urlpath=rstudio">
href="https://mybinder.org/v2/gh/dlab-berkeley/R-Fundamentals/HEAD?urlpath=rstudio">
<i class="fas fa-book"></i> Binder
</a>
</div>
Expand Down Expand Up @@ -168,7 +168,7 @@ <h4 class="card-title">R Data Wrangling and Manipulation</h4>
<a
class="btn btn-primary"
tabindex="0"
href="https://mybinder.org/XXX">
href="https://mybinder.org/v2/gh/dlab-berkeley/R-Fundamentals-Pilot/HEAD?urlpath=rstudio">
<i class="fas fa-book"></i> Binder
</a>
</div>
Expand Down Expand Up @@ -208,14 +208,14 @@ <h4 class="card-title">R Data Visualization</h4>
<a
class="btn btn-primary"
tabindex="0"
href="http://datahub.berkeley.edu/XXX">
href="http://dlab.datahub.berkeley.edu/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2Fdlab-berkeley%2FR-Data-Visualization&urlpath=rstudio%2F">
<i class="fas fa-database"></i> Datahub
</a>

<a
class="btn btn-primary"
tabindex="0"
href="https://mybinder.org/XXX">
href="ps://mybinder.org/v2/gh/dlab-berkeley/R-Data-Visualization/HEAD?urlpath=rstudio">
<i class="fas fa-book"></i> Binder
</a>
</div>
Expand All @@ -235,7 +235,7 @@ <h4 class="card-title">R Data Visualization</h4>
<!-- Title Column -->
<div class="d-flex justify-content-center flex-column col-md-3">
<h4 class="card-title">R Machine Learning with tidymodels</h4>
<p class="lead">Using R for ML!</p>
<p class="lead">Using R for ML</p>
</div>
<!-- Paragraph Column -->
<div class="d-flex justify-content-center flex-column col-md-6">
Expand Down Expand Up @@ -337,7 +337,7 @@ <h4 class="card-title">R Deep Learning</h4>
<!-- Title Column -->
<div class="d-flex justify-content-center flex-column col-md-3">
<h4 class="card-title">R Geospatial Fundamentals</h4>
<p class="lead">Working with spatial data</p>
<p class="lead">Working with spatial data in R</p>
</div>
<!-- Paragraph Column -->
<div class="d-flex justify-content-center flex-column col-md-6">
Expand All @@ -360,28 +360,29 @@ <h4 class="card-title">R Geospatial Fundamentals</h4>
<a
class="btn btn-primary"
tabindex="0"
href="http://datahub.berkeley.edu/XXX">
href="http://dlab.datahub.berkeley.edu/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2Fdlab-berkeley%2FR-Geospatial-Fundamentals&urlpath=rstudio%2F">
<i class="fas fa-database"></i> Datahub
</a>

<a
class="btn btn-primary"
tabindex="0"
href="https://mybinder.org/XXX">
href="https://mybinder.org/v2/gh/dlab-berkeley/R-Geospatial-Fundamentals/HEAD?urlpath=rstudio">
<i class="fas fa-book"></i> Binder
</a>
</div>
</div>
</div>
</div>


<a href="R_graph.html"><button type="button" class="btn btn-dark">View as graph</button></a>

</div>


<!-- End Content -->


<a href="https://dlab.berkeley.edu/training/upcoming-workshops"><button type="button" class="btn btn-info">Book a workshop!</button></a>
</div>
</div>

Expand Down
219 changes: 219 additions & 0 deletions R_graph.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,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>
6 changes: 6 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ <h4 class="text-center mb-4">What do you want to learn?</h4>
<a href="other.html" class="btn btn-success mx-1">Other</a>
</div>
</div>
<div class="row justify-content-center mt-4">
<div class="col-auto">
<a href="library.html" class="btn btn-secondary mx-1">View All Workshops</a>
</div>
</div>

</div>
<!-- End Content -->
<!-- Bootstrap JS -->
Expand Down
Loading

0 comments on commit 1b902dd

Please sign in to comment.